query-3180ad0c82a708d491ef1a14bfa015b3

rq turtle/ttl

: 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

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" .
  }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v5("?PlayerID"):::projected v6("?Wikipedia") v9("?citizenship") v10("?country") v11("?country_code"):::projected v8("?language_code") v2("?player"):::projected v3("?playerLabel"):::projected v7("?playerlink"):::projected v8("?represents") v1("?start_date") a1((" ")) c13(["de"]):::literal c14(["en"]):::literal c11(["bd:serviceParam"]):::iri f0[["not "]] subgraph f0e0["Exists Clause"] e0f0[["?start_date > ?start_date"]] e0f0 --> e0v1 e0v2 --"p:P1532"--> e0a1 e0a1 --"p:qualifier/P580"--> e0v1 e0v2("?player"):::projected e0v1("?start_date"):::projected e0a1((" ")):::projected end f0--EXISTS--> f0e0 f0 --> v1 f0 --> v2 f0 --> c1 f0 --> a1 f0 --> c2 f1[["?start_date > ?start_date"]] f1 --> v1 v2 --"p:P1532"--> a1 a1 --"p:qualifier/P580"--> v1 bind2[/VALUES ?PlayerID/] bind2-->v5 bind20(["324166/elena-rybakina"]) bind20 --> bind2 bind3[/VALUES ?language_code/] bind3-->v8 bind30(["de"]) bind30 --> bind3 v2 --"p:direct/P597"--> v5 bind4[/"concat('https://',?language_code,'.wikipedia.org/')"/] v8 --o bind4 bind4 --as--o v6 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v7 -."schema:about".-> v2 v7 --"schema:isPartOf"--> v6 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; bind5[/VALUES ?language_code/] bind5-->v8 bind50(["?language_code"]) bind50 --> bind5 v2 -."rdfs:label".-> v3 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:direct/P1532".-> v8 end subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:direct/P27".-> v9 end bind6[/"?represents?citizenship''"/] v8 --o bind6 v9 --o bind6 bind6 --as--o v10 v10 --"p:direct/P298"--> v11 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c11 --"wikibase:language"--> c13 c11 --"wikibase:language"--> c14 end