-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathannotation.py
50 lines (38 loc) · 1.42 KB
/
annotation.py
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
import requests
class Annotation():
def __init__(self,text):
bio_ner = "https://librairy.linkeddata.es/bio-ner/entities"
headers = {'Content-type': 'application/json; charset=utf-8'}
response = requests.post(bio_ner, json = { 'text':text}, headers=headers)
self.chemicals = []
self.diseases = []
self.covid = []
self.genetics = []
if (response.status_code == 200):
data = response.json()
if ('entities' in data):
entities = data['entities']
if ('chemicals' in entities):
self.chemicals = entities['chemicals']
if ('diseases' in entities):
self.diseases = entities['diseases']
if ('covid' in entities):
self.covid = entities['covid']
if ('genetics' in entities):
self.genetics = entities['genetics']
def get_chemicals(self):
return self.chemicals
def has_chemicals(self):
return len(self.chemicals) > 0
def get_diseases(self):
return self.diseases
def has_diseases(self):
return len(self.diseases) > 0
def get_covid(self):
return self.covid
def has_covid(self):
return len(self.covid) > 0
def get_genetics(self):
return self.genetics
def has_genetics(self):
return len(self.genetics) > 0