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

Konten dihapus Konten ditambahkan
Nyilvoskt (bicara | kontrib)
Tidak ada ringkasan suntingan
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').jsonDecode
local urlEncode = require('mw.uri').encode
 
function p.fetchDataqueryLink()
-- 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 14 ⟶ 12:
(SAMPLE(?gmbr) AS ?gmbr_)
(MIN(?partyId) AS ?geo)
(SAMPLE (?idLabel) AS ?title)
-- 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
]]
 
-- BuildCreate the URL withfor theWikidata encodedQuery queryService
local urlqueryUrl = endpointUrl 'https://query.wikidata. '?query=org/#' .. urlEncode(sparqlQuery) .. '&format=json'
 
-- FetchReturn dataa fromwikitext Wikidatalink to the query
return '[ ' .. queryUrl .. ' Klik untuk melihat data bahasa di Wikidata Query Service ]'
local result = mw.http.request {
url = 'https://wiki-indonesia.club',
headers = { ['Accept'] = 'application/sparql-results+json' },
method = 'GET'
}
 
-- Decode JSON response and return it
local data = json(result.body)
return data
end
 
function p.showData()
local data = p.fetchData()
-- Convert data into wikitext or HTML for display
local output = ""
for _, item in ipairs(data.results.bindings) do
output = output .. "* " .. item.idLabel.value .. ": " .. item.populasi.value .. "\n"
end
return output
end