Skip to content

Commit

Permalink
working tests for diso/behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomzoy committed Sep 24, 2024
1 parent 173bdfc commit 4005c96
Show file tree
Hide file tree
Showing 16 changed files with 37 additions and 43 deletions.
2 changes: 1 addition & 1 deletion edsnlp/pipes/ner/behaviors/alcohol/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
),
dict(
name="zero_after",
regex=r"(?=^[a-z]*\s*:?[\s-]*(0|non))",
regex=r"(?=^[a-z]*\s*:?[\s-]*(0|non|aucun|jamais))",
window=3,
reduce_mode="keep_first",
),
Expand Down
2 changes: 1 addition & 1 deletion edsnlp/pipes/ner/behaviors/tobacco/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
),
dict(
name="zero_after",
regex=r"(?=^[a-z]*\s*:?[\s-]*(0|non))",
regex=r"(?=^[a-z]*\s*:?[\s-]*(0|non|aucun|jamais))",
window=3,
reduce_mode="keep_first",
),
Expand Down
2 changes: 1 addition & 1 deletion tests/pipelines/ner/disorders/CKD.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
True,
False,
],
detailled_status="PRESENT",
detailled_status=None,
assign=8 * [None] + [{"stage": "IV"}, {"dfg": 30}, None],
texts=[
"Patient atteint d'une glomérulopathie.",
Expand Down
2 changes: 1 addition & 1 deletion tests/pipelines/ner/disorders/COPD.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
False,
True,
],
detailled_status="PRESENT",
detailled_status=None,
assign=None,
texts=[
"Une fibrose interstitielle diffuse idiopathique",
Expand Down
2 changes: 1 addition & 1 deletion tests/pipelines/ner/disorders/cerebrovascular_accident.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
True,
True,
],
detailled_status="PRESENT",
detailled_status=None,
assign=None,
texts=[
"Patient hospitalisé à AVC.",
Expand Down
2 changes: 1 addition & 1 deletion tests/pipelines/ner/disorders/congestive_heart_failure.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
True,
False,
],
detailled_status="PRESENT",
detailled_status=None,
assign=None,
texts=[
"Présence d'un oedème pulmonaire",
Expand Down
2 changes: 1 addition & 1 deletion tests/pipelines/ner/disorders/connective_tissue_disease.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
True,
True,
],
detailled_status="PRESENT",
detailled_status=None,
assign=None,
texts=[
"Présence d'une sclérodermie.",
Expand Down
2 changes: 1 addition & 1 deletion tests/pipelines/ner/disorders/dementia.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
False,
True,
],
detailled_status="PRESENT",
detailled_status=None,
assign=None,
texts=[
"D'importants déficits cognitifs",
Expand Down
2 changes: 1 addition & 1 deletion tests/pipelines/ner/disorders/hemiplegia.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
True,
True,
],
detailled_status="PRESENT",
detailled_status=None,
assign=None,
texts=[
"Patient hémiplégique",
Expand Down
2 changes: 1 addition & 1 deletion tests/pipelines/ner/disorders/leukemia.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
True,
True,
],
detailled_status="PRESENT",
detailled_status=None,
assign=None,
texts=[
"Sydrome myéloprolifératif",
Expand Down
2 changes: 1 addition & 1 deletion tests/pipelines/ner/disorders/lymphoma.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
True,
False,
],
detailled_status="PRESENT",
detailled_status=None,
assign=None,
texts=[
"Un lymphome de Hodgkin.",
Expand Down
2 changes: 1 addition & 1 deletion tests/pipelines/ner/disorders/myocardial_infarction.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
False,
True,
],
detailled_status="PRESENT",
detailled_status=None,
assign=None,
texts=[
"Une cardiopathie ischémique",
Expand Down
2 changes: 1 addition & 1 deletion tests/pipelines/ner/disorders/peptic_ulcer_disease.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
False,
True,
],
detailled_status="PRESENT",
detailled_status=None,
assign=None,
texts=[
"Beaucoup d'ulcères gastriques",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
True,
False,
],
detailled_status="PRESENT",
detailled_status=None,
assign=None,
texts=[
"Un AOMI",
Expand Down
25 changes: 1 addition & 24 deletions tests/pipelines/ner/disorders/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __init__(
else len(texts) * [detailled_status]
)
self.assign = assign if assign is not None else len(texts) * [None]
self.negation = negation
self.negation = negation if negation is not None else len(texts) * [None]

self.nlp.add_pipe(f"eds.{disorder}")

Expand Down Expand Up @@ -124,26 +124,3 @@ def test_disorder(normalized_nlp, disorder):
)

expect.check()


def test_behavior_negation(blank_nlp):
blank_nlp.add_pipe("eds.normalizer")
blank_nlp.add_pipe("eds.tobacco")
blank_nlp.add_pipe("eds.alcohol")
blank_nlp.add_pipe("eds.negation")

negated_texts = [
"Le patient ne fume aucun truc.",
"Le patient fume 0 PA.",
"Il ne boit pas d'alcool." "Boit très rarement de l'alcool.",
]

positive_texts = ["Le patient ne fume que le soir.", "Il ne boit plus d'alcool."]

for text in negated_texts:
doc = blank_nlp(text)
assert doc.ents[0]._.negation is True, text

for text in positive_texts:
doc = blank_nlp(text)
assert doc.ents[0]._.negation is False, text
27 changes: 22 additions & 5 deletions tests/pipelines/ner/disorders/tobacco.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,32 @@
True,
True,
True,
True,
True,
],
detailled_status=[
"PRESENT",
"PRESENT",
None,
None,
None,
"ABSTINENCE",
"ABSENT",
"ABSENT",
None,
None,
"ABSTINENCE",
None,
None,
],
negation=[
None,
None,
None,
None,
True,
True,
None,
True,
True,
],
assign=[{"PA": 15}] + 6 * [None],
assign=[{"PA": 15}] + 8 * [None],
texts=[
"Tabagisme évalué à 15 PA",
"Patient tabagique",
Expand All @@ -26,5 +41,7 @@
"Tabac: 0",
"Tabagisme passif",
"Tabac: sevré depuis 5 ans",
"Le patient ne fume aucun truc.",
"Le patient fume 0 PA.",
],
)

0 comments on commit 4005c96

Please sign in to comment.