モジュール:sem-arb-utilities
表示
このモジュールについての説明文ページを モジュール:sem-arb-utilities/doc に作成できます
local export = {}
local lang = require("モジュール:languages").getByCode("ar")
local m_utilities = require("モジュール:utilities")
local m_links = require("モジュール:links")
local m_headword = require("モジュール:headword")
local rsplit = mw.text.split
local function link(term, alt, id)
if word == "" or word == "—" then
return word
else
return m_links.full_link({
term = term,
alt = alt,
lang = lang,
id = id,
}, face)
end
end
local function validateRoot(rootTable, joined_root)
if type(rootTable) ~= "table" then
error("rootTable is not a table", 2)
end
for i, letter in ipairs(rootTable) do
if mw.ustring.len(letter) > 1 then
error("'" .. letter .. "', the " .. ordinal[i] ..
" letter in the root '" .. joined_root ..
"' should be a single letter.")
end
end
end
function export.root(frame)
local output = {}
local categories = {}
local title = mw.title.getCurrentTitle()
local fulltitle = title.fullText
local namespace = title.nsText
if frame.args["lang"] then
lang = require("モジュール:languages").getByCode(frame.args["lang"])
end
local params = {
[1] = {},
["nocat"] = { type = "boolean" },
["plain"] = { type = "boolean" },
["notext"] = { type = "boolean" },
["sense"] = {},
}
local args = require("モジュール:parameters").process(frame:getParent().args,
params)
local rootLetters = {}
local separator = " "
if frame.args["lang"] ~= "acy" then
separator = " "
else
separator = "-"
end
if not args[1] and namespace == "テンプレート" then
if frame.args["lang"] ~= "acy" then rootLetters = {"ك", "ت", "ب"} else rootLetters = {"k", "t", "p"} end
elseif args[1] then
rootLetters = rsplit(args[1], separator)
else
rootLetters = rsplit(fulltitle, separator)
end
local joined_root = table.concat(rootLetters, separator)
validateRoot(rootLetters, joined_root)
local sense = args["sense"]
local sense_formatted = ""
if sense ~= nil then
sense_formatted = " (" .. sense .. ") "
end
if fulltitle == joined_root then
table.insert(output, m_headword.full_headword(
{
lang = lang,
pos_category = "語根",
categories = {},
heads = { joined_root }
}))
table.insert(categories, "[[カテゴリ:" .. lang:getCanonicalName() .. " 語根|" .. (args["sort"] or joined_root) .. "]]")
if args["nocat"] then
return table.concat(output)
else
return table.concat(output) .. table.concat(categories)
end
else
local link_text
link_text = link(joined_root, joined_root .. sense_formatted, sense)
table.insert(output, link_text)
table.insert(categories, m_utilities.format_categories(
{ lang:getCanonicalName() .. "語根" .. joined_root .. sense_formatted .. "に属する語"},
lang))
if args["nocat"] then
return table.concat(output)
elseif args["plain"] then
return table.concat(output)
else
local term_count = mw.site.stats.pagesInCategory(lang:getCanonicalName() .. "語根" .. joined_root .. sense_formatted .. "に属する語", "pages")
return "<table class=\"wikitable\" style=\"float: right; clear: right; text-align: center;\"><tr><th>[[語根]]</th></tr><tr><td>" .. link_text .. "</td></tr><tr><td>[[:カテゴリ:" .. lang:getCanonicalName() .. " 語根" .. joined_root .. sense_formatted .. "に属する語|" .. term_count .. " 項目" .. (term_count == 1 and "" or "") .. "]]</td></tr></table>" .. table.concat(categories)
end
end
end
return export