1

Ive the following query, but I only want the country codes, not the entire link. This happens also with other fields and i cant find the solution

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT ?item ?itemLabel 
(group_concat(distinct ?country;separator=",") as ?country)
WHERE {

  SERVICE wikibase:label { bd:serviceParam wikibase:language "es,en,it,fr,de,cs,[AUTO_LANGUAGE]". }

FILTER (?item = wd:Q20004082)
  OPTIONAL { ?item wdt:P27 ?country. }
}
group by ?item ?itemLabel
  • 1
    Do yuo mean labels? You need manual mode: SERVICE wikibase:label { bd:serviceParam wikibase:language "es,[AUTO_LANGUAGE]". ?country rdfs:label ?countryLabel }. – Stanislav Kralin Jan 23 at 10:16
  • 1
    If you want ISO 2 letter country codes: just use wdt:P27/wdt:P297 insted of wdt:P27 – nvrandow Jan 23 at 10:36
  • @StanislavKralin and nvrandow Thanks for your comments. Some kind, actually I need: Q212 and Q15180 – MacGyver Jan 23 at 15:15
  • 1
    bind (strafter(str(?country), str(wd:)) as ?country_qid) – Stanislav Kralin Jan 23 at 15:35
  • oh silly me! is an object not a string, there is not existance without the url :D Thanks Stanislav, if you want you can make your comment as answer I'll accept it. – MacGyver Jan 23 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.