Module:anui-headword: Difference between revisions

From Linguifex
Jump to navigation Jump to search
No edit summary
No edit summary
 
(50 intermediate revisions by the same user not shown)
Line 1: Line 1:
local match = mw.ustring.match
local match = mw.ustring.match
local u = mw. ustring.char
local u = mw.ustring.char
local gsub = mw.ustring.gsub
local gsub = mw.ustring.gsub
local sub = mw.ustring.sub


local TILDEA = u(0x0303) -- COMBINING TILDE ̃◌
local TILDEB = u(0x0330) -- COMBINING TILDE BELOW ̰◌
local TILDEB = u(0x0330) -- COMBINING TILDE BELOW ̰◌


Line 9: Line 9:


local lang = require("Module:languages").getByCode("art-nui")
local lang = require("Module:languages").getByCode("art-nui")
local args = frame:getParent().args
local deabb = {["adj"] = "adjectives", ["v"] = "verbs", ["adv"] = "adverbs",}
local deabb = {["adj"] = "adjectives", ["v"] = "verb", ["adv"] = "adverb",}
local data = {lang = lang, pos_category = deabb[args[1]], categories = {}, inflections = {},}


local function glossary_link(entry, text)
local function glossary_link(entry, text)
text = text or entry
text = text or entry
return "[[w:Appendix:Glossary#" .. entry .. "|" .. text .. "]]"
return "[[wikt:Appendix:Glossary#" .. entry .. "|" .. text .. "]]"
end
 
local consonant = "[ǃǂǁʘʼʇxqrʛɴɬšṣschjklmptŋṉṭṯ]"
local vowel = "[aeiouàèìòùãĩõũḛḭṵ" .. TILDEB .. "v@]"
 
local function m(word)
word = word:gsub("mʼm", "v")
word = word:gsub("(" .. vowel .. ")m", "%1ũ")
word = word:gsub("(" .. vowel .. "*)@(" .. vowel .. "*)", "%1@%2")
return word
end
end


local function redup(word)
local function redup(word)
word = word:gsub("([ḛḭṵaɔ]" .. TILDEB .. "?)", {["ḛ"] = "è", [""] = "ì", [""] = "ù", ["a" .. TILDEBELOW] = "à", ["ɔ" .. TILDEBELOW] = "ò"})
word = m(word)
 
-- CV > C₁(v)C₂V
local C = match(word, "^" .. vowel .. "?(" .. consonant .. "*)")
local V = mw.ustring.toNFD(match(word, consonant .. "*(" .. vowel .. "*)"))
V = V:gsub("ḛ", "e"); V = V:gsub("ḭ", "i"); V = V:gsub("ṵ", "u"); V = V:gsub("v", "u")
local r2 = match(word, C .. "(.*)")
local v = sub(V, 1, 1)
local ejective = C == "tɬʼ" or match(C, "^[ṭcq]ʼ$") ~= nil
local fricative = match(C, "[sšṣɬ][ʇǃǂǁʘ]") ~= nil
local nasal = match(C, "ɴ") ~= nil
local glottal = match(C, "[ʇǃǂǁʘṭcɬq]ʼ") ~= nil
local uvular = match(C, "x") ~= nil
if ejective then word = C .. C .. r2
elseif (nasal or fricative) or glottal then word = C .. (glottal and "" or v) .. gsub(C, "[sšṣɬ]([ʇǃǂǁʘ])", "%1") .. r2
elseif uvular then word = gsub(C, "([ʇǃǂǁʘ])x", "%1") .. v .. C .. r2
else word = C .. v .. C .. r2 end
local consonant = "[ǃǂǁʘʼxqrʛɴɬšṣchjklmptŋṉṭṯ]"
word = word: gsub("v", "mʼm"); word = word:gsub("ũ", "m"); word = word:gsub("@", "ʼ")
local vowel = "[aeiouàèìòùʼ]"
local C = match(word, consonant .. "*")
return word
return word
end
end


