Junkwin
Junkwin

Reputation: 63

What SPARQL query can return item by its label and description text?

How should SPARQL query to looks like to return results by having label and description?

Upvotes: 1

Views: 1683

Answers (1)

Median Hilal
Median Hilal

Reputation: 1531

Could you please clarify, what is your query, and which dataset are posing it on?

In general, you can use rdfs:label to get labels, and you can filter them by language. The example SPARQL query hereinafter works on DBpedia SPARQL endpoint.

SELECT * 
WHERE {
   ?x ?y ?z . # any triple 
   ?x rdfs:label ?label . # getting the label of ?x
   FILTER (lang(?label) = "en") # filtering ?label to English labels
}
LIMIT 100

For Wikidata, you can use the SERVICE and then get item description and label. The following query against Wikidata endpoint selects instances of Human, and brings back label and description. By using SERVICE, you can get the variables labels and description by appending 'Label' and 'Description' to the query head variables, e.g., for ?x label, you write ?xLabel.

SELECT ?x ?xLabel ?xDescription # 
WHERE {
  ?x wdt:P31 wd:Q5. # ?x is an instance of Human
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # English
}
LIMIT 10

See Wikidata query examples for more wikidata details.

Upvotes: 2

Related Questions