Module:list of families
Appearance
- The following documentation is located at Module:list of families/documentation. [edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
This module displays the table of families in Wiktionary:List of families. It makes a list of families from Module:families/data and compiles information about each family from there and from the language data modules.
local export = {}
local m_families = require("Module:families")
local m_families_data = require("Module:families/data")
local m_table = require("Module:table")
local concat = table.concat
local insert = table.insert
local remove = table.remove
local size = m_table.size
local sorted_pairs = m_table.sortedPairs
local filters = {}
function export.count()
return size(m_families_data)
end
local function populate(t, stat, stats)
for code, data in pairs(t) do
local fam = data[3]
while fam do
stats[fam][stat][code] = true
if fam == "qfa-not" then
break
end
fam = m_families_data[fam]
fam = fam and fam[3] or nil
end
end
for code, fam in pairs(stats) do
local list = {}
for k in pairs(fam[stat]) do
insert(list, k)
end
stats[code][stat] = list
end
end
function export.show(frame)
local args = frame.args
local filter = filters[args[1]]
local languages = require("Module:languages/data/all")
local stats = {}
for code in pairs(m_families_data) do
stats[code] = {langs = {}, subfams = {}}
end
populate(languages, "langs", stats)
populate(m_families_data, "subfams", stats)
local rows = {}
for code, data in sorted_pairs(m_families_data) do
if (not filter) or filter(code, data, args) then
local fam = m_families.makeObject(code, data)
local names = fam:getAllNames()
local name = remove(names, 1) -- Remove the canonical name.
local catname = fam:getCategoryName()
local parent_fam = fam:getFamily()
insert(rows, string.format(
' id="%s"\n' ..
'| <code>%s</code>\n' ..
'| [[:Category:%s|%s]]\n' ..
'| %s\n' ..
'| %s\n' ..
'| %u\n' ..
'| %u\n',
code, code,
catname, name,
(parent_fam ~= nil) and ('[[#' .. parent_fam:getCode() .. '|' .. parent_fam:getCanonicalName() .. ']]') or '',
#names > 0 and concat(names, ", ") or " ",
#stats[code].subfams,
#stats[code].langs
))
end
end
return
"{| class=\"wikitable sortable\"\n" ..
"! Code\n" ..
"! Canonical name\n" ..
"! Parent family\n" ..
"! Other names\n" ..
"! Subfamilies\n" ..
"! Languages\n" ..
"|-" .. concat(rows, "\n|-") .. "\n|}"
end
filters["three-letter code"] = function (code, data, args)
local firstletter = args[2]
return data[3] ~= "qfa-not" and code:find("^" .. (firstletter or "[a-z]") .. "[a-z][a-z]$") ~= nil
end
filters["exceptional"] = function (code, data, args)
return data[3] ~= "qfa-not" and code:find("-") ~= nil
end
filters["special"] = function (code, data, args)
return data[3] == "qfa-not"
end
return export