Repository: jenojp/negspacy (language: python)

Issue:
Increase spaCy version requirements to v3.1
negspaCy also works with the newest spaCy version 3.1.2.
Increased the requirements from >3.1 to >3.2


Discussion / hints:
Thanks! Awaiting updated model from scispacy for many of our test cases and then will release. https://github.com/allenai/scispacy/tree/upgrade31


Fix patch:
diff --git a/azure-pipelines.yml b/azure-pipelines.yml
index 0c18707..1d94ba6 100644
--- a/azure-pipelines.yml
+++ b/azure-pipelines.yml
@@ -13,22 +13,22 @@ trigger:
 strategy:
   matrix:
     Python36Linux:
-      imageName: 'ubuntu-16.04'
+      imageName: 'ubuntu-18.04'
       python.version: '3.6'
     Python37Linux:
-      imageName: 'ubuntu-16.04'
+      imageName: 'ubuntu-18.04'
       python.version: '3.7'
     Python38Linux:
-      imageName: 'ubuntu-16.04'
+      imageName: 'ubuntu-18.04'
       python.version: '3.8'
     Python36Mac:
-      imageName: 'macos-10.14'
+      imageName: 'macos-10.15'
       python.version: '3.6'
     Python37Mac:
-      imageName: 'macos-10.14'
+      imageName: 'macos-10.15'
       python.version: '3.7'
     Python38Mac:
-      imageName: 'macos-10.14'
+      imageName: 'macos-10.15'
       python.version: '3.8'
     Python36Windows:
       imageName: 'vs2017-win2016'
@@ -55,8 +55,6 @@ steps:
     python -m pip install -U setuptools
     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.4.0/en_core_sci_sm-0.4.0.tar.gz
   displayName: 'Install dependencies'
 
 - script: |
@@ -76,4 +74,14 @@ steps:
 - script: |
     cd negspacy
     python -m pytest test.py
