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
Baris 1:
local p = {}
local json = require("'mw.text').json")jsonDecode
local httpurlEncode = require("'mw.http"uri').encode
 
function p.queryfetchData(frame)
-- Define the SPARQL endpoint URL and the query
local endpointUrl = "'https://query.wikidata.org/sparql"'
local sparqlQuery = [[
SELECT ?id ?idLabel ?head
(SAMPLE(?pop) AS ?populasi)
(SAMPLE(?ison) AS ?iso)
Baris 12 ⟶ 14:
(SAMPLE(?gmbr) AS ?gmbr_)
(MIN(?partyId) AS ?geo)
else
-- The rest of your query goes here
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 . }
}
OPTIONAL { ?id wdt:P220 ?ison . }
OPTIONAL { ?id wdt:P1394 ?glotton . }
OPTIONAL { ?id wdt:P18 ?img . }
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/> .
-- Add the remaining parts of your WHERE clause here
}
GROUP BY ?id ?idLabel ?head ?headLabel ?link2 ?link ?geo
]]
 
-- PrepareBuild the HTTPURL requestwith the encoded query
local url = endpointUrl .. '?query=' .. urlEncode(sparqlQuery) .. '&format=json'
local http = require("mw.http")
 
local json = require("mw.text.json")
-- Fetch data from Wikidata
local resresult = mw.http.request {
url = endpointUrl,
methodurl = "POST"url,
headers = { ["'Accept"'] = "'application/sparql-results+json"' },
returnmethod result= 'GET'
body = "query=" .. mw.uri.encode(sparqlQuery),
}
 
-- ParseDecode andJSON processresponse theand responsereturn it
local data = json(result.body)
if res and res.status == 200 then
localreturn data = json.decode(res.body)
end
local result = ""
 
for i, binding in ipairs(data.results.bindings) do
function p.showData()
result = result .. binding.idLabel.value .. " (Population: " .. (binding.populasi and binding.populasi.value or "Unknown") .. ")<br/>"
local data = endp.fetchData()
-- Convert data into wikitext or HTML for display
return result
local resultoutput = ""
else
for i_, bindingitem in ipairs(data.results.bindings) do
return "Error retrieving data from SPARQL endpoint."
output = output .. "* " .. item.idLabel.value .. ": " .. item.populasi.value .. "\n"
end
return output
end