简体   繁体   中英

How can I get the list of movies by a director from dbpedia using sparql query

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)

在此处输入图像描述

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM