Jump to content

Module:accel/bg

From Wiktionary, the free dictionary

This module contains new entry creation rules for Bulgarian; see WT:ACCEL for an overview, and Module:accel for information on creating new rules.


local rfind = mw.ustring.find
local rsplit = mw.text.split
local rsub = mw.ustring.sub

local function generate_pronunc(target)
	pronunc_parts = {}
	
	table.insert(pronunc_parts, "* {{bg-IPA|" .. target .. "}}")
	table.insert(pronunc_parts, "* {{bg-hyph}}")
	
	return table.concat(pronunc_parts, "\n")
end

-- Parses a participle form conveyed by inflection tags.
local function parse_participle_form(form)
	local part = {}; part.gender = nil; part.kind = nil
	local is_definite_form = false
	
	local tag_set = rsplit(form, "|")
	for _, tag in ipairs(tag_set) do
		if tag == "def" then is_definite_form = true
		elseif tag == "m" then part.gender = "m"
		elseif tag == "f" then part.gender = "f"
		elseif tag == "n" then part.gender = "n"
		elseif tag == "pres" then part.kind = "pres"
		elseif tag == "aor" then part.kind = "aor"
		elseif tag == "pass" then part.kind = "pass"
		elseif tag == "impf" then part.kind = "impf"
		elseif tag == "adv" then part.kind = "adv"
		end
	end
	
	part.is_base_form = part.kind == "adv" or
		((not is_definite_form) and part.gender == "m")
		
	return part
end

return {
	generate = function (params, entry)
		local form, target, pos = params.form, params.target, params.pos
		
		entry.pronunc = generate_pronunc(target)
		
		-- Special handling for relational adjectives of nouns
		if form == "relational adjective" then
			local declension_spec = "<!"
			if rsub(target, -2) == "ен" then
				declension_spec = declension_spec .. "*" -- Adjectives in -ен are usually reducible
			end

			entry.pos_header = "Adjective"
			entry.etymology = "{{rfe|bg}}"
			entry.head = "{{bg-adj|" .. target .. "}} <!-- Specify other template params if/as needed. -->"
			entry.def = "{{lb|bg|relational}} {{rfdef|bg}}"
			entry.declension = "{{bg-adecl|" .. target .. declension_spec .. ">}} <!-- CHECK ME -->\n"
		end
		
		-- Special handling for female equivalent nouns, noun diminutives and augmentatives,
		-- and abstract nouns from adjectives.
		if pos == "noun" and (form == "f" or form == "diminutive" or form == "augmentative" or form == "abstract noun") then
			entry.etymology = "{{rfe|bg}}"
			entry.declension = "{{bg-ndecl|" .. target .. "<>}} <!-- CHECK ME -->"
			
			if form == "f" then
				entry.head = "{{bg-noun|" .. target .. "|f}}"
			else
				entry.head = "{{bg-noun|" .. target .. "}} <!-- SPECIFY GENDER -->"
			end
		end
		
		-- Ensure participles and participle forms show under the correct POS header,
		-- and use the correct Bulgarian headword templates.
		if pos == "verb" and rfind(form, "|part$") then
			local part = parse_participle_form(form)
			
			entry.pos_header = "Participle"
			
			if part.is_base_form then
				if part.kind == "adv" or part.kind == "pass" or part.kind == "pres" then
					entry.head = "{{bg-part|" .. target .. "|" .. part.kind .. "}}"
				else
					-- Sometimes the past active aorist and past active imperfect participle
					-- have the same form. If we provide the participle kind to the headword template,
					-- Module:accel won't be able to merge the two inflections, so we have to
					-- do it manually when the non-lemma entry page is being created.
					entry.head = "{{bg-part|" .. target .. "}} <!-- SPECIFY past participle types: aor and/or impf! -->"
				end
			else
				-- For inflected participle forms, we just specify the gender (if in the singular).
				local gender = ""
				if part.gender then gender = "|g=" .. part.gender end
				entry.head = "{{bg-part form|" .. target .. gender .. "}}"
			end
		end
		
		-- Use appropriate headword and declension templates for verbal nouns.
		-- For now, only the base form of verbal nouns is handled.
		if pos == "verb" and form == "indef|s|vnoun" then
			local origin = params.origin
			
			entry.pos_header = "Noun"
			entry.head = "{{bg-verbal noun|" .. target .. "}}"
			entry.def = "{{verbal noun of|bg|" .. origin .. "}}"
			entry.declension = "{{bg-ndecl|" .. target .. "<>}} <!-- CHECK ME. Indicate /n:sg or alternate plurals as needed. -->"
			entry.etymology = "From {{affix|bg|" .. origin .. "|-не}}."
		end
	end
}