La query di base è
SELECT ?ISTAT
WHERE
{
?item wdt:P31 wd:Q747074.
?item rdfs:label ?itemLabel.
FILTER(LCASE(?itemLabel)="nomecomuneinminuscolo"@it).
?item wdt:P635 ?ISTAT .
}
Per Messina è
SELECT ?ISTAT
WHERE
{
?item wdt:P31 wd:Q747074.
?item rdfs:label ?itemLabel.
FILTER(LCASE(?itemLabel)="messina"@it).
?item wdt:P635 ?ISTAT .
}
Qui per vederla in azione in modalità visuale https://w.wiki/8Yu
Per avere l'output in JSON tramite una chiamata via URL:
https://query.wikidata.org/bigdata/namespace/wdq/sparql?format=json&query=SELECT ?ISTAT WHERE {?item wdt:P31 wd:Q747074. ?item rdfs:label ?itemLabel. FILTER(LCASE(?itemLabel)="messina"@it). ?item wdt:P635 ?ISTAT .}
A cui però c'è da applicare l'URL encoding:
Che in output da:
{
"head": {
"vars": [
"ISTAT"
]
},
"results": {
"bindings": [
{
"ISTAT": {
"type": "literal",
"value": "083048"
}
}
]
}
}