Module:sla-headword

Hello, you have come here looking for the meaning of the word Module:sla-headword. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:sla-headword, but we will also tell you about its etymology, its characteristics and you will know how to say Module:sla-headword in singular and plural. Everything you need to know about the word Module:sla-headword you have here. The definition of the word Module:sla-headword will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:sla-headword, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

local u = require("Module:string/char")
local unpack = unpack or table.unpack -- Lua 5.2 compatibility

local export = {}

local lang = require("Module:languages").getByCode("sla-pro")

local GRAVE = u(0x300)
local TILDE = u(0x303)
local MACRON = u(0x304)
local CARON = u(0x30C)
local DGRAVE = u(0x30F)
local INVBREVE = u(0x311)
local OGONEK = u(0x328)


-- This could be moved to the common module
local function are_accents_valid(word)
	-- Split into syllables
	local rest = word:gsub("^%*", "")
	local consonants, vowel
	local syllables = {}
	
	while true do
		consonants, rest = mw.ustring.match(rest, "^(*)(.-)$")
		
		-- Shift initial l, r to previous syllable where necessary
		if #syllables > 0 and mw.ustring.find(consonants, "^.") then
			syllables.vowel = syllables.vowel .. consonants:sub(1, 1)
			consonants = consonants:sub(2)
		end
		
		rest = mw.ustring.toNFD(rest)
		vowel, rest = mw.ustring.match(rest, "^(*)(.-)$")
		
		if not vowel then
			break
		end
		
		rest = mw.ustring.toNFC(rest)
		
		-- Recombine ě, ę, ǫ
		if vowel:sub(1, 1) == "e" and vowel:find(CARON, nil, true) then
			vowel = vowel:gsub("^e", "ě")
			vowel = vowel:gsub(CARON, "")
		elseif vowel:sub(1, 1) == "e" and vowel:find(OGONEK, nil, true) then
			vowel = vowel:gsub("^e", "ę")
			vowel = vowel:gsub(OGONEK, "")
		elseif vowel:sub(1, 1) == "o" and vowel:find(OGONEK, nil, true) then
			vowel = vowel:gsub("^o", "ǫ")
			vowel = vowel:gsub(OGONEK, "")
		end
		
		local dia = mw.ustring.sub(vowel, 2)
		vowel = mw.ustring.sub(vowel, 1, 1)
		
		table.insert(syllables, {consonants = consonants, vowel = vowel, dia = dia})
	end
	
	-- Check each syllable's diacritics
	for i, syllable in ipairs(syllables) do
		if syllable.dia ~= "" then
			-- Historical short or long vowel?
			if mw.ustring.find(syllable.vowel, "^$") then
				if i == 1 then
					if not (syllable.dia == GRAVE or syllable.dia == DGRAVE) then
						-- First syllable only allows short rising and falling
						return false
					end
				elseif i == #syllables and mw.ustring.find(syllable.vowel, "^$") then
					-- Final yer doesn't allow any diacritics
					return false
				elseif not (syllable.dia == GRAVE) then
					-- Any remaining vowels allow only short rising
					return false
				end
			else
				-- Acute and macron allowed on any long syllable
				if not (syllable.dia == GRAVE or syllable.dia == MACRON) then
					if i == 1 then
						if not (syllable.dia == TILDE or syllable.dia == INVBREVE) then
							-- First syllable only allows neoacute and circumflex
							return false
						end
					elseif i == #syllables then
						-- Last syllable doesn't allow any of the remaining diacritics
						return false
					elseif not (syllable.dia == TILDE) then
						-- Medial syllable only allows neoacute
						return false
					end
				end
			end
		end
	end
	
	return true
end

-- Checks if the accents in the headword conform to ].
local function check_accents(heads, categories)
	for _, head in ipairs(heads) do
		if not are_accents_valid(head) then
			table.insert(categories, lang:getCanonicalName() .. " entries with invalid diacritics")
		end
	end
end


