Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Python library for Natural Language Preprocessing (NLPre)

NotificationsYou must be signed in to change notification settings

NIHOPA/NLPre

Repository files navigation

Build StatuscodecovPyPIPyVersion

Major version update! NLPre 2.0.0

  • Backend NLP enginepattern.en has been replaced withspaCy v 2.1.0. This is a major fix for some of the problems withpattern.en including poor lemmatization. (eg. cytokine -> cytocow)
  • Support for python 2 has been dropped
  • Support for custom dictionaries inreplace_from_dictionary
  • Option for suffix to be used instead of prefix inreplace_from_dictionary
  • URL replacement can now remove emails
  • token_replacement can remove symbols

NLPre is a text (pre)-processing library that helps smooth some of the inconsistencies found in real-world data.Correcting for issues like random capitalization patterns, strange hyphenations, and abbreviations are essential parts of wrangling textual data but are often left to the user.

While this library was developed by theOffice of Portfolio Analysis at theNational Institutes of Health to correct for historical artifacts in our data, we envision this module to encompass a broad spectrum of problems encountered in the preprocessing step of natural language processing.

NLPre is part of theword2vec-pipeline.

Installation

For the latest release, use

pip install nlpre

If installing the python 3 version on Ubuntu, you may need to use

sudo apt-get install libmysqlclient-dev

Example

fromnlpreimporttitlecaps,dedash,identify_parenthetical_phrasesfromnlpreimportreplace_acronyms,replace_from_dictionarytext= ("LYMPHOMA SURVIVORS IN KOREA. Describe the correlates of unmet needs ""among non-Hodgkin lymphoma (NHL) surv- ivors in Korea and identify ""NHL patients with an abnormal white blood cell count.")ABBR=identify_parenthetical_phrases()(text)parsers= [dedash(),titlecaps(),replace_acronyms(ABBR),replace_from_dictionary(prefix="MeSH_")]forfinparsers:text=f(text)print(text)''' lymphoma survivors in korea .    Describe the correlates of unmet needs among non_Hodgkin_lymphoma    ( non_Hodgkin_lymphoma ) survivors in Korea and identify non_Hodgkin_lymphoma    patients with an abnormal MeSH_Leukocyte_Count . '''

A longer example highlighting a "pipeline" of changes can be foundhere.

To see a detailed log of the changes made, set the level tologging.INFO orlogging.DEBUG,

importnlpre,loggingnlpre.logger.setLevel(logging.INFO)

What's included?

FunctionDescription
replace_from_dictionaryReplace phrases from an input dictionary. The replacement is done without regard to case, but punctuation is handled correctly. TheMeSH (Medical Subject Headings) dictionary is built-in.
(11-Dimethylethyl)-4-methoxyphenol is great
MeSH_Butylated_Hydroxyanisole is great
replace_acronymsReplaces acronyms and abbreviations found in a document with their corresponding phrase. If an acronym is explicitly identified with a phrase in a document, then all instances of that acronym in the document will be replaced with the given phrase. If there is no explicit indication what the phrase is within the document, then the most common phrase associated with the acronym in the given counter is used.
The EPA protects trees
The Environmental_Protection_Agency protects trees
identify_parenthetical_phrasesIdentify abbreviations of phrases found in a parenthesis. Returns a counter and can be passed directly intoreplace_acronyms.
'Environmental Protection Agency (EPA)
Counter((('Environmental', 'Protection', 'Agency'), 'EPA'):1)
separated_parenthesisSeparates parenthetical content into new sentences. This is useful when creating word embeddings, as associations should only be made within the same sentence. Terminal punctuation of a period is added to parenthetical sentences if necessary.
Hello (it is a beautiful day) world.
Hello world. it is a beautiful day .
pos_tokenizerRemoves all words that are of a designated part-of-speech (POS) from a document. For example, when processing medical text, it is useful to remove all words that are not nouns or adjectives. POS detection is provided by thespaCy module.
The boy threw the ball into the yard
boy ball yard
unidecoderConverts Unicode phrases into ASCII equivalent.
α-Helix β-sheet
a-Helix b-sheet
dedashHyphenations are sometimes erroneously inserted when text is passed through a word-processor. This module attempts to correct the hyphenation pattern by joining words that if they appear in an English word list.
How is the treat- ment going
How is the treatment going
decaps_textWe presume that case is important, but only when it differs from title case. This class normalizes capitalization patterns.
James and Sally had a fMRI
james and sally had a fMRI
titlecapsDocuments sometimes have sentences that are entirely in uppercase (commonly found in titles and abstracts of older documents). This parser identifies sentences where every word is uppercase, and returns the document with these sentences converted to lowercase.
ON THE STRUCTURE OF WATER.
On the structure of water .
token_replacementSimple token replacement.
Observed > 20%
Observed greater-than 20 percent
separate_referenceSeparates and optionally removes references that have been concatenated onto words.
Key feature of interleukin-1 in Drosophila3-5 and elegans(7).
Key feature of interleukin-1 in Drosophila and elegans .
url_replacementRemoves or replaces URLs
The source code is [here](www.github.com/NIHOPA/NLPre/).
The source code is [here](LINK).

Citations and Acknowledgments

Contributors

License

This project is in the public domain within the United States, andcopyright and related rights in the work worldwide are waived throughtheCC0 1.0 Universal public domain dedication.


[8]ページ先頭

©2009-2025 Movatter.jp