Skip to content

Commit

Permalink
Merge pull request #26 from jenojp/develop
Browse files Browse the repository at this point in the history
Issue #14 (compound chunk prefixes) and remove patterns bug fix
  • Loading branch information
jenojp committed Nov 17, 2020
2 parents 96198d9 + 71ea327 commit 5122767
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ steps:
pip install -r requirements.txt
python -m spacy download en_core_web_sm
pip install scispacy
pip install https://s3-us-west-2.amazonaws.com/ai2-s2-scispacy/releases/v0.2.4/en_core_sci_sm-0.2.4.tar.gz
pip install https://s3-us-west-2.amazonaws.com/ai2-s2-scispacy/releases/v0.3.0/en_core_sci_sm-0.3.0.tar.gz
displayName: 'Install dependencies'

- script: |
Expand Down
4 changes: 2 additions & 2 deletions negspacy/negation.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def remove_patterns(
for p in following_negations:
self.following_negations.remove(p)
else:
self.following_negations.extend(following_negations)
self.following_negations.remove(following_negations)
if termination:
if isinstance(termination, list):
for p in termination:
Expand Down Expand Up @@ -306,7 +306,7 @@ def negex(self, doc):
continue
if self.chunk_prefix:
if any(
c.text.lower() == doc[e.start].text.lower()
e.text.lower().startswith(c.text.lower())
for c in self.chunk_prefix
):
e._.set(self.extension_name, True)
Expand Down
20 changes: 18 additions & 2 deletions negspacy/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def build_med_docs():
(
"Patient denies cardiovascular disease but has headaches. No history of smoking. Alcoholism unlikely. Smoking not ruled out.",
[
("Patient denies", False),
("Patient", False),
("cardiovascular disease", True),
("headaches", False),
("No history", True),
Expand All @@ -63,7 +63,7 @@ def build_med_docs():
docs.append(
(
"Alcoholism was not the cause of liver disease.",
[("Alcoholism", True), ("cause", False), ("liver disease", False)],
[("Alcoholism", True), ("liver disease", False)],
)
)

Expand Down Expand Up @@ -213,6 +213,21 @@ 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.remove_patterns(following_negations="free")
nlp.add_pipe(negex, last=True)
print(negex.get_patterns())

doc = nlp("The patient has a cancer free diagnosis")
expected = [False, True]
for i, e in enumerate(doc.ents):
print(e.text, e._.negex)
assert e._.negex == expected[i]


if __name__ == "__main__":
test()
Expand All @@ -222,3 +237,4 @@ def test_add_remove_patterns():
test_get_patterns()
test_issue7()
test_add_remove_patterns()
test_issue_14()

0 comments on commit 5122767

Please sign in to comment.