[cad161]: / tests / utils / test_examples.py

Download this file

51 lines (31 with data), 1.3 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from edsnlp.utils.examples import find_matches, parse_example, parse_match
example = (
"Le <ent int_value=1 float_value=0.3>patient</ent> "
"n'est pas <ent polarity_=NEG negation=true>malade</ent>."
)
def test_find_matches():
matches = find_matches(example=example)
assert len(matches) == 2
match1, match2 = matches
assert match1.group() == "<ent int_value=1 float_value=0.3>patient</ent>"
assert match2.group() == "<ent polarity_=NEG negation=true>malade</ent>"
def test_parse_match():
matches = find_matches(example=example)
match = parse_match(matches[0])
assert match.text == "patient"
assert match.modifiers == "int_value=1 float_value=0.3"
def test_parse_example():
text, entities = parse_example(example=example)
assert text == "Le patient n'est pas malade."
entity1, entity2 = entities
assert text[entity1.start_char : entity1.end_char] == "patient"
assert text[entity2.start_char : entity2.end_char] == "malade"
m1, m2, m3, m4 = entity1.modifiers + entity2.modifiers
assert m1.key == "int_value"
assert m1.value == 1
assert m2.key == "float_value"
assert m2.value == 0.3
assert m3.key == "polarity_"
assert m3.value == "NEG"
assert m4.key == "negation"
assert m4.value