问题
For my current project I need to extract information from dbpedia. The only information I have is the label of the resource.
To give you an example:
I have the resource "car". Now I would like to get e.g. the abstract. Is there a way to solve this with SPARQL?
回答1:
That other answer doesn't get you results from DBpedia, which is what you said you wanted. It's also not clear whether you want results for resources which label includes your known string, or is your known string.
A couple of examples, directly linked to query forms and results, presuming you only care about English abstracts and labels...
Label case-insensitively includes car (live results)
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX bif: <bif:>
SELECT DISTINCT ?itemLabel
?item
?itemDescription
WHERE
{
?item rdfs:label ?itemLabel .
?itemLabel bif:contains "car" .
?item dbo:abstract ?itemDescription .
FILTER (lang(?itemDescription) = 'en')
FILTER (lang(?itemLabel) = 'en')
}
ORDER BY ?itemLabel
Label is exactly "Car"@en (live results)
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT DISTINCT *
WHERE
{
?item rdfs:label ?itemLabel .
FILTER ( ?itemLabel = "Car"@en ) .
?item dbo:abstract ?itemDescription .
FILTER (lang(?itemDescription) = 'en')
}
ORDER BY ?itemLabel
回答2:
If you're looking by label, for example:
SELECT distinct ?item ?itemLabel ?itemDescription WHERE{
?item ?label "Car"@en.
?article schema:about ?item .
?article schema:inLanguage "en" .
?article schema:isPartOf <https://en.wikipedia.org/>.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
you get several items:
You can see it on Wikidata Query Page. (I prefer Wikidata Query services to DBpedia).
So you need to specify some additional parameter to get only required item.
来源:https://stackoverflow.com/questions/41201189/sparql-get-properties-by-label