Module:bg-headword: difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
support adj= |
support dim= for diminutives of nouns |
||
Line 133: | Line 133: | ||
["m"] = {list = true}, |
["m"] = {list = true}, |
||
["f"] = {list = true}, |
["f"] = {list = true}, |
||
["dim"] = {list = true}, |
|||
["adj"] = {list = true}, |
["adj"] = {list = true}, |
||
["id"] = {}, |
["id"] = {}, |
||
Line 168: | Line 169: | ||
f.label = "feminine" |
f.label = "feminine" |
||
table.insert(data.inflections, f) |
table.insert(data.inflections, f) |
||
end |
|||
local dim = args.dim |
|||
if #dim > 0 then |
|||
dim.label = "diminutive" |
|||
table.insert(data.inflections, dim) |
|||
end |
end |
||
local adj = args.adj |
local adj = args.adj |
Revision as of 01:34, 3 April 2020
- This module lacks a documentation subpage. Please create it.
- Useful links: subpage list • links • transclusions • testcases • sandbox
local export = {}
local pos_functions = {}
local lang = require("Module:languages").getByCode("bg")
local rfind = mw.ustring.find
local rsubn = mw.ustring.gsub
-- version of rsubn() that discards all but the first return value
local function rsub(term, foo, bar)
local retval = rsubn(term, foo, bar)
return retval
end
local function track(page)
require("Module:debug").track("bg-headword/" .. page)
return true
end
local function format(array, concatenater)
if #array == 0 then
return ""
else
local concatenated = table.concat(array, concatenater)
if concatenated == "" then
return ""
elseif rfind(concatenated, "'$") then
concatenated = concatenated .. " "
end
return "; ''" .. concatenated .. "''"
end
end
local function glossary_link(anchor, text)
text = text or anchor
return "[[Appendix:Glossary#" .. anchor .. "|" .. text .. "]]"
end
-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
local NAMESPACE = mw.title.getCurrentTitle().nsText
local PAGENAME = mw.title.getCurrentTitle().text
local iparams = {
[1] = {required = true},
["def"] = {},
["suff_type"] = {},
}
local iargs = require("Module:parameters").process(frame.args, iparams)
local args = frame:getParent().args
local poscat = iargs[1]
local def = iargs.def
local suff_type = iargs.suff_type
local postype = nil
if suff_type then
postype = poscat .. '-' .. suff_type
else
postype = poscat
end
local data = {lang = lang, categories = {}, heads = {}, genders = {}, inflections = {}}
local infl_classes = {}
local appendix = {}
local postscript = {}
if poscat == "suffixes" then
table.insert(data.categories, "Bulgarian " .. suff_type .. "-forming suffixes")
end
if pos_functions[postype] then
local new_poscat = pos_functions[postype](def, args, data, infl_classes, appendix, postscript)
if new_poscat then
poscat = new_poscat
end
end
data.pos_category = (NAMESPACE == "Reconstruction" and "reconstructed " or "") .. poscat
postscript = table.concat(postscript, ", ")
return
require("Module:headword").full_headword(data)
.. format(infl_classes, "/")
.. format(appendix, ", ")
.. (postscript ~= "" and " (" .. postscript .. ")" or "")
end
pos_functions["verbs"] = function(def, args, data, infl_classes, appendix)
local params = {
[1] = {alias_of = "head"},
["head"] = {list = true},
[2] = {},
["tr"] = {list = true, allow_holes = true},
["pf"] = {list = true},
["impf"] = {list = true},
["id"] = {},
}
local args = require("Module:parameters").process(args, params)
data.heads = args.head
data.translits = args.tr
data.id = args.id
if args[2] == "pf" then
data.genders = {"pf"}
elseif args[2] == "impf" then
data.genders = {"impf"}
elseif args[2] == "both" then
data.genders = {"impf", "pf"}
elseif args[2] then
error("Unrecognized aspect '" .. args[2] .. "'")
end
local pf = args.pf
if #pf > 0 then
pf.label = "perfective"
table.insert(data.inflections, pf)
end
local impf = args.impf
if #impf > 0 then
impf.label = "imperfective"
table.insert(data.inflections, impf)
end
end
local function nouns(pos, def, args, data, infl_classes, appendix)
local params = {
[1] = {alias_of = "head"},
["head"] = {list = true},
["tr"] = {list = true, allow_holes = true},
[2] = {alias_of = "g"},
["g"] = {list = true},
["m"] = {list = true},
["f"] = {list = true},
["dim"] = {list = true},
["adj"] = {list = true},
["id"] = {},
["indecl"] = {type = "boolean"},
}
local args = require("Module:parameters").process(args, params)
data.heads = args.head
data.translits = args.tr
local genders = {}
local cat2 = nil
for _, g in ipairs(args.g) do
if g == "m" or g == "m-p" then
cat2 = "Bulgarian masculine nouns"
elseif g == "f" or g == "f-p" then
cat2 = "Bulgarian feminine nouns"
elseif g == "n" or g == "n-p" then
cat2 = "Bulgarian neuter nouns"
elseif g ~= "p" then
error("Unrecognized gender: '" .. g .. "'")
end
table.insert(genders, g)
end
table.insert(data.categories, cat2)
if #genders > 1 then
table.insert(data.categories, "Bulgarian nouns with multiple genders")
end
data.genders = genders
local m = args.m
if #m > 0 then
m.label = "masculine"
table.insert(data.inflections, m)
end
local f = args.f
if #f > 0 then
f.label = "feminine"
table.insert(data.inflections, f)
end
local dim = args.dim
if #dim > 0 then
dim.label = "diminutive"
table.insert(data.inflections, dim)
end
local adj = args.adj
if #adj > 0 then
adj.label = "related adjective"
table.insert(data.inflections, adj)
end
if args.indecl then
table.insert(data.inflections, {label = "indeclinable"})
end
data.id = args.id
end
pos_functions["nouns"] = function(def, args, data, infl_classes, appendix)
return nouns("nouns", def, args, data, infl_classes, appendix)
end
pos_functions["proper nouns"] = function(def, args, data, infl_classes, appendix)
return nouns("proper nouns", def, args, data, infl_classes, appendix)
end
pos_functions["adverbs"] = function(def, args, data, infl_classes, appendix)
return adverbs("adverbs", def, args, data, infl_classes, appendix)
end
local function adjectives(pos, def, args, data, infl_classes, appendix)
local params = {
[1] = {alias_of = "head"},
["head"] = {list = true},
["tr"] = {list = true, allow_holes = true},
["g"] = {list = true},
["id"] = {},
}
local args = require("Module:parameters").process(args, params)
data.heads = args.head
data.translits = args.tr
data.genders = args.g
data.id = args.id
end
pos_functions["adjectives"] = function(def, args, data, infl_classes, appendix)
return adjectives("adjectives", def, args, data, infl_classes, appendix)
end
pos_functions["participles"] = function(def, args, data, infl_classes, appendix)
return adjectives("participles", def, args, data, infl_classes, appendix)
end
pos_functions["determiners"] = function(def, args, data, infl_classes, appendix)
return adjectives("determiners", def, args, data, infl_classes, appendix)
end
pos_functions["pronouns"] = function(def, args, data, infl_classes, appendix)
return adjectives("pronouns", def, args, data, infl_classes, appendix)
end
pos_functions["suffixes-adjective"] = function(def, args, data, infl_classes, appendix)
return adjectives("suffixes", def, args, data, infl_classes, appendix)
end
pos_functions["numerals-adjective"] = function(def, args, data, infl_classes, appendix)
return adjectives("numerals", def, args, data, infl_classes, appendix)
end
local function non_lemma_forms(def, args, data, infl_classes, appendix, postscript)
local params = {
[1] = {required = true, default = def}, -- headword or cases
["head"] = {list = true, require_index = true},
["g"] = {list = true},
["id"] = {},
}
local args = require("Module:parameters").process(args, params)
local heads = {args[1]}
for _, head in ipairs(args.head) do
table.insert(heads, head)
end
data.heads = heads
data.genders = args.g
data.id = args.id
end
pos_functions["noun forms"] = non_lemma_forms
pos_functions["proper noun forms"] = non_lemma_forms
pos_functions["pronoun forms"] = non_lemma_forms
pos_functions["verb forms"] = non_lemma_forms
pos_functions["adjective forms"] = non_lemma_forms
pos_functions["participle forms"] = non_lemma_forms
pos_functions["determiner forms"] = non_lemma_forms
pos_functions["numeral forms"] = non_lemma_forms
pos_functions["suffix forms"] = non_lemma_forms
return export