diff --git a/negspacy/negation.py b/negspacy/negation.py index 74782fc..1b2bcd1 100644 --- a/negspacy/negation.py +++ b/negspacy/negation.py @@ -7,9 +7,9 @@ class Negex: """ - A spaCy pipeline component which identifies negated tokens in text. + A spaCy pipeline component which identifies negated tokens in text. - Based on: NegEx - A Simple Algorithm for Identifying Negated Findings and Diseasesin Discharge Summaries + Based on: NegEx - A Simple Algorithm for Identifying Negated Findings and Diseasesin Discharge Summaries Chapman, Bridewell, Hanbury, Cooper, Buchanan Parameters @@ -31,7 +31,7 @@ class Negex: termination: list phrases that "terminate" a sentence for processing purposes such as "but". If empty, defaults are used - """ + """ def __init__( self, @@ -170,7 +170,7 @@ def add_patterns( def get_patterns(self): """ returns phrase patterns used for various negation dictionaries - + Returns ------- patterns: dict @@ -191,7 +191,7 @@ def process_negations(self, doc): """ Find negations in doc and clean candidate negations to remove pseudo negations - Parameters + Parameters ---------- doc: object spaCy Doc object @@ -282,7 +282,7 @@ def negex(self, doc): """ Negates entities of interest - Parameters + Parameters ---------- doc: object spaCy Doc object diff --git a/negspacy/test.py b/negspacy/test.py index f595bed..3cbd506 100644 --- a/negspacy/test.py +++ b/negspacy/test.py @@ -196,7 +196,7 @@ def test_add_remove_patterns(): ) negex.remove_patterns(termination="but") negex.remove_patterns( - preceding_negations="wow a negation", following_negations=["extra negation"] + preceding_negations="wow a negation", following_negations="extra negation" ) patterns_after = negex.get_patterns() assert ( @@ -213,11 +213,10 @@ def test_add_remove_patterns(): ) assert len(patterns_after["pseudo_patterns"]) == len(patterns["pseudo_patterns"]) + def test_issue_14(): nlp = spacy.load("en_core_sci_sm") - negex = Negex( - nlp, language="en_clinical", chunk_prefix=["no", "cancer free"] - ) + negex = Negex(nlp, language="en_clinical", chunk_prefix=["no", "cancer free"]) negex.remove_patterns(following_negations="free") nlp.add_pipe(negex, last=True) print(negex.get_patterns()) @@ -227,7 +226,16 @@ def test_issue_14(): for i, e in enumerate(doc.ents): print(e.text, e._.negex) assert e._.negex == expected[i] - + + nlp.remove_pipe("Negex") + negex = Negex(nlp, language="en_clinical", chunk_prefix=["no", "free"]) + nlp.add_pipe(negex, last=True) + doc = nlp("The patient has a cancer free diagnosis") + expected = [False, False] + for i, e in enumerate(doc.ents): + print(e.text, e._.negex) + assert e._.negex == expected[i] + if __name__ == "__main__": test() diff --git a/setup.py b/setup.py index c382e09..c96fb77 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name = 'negspacy', - version = 'v0.1.8', + version = 'v0.1.9', url = 'https://github.com/jenojp/negspacy', author = 'Jeno Pizarro', author_email = 'jenopizzaro@gmail.com',