简体   繁体   English

如何使用 sparql 查询从 dbpedia 获取导演的电影列表

[英]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.我在尝试编写 python 代码时遇到了很大的困难,该代码将返回导演弗朗西斯·福特·科波拉 (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尝试使用 RDFlib Store连接以包装 DBpedia SPARQL 端点,如下所示: https://github.com/RDFLib/rdflib/blob/master/examples/sparqlstore_example.py#L13

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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