Module:akk-utilities

local export = {}

local sc = require("Module:scripts").getByCode("Latn") local lang = require("Module:languages").getByCode("akk") local m_utilities = require("Module:utilities") local m_links = require("Module:links") local m_headword = require("Module:headword") local rsplit = mw.text.split

function export.catfix return m_utilities.catfix(lang, sc) end

local function link(term, alt, id) if word == "" or word == "&mdash;" 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

local params = { [1] = {},		["nocat"] = { type = "boolean" }, ["plain"] = { type = "boolean" }, ["notext"] = { type = "boolean" }, ["sense"] = {}, }

local args = require("Module:parameters").process(frame:getParent.args,			params) local rootLetters = {}

if not args[1] and namespace == "Template" then rootLetters = {"k", "t", "b"} elseif args[1] then rootLetters = rsplit(args[1], "-") else rootLetters = rsplit(fulltitle, "-") end

local joined_root = table.concat(rootLetters, "-") 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, sc = sc, pos_category = "roots", categories = {}, heads = { joined_root } }))

table.insert(categories, "")

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( { "Akkadian terms belonging to the root " .. 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("Akkadian terms belonging to the root " .. joined_root .. sense_formatted, "pages") return " " .. table.concat(categories) end

end

end

return export