Module:de-headword and Module:de-headword/sandbox: Difference between pages

(Difference between pages)
Jump to navigation Jump to search
Content deleted Content added
m Protected "Module:de-headword": (bot) automatically protect highly visible templates/modules (reference score: 2000+ >= 1000) ([Edit=Allow only autoconfirmed users] (indefinite) [Move=Allow only autoconfirmed users] (indefinite))
 
No edit summary
 
Line 48: Line 48:
function export.show(frame)
function export.show(frame)
local args = frame:getParent().args
local args = frame:getParent().args
PAGENAME = mw.title.getCurrentTitle().text
PAGENAME = mw.title.getCurrentTitle().text


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


local function old_adjectives(class, args, data)
(class, args, data)
track("de-adj-old")
local params = {
local params = {
[1] = {list = "comp"},
[1] = {list = "comp"},
Line 105: Line 104:
end
end



pos_functions.adjectives = function(class, args, data, proper)
-- Compatibility with old calling convention, either if old= is given or any arg no longer supported is given.
if ine(args.old) or ine(args[2]) or ine(args.comp1) or ine(args.comp2) or ine(args.comp3) or
ine(args.sup1) or ine(args.sup2) or ine(args.sup3) or args[1] == "-" then
return old_adjectives(class, args, data)
else
-- Remove this code once we convert to the new format.
track("de-adj-need-old")
end

local alternant_multiword_spec = require("Module:de-adjective").do_generate_forms(args, nil, "from headword")
data.heads = alternant_multiword_spec.args.head
data.id = alternant_multiword_spec.args.id
data.sort = alternant_multiword_spec.args.sort

local function do_adj_form(slot, label, should_be_present, accel_form)
local forms = alternant_multiword_spec.forms[slot]
local retval
if not forms then
if not should_be_present then
return
end
retval = {label = "no " .. label}
else
retval = {label = label, accel = accel_form and {form = accel_form} or nil}
local prev_footnotes
for _, form in ipairs(forms) do
local footnotes = form.footnotes
if footnotes and prev_footnotes and require("Module:table").deepEquals(footnotes, prev_footnotes) then
footnotes = nil
end
prev_footnotes = form.footnotes
local quals, refs = require("Module:inflection utilities").fetch_headword_qualifiers_and_references(footnotes)
local term = form.form
table.insert(retval, {term = term, q = quals, refs = refs, genders = genders})
end
end

table.insert(data.inflections, retval)
end

if alternant_multiword_spec.props.indecl then
table.insert(data.inflections, {label = glossary_link("indeclinable")})
if alternant_multiword_spec.props.predonly then
table.insert(data.inflections, {label = "predicative only"})
elseif alternant_multiword_spec.props.nopred then
table.insert(data.inflections, {label = "no predicative form"})
end
else
if alternant_multiword_spec.props.nopred then
table.insert(data.inflections, {label = "no predicative form"})
end
do_adj_form("str_nom_m", "strong nominative masculine singular", true)
local should_comp_sup =
alternant_multiword_spec.forms.comp_pred or alternant_multiword_spec.forms.sup_pred or
alternant_multiword_spec.forms.comp_str_nom_m or alternant_multiword_spec.forms.sup_str_nom_m
if not should_comp_sup then
table.insert(data.inflections, {label = "not comparable"})
else
-- If there is no predicative comparative, but there is an attributive comparative, include it;
-- otherwise, include the predicative comparative (if any). If there is no comparative but a superlative,
-- this will display "no comparative".
if not alternant_multiword_spec.forms.comp_pred and alternant_multiword_spec.forms.comp_str_nom_m then
do_adj_form("comp_str_nom_m", "strong comparative nominative masculine singular", true)
else
do_adj_form("comp_pred", glossary_link("comparative"), true, "comparative")
end
-- Same as above, for the superlative.
if not alternant_multiword_spec.forms.sup_pred and alternant_multiword_spec.forms.sup_str_nom_m then
do_adj_form("sup_str_nom_m", "strong superlative nominative masculine singular", true)
else
do_adj_form("sup_pred", glossary_link("superlative"), true, "superlative")
end
end
end

-- Add categories.
for _, cat in ipairs(alternant_multiword_spec.categories) do
table.insert(data.categories, cat)
end

-- Use the "linked" form of the lemma as the head if no head= explicitly given.
data.no_redundant_head_cat = true -- always set since we have a different lemma linking algorithm from [[Module:headword]].
if #data.heads == 0 then
data.heads = {}
local lemmas = alternant_multiword_spec.forms.the_lemma or {}
for _, lemma_obj in ipairs(lemmas) do
local head = alternant_multiword_spec.args.nolinkhead and lemma_obj.form or
require("Module:headword utilities").add_lemma_links(lemma_obj.form, alternant_multiword_spec.args.splithyph)
local quals, refs = require("Module:inflection utilities").fetch_headword_qualifiers_and_references(lemma_obj.footnotes)
table.insert(data.heads, {term = head, q = quals, refs = refs})
end
end
end


local function old_nouns(class, args, data)
local function old_nouns(class, args, data)
Line 311: Line 215:
end
end


local m_de_noun = require("Module:de-noun")
local = require("Module:de-noun")
local alternant_multiword_spec = m_de_noun.do_generate_forms(args, nil, "from headword", proper)
data.heads = alternant_multiword_spec.args.head
data.heads = alternant_multiword_spec.args.head
data.genders = alternant_multiword_spec.genders
data.genders = alternant_multiword_spec.genders

data.id = alternant_multiword_spec.args.id
local function expand_footnotes_and_references(footnotes)
data.sort = alternant_multiword_spec.args.sort
if not proper then
if not then
return nil
data.pos_category = alternant_multiword_spec.pos
if alternant_multiword_spec.pos == "suffixes" then
table.insert(data.categories, "German noun-forming suffixes")
end
end
local quals, refs
end
for _, qualifier in ipairs(footnotes) do

local this_footnote, this_refs =
local function get_nom_articles(alternant_multiword_spec)
require("Module:inflection utilities").expand_footnote_or_references(qualifier, "return raw")
local articles = {}
if this_refs then
local m_table = require("Module:table")
if alternant_multiword_spec.number == "pl" then
if then
refs = this_refs
m_table.insertIfNot(articles, "[[die]]")
else
for _, gender in ipairs(alternant_multiword_spec.genders) do
if gender.spec == "m" then
m_table.insertIfNot(articles, "[[der]]")
elseif gender.spec == "f" then
m_table.insertIfNot(articles, "[[die]]")
elseif gender.spec == "n" then
m_table.insertIfNot(articles, "[[das]]")
else
else
for _, ref in ipairs(this_refs) do
error("Internal error: Unrecognized gender '" .. gender.spec .. "'")
table.insert(refs, ref)
end
end
end
end
if not quals then
end
quals = {this_footnote}
return table.concat(articles, "/")
end

local function get_gen_s_articles(alternant_multiword_spec)
local articles = {}
local m_table = require("Module:table")
if alternant_multiword_spec.number == "pl" then
error("Internal error: Should not be called on plural-only nouns")
else
for _, gender in ipairs(alternant_multiword_spec.genders) do
if gender.spec == "m" or gender.spec == "n" then
m_table.insertIfNot(articles, "[[des]]")
elseif gender.spec == "f" then
m_table.insertIfNot(articles, "[[der]]")
else
else
table.insert(quals, this_footnote)
error("Internal error: Unrecognized gender '" .. gender.spec .. "'")
end
end
end
end
end
end
return table.concat(articles, "/")
return ,
end
end


local function do_noun_form(slot, label, should_be_present, accel_form, genders, prefix)
local function do_noun_form(slot, label, should_be_present, accel_form, genders)
local forms = alternant_multiword_spec.forms[slot]
local forms = alternant_multiword_spec.forms[slot]
local retval
local retval
Line 381: Line 263:
end
end
prev_footnotes = form.footnotes
prev_footnotes = form.footnotes
local quals, refs = require("Module:inflection utilities").fetch_headword_qualifiers_and_references(footnotes)
local quals, refs = (footnotes)
local term = form.form
term = form.form
if prefix then
if not term:find("[%[%]]") then
term = "[[" .. term .. "]]"
end
term = prefix .. " " .. term
end
table.insert(retval, {term = term, q = quals, refs = refs, genders = genders})
end
end
end
end
Line 399: Line 274:
table.insert(data.inflections, {label = glossary_link("proper noun")})
table.insert(data.inflections, {label = glossary_link("proper noun")})
end
end
if alternant_multiword_spec.props.weak == true then
local decl_types = alternant_multiword_spec.decl_type
table.insert(data.inflections, {label = glossary_link("weak declension", "weak")})
if decl_types and #decl_types > 0 then
elseif alternant_multiword_spec.props.weak == "both" then
local decl_descs = {}
table.insert(data.inflections, {label = glossary_link("weak declension", "weak") .. " or " .. glossary_link("strong declension", "strong")})
for _, decl_type in ipairs(decl_types) do
table.insert(decl_descs, glossary_link(decl_type .. " declension", decl_type))
end
table.insert(data.inflections, {label = table.concat(decl_descs, " or ")})
end
local overall_adj = alternant_multiword_spec.props.overall_adj
local article = alternant_multiword_spec.props.article
local surname = alternant_multiword_spec.props.surname
local langname = alternant_multiword_spec.props.langname
local saw_f = false
local saw_mn = false
for _, gender in ipairs(alternant_multiword_spec.genders) do
if gender.spec == "f" then
saw_f = true
elseif gender.spec == "m" or gender.spec == "n" then
saw_mn = true
end
end
local fem_sg_only = not saw_mn and alternant_multiword_spec.number ~= "pl"
if not alternant_multiword_spec.first_noun and alternant_multiword_spec.first_adj then
table.insert(data.inflections, {label = "adjectival"})
end
if surname then
table.insert(data.inflections, {label = "surname"})
end
if langname then
table.insert(data.inflections, {label = "language name"})
end
end
if alternant_multiword_spec.number == "pl" then
if alternant_multiword_spec.number == "pl" then
table.insert(data.inflections, {label = glossary_link("plural only")})
table.insert(data.inflections, {label = glossary_link("plural only")})
else
end
if article then
table.insert(data.inflections, {label = "usually definite"})
end
if alternant_multiword_spec.number == "pl" then
if overall_adj then
do_noun_form("wk_nom_p", "definite plural", true, nil, nil, "[[die]]")
end
elseif surname then
do_noun_form("gen_m_s", "masculine genitive", true)
do_noun_form("gen_f_s", "feminine genitive", true)
do_noun_form("nom_p", "plural", true)
elseif langname then
do_noun_form("gen_s", "genitive", true)
do_noun_form("gen_s", "genitive", true)
do_noun_form("nom_s_alt", "alternative nominative (used with the definite article)", true)
do_noun_form("", "", )
do_noun_form("gen_s_alt", "alternative genitive", true)
-- There should be no plural; this will trigger the display of 'no plural'.
do_noun_form("nom_p", "plural", true)
elseif overall_adj then
if article then
if not fem_sg_only then
do_noun_form("wk_nom_s", "definite nominative", true, nil, nil, get_nom_articles(alternant_multiword_spec))
end
do_noun_form("wk_gen_s", "definite genitive", true, nil, nil, get_gen_s_articles(alternant_multiword_spec))
do_noun_form("wk_nom_p", "definite plural", not proper, nil, nil, "[[die]]")
else
do_noun_form("wk_nom_s", "definite nominative", true, nil, nil, get_nom_articles(alternant_multiword_spec))
do_noun_form("str_gen_s", "genitive", true, nil, nil, not saw_f and "([[des]])" or nil)
if saw_f then
do_noun_form("wk_gen_s", "definite genitive", true, nil, nil, get_gen_s_articles(alternant_multiword_spec))
end
do_noun_form("str_nom_p", "plural", not proper)
do_noun_form("wk_nom_p", "definite plural", nil, nil, nil, "[[die]]")
end
else
if article then
do_noun_form("gen_s", "definite genitive", true, nil, nil, get_gen_s_articles(alternant_multiword_spec))
do_noun_form("nom_p", "definite plural", not proper, nil, nil, "[[die]]")
else
do_noun_form("gen_s", "genitive", true)
do_noun_form("nom_p", "plural", not proper)
end
end
end
do_noun_form("dim", "diminutive", nil, "diminutive", {"n"})
-- FIXME: Should we include the article in the singular equivalent if .article is given? I have no examples to go by.
do_noun_form("sg", "singular")
do_noun_form("", "")
do_noun_form("dim", "diminutive", nil, "diminutive", {"n"}, article and "[[das]]" or nil)
do_noun_form("", "")
do_noun_form("m", "masculine", nil, nil, nil, article and "[[der]]" or nil)
do_noun_form("f", "feminine", nil, "feminine", nil, article and "[[die]]" or nil)
do_noun_form("n", "neuter", nil, "neuter", nil, article and "[[das]]" or nil)


-- Add categories.
-- Add categories.
Line 488: Line 295:


-- Use the "linked" form of the lemma as the head if no head= explicitly given.
-- Use the "linked" form of the lemma as the head if no head= explicitly given.
data.no_redundant_head_cat = true -- always set since we have a different lemma linking algorithm from [[Module:headword]].
if #data.heads == 0 then
if #data.heads == 0 then
data.heads = {}
data.heads = {}
local lemmas = m_de_noun.get_lemmas(alternant_multiword_spec, "linked variant")
local lemmas = .alternant_multiword_spec
for _, lemma_obj in ipairs(lemmas) do
for _, lemma_obj in ipairs(lemmas) do
-- FIXME, can't yet specify qualifiers or references for heads
local head = alternant_multiword_spec.args.nolinkhead and lemma_obj.form or
require("Module:headword utilities").add_lemma_links(lemma_obj.form, alternant_multiword_spec.args.splithyph)
.(., alternant_multiword_spec.args.
require("Module:headword utilities").add_lemma_links(lemma_obj.form, alternant_multiword_spec.args.splithyph))
if article and (not overall_adj or fem_sg_only) then
-- local quals, refs = expand_footnotes_and_references(lemma_obj.footnotes)
head = get_nom_articles(alternant_multiword_spec) .. " " .. head
-- table.insert(data.heads, {term = lemma_obj.form, qualifiers = quals, refs = refs})
end
local quals, refs = require("Module:inflection utilities").fetch_headword_qualifiers_and_references(lemma_obj.footnotes)
table.insert(data.heads, {term = head, q = quals, refs = refs})
end
end
end
end
Line 512: Line 316:
local params = {
local params = {
[1] = {list = "pres", required = true},
[1] = {list = "pres", required = true},
["pres_qual"] = {list = "pres\1_qual", allow_holes = true},
["pres_qual"] = {list = "pres", allow_holes = true},
[2] = {list = "past", required = true},
[2] = {list = "past", required = true},
["past_qual"] = {list = "past\1_qual", allow_holes = true},
["past_qual"] = {list = "past", allow_holes = true},
[3] = {list = "pp", required = true},
[3] = {list = "pp", required = true},
["pp_qual"] = {list = "pp\1_qual", allow_holes = true},
["pp_qual"] = {list = "pp", allow_holes = true},
[4] = {list = "pastsubj"},
[4] = {list = "pastsubj"},
["pastsubj_qual"] = {list = "pastsubj\1_qual", allow_holes = true},
["pastsubj_qual"] = {list = "pastsubj", allow_holes = true},
["aux"] = {list = true},
["aux"] = {list = true},
["aux_qual"] = {list = "aux\1_qual", allow_holes = true},
["aux_qual"] = {list = "aux", allow_holes = true},
["head"] = {list = true},
["head"] = {list = true},
["class"] = {list = true},
["class"] = {list = true},
Line 534: Line 338:
local into_table = accel_form and {label = label, accel = {form = accel_form}} or {label = label}
local into_table = accel_form and {label = label, accel = {form = accel_form}} or {label = label}
for i, form in ipairs(forms) do
for i, form in ipairs(forms) do
table.insert(into_table, {term = form, q = qualifiers[i] and {qualifiers[i]} or nil})
table.insert(into_table, {term = form, = qualifiers[i] and {qualifiers[i]} or nil})
end
end
return into_table
return into_table
Line 571: Line 375:
end
end
end
end
table.insert(inflection, {term = form.form, q = qualifiers})
table.insert(inflection, {term = form.form, = qualifiers})
end
end
return inflection
return inflection
Line 588: Line 392:


if #data.heads == 0 then
if #data.heads == 0 then
data.no_redundant_head_cat = true
for _, head in ipairs(alternant_multiword_spec.forms.infinitive_linked) do
for _, head in ipairs(alternant_multiword_spec.forms.infinitive_linked) do
table.insert(data.heads, head.form)
table.insert(data.heads, head.form)