Module:accel/bg/sandbox


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

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
			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 = "{{rfinfl|bg}}"
		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
	end
}