Ugrás a tartalomhoz

Modul:compound/hu

A Wikiszótárból, a nyitott szótárból

A modult a Modul:compound/hu/doc lapon tudod dokumentálni

local p = {}

local canonical = {
	["word"] = "*",
	["words"] = "*",
	["szó"] = "*",
	["szavak"] = "*",
	["noun"] = "noun",
	["nouns"] = "noun",
	["fn"] = "noun",
	["főnév"] = "noun",
	["főnevek"] = "noun",
	["adjective"] = "adjective",
	["adjectives"] = "adjective",
	["mn"] = "adjective",
	["melléknév"] = "adjective",
	["melléknevek"] = "adjective",
	["verb"] = "verb",
	["verbs"] = "verb",
	["ige"] = "verb",
	["igék"] = "verb",
	["adverb"] = "adverb",
	["adverbs"] = "adverb",
	["hsz"] = "adverb",
	["hat"] = "adverb",
	["határozószó"] = "adverb",
	["határozószók"] = "adverb",
}

local can2hun = {
	noun = "főnevek",
	adjective = "melléknevek",
	verb = "igék",
	adverb = "határozószók",
}

local function derivcat(term, pos_canonical)
	local pos_hun = can2hun[pos_canonical]
	if pos_hun then
		return string.format("%s képzős magyar %s", term, pos_hun)
	else
		-- pos_canoncial should not be "*"
		return nil
	end
end

function p.canonalize_pos(pos)
	return can2hun[canonical[pos]]
end

function p.get_category(pos, affix_type, part)
	local pos_canonical = canonical[pos]
	local term = part.term
	local data = mw.loadData("Modul:compound/hu/data")
	if pos_canonical then
		if affix_type == "prefix" then
			if (pos_canonical == "*" or pos_canonical == "verb") and data.verb_prefixes[term] then
				return term .. " igekötős magyar igék"
			else
				-- ??? Only verbs should have prefixes in Hungarian, and only
				-- from the set of known prefixes
				return nil
			end
		elseif  affix_type == "suffix" then
			if data.derivations["*"][term] then
				if data.derivations["*"][term][pos_canonical] then
					return derivcat(term, pos_canonical)
				else
					-- The word has a part of speech it should not have
					-- (e.g. verb with "-ista" suffix), or no part of speech was
					-- given (generic "word"/"*"), and we’re unable to guess it
					-- since there are multiple possibilities
					return nil
				end
			elseif data.derivations[pos_canonical][term] then
				return derivcat(term, pos_canonical)
			elseif pos_canonical == "*" then
				for n, v in pairs(data.derivations) do
					if v[term] then
						-- Let’s guess that it’s the given part of speech
						return derivcat(term, n)
					end
				end
				-- Unknown suffix
				return nil
			else
				-- This suffix is not known for this part of speech
				return nil
			end
		else
			-- Unknown/unhandled affix type
			return nil
		end
	else
		-- Unknown/unhandled part of speech
		return nil
	end
end

return p