မာတိကာသို့ ခုန်သွားရန်

မော်ဂျူး:tl-headword

ဝစ်ရှင်နရီ မှ

Documentation for this module may be created at မော်ဂျူး:tl-headword/doc

local export = {}
local pos_functions = {}

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

local function track(page)
	require("Module:debug/track")("tl-headword/" .. page)
	return true
end

function export.show(frame)
	local tracking_categories = {}

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

	local head = {} -- supports multiple headword
	-- This is bullshit, clean this up!
	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 = "Baybayin spelling"}
	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, "Tagalog terms with Baybayin script")
		else
			table.insert(data.categories, "Tagalog terms without Baybayin script")
		end
	elseif script:getCode() == "Tglg" then
		--Categorize words with Baybayin
        table.insert(data.categories, "Tagalog terms in Baybayin script")
    end

	-- Baybayin to Latin
	local tr = args["tr"]
	if not tr then
		tr = require("Module:tl-translit")
	end
	
	-- feminines and masculines
	local fem = {label = "ဣိတ္ထိလိင်"}
	if args["f"] then table.insert(fem, {term = args["f"]}) end
	if #fem > 0 then table.insert(data.inflections, fem) end
	
	local masc = {label = "ပုလ္လိင်"}	
	if args["m"] then table.insert(masc, {term = args["m"]}) end
	if #masc > 0 then table.insert(data.inflections, masc) end
	
	local plural = {label = "plural", accel = {form = "plural"} }	
	if args["plural"] then table.insert(plural, {term = args["plural"]}) end
	if #plural > 0 then table.insert(data.inflections, plural) end
	
	local collective = {label = "collective" }	
	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, "{{tl%-IPA[^}]*}}")

    --Categorize words without [[Template:tl-IPA]]
	if script:getCode() == "Latn" and not code then
		table.insert(tracking_categories, "Tagalog terms without tl-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", "Tagalog 1st actor focus verbs"},
	["actor II"] = { "2nd actor trigger", "Tagalog 2nd actor trigger verbs" },
	["actor III"] = { "3rd actor trigger", "Tagalog 3rd actor trigger verbs" },
	["actor IV"] = { "4th actor trigger", "Tagalog 4th actor trigger verbs" },
	["actor V"] = { "5th actor trigger", "Tagalog 5th actor trigger verbs" },
	["actor indirect"] = { "indirect actor trigger", "Tagalog indirect actor trigger verbs" },
	["actor 2nd indirect I"] = { "1st indirect actor trigger", "Tagalog 1st secondary indirect actor trigger verbs" },
	["actor 2nd indirect II"] = { "2nd indirect actor trigger", "Tagalog 2nd secondary indirect actor trigger verbs" },
	["actor 2nd indirect III"] = { "3rd indirect actor trigger", "Tagalog 3rd secondary indirect actor trigger verbs" },
	["actor 2nd indirect IV"] = { "4th indirect actor trigger", "Tagalog 4th second indirect actor trigger verbs" },
	["object I"] = { "1st object trigger", "Tagalog 1st object trigger verbs" },
	["object II"] = { "2nd object trigger", "Tagalog 2nd object trigger verbs" },
	["object III"] = { "3rd object trigger", "Tagalog 3rd object trigger verbs" },
	["object IV"] = { "4th object trigger", "Tagalog 4th object trigger verbs" },
	["object V"] = { "5th object trigger", "Tagalog 5th object trigger verbs" },
	["object VI"] = { "6th object trigger", "Tagalog 6th object trigger verbs" },
	["object VII"] = { "7th object trigger", "Tagalog 7th object trigger verbs" },
	["object VIII"] = { "8th object trigger", "Tagalog 8th object trigger verbs" },
	["object IX"] = { "9th object trigger", "Tagalog 9th object trigger verbs" },
	["object X"] = { "10th object trigger", "Tagalog 10th object trigger verbs" },
	["object XI"] = { "11th object trigger", "Tagalog 11th object trigger verbs" },
	["locative I"] = { "1st locative trigger", "Tagalog 1st locative trigger verbs" },
	["locative II"] = { "2nd locative trigger", "Tagalog 2nd locative trigger verbs" },
	["benefactive I"] = { "1st benefactive trigger", "Tagalog 1st benefactive trigger verbs" },
	["benefactive II"] = { "2nd benefactive trigger", "Tagalog 2nd benefactive trigger verbs" },
	["benefactive III"] = { "3rd benefactive trigger", "Tagalog 3rd benefactive trigger verbs" },
	["instrument I"] = { "1st instrument trigger", "Tagalog 1st instrument trigger verbs" },
	["instrument II"] = { "2nd instrument trigger", "Tagalog 2nd instrument trigger verbs" },
	["reason I"] = { "1st reason trigger", "Tagalog 1st reason trigger verbs" },
	["reason IA"] = { "alternate 1st reason trigger", "Tagalog alternate 1st reason trigger verbs" },
	["reason II"] = { "2nd reason trigger", "Tagalog 2nd reason trigger verbs" },
	["reason IIA"] = { "alternate 2nd reason trigger", "Tagalog alternate 2nd reason trigger verbs" },
	["reason III"] = { "3rd reason trigger", "Tagalog alternate 3rd reason trigger verbs" },
	["reason IIIA"] = { "alternate 3rd reason trigger", "Tagalog alternate 3rd reason trigger verbs" },
	["reason IV"] = { "4th reason trigger", "Tagalog 4th reason trigger verbs" },
	["directional I"] = { "1st directional trigger", "Tagalog 1st directional trigger verbs" },
	["directional II"] = { "2nd directional trigger", "Tagalog 2nd directional trigger verbs" },
	["directional III"] = { "3rd directional trigger", "Tagalog 3rd directional trigger verbs" },
	["directional IV"] = { "4th directional trigger", "Tagalog 4th directional trigger verbs" },
	["directional V"] = { "5th directional trigger", "Tagalog 5th directional trigger verbs" },
	["directional VI"] = { "6th directional trigger", "Tagalog 6th directional trigger verbs" },
	["reference"] = { "reference trigger", "Tagalog reference trigger verbs" },
	["reciprocal I"] = { "1st reciprocal trigger", "Tagalog 1st reciprocal trigger verbs" },
	["reciprocal II"] = { "2nd reciprocal trigger", "Tagalog 2nd reciprocal trigger verbs" },
}

