Olscream
Olscream

Reputation: 127

SPARQL - Get entity type from a String

I'm using Wikidata with the purpose to find, for the String "Scotland", the values of the properties "type / instance of", "subclass of" and "part of" if they exist.

For example, manually by browsing the Wikidata's website, I type Scotland, I find the ressource and those data are displayed inside it, just like : https://www.wikidata.org/wiki/Q22. Thus I can see that Scotland is an instance of "country within the United Kingdom".

What would be the equivalent query in SPARQL to do that please ?

I tried this "valid" query but it whether does not return any results or bypasses the time limit :

SELECT ?instanceOf ?subclassOf ?partOf WHERE {
  ?word rdfs:label ?label;
       wdt:P361 ?instanceOf;
       wdt:P279 ?subclassOf;
       wdt:P361 ?partOf.
  FILTER(CONTAINS(?label, "Scotland"))
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en".}
}

Try it here

Upvotes: 0

Views: 826

Answers (1)

Udi
Udi

Reputation: 30534

If you already now Scotland is Entity Q22 on wikidata,you can use the https://www.wikidata.org/wiki/Special:EntityData/Qxxxxx.json URL to retrieve all the statements related to Scotland, without using SQARQL: https://www.wikidata.org/wiki/Special:EntityData/Q22.json.

See also: About Data in WikiData's help.

To search matching entities by a string, use the wbsearchentities REST API, for example: https://www.wikidata.org/w/api.php?action=wbsearchentities&search=scotland&language=en .

Upvotes: 2

Related Questions