-
Notifications
You must be signed in to change notification settings - Fork 0
/
getSynonymsWiktionary.py
29 lines (26 loc) · 1018 Bytes
/
getSynonymsWiktionary.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
from rdflib import Graph
from SPARQLWrapper import TURTLE, SPARQLWrapper
sparql = SPARQLWrapper("http://localhost:7200/repositories/wiktionary")
sparql.setQuery("""
PREFIX dbnary: <http://kaiko.getalp.org/dbnary#>
PREFIX ontolex: <http://www.w3.org/ns/lemon/ontolex#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
CONSTRUCT {
?term rdf:type skos:Concept .
?term skos:prefLabel ?termlabel .
?term skos:altLabel ?synlabel .
}
WHERE {
?term rdf:type ontolex:LexicalEntry .
?term dbnary:partOfSpeech "Noun" .
?term dbnary:synonym ?syn .
BIND(strlang(strafter(str(?syn),"eng/"),"en") as ?synlabel) .
BIND(strlang(strbefore(strafter(str(?term),"eng/"), "__Noun"),"en") as ?termlabel) .
}
""")
sparql.setReturnFormat(TURTLE)
results = sparql.query().convert()
g = Graph()
g.parse(data=results, format="turtle")
g.serialize(destination='syn_wiktionary_2.ttl', format='turtle')