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 pyrudof import Rudof, RudofConfig, RDFFormat, QueryResultFormat
endpoint = "https://query.wikidata.org/sparql"
sparql_query = """
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX : <http://example.org/>
CONSTRUCT {
?p a :Person ;
:name ?person ;
:occupation ?occupation
} WHERE {
?p wdt:P31 wd:Q5 ;
wdt:P106 ?o ;
rdfs:label ?person ;
wdt:P19 wd:Q14317 .
?o rdfs:label ?occupation
FILTER (lang(?person) = "en" && lang(?occupation) = "en")
}
LIMIT 10
"""
rudof = Rudof(RudofConfig())
rudof.use_endpoint(endpoint)
result = rudof.run_query_construct_str(sparql_query, QueryResultFormat.Turtle)
print(result)
|