我正在使用以下查询来获取给定dbpedia URI的dbpedia类别(即skos:broader|dct:subject
)。
all_urls = ['http://dbpedia.org/resource/Machine_learning', 'http://dbpedia.org/resource/Category:Machine_learning']
for url in all_urls:
print("------")
print(url)
print("------")
sparql.setQuery("""
SELECT * WHERE {<"""
+url+
""">skos:broader|dct:subject ?resource
}
""")
sparql.setReturnFormat(JSON)
results = sparql.query().convert()
for result in results["results"]["bindings"]:
print('resource ---- ', result['resource']['value'])
输出为:
------
http://dbpedia.org/resource/Machine_learning
------
resource ---- http://dbpedia.org/resource/Category:Cybernetics
resource ---- http://dbpedia.org/resource/Category:Learning
resource ---- http://dbpedia.org/resource/Category:Machine_learning
------
http://dbpedia.org/resource/Category:Machine_learning
------
resource ---- http://dbpedia.org/resource/Category:Artificial_intelligence
resource ---- http://dbpedia.org/resource/Category:Learning
现在,我想检查输出中每个类别与dbpedia类别系统顶层之间的距离(根据我目前的理解,dbc:Contents
是skos:broader和dct:subject层次结构中的顶层元素) 。可以在sparql中做到吗?
很高兴在需要时提供更多详细信息。