Module:Chak-utilities
- The following documentation is located at Module:Chak-utilities/documentation. [edit]
- Useful links: subpage list • transclusions • testcases • sandbox
Utilities for Chakobsa scripts. Implements {{chak-from-root}}
.
Exposed functions
l(term, face, alt)
- Creates a link to a Chakobsa lexeme - similar to
{{l|chak|term}}
is_geminate(char)
- returns true if the supplied 'character' is geminate
compress_consonants(str)
- Returns a 'compressed' version of the string where consonant digraphs are reduced to a single character and trigraph geminates are reduced to a geminate of a single character. Mostly for use with other functions for parsing.
expand_consonants(str)
- Returns an 'expanded' version of the string where reductions from
compress_consonants
are replaced with the original romanizations.
parse_consonants(str)
- Returns a string where the consonants have been split out, delimited by hyphens. Understands geminate consonants and considers them a 'single' consonant.
parse_root(root_str,expandFinal)
- Returns a table of parts of the root string is grouped by consonant and vowels. Example: "kkaalatg" > "kk","aa","l","a","tg". If expandFinal is true, returns the final part parsed out through
parse_consonants
The above example would be "kkaalatg" > "kk","aa","l","a","t-g". Used for inflection functions.
export = {}
local m_links = require("Module:links")
local m_utilities = require("Module:utilities")
local m_headword = require("Module:headword")
local lang = require("Module:Languages").getByCode("chak")
local function ine(x) -- If Not Empty
if x == "" then
return nil
else
return x
end
end
local function link(term, gloss, face, alt)
return m_links.full_link( { term = term, lang = lang, gloss = gloss }, face )
end
function export.extract_root(input)
input = string.gsub(input,'-',' ')
parts = mw.text.split(input,' ')
if parts == nil or #parts == 0 or #parts > 2 or parts[1] == '' then
error("Invalid string for root")
elseif #parts == 1 then
parts[2] = nil
end
return parts[1],parts[2]
end
function export.chak_root(frame)
local output = {}
local categories = {}
local title = mw.title.getCurrentTitle()
local fulltitle = title.fullText
local pagename = title.text
local namespace = title.nsText
local params = {
[1] = { alias_of = "root"},
[2] = { alias_of = "mod"},
["root"] = {},
["mod"] = {},
["nocat"] = { type = "boolean", default = false },
["plain"] = { type = "boolean", default = false },
["t"] = {},
["gloss"] = { alias_of = "t" },
["face"] = { default = "term" },
["notext"] = { type = "boolean", default = false },
["nolink"] = { type = "boolean", default = false },
}
local args = require("Module:parameters").process(frame:getParent().args, params)
if not args["root"] and namespace == "Template" then
args["root"] = "tes"
args["mod"] = "t"
elseif args["root"] and not mod then
args["root"],args["mod"] = export.extract_root(root)
else
args["root"],args["mod"] = export.extract_root(fulltitle)
end
local joined_root = args["root"].."-"..args["mod"]
if fulltitle == joined_root then
table.insert(output, m_headword.full_headword({lang = lang, pos_category = "roots", categories = {}, heads = { joined_root }}))
else
local link_text
if args["nolink"] then
link_text = link(nil, ine(args["gloss"]), args["face"], joined_root)
else
link_text = link(joined_root, ine(args["gloss"]), args["face"] )
end
table.insert(output, link_text)
table.insert(categories, m_utilities.format_categories( { "Chakobsa terms belonging to the root " .. joined_root }, lang) )
end
if args["plain"] then
return joined_root
elseif args["nocat"] then
return table.concat(output)
elseif args["notext"] then
return table.concat(categories)
else
return table.concat(output) .. table.concat(categories)
end
return output
end
return export