Jump to content

Module:bcl-headwordtest

Hali sa Wiksyunaryo

local export = {} local pos_functions = {}

-- WIKIDATA INTEGRATION: Load the required mw.wikibase library local mw_wikibase = require('mw.wikibase')

local lang = require("Module:languages").getByCode("bcl") local PAGENAME = mw.title.getCurrentTitle().text local script = require("Module:scripts").findBestScript(PAGENAME, lang)

-- ================================================================= -- WIKIDATA INTEGRATION: Helper function to find a specific form in a Lexeme -- feature_qid is the Wikidata Q-ID for the grammatical feature (e.g., 'Q146786' for plural) -- ================================================================= local function get_form_from_wikidata(entity, feature_qid) if not entity or not entity.forms then return nil end

for _, form in ipairs(entity.forms) do for _, feature in ipairs(form.grammaticalFeatures) do if feature == feature_qid then if form.representations and form.representations.bcl then return form.representations.bcl.value end end end end return nil -- Return nil if not found end

-- ================================================================= -- Main function -- ================================================================= 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 = {} if args["head"] or args[1] then table.insert(head, args["head"] or args[1]) end if args["head2"] or args[2] then table.insert(head, args["head2"] or args[2]) end if args["head3"] or args[3] then table.insert(head, args["head3"] or args[3]) end if #head == 0 then table.insert(head, PAGENAME) end

local data = {lang = lang, sc = script, pos_category = poscat, categories = {}, heads = head, translits = {"-"}, inflections = {}}

local entity = mw_wikibase.getEntityObject()

-- Baybayin spelling handling 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 #baybayin == 1 and entity then local baybayin_claim = mw_wikibase.getBestStatements(entity.id, 'P5008') if baybayin_claim and baybayin_claim[1] and baybayin_claim[1].mainsnak.datavalue then local baybayin_script = baybayin_claim[1].mainsnak.datavalue.value table.insert(baybayin, { term = baybayin_script, sc = sc_tglg }) end end

if #baybayin > 1 then table.insert(data.inflections, baybayin) end

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

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

if script:getCode() == "Latn" and not code then table.insert(tracking_categories, "Bikol Sentral na tataramon na mayong plantillang IPA") end

table.insert(data.categories, "Bikol Sentral na mga " .. poscat)

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

-- FIX: The full table must be included. local conjugation_types = { ["actor I"] = {"1st actor trigger", "Bikol Sentral 1st actor focus verbs"}, ["actor II"] = { "2nd actor trigger", "Bikol Sentral 2nd actor trigger verbs" }, ["actor III"] = { "3rd actor trigger", "Bikol Sentral 3rd actor trigger verbs" }, ["actor IV"] = { "4th actor trigger", "Bikol Sentral 4th actor trigger verbs" }, ["actor V"] = { "5th actor trigger", "Bikol Sentral 5th actor trigger verbs" }, ["actor VI"] = { "6th actor trigger", "Bikol Sentral 6th actor trigger verbs" }, ["actor VII"] = { "7th actor trigger", "Bikol Sentral 7th actor trigger verbs" }, ["actor VIII"] = { "8th actor trigger", "Bikol Sentral 8th actor trigger verbs" }, ["actor IX"] = { "9th actor trigger", "Bikol Sentral 9th actor trigger verbs" }, ["object I"] = { "1st object trigger", "Bikol Sentral 1st object trigger verbs" }, ["object II"] = { "2nd object trigger", "Bikol Sentral 2nd object trigger verbs" }, ["object III"] = { "3rd object trigger", "Bikol Sentral 3rd object trigger verbs" }, ["object IV"] = { "4th object trigger", "Bikol Sentral 4th object trigger verbs" }, ["object V"] = { "5th object trigger", "Bikol Sentral 5th object trigger verbs" }, ["object VI"] = { "6th object trigger", "Bikol Sentral 6th object trigger verbs" }, ["locative I"] = { "1st locative trigger", "Bikol Sentral 1st locative trigger verbs" }, ["locative II"] = { "2nd locative trigger", "Bikol Sentral 2nd locative trigger verbs" }, ["locative III"] = { "3rd locative trigger", "Bikol Sentral 3rd locative trigger verbs" }, ["locative IV"] = { "4th locative trigger", "Bikol Sentral 4th locative trigger verbs" }, ["locative V"] = { "5th locative trigger", "Bikol Sentral 5th locative trigger verbs" }, ["benefactive I"] = { "1st benefactive trigger", "Bikol Sentral 1st benefactive trigger verbs" }, ["benefactive II"] = { "2nd benefactive trigger", "Bikol Sentral 2nd benefactive trigger verbs" }, ["benefactive III"] = { "3rd benefactive trigger", "Bikol Sentral 3rd benefactive trigger verbs" }, ["instrument I"] = { "1st instrument trigger", "Bikol Sentral 1st instrument trigger verbs" }, ["instrument II"] = { "2nd instrument trigger", "Bikol Sentral 2nd instrument trigger verbs" }, ["reason"] = { "reason trigger", "Bikol Sentral reason trigger verbs" }, ["directional I"] = { "1st directional trigger", "Bikol Sentral 1st directional trigger verbs" }, ["directional II"] = { "2nd directional trigger", "Bikol Sentral 2nd directional trigger verbs" }, ["reference"] = { "reference trigger", "Bikol Sentral reference trigger verbs" }, ["reciprocal I"] = { "1st reciprocal trigger", "Bikol Sentral 1st reciprocal trigger verbs" }, ["reciprocal II"] = { "2nd reciprocal trigger", "Bikol Sentral 2nd reciprocal trigger verbs" }, }

pos_functions["berbo"] = function(args, data, entity) -- FIX: The full params table must be defined.

   local 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 = {}, b= {}, b2= {}, b3= {} } -- FIX: Process the arguments *before* you check them. local processed_args = require("Module:parameters").process(args,params) data.heads = processed_args.head data.id = processed_args.id

-- NOTE: The logic for verb forms is now corrected. -- It checks the processed arguments first, then falls back to Wikidata.

-- Handle Complete form if processed_args.comp and #processed_args.comp > 0 then processed_args.comp.label = "complete" table.insert(data.inflections, processed_args.comp) elseif entity then local comp_form = get_form_from_wikidata(entity, 'Q1855938') -- perfective aspect if comp_form then table.insert(data.inflections, {label = "complete", comp_form}) end end

-- Handle Progressive form if processed_args.prog and #processed_args.prog > 0 then processed_args.prog.label = "progresibo" table.insert(data.inflections, processed_args.prog) elseif entity then local prog_form = get_form_from_wikidata(entity, 'Q1991410') -- imperfective aspect if prog_form then table.insert(data.inflections, {label = "progresibo", prog_form}) end end

-- Handle Contemplative form if processed_args.cont and #processed_args.cont > 0 then