Mô đun:ilo-headword

Từ điển mở Wiktionary
local export = {}
local pos_functions = {}

local lang = require("Module:languages").getByCode("ilo")
local PAGENAME = mw.title.getCurrentTitle().text
local script = lang:findBestScript(PAGENAME) -- Latn or Tglg

function export.show(frame)

	local tracking_categories = {}

	local args = frame:getParent().args
	local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")

	local head = {} -- supports multiple headword
	local function insert_head(arg)
		if arg == "" then
			-- track("blank-head")
			arg = PAGENAME
		end
		if arg then
			table.insert(head, arg)
		end
	end
	insert_head(args["head"] or args[1])
	insert_head(args["head2"] or args[2])
	insert_head(args["head3"] or args[3])

	local data = {lang = lang, sc = script, pos_category = poscat, categories = {}, heads = head, tr = tr, inflections = {}}
	
	local baybayin = {label = "chính tả Kur-itan"}
	local sc_Tglg = require("Module:scripts").getByCode("Tglg")
	if args["b"] then table.insert(baybayin, { term = args["b"], sc = sc_Tglg }) end
	if args["b2"] then table.insert(baybayin, { term = args["b2"], sc = sc_Tglg }) end
	if args["b3"] then table.insert(baybayin, { term = args["b3"], sc = sc_Tglg }) end
	if script:getCode() == "Latn" then
		if #baybayin > 0 then 
			table.insert(data.inflections, baybayin) 
			table.insert(data.categories, "Ilocano terms with Baybayin script")
		else
			table.insert(data.categories, "Ilocano terms without Baybayin script")
		end
	elseif script:getCode() == "Tglg" then
		--Categorize words with Kur-itan
        table.insert(data.categories, "Ilocano terms in Baybayin script")
    end

	-- Kur-itan to Latin
	local tr = args["tr"]
	if not tr then
		tr = require("Module:ilo-translit")
	end
	
	-- feminines and masculines
	local fem = {label = "giống cái"}
	if args["f"] then table.insert(fem, {term = args["f"]}) end
	if #fem > 0 then table.insert(data.inflections, fem) end
	
	local masc = {label = "giống đực"}	
	if args["m"] then table.insert(masc, {term = args["m"]}) end
	if #masc > 0 then table.insert(data.inflections, masc) end
	
	local collective = {label = "tập hợp" }	
	if args["collective"] then table.insert(collective, {term = args["collective"]}) end
	if #collective > 0 then table.insert(data.inflections, collective) end

	if pos_functions[poscat] then
		pos_functions[poscat](args, data)
	end

	local content = mw.title.new(PAGENAME):getContent()
	local code = content and mw.ustring.match(content, "{{ilo%-IPA[^}]*}}")

    --Categorize words without [[Template:ilo-IPA]]
	if script:getCode() == "Latn" and not code then
		table.insert(tracking_categories, "Ilocano terms without ilo-IPA template")
	end

	return require("Module:headword").full_headword(data) .. require("Module:utilities").format_categories(tracking_categories, lang)

end

local conjugation_types = {
	["actor I"] = {"1st actor trigger", "Ilocano 1st actor focus verbs"}, -- um- or -um-
	["actor II"] = { "2nd actor trigger", "Ilocano 2nd actor trigger verbs" }, -- ag-
	["actor III"] = { "3rd actor trigger", "Ilocano 3rd actor trigger verbs" }, -- mang-
	["actor IV"] = { "4th actor trigger", "Ilocano 4th actor trigger verbs" }, -- ma-
	["actor potentive I"] = { "1st actor trigger potential mood", "Ilocano 1st actor trigger potential mood verbs" }, -- maka-
	["actor potential II"] = { "2nd actor trigger potential mood", "Ilocano 2nd actor trigger potential mood verbs" }, -- makapag-
	["actor causative I"] = { "2nd actor trigger potential mood", "Ilocano 1st actor trigger causative mood verbs" }, -- agpa-
	["actor causative II"] = { "2nd actor trigger potential mood", "Ilocano 2nd actor trigger causative mood verbs" }, -- mangpa-
	["object"] = { "object trigger", "Ilocano object trigger verbs" }, -- -en
	["object potential"] = { "object trigger potential mood", "Ilocano object trigger potential mood verbs" }, -- ma-
	["object causative"] = { "2nd actor trigger potential mood", "Ilocano object trigger causative mood verbs" }, -- ipai-
    ["comitative"] = { "comitative trigger", "Ilocano comitative trigger verbs" }, -- ka-
	["comitative potential"] = { "comitative trigger potential mood", "Ilocano comitative trigger potential mood verbs" }, -- maka-
    ["comitative causative I"] = { "1st comitative trigger causative mood", "Ilocano 1st comitative trigger causative mood verbs" }, -- makapa-
    ["comitative causative II"] = { "2nd comitative trigger causative mood", "Ilocano 2nd comitative trigger causative mood verbs" }, -- makipa-
	["locative"] = { "locative trigger", "Ilocano locative trigger verbs" },-- -an
	["locative potential"] = { "locative trigger potential mood", "Ilocano locative trigger potential mood verbs" }, -- ma- -an
	["locative causative"] = { "locative trigger causative mood", "Ilocano locative trigger causative mood verbs" }, -- pa- -an
    ["thematic"] = { "thematic trigger", "Ilocano thematic trigger verbs" }, -- i-
    ["thematic potential"] = { "thematic trigger potential mood", "Ilocano thematic trigger potential mood verbs" }, -- mai-
	["thematic causative"] = { "thematic trigger causative mood", "Ilocano thematic trigger causative mood verbs" }, -- ipa-
	["benefactive"] = { "benefactive trigger", "Ilocano benefactive trigger verbs" }, -- i- -an
	["benefactive potential"] = { "benefactive trigger potential mood", "Ilocano thematic trigger potential mood verbs" }, -- mai- -an
	["benefactive causative"] = { "benefactive trigger causative mood", "Ilocano thematic trigger causative mood verbs" }, -- ipa- -an
	["instrument"] = { "instrument trigger", "Ilocano instrument trigger verbs" }, -- pag-
	["instrument potential"] = { "instrument trigger potential mood", "Ilocano instrument trigger potential mood verbs" }, -- mapag-
	["instrument causative"] = { "1st instrument trigger causative mood", "Ilocano 1st instrument trigger causative mood verbs" }, -- pagpa- -an
	["instrument causative II"] = { "2nd instrument trigger causative mood", "Ilocano 2nd instrument trigger causative mood verbs" }, -- panagpa- 

}