function export.show()
function export.show(frame)
local word = mw.title.getCurrentTitle().text or args["w"]
local args = frame:getParent().args
local word = args["w"] or mw.title.getCurrentTitle().text
local pos = args[1]; local f = args[2]
local pos = args[1]; local f = args[2]
local data = {lang = lang, pos_category = deabb[pos], heads = {word}, categories = {}, inflections = {},}
if f == '-' then
if f == '-' then
if pos == "adj" then
if pos == "adj" then
table.insert(data.inflections, {label = "not " .. glossary_link("comparable")})
table.insert(data.inflections, {label = "not " .. glossary_link("comparable")})
table.insert(data.categories, lang:getCanonicalName() .. " uncomparable adjectives")
table.insert(data.categories, lang:getCanonicalName() .. " uncomparable " .. deabb[pos])
end
end
elseif not pos == "v" then
elseif pos ~= "v" then
table.insert(data.inflections, {label = glossary_link("comparative"), redup(word)})
table.insert(data.inflections, {label = glossary_link("comparative"), redup(word)})
if pos == "adverbs" then table.insert(data.categories, lang:getCanonicalName() .. " comparative " .. pos) end
if pos == "adv" then table.insert(data.categories, lang:getCanonicalName() .. " comparative " .. deabb[pos]) end
else
else
table.insert(data.inflections, {label = glossary_link("applicative"), redup(word)})
table.insert(data.inflections, {label = "[[w:applicative voice|applicative]]", redup(word)})
end
end

Latest revision as of 13:45, 14 September 2022



local match = mw.ustring.match
local u = mw.ustring.char
local gsub = mw.ustring.gsub
local sub = mw.ustring.sub

local TILDEB = u(0x0330) -- COMBINING TILDE BELOW ̰◌

local export = {}

local lang = require("Module:languages").getByCode("art-nui")
local deabb = {["adj"] = "adjectives", ["v"] = "verbs", ["adv"] = "adverbs",}

local function glossary_link(entry, text)
	text = text or entry
	return "[[wikt:Appendix:Glossary#" .. entry .. "|" .. text .. "]]"
end

local consonant = "[ǃǂǁʘʼʇxqrʛɴɬšṣschjklmptŋṉṭṯ]"
local vowel = "[aeiouàèìòùãĩõũḛḭṵ" .. TILDEB .. "v@]"

local function m(word)
	word = word:gsub("mʼm", "v")
	word = word:gsub("(" .. vowel .. ")m", "%1ũ")
	word = word:gsub("(" .. vowel .. "*)@(" .. vowel .. "*)", "%1@%2")
	
	return word
end

local function redup(word)
	word = m(word)

	-- CV > C₁(v)C₂V
	local C = match(word, "^" .. vowel .. "?(" .. consonant .. "*)")
	local V = mw.ustring.toNFD(match(word, consonant .. "*(" .. vowel .. "*)"))
	V = V:gsub("ḛ", "e"); V = V:gsub("ḭ", "i"); V = V:gsub("ṵ", "u"); V = V:gsub("v", "u")
	
	local r2 = match(word, C .. "(.*)")
	local v = sub(V, 1, 1)
	
	local ejective = C == "tɬʼ" or match(C, "^[ṭcq]ʼ$") ~= nil
	local fricative = match(C, "[sšṣɬ][ʇǃǂǁʘ]") ~= nil
	local nasal = match(C, "ɴ") ~= nil
	local glottal = match(C, "[ʇǃǂǁʘṭcɬq]ʼ") ~= nil
	local uvular = match(C, "x") ~= nil
	
	if ejective then word = C .. C .. r2
	elseif (nasal or fricative) or glottal then word = C .. (glottal and "" or v) .. gsub(C, "[sšṣɬ]([ʇǃǂǁʘ])", "%1") .. r2
	elseif uvular then word = gsub(C, "([ʇǃǂǁʘ])x", "%1") .. v .. C .. r2
	else word = C .. v .. C .. r2 end
	
	word = word: gsub("v", "mʼm"); word = word:gsub("ũ", "m"); word = word:gsub("@", "ʼ")
	
	return word
end

function export.show(frame)
	local args = frame:getParent().args
	local word = args["w"] or mw.title.getCurrentTitle().text
	local pos = args[1]; local f = args[2]
	local data = {lang = lang, pos_category = deabb[pos], heads = {word}, categories = {}, inflections = {},}
	
	if f == '-' then
		if pos == "adj" then
			table.insert(data.inflections, {label = "not " .. glossary_link("comparable")})
			table.insert(data.categories, lang:getCanonicalName() .. " uncomparable " .. deabb[pos])
		end
	elseif pos ~= "v" then
		table.insert(data.inflections, {label = glossary_link("comparative"), redup(word)})
		if pos == "adv" then table.insert(data.categories, lang:getCanonicalName() .. " comparative " .. deabb[pos]) end
	else
		table.insert(data.inflections, {label = "[[w:applicative voice|applicative]]", redup(word)})
	end
	
	return require('Module:headword').full_headword(data)
end

return export