In [55]:
from SPARQLWrapper import SPARQLWrapper, SPARQLWrapper2, JSON
In [62]:
sparql = SPARQLWrapper("http://dbpedia.org/sparql")
sparql.setQuery("""
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?label
WHERE { <http://dbpedia.org/resource/Love> rdfs:label ?label }
""")
sparql.setReturnFormat(JSON)
results = sparql.query().convert()
for result in results["results"]["bindings"]:
print(result["label"]["value"]+", "+result["label"]["xml:lang"])
In [189]:
PREFIX="""PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ops: <http://purl.org/socialparticipation/ops#>
PREFIX opa: <http://purl.org/socialparticipation/opa#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/terms/>
"""
q1="SELECT ?s WHERE {?s ?p ?o}"
q2="SELECT ?nome WHERE {?s rdf:type ops:Participant . ?s foaf:name ?nome .}"
In [95]:
#sparql3 = SPARQLWrapper("http://200.144.255.210:8082/participabr/query")
sparql3 = SPARQLWrapper("http://localhost:82/participabr/query")
In [116]:
sparql3.setQuery(PREFIX+q2)
sparql3.setReturnFormat(JSON)
In [117]:
results3 = sparql3.query().convert()
In [118]:
results3["results"]["bindings"][0]
Out[118]:
In [119]:
for i in results3["results"]["bindings"][-10:]: print(u"participante: " +i["nome"]["value"])
In [121]:
q3="""SELECT DISTINCT ?aname ?bname
WHERE {
?a foaf:knows ?b .
?a foaf:name ?aname .
?b foaf:name ?bname .
}"""
sparql3.setQuery(PREFIX+q3)
sparql3.setReturnFormat(JSON)
results4 = sparql3.query().convert()
In [122]:
for i in results4["results"]["bindings"][-10:]: print(i["aname"]["value"]+u" -- conhece -- "+i["bname"]["value"])
#for i in results3["results"]["bindings"][-10:]: print(i)
In [124]:
print(u"são %s amizades e %s participantes"%(len(results4["results"]["bindings"]),len(results3["results"]["bindings"])))
In [172]:
q4="""SELECT (COUNT(DISTINCT ?instance) AS ?count) WHERE {
?instance rdf:type foaf:Group .
}"""
sparql4 = SPARQLWrapper("http://localhost:82/participabr/query")
sparql4.setQuery(PREFIX+q4)
sparql4.setReturnFormat(JSON)
results5 = sparql4.query().convert()
In [178]:
print(u"são %s grupos"%(foo["bindings"][0]["count"]["value"],))
In [179]:
q5="""SELECT (COUNT(?instance) AS ?count) WHERE {
?instance ops:performsParticipation ?foo .
}"""
sparql5 = SPARQLWrapper("http://localhost:82/participabr/query")
sparql5.setQuery(PREFIX+q5)
sparql5.setReturnFormat(JSON)
results6 = sparql5.query().convert()
In [185]:
print(u"são %s participações"%(results6["results"]["bindings"][0]["count"]["value"],))
In [197]:
q6="""SELECT ?trilha WHERE {
?trilha dc:type opa:ParticipationTrack .
}"""
sparql6 = SPARQLWrapper("http://localhost:82/participabr/query")
sparql6.setQuery(PREFIX+q6)
sparql6.setReturnFormat(JSON)
results7 = sparql6.query().convert()
In [199]:
print("são %i trilhas, cujas URIs são: "%(len(results7["results"]["bindings"]),))
for i in results7["results"]["bindings"]: print(i["trilha"]["value"])
In [200]:
q7="""SELECT ?etapa WHERE {
?etapa dc:type opa:ParticipationStep .
}"""
sparql7 = SPARQLWrapper("http://localhost:82/participabr/query")
sparql7.setQuery(PREFIX+q7)
sparql7.setReturnFormat(JSON)
results8 = sparql7.query().convert()
In [205]:
print(u"são %i etapas, cujas URIs são: "%(len(results8["results"]["bindings"]),))
for i in results8["results"]["bindings"]: print(i["etapa"]["value"])
In [ ]: