-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_event_clusters.py
40 lines (32 loc) · 1.33 KB
/
gen_event_clusters.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
from gastrodon import RemoteEndpoint, inline
import json
namespaces_str = """
@prefix : <https://tac.nist.gov/tracks/SM-KBP/2018/ontologies/AidaDomainOntologiesCommon#> .
@prefix aida: <https://tac.nist.gov/tracks/SM-KBP/2019/ontologies/InterchangeOntology#> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix domainOntology: <https://tac.nist.gov/tracks/SM-KBP/2019/ontologies/SeedlingOntology> .
@prefix ldc: <https://tac.nist.gov/tracks/SM-KBP/2019/ontologies/LdcAnnotations#> .
@prefix ldcOnt: <https://tac.nist.gov/tracks/SM-KBP/2019/ontologies/LDCOntology#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
"""
def gen_event_clusters(endpoint_url, outfile):
endpoint = RemoteEndpoint(url=endpoint_url,
prefixes=inline(namespaces_str).graph)
df = endpoint.select("""
SELECT DISTINCT ?e {
SELECT ?e
WHERE {
?e a aida:Event;
}
}
""")
def to_list(e):
return [str(e)]
events = df['e'].apply(to_list).values.tolist()
with open(outfile, 'w') as f:
for c in events:
f.write(json.dumps(c) + '\n')