|
a |
|
b/tests/methods/test_deduce_labeler.py |
|
|
1 |
from deidentify.base import Annotation |
|
|
2 |
from deidentify.methods.deduce.deduce_labeler import DeduceAnnotator |
|
|
3 |
|
|
|
4 |
TEST_TEXT = u"Dit is stukje tekst met daarin de naam Jan Jansen. De patient J. Jansen (e: j.jnsen@email.com, t: 06-12345678) is 64 jaar oud en woonachtig in Utrecht. Hij werd op 10 oktober door arts Peter de Visser ontslagen van de kliniek van het UMCU." |
|
|
5 |
|
|
|
6 |
ANNOTATOR = DeduceAnnotator(text=TEST_TEXT) |
|
|
7 |
|
|
|
8 |
|
|
|
9 |
def test_annotation_content(): |
|
|
10 |
assert ANNOTATOR.annotation_content('<LOCATIE Laverhof>') == 'Laverhof' |
|
|
11 |
|
|
|
12 |
|
|
|
13 |
def test_annotation_tag(): |
|
|
14 |
assert ANNOTATOR.annotation_tag('<LOCATIE Laverhof>') == 'LOCATIE' |
|
|
15 |
|
|
|
16 |
|
|
|
17 |
def test_is_annotation(): |
|
|
18 |
assert ANNOTATOR.is_annotation('<LOCATIE Laverhof>') |
|
|
19 |
assert not ANNOTATOR.is_annotation('This is not an annotation') |
|
|
20 |
assert not ANNOTATOR.is_annotation('This is also not an annotation <LOCATIE Laverhof>') |
|
|
21 |
|
|
|
22 |
|
|
|
23 |
def test_flatten_tag_content(): |
|
|
24 |
fac = ANNOTATOR.flatten_annotation_content |
|
|
25 |
assert fac('<PERSOON <LOCATIE Laverhof >Ondersteuning Thuis>') == 'Laverhof Ondersteuning Thuis' |
|
|
26 |
assert fac('Ondersteuning Thuis') == 'Ondersteuning Thuis' |
|
|
27 |
assert fac('<LOCATIE Laverhof> Ondersteuning <LOCATIE Thuis>') == 'Laverhof Ondersteuning Thuis' |
|
|
28 |
assert fac('<LOCATIE Laverhof>') == 'Laverhof' |
|
|
29 |
|
|
|
30 |
|
|
|
31 |
def test_annotate_text(): |
|
|
32 |
assert ANNOTATOR.annotated_text == "Dit is stukje tekst met daarin de naam <PERSOON Jan Jansen>. De <PERSOON patient J. Jansen> (e: <URL j.jnsen@email.com>, t: <TELEFOONNUMMER 06-12345678>) is <LEEFTIJD 64> jaar oud en woonachtig in <LOCATIE Utrecht>. Hij werd op <DATUM 10 oktober> door arts <PERSOON Peter de Visser> ontslagen van de kliniek van het <INSTELLING umcu>." |
|
|
33 |
|
|
|
34 |
|
|
|
35 |
def test_annotations(): |
|
|
36 |
actual = ANNOTATOR.annotations() |
|
|
37 |
|
|
|
38 |
assert actual == [ |
|
|
39 |
Annotation('Jan Jansen', 39, 49, 'PERSOON'), |
|
|
40 |
Annotation('patient J. Jansen', 54, 71, 'PERSOON'), |
|
|
41 |
Annotation('j.jnsen@email.com', 76, 93, 'URL'), |
|
|
42 |
Annotation('06-12345678', 98, 109, 'TELEFOONNUMMER'), |
|
|
43 |
Annotation('64', 114, 116, 'LEEFTIJD'), |
|
|
44 |
Annotation('Utrecht', 143, 150, 'LOCATIE'), |
|
|
45 |
Annotation('10 oktober', 164, 174, 'DATUM'), |
|
|
46 |
Annotation('Peter de Visser', 185, 200, 'PERSOON'), |
|
|
47 |
# We explicitly check that the following annotation is included in it's correct form. |
|
|
48 |
# Deduce annotates UMCU as umcu. During annotation, we attempt to recover the original text. |
|
|
49 |
Annotation('UMCU', 234, 238, 'INSTELLING') |
|
|
50 |
] |