query-3180ad0c82a708d491ef1a14bfa015b3
: The query seemed to time out when finding the language code for the language used in a Wikipedia version when finding values for ?sitelink was made optional. I couldn't find a good solution, but made a workaround where the language code has to be given. So in the query below there are three constants:Mad melone@ 10:03, 13 April 2020 (UTC)) talk (Mad melone, but it didn't work. Could you help one last time, please?--https://stackoverflow.com/questions/49066390/how-to-get-only-the-most-recent-value-from-a-wikidata-property. I would like to get only the most current one, in the example {Q|232}}. I already tried to add some code like described in (Q42055714)Elena Rybakina I now run into the problem that sometimes players have more than one country that they represented, e.g. For clarification purposes, here is the code (without the language codes, these are still in there, but I wanted to make the query focus on the relevant part):
Use at
- https://query.wikidata.org/sparql
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX schema: <http://schema.org/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT DISTINCT ?player ?playerLabel ?PlayerID ?playerlink ?country_code
WHERE {
VALUES ?PlayerID { "324166/elena-rybakina" }
VALUES ?language_code { "de" }
# Find the player
?player wdt:P597 ?PlayerID.
# Find the Wikipedia, its language(s), and sitelink for the Wikipedia
BIND (URI(CONCAT("https://", ?language_code, ".wikipedia.org/")) AS ?Wikipedia)
OPTIONAL {
?playerlink schema:about ?player.
?playerlink schema:isPartOf ?Wikipedia.
}
# Find player's label in the language(s)
OPTIONAL {
VALUES ?language_code { "?language_code" } # Language code for player label
?player rdfs:label ?playerLabel.
FILTER (LANG(?playerLabel) = ?language_code)
}
# Find the country/ies and country code(s)
OPTIONAL { ?player wdt:P1532 ?represents. }
OPTIONAL { ?player wdt:P27 ?citizenship. }
BIND (COALESCE(?represents, ?citizenship, "") AS ?country)
?country wdt:P298 ?country_code.
FILTER NOT EXISTS {
?player p:P1532/pq:P580 ?start_date .
FILTER (?start_date > ?start_date)
}
SERVICE wikibase:label {
bd:serviceParam wikibase:language "de", "en" .
}
}