Skip to content

Commit

Permalink
Merge pull request #28 from jenojp/develop
Browse files Browse the repository at this point in the history
prep for 0.1.9 release
  • Loading branch information
jenojp authored Nov 18, 2020
2 parents 5122767 + 692cddb commit 02fae3f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
12 changes: 6 additions & 6 deletions negspacy/negation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -170,7 +170,7 @@ def add_patterns(
def get_patterns(self):
"""
returns phrase patterns used for various negation dictionaries
Returns
-------
patterns: dict
Expand All @@ -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
Expand Down Expand Up @@ -282,7 +282,7 @@ def negex(self, doc):
"""
Negates entities of interest
Parameters
Parameters
----------
doc: object
spaCy Doc object
Expand Down
18 changes: 13 additions & 5 deletions negspacy/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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())
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 02fae3f

Please sign in to comment.