|
|
| Line 62: |
Line 62: |
| local function ine(val) | | local function ine(val) |
| if val == "" then return nil else return val end | | if val == "" then return nil else return val end |
| end
| |
|
| |
| local function track(track_id, pos)
| |
| local tracking_pages = {}
| |
| insert(tracking_pages, "sh-headword/" .. track_id)
| |
| if pos then
| |
| insert(tracking_pages, "sh-headword/" .. track_id .. "/" .. pos)
| |
| end
| |
| require("Module:debug/track")(tracking_pages)
| |
| return true
| |
| end | | end |
|
| |
|
| Line 111: |
Line 101: |
|
| |
|
| local params = { | | local params = { |
| [1] = {list = "head", disallow_holes = true, template_default = def or "књи̏га"}, | | [1] = {list = "head", disallow_holes = true, template_default = def or "վիլֆը"}, |
| tr = {list = true, allow_holes = true}, | | tr = {list = true, allow_holes = true}, |
| id = true, | | id = true, |
| Line 117: |
Line 107: |
| -- no nolinkhead= because head in 1= should always be specified | | -- no nolinkhead= because head in 1= should always be specified |
| altform = boolean_param, | | altform = boolean_param, |
| json = boolean_param,
| |
| pagename = true, -- for testing | | pagename = true, -- for testing |
| } | | } |
| Line 171: |
Line 160: |
| | | |
| if sc:getCode() == "Latn" then | | if sc:getCode() == "Latn" then |
| other_sc = "Cyrl" | | other_sc = "Armn" |
| elseif sc:getCode() == "Cyrl" then | | elseif sc:getCode() == "Armn" then |
| other_sc = "Latn" | | other_sc = "Latn" |
| end | | end |
| Line 192: |
Line 181: |
| end | | end |
|
| |
|
| -- If pagename is Latin or Cyrillic, display the other-script transliteration as an inflection. Use manually | | -- If pagename is Latin or Armenian, display the other-script transliteration as an inflection. Use manually |
| -- specified translit if available, otherwise auto-translit. | | -- specified translit if available, otherwise auto-translit. |
| if other_sc then | | if other_sc then |
| Line 205: |
Line 194: |
| | | |
| if not tr then | | if not tr then |
| tr = require("Module:sh-translit").tr(require("Module:links").remove_links(head.term), "sh", sc:getCode()) | | tr = require("Module:sish-translit").tr(require("Module:links").remove_links(head.term), "sish", sc:getCode()) |
| end | | end |
| | | |
| Line 218: |
Line 207: |
| if head.tr then | | if head.tr then |
| if not other_sc then | | if not other_sc then |
| error(("Translit specified for head #%s when pagename is neither Latin nor Cyrillic"):format(i)) | | error(("Translit specified for head #%s when pagename is neither Latin nor Armenian"):format(i)) |
| end | | end |
| head.tr = nil | | head.tr = nil |
| Line 226: |
Line 215: |
|
| |
|
| local singular_poscat = require(en_utilities_module).singularize(actual_poscat) | | local singular_poscat = require(en_utilities_module).singularize(actual_poscat) |
|
| |
| local needs_accents = false
| |
| for _, head in ipairs(heads) do
| |
| -- FIXME, should split by space and check each word
| |
| local lower_nfd_head = ulower(unfd(head.term))
| |
| if rfind(lower_nfd_head, "[" .. vowels_that_can_bear_tone .. "]") and not
| |
| rfind(lower_nfd_head, "[" .. vowels_that_can_bear_tone .. "][" .. tonal_accents .. "]") then
| |
| needs_accents = true
| |
| break
| |
| end
| |
| end
| |
| if needs_accents then
| |
| insert(data.categories, "Requests for accents in " .. langname .. " " .. singular_poscat .. " entries")
| |
| end
| |
|
| |
| if pagename:find("^%-") and actual_poscat ~= "suffixes" and actual_poscat ~= "suffix forms" and
| |
| actual_poscat ~= "combining forms" then
| |
| data.is_suffix = true
| |
| data.pos_category = "suffixes"
| |
| insert(data.categories, langname .. " " .. singular_poscat .. "-forming suffixes")
| |
| insert(data.inflections, {label = singular_poscat .. "-forming suffix"})
| |
| end
| |
|
| |
| if pos_functions[poscat] then
| |
| pos_functions[poscat].func(args, data)
| |
| end
| |
|
| |
| -- unfd (mw.ustring.toNFD) performs decomposition, so letters that decompose to an ASCII vowel and a diacritic,
| |
| -- such as é, are counted as vowels and do not need to be included in the pattern.
| |
| if not pagename:find("[ %-]") and not rfind(ulower(unfd(pagename)), V) then
| |
| insert(data.categories, langname .. " words spelled without vowels")
| |
| end
| |
|
| |
| if args.json then
| |
| return require("Module:JSON").toJSON(data)
| |
| end
| |
| | | |
| return require(headword_module).full_headword(data) | | return require(headword_module).full_headword(data) |
| end | | end |
|
| |
| local function get_noun_params(is_proper)
| |
| return {
| |
| [2] = {default = "?", type = "genders"},
| |
| indecl = boolean_param,
| |
| m = list_param,
| |
| f = list_param,
| |
| adj = list_param,
| |
| pos = list_param,
| |
| dim = list_param,
| |
| aug = list_param,
| |
| pej = list_param,
| |
| dem = list_param,
| |
| fdem = list_param,
| |
| gen = list_param,
| |
| voc = list_param,
| |
| loc = list_param,
| |
| pl = list_param,
| |
| nompl = {alias_of = "pl", list = true, disallow_holes = true},
| |
| genpl = list_param,
| |
| }
| |
| end
| |
|
| |
| local function validate_genders(data, genders, categorize)
| |
| for _, g in ipairs(genders) do
| |
| local canon_g = valid_genders[g.spec]
| |
| if canon_g then
| |
| track("gender-" .. g.spec)
| |
| if canon_g ~= true then
| |
| g.spec = canon_g
| |
| end
| |
| if categorize then
| |
| -- Categorize by gender, in addition to what's done already by [[Module:gender and number]].
| |
| if g.spec == "m-an" then
| |
| insert(data.categories, langname .. " masculine animate nouns")
| |
| elseif g.spec == "m-in" then
| |
| insert(data.categories, langname .. " masculine inanimate nouns")
| |
| end
| |
| end
| |
| else
| |
| error("Unrecognized gender: '" .. g.spec .. "'")
| |
| end
| |
| end
| |
| end
| |
|
| |
| local function do_nouns(is_proper, args, data)
| |
| validate_genders(data, args[2], true)
| |
| data.genders = args[2]
| |
| if args.indecl then
| |
| insert(data.inflections, {label = glossary_link("indeclinable")})
| |
| insert(data.categories, langname .. " indeclinable nouns")
| |
| end
| |
|
| |
| -- Parse and insert an inflection not requiring additional processing into `data.inflections`. The raw arguments
| |
| -- come from `args[field]`, which is parsed for inline modifiers. `label` is the label that the inflections are
| |
| -- given; <<..>> ini the label is linked to the glossary). `accel` is the accelerator form, or nil.
| |
| local function handle_infl(field, label)
| |
| parse_and_insert_inflection("noun", data, args, field, label)
| |
| end
| |
|
| |
| handle_infl("gen", "<<genitive>> <<singular>>")
| |
| handle_infl("voc", "<<vocative>> <<singular>>")
| |
| handle_infl("loc", "<<locative>> <<singular>>")
| |
| handle_infl("pl", "<<nominative>> <<plural>>")
| |
| handle_infl("genpl", "<<genitive>> <<plural>>")
| |
| handle_infl("m", "male equivalent")
| |
| handle_infl("f", "female equivalent")
| |
| handle_infl("adj", "<<relational adjective>>")
| |
| handle_infl("pos", "<<possessive adjective>>")
| |
| handle_infl("dim", "<<diminutive>>")
| |
| handle_infl("aug", "<<augmentative>>")
| |
| handle_infl("pej", "<<pejorative>>")
| |
| handle_infl("dem", "<<demonym>>")
| |
| handle_infl("fdem", "female <<demonym>>")
| |
| end
| |
|
| |
| pos_functions["nouns"] = {
| |
| params = get_noun_params(false),
| |
| func = function(args, data)
| |
| return do_nouns(false, args, data)
| |
| end,
| |
| }
| |
|
| |
| pos_functions["proper nouns"] = {
| |
| params = get_noun_params("proper noun"),
| |
| func = function(args, data)
| |
| return do_nouns("proper noun", args, data)
| |
| end,
| |
| }
| |
|
| |
| local function do_gendered_pos(args, data)
| |
| validate_genders(data, args[2], true)
| |
| data.genders = args[2]
| |
| end
| |
|
| |
| local function get_gendered_params()
| |
| return {
| |
| [2] = {default = "?", type = "genders"},
| |
| }
| |
| end
| |
|
| |
| pos_functions["pronouns"] = {
| |
| params = get_gendered_params(),
| |
| func = do_gendered_pos,
| |
| }
| |
|
| |
| local function get_verb_params()
| |
| return {
| |
| [2] = {default = "?", type = "genders"},
| |
| pf = list_param,
| |
| impf = list_param,
| |
| pres = list_param,
| |
| pres3s = list_param,
| |
| pres3p = list_param,
| |
| past = list_param,
| |
| pastf = list_param,
| |
| pastn = list_param,
| |
| impft = list_param,
| |
| impft3s = list_param,
| |
| impft3p = list_param,
| |
| aor = list_param,
| |
| aor3s = list_param,
| |
| aor3p = list_param,
| |
| vn = list_param,
| |
| pradvp = list_param,
| |
| padvp = list_param,
| |
| pap = list_param,
| |
| papf = list_param,
| |
| papn = list_param,
| |
| ppp = list_param,
| |
| pppf = list_param,
| |
| pppn = list_param,
| |
| }
| |
| end
| |
|
| |
| local function do_verbs(pos, args, data)
| |
| for _, a in ipairs(args[2]) do
| |
| if a.spec == "both" then
| |
| a.spec = "biasp"
| |
| end
| |
| if a.spec == "pf-impf" or a.spec == "impf-pf" or a.spec == "dual" or a.spec == "ip" then
| |
| a.spec = "biasp"
| |
| end
| |
| if valid_aspects[a.spec] then
| |
| track("aspect-" .. a.spec)
| |
| else
| |
| error("Unrecognized aspect: '" .. a.spec .. "'")
| |
| end
| |
| if a.spec == "impf" and args.impf[1] then
| |
| error("Imperfective verbs cannot have an imperfective equivalent")
| |
| elseif a.spec == "pf" and args.pf[1] then
| |
| error("Perfective verbs cannot have a perfective equivalent")
| |
| end
| |
| end
| |
| data.genders = args[2]
| |
|
| |
| -- Parse and insert an inflection not requiring additional processing into `data.inflections`. The raw arguments
| |
| -- come from `args[field]`, which is parsed for inline modifiers. `label` is the label that the inflections are
| |
| -- given; <<..>> ini the label is linked to the glossary). `accel` is the accelerator form, or nil.
| |
| local function handle_infl(field, label)
| |
| parse_and_insert_inflection(pos, data, args, field, label)
| |
| end
| |
| handle_infl("pf", "perfective")
| |
| handle_infl("impf", "imperfective")
| |
| handle_infl("pres", "first-singular present")
| |
| handle_infl("pres3s", "third-singular present")
| |
| handle_infl("pres3p", "third-plural present")
| |
| handle_infl("impft", "first-singular imperfect")
| |
| handle_infl("impft3s", "third-singular imperfect")
| |
| handle_infl("impft3p", "third-plural imperfect")
| |
| handle_infl("aor", "first-singular aorist")
| |
| handle_infl("aor3s", "third-singular aorist")
| |
| handle_infl("aor3p", "third-plural aorist")
| |
| handle_infl("pap", "masculine singular past active participle")
| |
| handle_infl("papf", "feminine singular past active participle")
| |
| handle_infl("papn", "neuter singular past active participle")
| |
| handle_infl("ppp", "masculine singular past passive participle")
| |
| handle_infl("pppf", "feminine singular past passive participle")
| |
| handle_infl("pppn", "neuter singular past passive participle")
| |
| handle_infl("pradvp", "present adverbial participle")
| |
| handle_infl("padvp", "past adverbial participle")
| |
| handle_infl("vn", "verbal noun")
| |
| end
| |
|
| |
| pos_functions["verbs"] = {
| |
| params = get_verb_params(),
| |
| func = function(args, data)
| |
| do_verbs("verb", args, data)
| |
| end,
| |
| }
| |
|
| |
| pos_functions["verbal combining forms"] = {
| |
| params = get_verb_params(),
| |
| get_actual_pos = function(args)
| |
| return "combining forms"
| |
| end,
| |
| func = function(args, data)
| |
| do_verbs("combining form", args, data)
| |
| end,
| |
| }
| |
|
| |
| pos_functions["adjectives"] = {
| |
| params = {
| |
| def = list_param,
| |
| comp = list_param,
| |
| sup = list_param,
| |
| adv = list_param,
| |
| indecl = boolean_param,
| |
| },
| |
| func = function(args, data)
| |
| if args.indecl then
| |
| insert(data.inflections, {label = glossary_link("indeclinable")})
| |
| insert(data.categories, langname .. " indeclinable adjectives")
| |
| end
| |
| -- Parse and insert an inflection not requiring additional processing into `data.inflections`. The raw arguments
| |
| -- come from `args[field]`, which is parsed for inline modifiers. `label` is the label that the inflections are
| |
| -- given; <<..>> ini the label is linked to the glossary). `accel` is the accelerator form, or nil.
| |
| local function handle_infl(field, label)
| |
| parse_and_insert_inflection("adjective", data, args, field, label)
| |
| end
| |
| handle_infl("def", "definite")
| |
| handle_infl("comp", "<<comparative>>")
| |
| handle_infl("sup", "<<superlative>>")
| |
| handle_infl("adv", "derived adverb")
| |
| end,
| |
| }
| |
|
| |
| pos_functions["adverbs"] = {
| |
| params = {
| |
| comp = list_param,
| |
| sup = list_param,
| |
| },
| |
| func = function(args, data)
| |
| -- Parse and insert an inflection not requiring additional processing into `data.inflections`. The raw arguments
| |
| -- come from `args[field]`, which is parsed for inline modifiers. `label` is the label that the inflections are
| |
| -- given; <<..>> ini the label is linked to the glossary). `accel` is the accelerator form, or nil.
| |
| local function handle_infl(field, label)
| |
| parse_and_insert_inflection("adverb", data, args, field, label)
| |
| end
| |
| handle_infl("comp", "<<comparative>>")
| |
| handle_infl("sup", "<<superlative>>")
| |
| end,
| |
| }
| |
|
| |
|
| pos_functions["letters"] = { | | pos_functions["letters"] = { |
| Line 522: |
Line 232: |
| insert(data.inflections, {label = "lower case", args.lower}) | | insert(data.inflections, {label = "lower case", args.lower}) |
| end | | end |
| end,
| |
| }
| |
|
| |
| -----------------------------------------------------------------------------------------
| |
| -- Suffix forms --
| |
| -----------------------------------------------------------------------------------------
| |
|
| |
| pos_functions["suffix forms"] = {
| |
| params = {
| |
| [2] = {required = true, template_default = "noun"},
| |
| [3] = {type = "genders"},
| |
| },
| |
| func = function(args, data)
| |
| if args[3] then
| |
| validate_genders(data, args[3], false)
| |
| data.genders = args[3]
| |
| end
| |
| local suffix_type = {}
| |
| for _, typ in ipairs(split_on_comma(args[2])) do
| |
| insert(suffix_type, typ .. "-forming suffix")
| |
| end
| |
| insert(data.inflections, {label = "non-lemma form of " .. m_table.serialCommaJoin(suffix_type, {conj = "or"})})
| |
| end, | | end, |
| } | | } |
| Line 554: |
Line 242: |
| params = { | | params = { |
| [2] = {required = true, template_default = "interjection"}, -- actual part of speech | | [2] = {required = true, template_default = "interjection"}, -- actual part of speech |
| [3] = {type = "genders"},
| |
| }, | | }, |
| get_actual_pos = function(args) | | get_actual_pos = function(args) |
| return require(headword_module).canonicalize_pos(args[2]) | | return require(headword_module).canonicalize_pos(args[2]) |
| end,
| |
| func = function(args, data)
| |
| if data.is_suffix then
| |
| error("Can't use [[Template:sh-head]] with suffixes")
| |
| end
| |
| if args[3] then
| |
| validate_genders(data, args[3], false)
| |
| data.genders = args[3]
| |
| end
| |
| end, | | end, |
| } | | } |
|
| |
|
| return export | | return export |