Lompat ke isi

Teknik Informatika/SPARQL

Dari Wikibuku bahasa Indonesia, sumber buku teks bebas
import sparql

q = ("""
SELECT ?item ?itemLabel 
WHERE 
{
  ?item wdt:P31 wd:Q5;
  wdt:P166 wd:Q1369309;
  wdt:P21 wd:Q6581072.

  SERVICE wikibase:label { bd:serviceParam wikibase:language "en,id". }
}
""")

result = sparql.query('https://query.wikidata.org/bigdata/namespace/wdq/sparql',q)

for row in result:
	values = sparql.unpack_row(row)
	print(values[0],values[1])


Seperti ini, templatenya kalau pakai Python. Pakai library sparql-client 3.8.

Select _ where

[sunting]
SELECT ?bookLabel ?authorLabel
WHERE
{
  ?book wdt:P7937 wd:Q8261.
  ?book wdt:P495 wd:Q252.
  ?book wdt:P50 ?author
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }
}


Query Lain

[sunting]