pos_functions["Động từ"] = function(args, data)

    params = {
		[1] = {alias_of = 'head'},
		[2] = {alias_of = 'perf'},
		[3] = {alias_of = 'imperf'},
		[4] = {alias_of = 'past_imperf'},
		[5] = {alias_of = 'fut'},
		head = {list = true},
		head2= {},
		head3= {},
		perf = {list = true},
		imperf = {list = true},
		past_imperf = {list = true},
		fut = {list = true},
		rootword = {},
		type = {},
        type2 = {},
        type3 = {},
		b= {},
		b2= {},
		b3= {}
	}

	local args = require("Module:parameters").process(args,params)
	data.heads = args.head
	data.id = args.id
	local pattern = args.pattern
	
	args.perf.label = "perfective"
	args.imperf.label = "imperfective"
	args.past_imperf.label = "past imperfective"
	args.fut.label = "future"

	args.perf.accel = {form = "perf"}
	args.imperf.accel = {form = "imperf"}
	args.past_imperf.accel = {form = "past|imperf"}
	args.fut.accel = {form = "fut"}


	if #args.perf > 0 then table.insert(data.inflections, args.perf) end
	if #args.imperf > 0 then table.insert(data.inflections, args.imperf) end
	if #args.past_imperf > 0 then table.insert(data.inflections, args.past_imperf) end
	if #args.fut > 0 then table.insert(data.inflections, args.fut) end

    --Tagging verb trigger
    local conjtype = args["type"] or nil
    if conjtype and conjugation_types[conjtype] then
		table.insert(data.inflections, {label = conjugation_types[conjtype][1]})
		table.insert(data.categories, conjugation_types[conjtype][2])
    end
    
        local conjtype = args["type2"] or nil
    if conjtype and conjugation_types[conjtype] then
		table.insert(data.inflections, {label = conjugation_types[conjtype][1]})
		table.insert(data.categories, conjugation_types[conjtype][2])
	end	
		
		    local conjtype = args["type3"] or nil
    if conjtype and conjugation_types[conjtype] then
		table.insert(data.inflections, {label = conjugation_types[conjtype][1]})
		table.insert(data.categories, conjugation_types[conjtype][2])
    end

end

pos_functions["Tính từ"] = function(args, data)

	--Mark adjective degrees
	    params = {
		[1] = {alias_of = 'head'},
		[2] = {alias_of = 'comp'},
		[3] = {alias_of = 'mod'},
		[4] = {alias_of = 'comp_sup'},
		[5] = {alias_of = 'abs_sup'},	
		[6] = {alias_of = 'int'},		
        head = {list = true},
		head2= {},
		head3= {},
		comp = {list = true},
		mod = {list = true},
		comp_sup = {list = true},
		abs_sup = {list = true},
		int = {list = true},
		b= {},
		b2= {},
		b3= {},
        tr= {}
	}
	
	local args = require("Module:parameters").process(args,params)
	data.heads = args.head
	data.id = args.id
	local pattern = args.pattern
	
	args.comp.label = "comparative"
	args.mod.label = "moderative"
	args.comp_sup.label = "comparative superlative"
	args.abs_sup.label = "absolutive superlative"
	args.int.label = "intensive"

	args.comp.accel = {form = "comparative"}
	args.mod.accel = {form = "moderative"}
	args.comp_sup.accel = {form = "comparative|superlative"}
	args.abs_sup.accel = {form = "absolutive|superlative"}
	args.int.accel = {form = "intensive"}

	if #args.comp > 0 then table.insert(data.inflections, args.comp) end
	if #args.mod > 0 then table.insert(data.inflections, args.mod) end
	if #args.comp_sup > 0 then table.insert(data.inflections, args.comp_sup) end
	if #args.abs_sup > 0 then table.insert(data.inflections, args.abs_sup) end
	if #args.int > 0 then table.insert(data.inflections, args.int) end
	
end

pos_functions["Danh từ"] = function(args, data)

	--Tagging plurals
	    params = {
		[1] = {alias_of = 'head'},
		head = {list = true},
		head2= {},
		head3= {},
		plural = {list = true},
		b= {},
		b2= {},
		b3= {},
        tr= {}
	}
	
	local args = require("Module:parameters").process(args,params)
	data.heads = args.head
	data.id = args.id
	local pattern = args.pattern
	
	args.plural.label = "số nhiều"

	args.plural.accel = {form = "plural"}

	if #args.plural > 0 then table.insert(data.inflections, args.plural) end
	
end

return export