Skip to content

Wikidata lembretes

Peter edited this page Aug 9, 2018 · 6 revisions

Important! https://github.com/EdwardBetts/osm-wikidata

Preservação

Ver também https://www.w3.org/TR/sparql11-query/#propertypaths e https://stackoverflow.com/q/51660914/287948

SELECT DISTINCT ?qid ?osm_relid ?wgs84 ?codIBGE ?itemLabel 
WHERE {
  ?item wdt:P625 _:b0.
  ?item wdt:P31*/wdt:P279*/wdt:P17 wd:Q155.
  BIND(STRAFTER(STR(?item), "http://www.wikidata.org/entity/") AS ?qid)
  OPTIONAL { ?item wdt:P1448 ?name. }
  OPTIONAL { ?item wdt:P402 ?osm_relid .}
  OPTIONAL { ?item wdt:P625 ?wgs84 .}  
  OPTIONAL { ?item wdt:P1585 ?codIBGE .}
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en,[AUTO_LANGUAGE]". }
}
ORDER BY ?qid

Dumps

Em portugues seria:

SELECT DISTINCT ?iso2 ?qid ?qidLabel
WHERE {
  ?qid wdt:P297 _:b0.
  OPTIONAL { ?qid wdt:P1448 ?name .}
  OPTIONAL { ?qid wdt:P297 ?iso2 .}
  SERVICE wikibase:label { bd:serviceParam wikibase:language "pt-BR,pt,es,en" . }
}
ORDER BY ?iso2

O que estamos usando é

curl -o countries.csv -G 'https://query.wikidata.org/sparql' \
     --header "Accept: text/csv"  \
     --data-urlencode query='
 SELECT DISTINCT ?iso2 ?qid ?osm_relid ?itemLabel
 WHERE {
  ?item wdt:P297 _:b0.
  BIND(strafter(STR(?item),"http://www.wikidata.org/entity/") as ?qid).
  OPTIONAL { ?item wdt:P1448 ?name .}
  OPTIONAL { ?item wdt:P297 ?iso2 .}
  OPTIONAL { ?item wdt:P402 ?osm_relid .}
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en,[AUTO_LANGUAGE]" . }
 }
 ORDER BY ?iso2
'

Para acrescentar fragment com #defaultView:Table mais complicado, mas vale testar

curl -o test.html  -G 'https://query.wikidata.org/sparql?query=SELECT%20DISTINCT%20%3Fiso2%20%3Fqid%20%3FqidLabel%0AWHERE%20%7B%0A%20%20%3Fqid%20wdt%3AP297%20_%3Ab0.%0A%20%20OPTIONAL%20%7B%20%3Fqid%20wdt%3AP1448%20%3Fname%20.%7D%0A%20%20OPTIONAL%20%7B%20%3Fqid%20wdt%3AP297%20%3Fiso2%20.%7D%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20"en%2C%5BAUTO_LANGUAGE%5D"%20.%20%7D%0A%7D%0AORDER%20BY%20%3Fiso2%0A#defaultView:Table' 

Geral para PostgREST, wiki e cia

curl --header "Content-Type: application/json" \
  --request POST \
  --data '{"username":"xyz","password":"xyz"}' \
  http://localhost:3000/api/login