0

I have the following code already:

movie = "http://dbpedia.org/resource/Cannes_Man"
Q = "PREFIX dbo:     <http://dbpedia.org/property/> PREFIX dbpedia: <http://dbpedia.org/resource/>  SELECT ?actor WHERE {?actor dbo:starring <"+movie+">.} "
sparql = SPARQLWrapper("http://dbpedia.org/sparql")
sparql.setReturnFormat(JSON)
sparql.setQuery(Q)  # the previous query as a literal string
activity_feed3 = sparql.query().convert()
print activity_feed3
for result5 in activity_feed3["results"]["bindings"]:
    print result5

it returns empty results. I am new to sprawl client and dbpedia and am trying to understand how to run simple queries. Any help would be greatly appreciated!

pacubs92
  • 1
  • 1

1 Answers1

1
  1. RDF data is modeled as directed graph, thus, you have to figure out the direction of a relation.
  2. You can see this if you just have a look at the data of some films in DBpedia, like your example http://dbpedia.org/resource/Cannes_Man. There you can see that a film has information about actors by the property http://dbpedia.org/ontology/starring. You can also check for incoming and outgoing data by using SPARQL: SELECT * WHERE {?s ?p_in <URI>} resp. SELECT * WHERE {<URI> ?p_out ?o}
  3. You should try to use common prefixes, i.e. dbo: is usually used for http://dbpedia.org/ontology/ and not http://dbpedia.org/property/

Therefore, the SPARQL query you probably need is

SELECT ?actor WHERE {
   <http://dbpedia.org/resource/Cannes_Man> <http://dbpedia.org/ontology/starring> ?actor 
}
UninformedUser
  • 8,397
  • 1
  • 14
  • 23