File size: 1,639 Bytes
44921ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
51
52
53
54
55
56
57
58
59
from dataclasses import dataclass

from span_dataclass_converters import get_ner_spans_from_annotations


@dataclass
class PredefinedExample:
    text: str
    gt_labels: dict
    # gt_spans: list
    # predictions: list

    @property
    def gt_spans(self):
        return sorted(
            get_ner_spans_from_annotations(self.gt_labels),
            key=lambda span: span["start"],
        )

    @property
    def predictions(self):
        return [self.gt_spans]


small_example = PredefinedExample(
    text="The patient was diagnosed with bronchitis and was prescribed a mucolytic",
    gt_labels={
        "Disease": [
            {"start": 31, "end": 41, "label": "bronchitis"},
        ],
        "Drug": [
            {"start": 63, "end": 72, "label": "mucolytic"},
        ],
    },
)

big_example = PredefinedExample(
    text=(
        "The patient was experiencing stomach pain and flu like symptoms for 3 days. "
        "Upon investigation, the chest xray revealed acute bronchitis disease. "
        "The patient was asked to take rest for a week and was prescribed a mucolytic along with paracetamol for body pains."
    ),
    gt_labels={
        "Disease": [
            {"start": 120, "end": 144, "label": "acute bronchitis disease"},
        ],
        "Drug": [
            {"start": 213, "end": 222, "label": "mucolytic"},
            {"start": 234, "end": 245, "label": "paracetamol"},
        ],
        "Symptoms": [
            {"start": 29, "end": 41, "label": "stomach pain"},
            {"start": 46, "end": 63, "label": "flu like symptoms"},
        ],
    },
)

EXAMPLES = [small_example, big_example]