Module:ColorTree: Difference between revisions
Appearance
Created page with "local p = {} function p.display() local endpoint = "https://pac.cenagis.edu.pl/query/sparql" local sparql = [[ PREFIX wd: <https://pac.cenagis.edu.pl/entity/> PREFIX wdt: <https://pac.cenagis.edu.pl/prop/direct/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?rootLabel ?level1Label ?level2Label WHERE { BIND(wd:Q3 AS ?root) { ?level1 wdt:P2 ?root . FILTER NOT EXISTS { ?sub wdt:P2 ?level1 ...." |
new version |
||
| Line 2: | Line 2: | ||
function p.display() | function p.display() | ||
local | local rootId = "Q3" | ||
local | local rootLabel = mw.wikibase.getLabel(rootId) or rootId | ||
local html = "* '''" .. rootLabel .. "'''\n" | |||
local claims = mw.wikibase.getAllStatements(rootId, "P2") | |||
if not claims then | |||
return html | |||
local | |||
if not | |||
return | |||
end | end | ||
local | local level1_items = {} | ||
for _, claim in ipairs(claims) do | |||
if claim.mainsnak and claim.mainsnak.datavalue and claim.mainsnak.datavalue.value then | |||
local id = claim.mainsnak.datavalue.value.id | |||
if id then | |||
local label = mw.wikibase.getLabel(id) or id | |||
table.insert(level1_items, { id = id, label = label }) | |||
end | |||
end | |||
end | end | ||
table.sort(level1_items, function(a, b) return a.label < b.label end) | |||
for _, | for _, l1 in ipairs(level1_items) do | ||
html = html .. "** " .. l1.label .. "\n" | |||
local | |||
local sub_claims = mw.wikibase.getAllStatements(l1.id, "P2") | |||
if | if sub_claims then | ||
local level2_items = {} | |||
for _, sub_claim in ipairs(sub_claims) do | |||
if sub_claim.mainsnak and sub_claim.mainsnak.datavalue and sub_claim.mainsnak.datavalue.value then | |||
local sub_id = sub_claim.mainsnak.datavalue.value.id | |||
if sub_id then | |||
html = html .. "*** " .. | local sub_label = mw.wikibase.getLabel(sub_id) or sub_id | ||
table.insert(level2_items, sub_label) | |||
end | |||
end | |||
end | |||
table.sort(level2_items) | |||
for _, l2_label in ipairs(level2_items) do | |||
html = html .. "*** " .. l2_label .. "\n" | |||
end | |||
end | end | ||
end | end | ||
Latest revision as of 19:01, 23 June 2026
Documentation for this module may be created at Module:ColorTree/doc
local p = {}
function p.display()
local rootId = "Q3"
local rootLabel = mw.wikibase.getLabel(rootId) or rootId
local html = "* '''" .. rootLabel .. "'''\n"
local claims = mw.wikibase.getAllStatements(rootId, "P2")
if not claims then
return html
end
local level1_items = {}
for _, claim in ipairs(claims) do
if claim.mainsnak and claim.mainsnak.datavalue and claim.mainsnak.datavalue.value then
local id = claim.mainsnak.datavalue.value.id
if id then
local label = mw.wikibase.getLabel(id) or id
table.insert(level1_items, { id = id, label = label })
end
end
end
table.sort(level1_items, function(a, b) return a.label < b.label end)
for _, l1 in ipairs(level1_items) do
html = html .. "** " .. l1.label .. "\n"
local sub_claims = mw.wikibase.getAllStatements(l1.id, "P2")
if sub_claims then
local level2_items = {}
for _, sub_claim in ipairs(sub_claims) do
if sub_claim.mainsnak and sub_claim.mainsnak.datavalue and sub_claim.mainsnak.datavalue.value then
local sub_id = sub_claim.mainsnak.datavalue.value.id
if sub_id then
local sub_label = mw.wikibase.getLabel(sub_id) or sub_id
table.insert(level2_items, sub_label)
end
end
end
table.sort(level2_items)
for _, l2_label in ipairs(level2_items) do
html = html .. "*** " .. l2_label .. "\n"
end
end
end
return html
end
return p