function export.adjective(frame)
	local params = {
		 = {list = true},
		
		 = {},
		 = {list = true},
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	local data = {lang = lang, pos_category = "adjectives", categories = {}, heads = args, inflections = {}}
	
	if args == "adjective-forming suffixes" then
		data.pos_category = "suffixes"
		table.insert(data.categories, lang:getCanonicalName() .. " " .. args)
	end
	
	-- Comparative
	if args then
		args.label = "comparative"
		table.insert(data.inflections, args)
	end
	
	check_accents(data.heads, data.categories)
	
	return require("Module:headword").full_headword(data)
end


function export.adverb(frame)
	local params = {
		 = {},
		 = {},
		 = {list = true},
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	local data = {lang = lang, pos_category = "adverbs", categories = {}, heads = args}
	
	if args == "adverb-forming suffixes" then
		data.pos_category = "suffixes"
		table.insert(data.categories, lang:getCanonicalName() .. " " .. args)
	end
	
	if args then
		table.insert(data.categories, lang:getCanonicalName() .. " " .. args)
	end
	
	check_accents(data.heads, data.categories)
	
	return require("Module:headword").full_headword(data)
end


function export.noun(frame)
	local params = {
		 = {list = true, default = "?"},
		
		 = {},
		 = {list = true},
		 = {list = true},
		 = {list = true},
         = {list = true},
         = {list = true},
         = {list = true}
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	local data = {lang = lang, pos_category = "nouns", categories = {}, heads = args, genders = {}, inflections = {}}
	
	if args == "noun-forming suffixes" then
		data.pos_category = "suffixes"
		table.insert(data.categories, lang:getCanonicalName() .. " " .. args)
	end
	
	-- Genders
	for i, val in ipairs(args) do
		if val == "m" or val == "f" or val == "n" or val == "m-d" or val == "f-d" or val == "n-d" or val == "m-p" or val == "f-p" or val == "n-p" then
			table.insert(data.genders, val)
			
			if val == "m-d" or val == "f-d" or val == "n-d" then
				table.insert(data.categories, lang:getCanonicalName() .. " dualia tantum")
			elseif val == "m-p" or val == "f-p" or val == "n-p" then
				table.insert(data.categories, lang:getCanonicalName() .. " pluralia tantum")
			end
		else
			table.insert(data.genders, "?")
		end
	end
	
	-- add parameters
	for _, val in pairs {{ "f", "feminine" }, { "m", "masculine" }, {"dim", "diminutive"}, {"aug", "augmentative"}, {"adj", "related adjective"}} do
		local param_name, label = unpack(val)
		local forms = args
		if forms then
			forms.label = label
			table.insert(data.inflections, forms)
		end
	end

	check_accents(data.heads, data.categories)
	
	return require("Module:headword").full_headword(data)
end


function export.verb(frame)
	local params = {
		 = {list = true},
		 = {},
		 = {list = true},
		 = {list = true},
		 = {list = true},
		 = {list = true},
		 = {list = true},
		 = {list = true}
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	local data = {lang = lang, pos_category = "verbs", categories = {}, heads = args, genders = {}, inflections = {}}
	
	if args == "verb-forming suffixes" then
		data.pos_category = "suffixes"
		table.insert(data.categories, lang:getCanonicalName() .. " " .. args)
	end
	
	-- Aspects
	for i, val in ipairs(args) do
		if val == "pf" then
			table.insert(data.genders, val)
			table.insert(data.categories, lang:getCanonicalName() .. " perfective verbs")
		elseif (val == "impf") or (val == "impf-det") or (val == "impf-indet") or (val == "impf-freq") then	
			table.insert(data.genders, "impf")
			table.insert(data.categories, lang:getCanonicalName() .. " imperfective verbs")
		else
			table.insert(data.genders, "?")
		end
		
		if val == "impf-det" then
			table.insert(data.inflections, {label = "determinate"})
		elseif val == "impf-indet" then
			table.insert(data.inflections, {label = "indeterminate"})
		elseif val  == "impf-freq" then
			table.insert(data.inflections, {label = "indeterminate"})
			table.insert(data.inflections, {label = "frequentative"})
		end

	end
	
	-- Imperfective equivalent
	if args then
		args.label = "imperfective"
		table.insert(data.inflections, args)
	end
	
	-- Perfective equivalent
	if args then
		args.label = "perfective"
		table.insert(data.inflections, args)
	end
	
	--Indeterminate equivalent
	if args then
		args.label = "indeterminate"
		table.insert(data.inflections, args)
	end
	
	--Frequentative equivalent
	if args then
		args.label = "frequentative"
		table.insert(data.inflections, args)
	end
	
	--Imperfective determinate equivalent
	if args then
		args.label = "imperfective determinate"
		table.insert(data.inflections, args)
	end
	
	check_accents(data.heads, data.categories)
	
	return require("Module:headword").full_headword(data)
end

function export.root(frame)
	local params = {
		 = {list = true, default = "?"},
		
		 = {},
		 = {list = true},
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	local data = {lang = lang, pos_category = "roots", categories = {}, heads = args, genders = {}}

	check_accents(data.heads, data.categories)
	
	return require("Module:headword").full_headword(data)
end

return export