Modul:ProyekWiki Bahasa/pemeliharaan/peta/rawdata/2: Perbedaan antara revisi

Konten dihapus Konten ditambahkan
Nyilvoskt (bicara | kontrib)
←Membuat halaman berisi 'local p = {} function p.query(frame) -- Define the endpoint and query local endpointUrl = "https://query.wikidata.org/sparql" local sparqlQuery = [[ SELECT ?id ?idLabel ?head (SAMPLE(?pop) AS ?populasi) (SAMPLE(?ison) AS ?iso) (SAMPLE(?glotton) AS ?glotto) (SAMPLE(?img) AS ?img_) (SAMPLE(?gmbr) AS ?gmbr_) (MIN(?partyId) AS ?geo) WHERE { ?id wdt:P31 wd:Q34770 . ?id...'
Tag: Suntingan perangkat seluler Suntingan peramban seluler Suntingan seluler lanjutan
 
Nyilvoskt (bicara | kontrib)
Tidak ada ringkasan suntingan
Tag: Suntingan perangkat seluler Suntingan peramban seluler Suntingan seluler lanjutan
 
(2 revisi perantara oleh pengguna yang sama tidak ditampilkan)
Baris 1:
local p = {}
local jsonurlEncode = require("'mw.texturi').json")encode
 
function p.queryqueryLink(frame)
-- Define the endpoint andSPARQL query
local endpointUrl = "https://query.wikidata.org/sparql"
local sparqlQuery = [[
SELECT ?id ?idLabel ?head
Baris 12:
(SAMPLE(?gmbr) AS ?gmbr_)
(MIN(?partyId) AS ?geo)
(SAMPLE (?idLabel) AS ?title)
WHERE {
?id wdt:P31 wd:Q34770 .
?id wdt:P279 ?head .
?id wdt:P625 ?geo .
SERVICE wikibase:label {
bd:serviceParam wikibase:language "'id"' .
?head rdfs:label ?headLabel .
?id rdfs:label ?idLabel . }
end }
OPTIONAL { ?id wdt:P220 ?ison . }
OPTIONAL { ?id wdt:P1394 ?glotton . }
Baris 22 ⟶ 27:
OPTIONAL { ?id wdt:P1098 ?pop . }
OPTIONAL { ?id wdt:P1846 ?gmbr . }
?link schema:about ?head .
?link schema:isPartOf <https://wiki-indonesia.club/> .
?link2 schema:about ?id .
?link2 schema:isPartOf <https://wiki-indonesia.club/> .
}
GROUP BY ?id ?idLabel ?head ?headLabel ?link2 ?link ?geo
]]
 
-- PrepareCreate the HTTPURL requestfor Wikidata Query Service
local endpointUrlqueryUrl = "'https://query.wikidata.org/sparql"#' .. urlEncode(sparqlQuery)
local http = require("mw.http")
local json = require("mw.text.json")
local res = http.request {
url = endpointUrl,
method = "POST",
headers = { ["Accept"] = "application/sparql-results+json" },
body = "query=" .. mw.uri.encode(sparqlQuery),
}
 
-- ParseReturn anda processwikitext link to the responsequery
return '[ ' .. queryUrl .. ' Klik untuk melihat data bahasa di Wikidata Query Service ]'
if res and res.status == 200 then
local data = json.decode(res.body)
local result = ""
for i, binding in ipairs(data.results.bindings) do
result = result .. binding.idLabel.value .. " (Population: " .. (binding.populasi and binding.populasi.value or "Unknown") .. ")<br/>"
end
return result
else
return "Error retrieving data from SPARQL endpoint."
end
end