I have got a list of 1200 geographic enties like cities, lakes oder mountains as strings. I would like to enrich these enties with the authority file WikiData ID. This works but as result I get sometimes more than one WikiDataID suggestion. I need to define the right one by the apperance of an country in the Statements.
As an example I tried the city Karlsruhe.
For the string "Karlsruhe" I get three results. But I want just one specific WikiData ID (in this case: https://www.wikidata.org/wiki/Q1040) with the label and the altLabel (Also known as) in German, Englisch and French.
As an condition the entity should be part of an country.
This you can define by the property P17 or as an value Q6256.
Is there a way just to query a property without the value in Filter of the Query Helper?
Thank you very much for your help!
Here is the query:
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
prefix schema: <http://schema.org/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
SELECT DISTINCT ?country ?item ?itemLabel ?altLabel ?label_en ?
label_de ?label_fr
WHERE {
?item rdfs:label "Karlsruhe"@de.
?item skos:altLabel ?altLabel.
?item rdfs:label ?label_en.
?item rdfs:label ?label_de.
?item rdfs:label ?label_fr.
FILTER(LANGMATCHES(LANG(?altLabel), "de"))
FILTER((LANG(?label_en)) = "en")
FILTER((LANG(?label_de)) = "de")
FILTER((LANG(?label_fr)) = "fr")
SERVICE wikibase:label { bd:serviceParam wikibase:language "
[AUTO_LANGUAGE],de, en, fr". }
}
As an condition the entity should be part of an country. This you can define by the property P17 or as an value Q6256. Is there a way just to query a property without the value in Filter of the Query Helper?
If I understand correctly, you're asking if you can modify the query such that it only returns results if the item has some country (we don't care which one) attached to it. If that is the case, you can just add the following graph pattern to your query:
?item wdt:P17 ?country .
or even:
?item wdt:P17 [] .
(the []
is a blank node, which in SPARQL signifies an anonymous variable, i.e. a variable placeholder for a value we're not interested in).
This query is working for my purposes:
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX schema: <http://schema.org/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
SELECT DISTINCT *
WHERE {
?item rdfs:label "Karlsruhe"@de.
?item rdfs:label ?label_de.
FILTER((LANG(?label_de)) = "de").
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE], de, en, fr". }
bind(if(exists{?item wdt:P17 []}, "yes", "no") as ?country_)
optional {
?item rdfs:label ?label_en.
FILTER((LANG(?label_en)) = "en").
?item rdfs:label ?label_fr.
FILTER((LANG(?label_fr)) = "fr").
?item skos:altLabel ?altLabel_de.
FILTER(LANGMATCHES(LANG(?altLabel_de), "de"))
optional {
?item skos:altLabel ?altLabel_en.
FILTER(LANGMATCHES(LANG(?altLabel_en), "en"))
}
optional {
?item skos:altLabel ?altLabel_fr.
FILTER(LANGMATCHES(LANG(?altLabel_fr), "fr"))
}
}
}
order by ?item