English 中文(简体)
如何查询 dbpedia 资源本体学 wikiPage 外部链接
原标题:How to query dbpedia resource ontology wikiPageExternalLink

Using sparqlsparqlwrapper in python, how will I be able to query for the values of a certain dbpedia resource? For example, how will I be able to get the dbpedia-owl:wikiPageExternalLink values of http://dbpedia.org/page/Asturias? Here s a simple example on how will I be able to query for the rdfs:label of Asturias. But I don t know how to modify the query/query parameters to get values of property/ontology other than those included on rdfs schema. Here s the sample:

from SPARQLWrapper import SPARQLWrapper, JSON, XML, N3, RDF
sparql = SPARQLWrapper("http://dbpedia.org/sparql")
sparql.setQuery("""
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
    SELECT ?label
    WHERE { <http://dbpedia.org/resource/Asturias> rdfs:label ?label }
""")
print  

*** JSON Example 
sparql.setReturnFormat(JSON)
results = sparql.query().convert()
for result in results["results"]["bindings"]:
    print result["label"]["value"]

希望收到反馈 提前感谢!

问题回答

不清楚你被困在哪里-这很简单:

SELECT ?label
WHERE { <http://dbpedia.org/resource/Asturias>
            dbpedia-owl:wikiPageExternalLink ?label }

通常您需要声明命名空间前缀, 如 rdfs: dbpedia-owl: , 如果您想要在查询中使用它们, 但是在 DBpedia 端点上即使不使用, 也仍然有效。 如果您想要, 您也可以声明它们 :

PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT ?label
WHERE { <http://dbpedia.org/resource/Asturias>
            dbpedia-owl:wikiPageExternalLink ?label }

您可以通过 < a href=" http://dbpedia.org/sparql" rel=“ noreferrer” > http://dbpedia.org/sparql 并点击右上角附近的“空间前缀名称” 来找到与前缀相对应的完整 URI 。

如果您想要重命名变量( 例如, 从 ? label ?link ), 那么是否要重命名变量( 从 ? label ?link )?

PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT ?link
WHERE { <http://dbpedia.org/resource/Asturias>
            dbpedia-owl:wikiPageExternalLink ?link }

并且您还必须在 Python 代码中将 “ label” 更改为 “link” , 从而从 JSON 结果中获取值 。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签