Reputation: 79
I have been facing a great deal of difficulty trying to write a python code that will return the list of movies by the director called Francis Ford Coppola. Below is a good that I have so far your assistance will be greatly appreciated. I have also added a picture of the list movie, I hope it helps.
director = 'http://dbpedia.org/resource/Francis_Ford_Coppola'
director_graph = rdflib.Graph()
director_graph.load(URIRef(director))
movie_list_query = """PREFIX dbo: <http://dbpedia.org/ontology/> PREFIX dbr: <http://dbpedia.org/resource/> SELECT ?x WHERE {?x a dbo:Film; dbo:director dbr:Francis_Ford_Coppola}"""
query = director_graph.query(movie_list_query)
print(dir(query))
for x in query:
print(x)
Upvotes: 2
Views: 576
Reputation: 1241
Try using an RDFlib Store
to connect to wrap the DBpedia SPARQL endpoint like this: https://github.com/RDFLib/rdflib/blob/master/examples/sparqlstore_example.py#L13
Upvotes: 1