pos_functions["verbs"] = function(args, data)

    params = {
		[1] = {alias_of = 'head'},
		[2] = {alias_of = 'comp'},
		[3] = {alias_of = 'prog'},
		[4] = {alias_of = 'cont'},
		head = {list = true},
		head2= {},
		head3= {},
		comp = {list = true},
		prog = {list = true},
		cont = {list = true},
		rootword = {},
		type = {},
        type2 = {},
        type3 = {},
		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 = "complete"
	args.prog.label = "progressive"
	args.cont.label = "contemplative"

	args.comp.accel = {form = "comp"}
	args.prog.accel = {form = "prog"}
	args.cont.accel = {form = "cont"}

	if #args.comp > 0 then table.insert(data.inflections, args.comp) end
	if #args.prog > 0 then table.insert(data.inflections, args.prog) end
	if #args.cont > 0 then table.insert(data.inflections, args.cont) end

    --Tagging root forms of verbs
	local rootword = args["rootword"] or nil
	if require("Module:yesno")(rootword) then 
		table.insert(data.inflections, {label = "root word"}) 
		table.insert(data.categories, "Tagalog roots")
	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["nouns"] = function(args, data)

	--Tagging root forms of nouns
	local rootword = args["rootword"] or nil 
	if require("Module:yesno")(rootword) then 
		table.insert(data.inflections, {label = "root word"}) 
		table.insert(data.categories, "Tagalog roots")
	end

end

return export