How to request the ontology of the dbpedia resource 'wikiPageExternalLink'

Using sparql \ sparqlwrapper in python, how can I request values ​​for a specific dbpedia resource? For example, how can I get the values ​​of dbpedia-owl: wikiPageExternalLink http://dbpedia.org/page/Asturias ? Here is a simple example of how I can request the Rdfs label: Asturias. But I do not know how to change the request / request parameters to get property / ontology values ​​different from those included in the rdfs schema. Here's a 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 '\n\n*** JSON Example' sparql.setReturnFormat(JSON) results = sparql.query().convert() for result in results["results"]["bindings"]: print result["label"]["value"] 

Waiting for feedback. Thanks in advance!

+7
source share
1 answer

Not sure where you are stuck - it is very simple:

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

Typically, you need to declare namespace prefixes such as rdfs: or dbpedia-owl: if you want to use them in a query, but at the DBpedia endpoint this works even without. If you want, you can declare them anyway:

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

You can find out the full URI corresponding to the prefix by going to http://dbpedia.org/sparql and clicking on the "Namespace Prefix" in the upper right corner.

If you want to rename a variable (for example, from ?label to ?link ), follow these steps:

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

and you should also change the "label" to "link" in the Python code, which gets the value from the JSON result.

+7
source

All Articles