-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystemparser.py
More file actions
executable file
·46 lines (40 loc) · 1.56 KB
/
systemparser.py
File metadata and controls
executable file
·46 lines (40 loc) · 1.56 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
import json
import urllib.parse
import urllib.request
from urllib.request import urlopen, Request
from urllib.parse import urlencode
spotlightUrl = 'http://spotlight.sztaki.hu:2222/rest/candidates?'
headers = {'Accept': 'application/json'}
#agdistisUrl="http://139.18.2.164:8080/AGDISTIS"
agdistisUrl = "http://akswnc9.informatik.uni-leipzig.de:8113/AGDISTIS"
def disambiguateAgdistis(xmlText, type='agdistis'):
params={"text": xmlText, "type": type}
request = Request(agdistisUrl, urlencode(params).encode())
thisJson = urlopen(request).read().decode()
return json.loads(thisJson)
def annotateSpotlight(query):
args = urllib.parse.urlencode([("text", query), ("confidence", 0), ("support", 0)]).encode("utf-8")
request = urllib.request.Request(spotlightUrl, data=args, headers={"Accept": "application/json"})
response = urllib.request.urlopen(request).read()
pydict= json.loads(response.decode('utf-8'))
return pydict
def getSpotlightCandidates(mention):
candidates = annotateSpotlight(mention)
candSet=set()
if 'surfaceForm' in candidates['annotation']:
if type(candidates['annotation']['surfaceForm']) is list:
for sf in candidates['annotation']['surfaceForm']:
resources=sf['resource']
if type(resources) is list:
for candidate in resources:
candSet.add(candidate['@uri'])
else:
candSet.add(resources['@uri'])
else:
resources=candidates['annotation']['surfaceForm']['resource']
if type(resources) is list:
for candidate in resources:
candSet.add(candidate['@uri'])
else:
candSet.add(resources['@uri'])
return candSet