-  displayName: 'pytest'
\ No newline at end of file
+  displayName: 'pytest'
+
+- script: |
+    pip install scispacy
+    pip install https://s3-us-west-2.amazonaws.com/ai2-s2-scispacy/releases/v0.4.0/en_core_sci_sm-0.4.0.tar.gz
+  displayName: 'Install dependencies scispacy'
+
+- script: |
+    cd negspacy
+    python -m pytest test_scispacy_dep.py
+  displayName: 'pytest'
diff --git a/setup.py b/setup.py
index f098a4d..27dbe5a 100644
--- a/setup.py
+++ b/setup.py
@@ -3,7 +3,7 @@
 
 setup(
     name = 'negspacy',
-    version = 'v1.0.0',
+    version = 'v1.0.1',
     url = 'https://github.com/jenojp/negspacy',
     author = 'Jeno Pizarro',
     author_email = 'jenopizzaro@gmail.com',
@@ -24,7 +24,7 @@
     packages = find_packages(exclude=["*.tests", "*.tests.*", "tests.*", "tests"]),
     license="MIT",
     install_requires=[
-        "spacy>=3.0.1,<3.1.0",
+        "spacy>=3.0.1,<3.2.0",
         ],
     tests_require=[
         "pytest",


Test patch:
diff --git a/negspacy/test.py b/negspacy/test.py
index bc4f490..edefc3f 100644
--- a/negspacy/test.py
+++ b/negspacy/test.py
@@ -1,7 +1,7 @@
 import pytest
 import spacy
 import copy
-from negation import Negex
+import negation
 from termsets import termset
 from spacy.pipeline import EntityRuler
 
@@ -32,51 +32,6 @@ def build_docs():
     return docs
 
 
-def build_med_docs():
-    docs = list()
-    docs.append(
-        (
-            "Patient denies cardiovascular disease but has headaches. No history of smoking. Alcoholism unlikely. Smoking not ruled out.",
-            [
-                ("Patient denies", False),
-                ("cardiovascular disease", True),
-                ("smoking", True),
-                ("Alcoholism", True),
-                ("unlikely", False),
-                ("Smoking", False),
-            ],
-        )
-    )
-    docs.append(
-        (
-            "No history of headaches, prbc, smoking, acid reflux, or GERD.",
-            [
-                ("No history", True),
-                ("headaches", True),
-                ("prbc", True),
-                ("smoking", True),
-                ("acid reflux", True),
-                ("GERD", True),
-            ],
-        )
-    )
-
-    docs.append(
-        (
-            "Alcoholism was not the cause of liver disease.",
-            [("Alcoholism", True), ("liver disease", False)],
-        )
-    )
-
-    # docs.append(
-    #     (
-    #         "There was no headache for this patient.",
-    #         [("no headache", True), ("patient", True)],
-    #     )
-    # )
-    return docs
-
-
 def test():
     nlp = spacy.load("en_core_web_sm")
     nlp.add_pipe("negex", last=True)
@@ -100,64 +55,6 @@ def test_en():
             assert (e.text, e._.negex) == d[1][i]
 
 
-def test_umls():
-    nlp = spacy.load("en_core_sci_sm")
-    ts = termset("en_clinical")
-    nlp.add_pipe(
-        "negex",
-        config={
-            "neg_termset": ts.get_patterns(),
-            "ent_types": ["ENTITY"],
-            "chunk_prefix": ["no"],
-        },
-        last=True,
-    )
-    # negex = Negex(
-    #     nlp, language="en_clinical", ent_types=["ENTITY"], chunk_prefix=["no"]
-    # )
-    # nlp.add_pipe("negex", last=True)
-    docs = build_med_docs()
-    for d in docs:
-        doc = nlp(d[0])
-        print(doc.ents)
-        for i, e in enumerate(doc.ents):
-            print(e.text, e._.negex)
-            assert (e.text, e._.negex) == d[1][i]
-
-
-def __test_umls2():
-    nlp = spacy.load("en_core_sci_sm")
-    # negex = Negex(
-    #     nlp, language="en_clinical_sensitive", ent_types=["ENTITY"], chunk_prefix=["no"]
-    # )
-    # nlp.add_pipe("negex", last=True)
-    ts = termset("en_clinical")
-    nlp.add_pipe(
-        "negex",
-        config={
-            "neg_termset": ts.get_patterns(),
-            "ent_types": ["ENTITY"],
-            "chunk_prefix": ["no"],
-        },
-        last=True,
-    )
-    docs = build_med_docs()
-    for d in docs:
-        doc = nlp(d[0])
-        for i, e in enumerate(doc.ents):
-            print(e.text, e._.negex)
-            assert (e.text, e._.negex) == d[1][i]
-
-
-# blocked by spacy 2.1.8 issue. Adding back after spacy 2.2.
-# def test_no_ner():
-#     nlp = spacy.load("en_core_web_sm", disable=["ner"])
-#     negex = Negex(nlp)
-#     nlp.add_pipe(negex, last=True)
-#     with pytest.raises(ValueError):
-#         doc = nlp("this doc has not been NERed")
-
-
 def test_own_terminology():
     nlp = spacy.load("en_core_web_sm")
     nlp.add_pipe(
@@ -239,55 +136,11 @@ def test_add_remove_patterns():
     assert len(patterns_after["pseudo_negations"]) == len(patterns["pseudo_negations"])
 
 
-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")
-    ts = termset("en_clinical")
-    ts.remove_patterns({"following_negations": ["free"]})
-    print(ts.get_patterns())
-    nlp.add_pipe(
-        "negex",
-        config={
-            "neg_termset": ts.get_patterns(),
-            "chunk_prefix": ["no", "cancer free"],
-        },
-        last=True,
-    )
-
-    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]
-
-    nlp.remove_pipe("negex")
-    # negex = Negex(nlp, language="en_clinical", chunk_prefix=["no", "free"])
-    # nlp.add_pipe("negex", last=True)
-    ts = termset("en_clinical")
-    nlp.add_pipe(
-        "negex",
-        config={
-            "neg_termset": ts.get_patterns(),
-            "chunk_prefix": ["no", "free"],
-        },
-        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()
-    test_umls()
-    test_umls2()
     test_en()
     test_bad_beharor()
     test_own_terminology()
     test_get_patterns()
     test_issue7()
     test_add_remove_patterns()
-    test_issue_14()
diff --git a/negspacy/test_scispacy_dep.py b/negspacy/test_scispacy_dep.py
new file mode 100644
index 0000000..db3bc30
--- /dev/null
+++ b/negspacy/test_scispacy_dep.py
@@ -0,0 +1,141 @@
+import pytest
+import spacy
+import copy
+import negation
+from termsets import termset
+from spacy.pipeline import EntityRuler
+
+
+def build_med_docs():
+    docs = list()
+    docs.append(
+        (
+            "Patient denies cardiovascular disease but has headaches. No history of smoking. Alcoholism unlikely. Smoking not ruled out.",
+            [
+                ("Patient denies", False),
+                ("cardiovascular disease", True),
+                ("smoking", True),
+                ("Alcoholism", True),
+                ("unlikely", False),
+                ("Smoking", False),
+            ],
+        )
+    )
+    docs.append(
+        (
+            "No history of headaches, prbc, smoking, acid reflux, or GERD.",
+            [
+                ("No history", True),
+                ("headaches", True),
+                ("prbc", True),
+                ("smoking", True),
+                ("acid reflux", True),
+                ("GERD", True),
+            ],
+        )
+    )
+
+    docs.append(
+        (
+            "Alcoholism was not the cause of liver disease.",
+            [("Alcoholism", True), ("liver disease", False)],
+        )
+    )
+
+    return docs
+
+
+def test_umls():
+    nlp = spacy.load("en_core_sci_sm")
+    ts = termset("en_clinical")
+    nlp.add_pipe(
+        "negex",
+        config={
+            "neg_termset": ts.get_patterns(),
+            "ent_types": ["ENTITY"],
+            "chunk_prefix": ["no"],
+        },
+        last=True,
+    )
+    # negex = Negex(
+    #     nlp, language="en_clinical", ent_types=["ENTITY"], chunk_prefix=["no"]
+    # )
+    # nlp.add_pipe("negex", last=True)
+    docs = build_med_docs()
+    for d in docs:
+        doc = nlp(d[0])
+        print(doc.ents)
+        for i, e in enumerate(doc.ents):
+            print(e.text, e._.negex)
+            assert (e.text, e._.negex) == d[1][i]
+
+
+def __test_umls2():
+    nlp = spacy.load("en_core_sci_sm")
+    # negex = Negex(
+    #     nlp, language="en_clinical_sensitive", ent_types=["ENTITY"], chunk_prefix=["no"]
+    # )
+    # nlp.add_pipe("negex", last=True)
+    ts = termset("en_clinical")
+    nlp.add_pipe(
+        "negex",
+        config={
+            "neg_termset": ts.get_patterns(),
+            "ent_types": ["ENTITY"],
+            "chunk_prefix": ["no"],
+        },
+        last=True,
+    )
+    docs = build_med_docs()
+    for d in docs:
+        doc = nlp(d[0])
+        for i, e in enumerate(doc.ents):
+            print(e.text, e._.negex)
+            assert (e.text, e._.negex) == d[1][i]
+
+
+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")
+    ts = termset("en_clinical")
+    ts.remove_patterns({"following_negations": ["free"]})
+    print(ts.get_patterns())
+    nlp.add_pipe(
+        "negex",
+        config={
+            "neg_termset": ts.get_patterns(),
+            "chunk_prefix": ["no", "cancer free"],
+        },
+        last=True,
+    )
+
+    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]
+
+    nlp.remove_pipe("negex")
+    # negex = Negex(nlp, language="en_clinical", chunk_prefix=["no", "free"])
+    # nlp.add_pipe("negex", last=True)
+    ts = termset("en_clinical")
+    nlp.add_pipe(
+        "negex",
+        config={
+            "neg_termset": ts.get_patterns(),
+            "chunk_prefix": ["no", "free"],
+        },
+        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_umls()
+    test_umls2()
+    test_issue_14()