45,625
edits
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
local m_links = require("Module:links") | local m_links = require("Module:links") | ||
local m_utilities = require("Module:utilities") | local m_utilities = require("Module:utilities") | ||
local m_lang = require("Module:languages") | |||
local export = {} | local export = {} | ||
Line 10: | Line 11: | ||
local rfind = mw.ustring.find | local rfind = mw.ustring.find | ||
local rmatch = mw.ustring.match | local rmatch = mw.ustring.match | ||
local debug_force_cat = false -- if set to true, always display categories even on userspace pages | |||
-- ABOUT TEMPLATE AND DISPLAY HYPHENS: | -- ABOUT TEMPLATE AND DISPLAY HYPHENS: | ||
Line 137: | Line 141: | ||
-- Arabic scripts get added below | -- Arabic scripts get added below | ||
["Hani"] = no_display_hyphen, | ["Hani"] = no_display_hyphen, | ||
-- The following | -- The following is a mixture of several scripts. Hopefully | ||
-- the specs here are correct! | -- the specs here are correct! | ||
["Jpan"] = no_display_hyphen, | ["Jpan"] = no_display_hyphen, | ||
["Laoo"] = no_display_hyphen, | ["Laoo"] = no_display_hyphen, | ||
["Nshu"] = no_display_hyphen, | ["Nshu"] = no_display_hyphen, | ||
Line 148: | Line 151: | ||
display_hyphens[script] = arab_get_display_hyphen | display_hyphens[script] = arab_get_display_hyphen | ||
end | end | ||
local function glossary_link(entry, text) | |||
text = text or entry | |||
return "[[Appendix:Glossary#" .. entry .. "|" .. text .. "]]" | |||
end | |||
local function make_compound_type(typ, alttext) | |||
return { | |||
text = glossary_link(typ, alttext) .. " compound", | |||
cat = typ .. " compounds", | |||
} | |||
end | |||
-- Make a compound type entry with a simple rather than glossary link. | |||
-- These should be replaced with a glossary link when the entry in the glossary | |||
-- is created. | |||
local function make_non_glossary_compound_type(typ, alttext) | |||
local link = alttext and "[[" .. typ .. "|" .. alttext .. "]]" or "[[" .. typ .. "]]" | |||
return { | |||
text = link .. " compound", | |||
cat = typ .. " compounds", | |||
} | |||
end | |||
export.compound_types = { | |||
["alliterative"] = make_non_glossary_compound_type("alliterative"), | |||
["allit"] = "alliterative", | |||
["antonymous"] = make_non_glossary_compound_type("antonymous"), | |||
["ant"] = "antonymous", | |||
["bahuvrihi"] = make_compound_type("bahuvrihi", "bahuvrīhi"), | |||
["bahu"] = "bahuvrihi", | |||
["bv"] = "bahuvrihi", | |||
["coordinative"] = make_compound_type("coordinative"), | |||
["coord"] = "coordinative", | |||
["descriptive"] = make_compound_type("descriptive"), | |||
["desc"] = "descriptive", | |||
["determinative"] = make_compound_type("determinative"), | |||
["det"] = "determinative", | |||
["dvandva"] = make_compound_type("dvandva"), | |||
["dva"] = "dvandva", | |||
["endocentric"] = make_compound_type("endocentric"), | |||
["endo"] = "endocentric", | |||
["exocentric"] = make_compound_type("exocentric"), | |||
["exo"] = "exocentric", | |||
["karmadharaya"] = make_compound_type("karmadharaya", "karmadhāraya"), | |||
["karma"] = "karmadharaya", | |||
["kd"] = "karmadharaya", | |||
["rhyming"] = make_non_glossary_compound_type("rhyming"), | |||
["rhy"] = "rhyming", | |||
["synonymous"] = make_non_glossary_compound_type("synonymous"), | |||
["syn"] = "synonymous", | |||
["tatpurusa"] = make_compound_type("tatpurusa", "tatpuruṣa"), | |||
["tat"] = "tatpurusa", | |||
["tp"] = "tatpurusa", | |||
} | |||
local function pluralize(pos) | local function pluralize(pos) | ||
Line 160: | Line 222: | ||
end | end | ||
local function link_term(terminfo, display_term, lang, sc, sort_key) | local function make_entry_name_no_links(lang, term) | ||
-- Remove links and call lang:makeEntryName(term). | |||
return m_lang.getNonEtymological(lang):makeEntryName(m_links.remove_links(term)) | |||
end | |||
local function link_term(terminfo, display_term, lang, sc, sort_key, force_cat) | |||
local terminfo_new = require("Module:table").shallowcopy(terminfo) | local terminfo_new = require("Module:table").shallowcopy(terminfo) | ||
local result | local result | ||
terminfo_new.term = display_term | terminfo_new.term = display_term | ||
if terminfo_new.lang then | if terminfo_new.lang then | ||
result = require("Module:etymology").format_derived(lang, terminfo_new, sort_key) | result = require("Module:etymology").format_derived(lang, terminfo_new, sort_key, nil, | ||
force_cat or debug_force_cat) | |||
else | else | ||
terminfo_new.lang = lang | terminfo_new.lang = lang | ||
Line 172: | Line 240: | ||
result = m_links.full_link(terminfo_new, "term", false) | result = m_links.full_link(terminfo_new, "term", false) | ||
end | end | ||
if terminfo_new.q then | if terminfo_new.q then | ||
result = result .. " " .. require("Module:qualifier").format_qualifier(terminfo_new.q) | result = result .. " " .. require("Module:qualifier").format_qualifier(terminfo_new.q) | ||
end | end | ||
return result | return result | ||
end | end | ||
Line 191: | Line 259: | ||
scode = sc:getCode() | scode = sc:getCode() | ||
else | else | ||
lang = | lang = m_lang.getNonEtymological(lang) | ||
-- If we don't call shallowClone here, #possible_scripts always == 0. | -- If we don't call shallowClone here, #possible_scripts always == 0. | ||
-- Something weird to do with the metatable that's set on the table, | -- Something weird to do with the metatable that's set on the table, | ||
Line 240: | Line 308: | ||
return nil, nil | return nil, nil | ||
end | end | ||
local scode, thyph, dhyph = get_template_and_display_hyphens(part, lang, sc) | local scode, thyph, dhyph = get_template_and_display_hyphens(part, lang, sc) | ||
thyph = "([" .. thyph .. "])" | thyph = "([" .. thyph .. "])" | ||
Line 295: | Line 363: | ||
-- Iterate an array up to the greatest integer index found. | -- Iterate an array up to the greatest integer index found. | ||
local function ipairs_with_gaps(t) | local function ipairs_with_gaps(t) | ||
local | local indices = require("Module:table").numKeys(t) | ||
local max_index = #indices > 0 and math.max(unpack(indices)) or 0 | |||
local i = 0 | local i = 0 | ||
return function() | return function() | ||
Line 308: | Line 377: | ||
function export.show_affixes(lang, sc, parts, pos, sort_key, nocat) | -- Concatenate formatted parts together with any overall lit= spec plus categories, which are formatted | ||
-- by prepending the language name. The value of an entry in CATEGORIES can be either a string | |||
-- (which is formatted using SORT_KEY) or a table of the form {cat=CATEGORY, sort_key=SORT_KEY, sort_base=SORT_BASE}, | |||
-- specifying the sort key and sort base to use when formatting the category. If NOCAT is given, no | |||
-- categories are added. | |||
local function concat_parts(lang, parts_formatted, categories, nocat, sort_key, lit, force_cat) | |||
local cattext | |||
if nocat then | |||
cattext = "" | |||
else | |||
for i, cat in ipairs(categories) do | |||
if type(cat) == "table" then | |||
categories[i] = m_utilities.format_categories({lang:getCanonicalName() .. " " .. cat.cat}, lang, | |||
cat.sort_key, cat.sort_base, force_cat or debug_force_cat) | |||
else | |||
categories[i] = m_utilities.format_categories({lang:getCanonicalName() .. " " .. cat}, lang, | |||
sort_key, nil, force_cat or debug_force_cat) | |||
end | |||
end | |||
cattext = table.concat(categories) | |||
end | |||
return table.concat(parts_formatted, " +‎ ") .. (lit and ", literally " .. m_links.mark(lit, "gloss") or "") .. cattext | |||
end | |||
local function process_compound_type(typ, nocap, notext, has_parts) | |||
local text_sections = {} | |||
local categories = {} | |||
if typ then | |||
local typdata = export.compound_types[typ] | |||
if type(typdata) == "string" then | |||
typdata = export.compound_types[typdata] | |||
end | |||
if not typdata then | |||
error("Internal error: Unrecognized type '" .. typ .. "'") | |||
end | |||
local text = typdata.text | |||
if not nocap then | |||
text = require("Module:string utilities").ucfirst(text) | |||
end | |||
local cat = typdata.cat | |||
local oftext = typdata.oftext or "of" | |||
if not notext then | |||
table.insert(text_sections, text) | |||
if has_parts then | |||
table.insert(text_sections, " ") | |||
table.insert(text_sections, oftext) | |||
table.insert(text_sections, " ") | |||
end | |||
end | |||
table.insert(categories, cat) | |||
end | |||
return text_sections, categories | |||
end | |||
function export.show_affixes(lang, sc, parts, pos, sort_key, typ, nocap, notext, nocat, lit, force_cat) | |||
pos = pos or "word" | pos = pos or "word" | ||
pos = pluralize(pos) | pos = pluralize(pos) | ||
local text_sections, categories = process_compound_type(typ, nocap, notext, #parts > 0) | |||
-- Process each part | -- Process each part | ||
local parts_formatted = {} | local parts_formatted = {} | ||
local whole_words = 0 | local whole_words = 0 | ||
for i, part in ipairs_with_gaps(parts) do | for i, part in ipairs_with_gaps(parts) do | ||
part = part or {} | part = part or {} | ||
local part_lang = part.lang or lang | local part_lang = part.lang or lang | ||
local part_sc = part.sc or sc | local part_sc = part.sc or sc | ||
-- Is it an affix, and if so, what type of affix? | -- Is it an affix, and if so, what type of affix? | ||
local affix_type, display_term = get_affix_type(part_lang, part_sc, part.term) | local affix_type, display_term = get_affix_type(part_lang, part_sc, part.term) | ||
-- Make a link for the part | -- Make a link for the part | ||
if display_term == "" then | if display_term == "" then | ||
Line 333: | Line 462: | ||
table.insert(parts_formatted, "") | table.insert(parts_formatted, "") | ||
else | else | ||
table.insert(parts_formatted, link_term(part, display_term, lang, sc, sort_key)) | table.insert(parts_formatted, link_term(part, display_term, lang, sc, sort_key, force_cat)) | ||
end | end | ||
if affix_type then | if affix_type then | ||
-- Make a sort key | -- Make a sort key | ||
Line 341: | Line 470: | ||
local part_sort_base = nil | local part_sort_base = nil | ||
local part_sort = part.sort or sort_key | local part_sort = part.sort or sort_key | ||
if i == 1 and parts[2] and parts[2].term then | if i == 1 and parts[2] and parts[2].term then | ||
local part2_lang = parts[2].lang or lang | local part2_lang = parts[2].lang or lang | ||
local part2_sc = parts[2].sc or sc | local part2_sc = parts[2].sc or sc | ||
local part2_affix_type, part2_display_term = get_affix_type(part2_lang, part2_sc, parts[2].term) | local part2_affix_type, part2_display_term = get_affix_type(part2_lang, part2_sc, parts[2].term) | ||
part_sort_base = part2_lang | part_sort_base = make_entry_name_no_links(part2_lang, part2_display_term) | ||
end | end | ||
if affix_type == "infix" then affix_type = "interfix" end | if affix_type == "infix" then affix_type = "interfix" end | ||
if part.pos and rfind(part.pos, "patronym") then | if part.pos and rfind(part.pos, "patronym") then | ||
table.insert( | table.insert(categories, {cat="patronymics", sort_key=part_sort, sort_base=part_sort_base}) | ||
end | end | ||
if pos ~= "words" and part.pos and rfind(part.pos, "diminutive") then | if pos ~= "words" and part.pos and rfind(part.pos, "diminutive") then | ||
table.insert( | table.insert(categories, {cat="diminutive " .. pos, sort_key=part_sort, sort_base=part_sort_base}) | ||
end | end | ||
table.insert( | table.insert(categories, {cat=pos .. " " .. affix_type .. "ed with " .. make_entry_name_no_links(part_lang, display_term) .. (part.id and " (" .. part.id .. ")" or ""), sort_key=part_sort, sort_base=part_sort_base}) | ||
else | else | ||
whole_words = whole_words + 1 | whole_words = whole_words + 1 | ||
if whole_words == 2 then | if whole_words == 2 then | ||
table.insert( | table.insert(categories, "compound " .. pos) | ||
end | end | ||
end | end | ||
end | end | ||
-- If there are no categories, then there were no actual affixes, only regular | -- If there are no categories, then there were no actual affixes, only a single regular word. | ||
if #categories == 0 then | |||
if # | |||
error("The parameters did not include any affixes, and the word is not a compound. Please provide at least one affix.") | error("The parameters did not include any affixes, and the word is not a compound. Please provide at least one affix.") | ||
end | end | ||
table.insert(text_sections, concat_parts(lang, parts_formatted, categories, nocat, sort_key, lit, force_cat)) | |||
return table.concat(text_sections) | |||
end | end | ||
function export.show_compound(lang, sc, parts, pos, sort_key, nocat) | function export.show_compound(lang, sc, parts, pos, sort_key, typ, nocap, notext, nocat, lit, force_cat) | ||
pos = pos or " | pos = pos or "word" | ||
pos = pluralize(pos) | |||
local text_sections, categories = process_compound_type(typ, nocap, notext, #parts > 0) | |||
local parts_formatted = {} | local parts_formatted = {} | ||
table.insert(categories, "compound " .. pos) | |||
table.insert( | |||
-- Make links out of all the parts | -- Make links out of all the parts | ||
local whole_words = 0 | local whole_words = 0 | ||
Line 399: | Line 532: | ||
-- tracking purposes) | -- tracking purposes) | ||
if affix_type == "infix" then | if affix_type == "infix" then | ||
table.insert( | table.insert(categories, {cat=pos .. " interfixed with " .. make_entry_name_no_links(part_lang, display_term), sort_key=part.sort or sort_key}) | ||
else | else | ||
display_term = part.term | display_term = part.term | ||
Line 406: | Line 539: | ||
end | end | ||
end | end | ||
table.insert(parts_formatted, link_term(part, display_term, lang, sc, sort_key)) | table.insert(parts_formatted, link_term(part, display_term, lang, sc, sort_key, force_cat)) | ||
end | end | ||
table.insert(text_sections, concat_parts(lang, parts_formatted, categories, nocat, sort_key, lit, force_cat)) | |||
return table.concat(text_sections) | |||
end | end | ||
function export.show_compound_like(lang, sc, parts, sort_key, text, oftext, cat) | function export.show_compound_like(lang, sc, parts, sort_key, text, oftext, cat, lit, force_cat) | ||
local parts_formatted = {} | local parts_formatted = {} | ||
local | local categories = {} | ||
if cat then | if cat then | ||
table.insert( | table.insert(categories, cat) | ||
end | end | ||
-- Make links out of all the parts | -- Make links out of all the parts | ||
for i, part in ipairs(parts) do | for i, part in ipairs(parts) do | ||
table.insert(parts_formatted, link_term(part, part.term, lang, sc, sort_key)) | table.insert(parts_formatted, link_term(part, part.term, lang, sc, sort_key, force_cat)) | ||
end | end | ||
Line 435: | Line 569: | ||
table.insert(text_sections, " ") | table.insert(text_sections, " ") | ||
end | end | ||
table.insert(text_sections, | -- FIXME, should support nocat= | ||
table.insert(text_sections, concat_parts(lang, parts_formatted, categories, nil, sort_key, lit, force_cat)) | |||
return table.concat(text_sections | return table.concat(text_sections) | ||
end | end | ||
Line 458: | Line 592: | ||
local function insert_affix_category(categories, lang, pos, affix_type, part) | local function insert_affix_category(categories, lang, pos, affix_type, part, sort_key, sort_base) | ||
if part.term then | if part.term then | ||
local part_lang = part.lang or lang | local part_lang = part.lang or lang | ||
local cat = pos .. " " .. affix_type .. "ed with " .. make_entry_name_no_links(part_lang, part.term) .. (part.id and " (" .. part.id .. ")" or "") | |||
if sort_key or sort_base then | |||
table.insert(categories, {cat=cat, sort_key=sort_key, sort_base=sort_base}) | |||
else | |||
table.insert(categories, cat) | |||
end | |||
end | end | ||
end | end | ||
function export.show_circumfix(lang, sc, prefix, base, suffix, pos, sort_key, nocat) | function export.show_circumfix(lang, sc, prefix, base, suffix, pos, sort_key, nocat, lit, force_cat) | ||
local categories = {} | local categories = {} | ||
pos = pos or "word" | pos = pos or "word" | ||
pos = pluralize(pos) | pos = pluralize(pos) | ||
-- Hyphenate the affixes | -- Hyphenate the affixes | ||
make_part_affix(prefix, lang, sc, "prefix") | make_part_affix(prefix, lang, sc, "prefix") | ||
make_part_affix(suffix, lang, sc, "suffix") | make_part_affix(suffix, lang, sc, "suffix") | ||
-- Create circumfix term | -- Create circumfix term | ||
local circumfix = nil | local circumfix = nil | ||
if prefix.term and suffix.term then | if prefix.term and suffix.term then | ||
circumfix = prefix.term .. " " .. suffix.term | circumfix = prefix.term .. " " .. suffix.term | ||
Line 487: | Line 625: | ||
suffix.term = circumfix | suffix.term = circumfix | ||
end | end | ||
-- Make links out of all the parts | -- Make links out of all the parts | ||
local parts_formatted = {} | local parts_formatted = {} | ||
local sort_base = (base.lang or lang | local sort_base | ||
if base.term then | |||
table.insert(parts_formatted, link_term(prefix, prefix.term, lang, sc, sort_key)) | sort_base = make_entry_name_no_links(base.lang or lang, base.term) | ||
table.insert(parts_formatted, link_term(base, base.term, lang, sc, sort_key)) | end | ||
table.insert(parts_formatted, link_term(suffix, suffix.term, lang, sc, sort_key)) | |||
table.insert(parts_formatted, link_term(prefix, prefix.term, lang, sc, sort_key, force_cat)) | |||
table.insert(parts_formatted, link_term(base, base.term, lang, sc, sort_key, force_cat)) | |||
table.insert(parts_formatted, link_term(suffix, suffix.term, lang, sc, sort_key, force_cat)) | |||
-- Insert the categories | -- Insert the categories | ||
table.insert(categories, | table.insert(categories, {cat=pos .. " circumfixed with " .. make_entry_name_no_links(prefix.lang or lang, circumfix), sort_key=sort_key, sort_base=sort_base}) | ||
return | return concat_parts(lang, parts_formatted, categories, nocat, sort_key, lit, force_cat) | ||
end | end | ||
function export.show_confix(lang, sc, prefix, base, suffix, pos, sort_key, nocat) | function export.show_confix(lang, sc, prefix, base, suffix, pos, sort_key, nocat, lit, force_cat) | ||
pos = pos or "word" | pos = pos or "word" | ||
pos = pluralize(pos) | pos = pluralize(pos) | ||
-- Hyphenate the affixes | -- Hyphenate the affixes | ||
make_part_affix(prefix, lang, sc, "prefix") | make_part_affix(prefix, lang, sc, "prefix") | ||
make_part_affix(suffix, lang, sc, "suffix") | make_part_affix(suffix, lang, sc, "suffix") | ||
-- Make links out of all the parts | -- Make links out of all the parts | ||
local parts_formatted = {} | local parts_formatted = {} | ||
local prefix_sort_base | local prefix_sort_base | ||
if suffix.term then | if base and base.term then | ||
prefix_sort_base = (suffix.lang or lang | prefix_sort_base = make_entry_name_no_links(base.lang or lang, base.term) | ||
elseif suffix.term then | |||
prefix_sort_base = make_entry_name_no_links(suffix.lang or lang, suffix.term) | |||
end | end | ||
local | local categories = {} | ||
table.insert(parts_formatted, link_term(prefix, prefix.term, lang, sc, sort_key, force_cat)) | |||
table.insert(parts_formatted, link_term(prefix, prefix.term, lang, sc, sort_key)) | insert_affix_category(categories, lang, pos, "prefix", prefix, sort_key, prefix_sort_base) | ||
insert_affix_category( | |||
if base then | if base then | ||
table.insert(parts_formatted, link_term(base, base.term, lang, sc, sort_key, force_cat)) | |||
table.insert(parts_formatted, link_term(base, base.term, lang, sc, sort_key)) | |||
end | end | ||
table.insert(parts_formatted, link_term(suffix, suffix.term, lang, sc, sort_key)) | table.insert(parts_formatted, link_term(suffix, suffix.term, lang, sc, sort_key, force_cat)) | ||
insert_affix_category( | insert_affix_category(categories, lang, pos, "suffix", suffix) | ||
return | return concat_parts(lang, parts_formatted, categories, nocat, sort_key, lit, force_cat) | ||
end | end | ||
function export.show_infix(lang, sc, base, infix, pos, sort_key, nocat) | function export.show_infix(lang, sc, base, infix, pos, sort_key, nocat, lit, force_cat) | ||
local categories = {} | local categories = {} | ||
pos = pos or "word" | pos = pos or "word" | ||
pos = pluralize(pos) | pos = pluralize(pos) | ||
-- Hyphenate the affixes | -- Hyphenate the affixes | ||
make_part_affix(infix, lang, sc, "infix") | make_part_affix(infix, lang, sc, "infix") | ||
-- Make links out of all the parts | -- Make links out of all the parts | ||
local parts_formatted = {} | local parts_formatted = {} | ||
table.insert(parts_formatted, link_term(base, base.term, lang, sc, sort_key)) | table.insert(parts_formatted, link_term(base, base.term, lang, sc, sort_key, force_cat)) | ||
table.insert(parts_formatted, link_term(infix, infix.term, lang, sc, sort_key)) | table.insert(parts_formatted, link_term(infix, infix.term, lang, sc, sort_key, force_cat)) | ||
-- Insert the categories | -- Insert the categories | ||
insert_affix_category(categories, lang, pos, "infix", infix) | insert_affix_category(categories, lang, pos, "infix", infix) | ||
return | return concat_parts(lang, parts_formatted, categories, nocat, sort_key, lit, force_cat) | ||
end | end | ||
function export.show_prefixes(lang, sc, prefixes, base, pos, sort_key, nocat) | function export.show_prefixes(lang, sc, prefixes, base, pos, sort_key, nocat, lit, force_cat) | ||
pos = pos or "word" | pos = pos or "word" | ||
pos = pluralize(pos) | pos = pluralize(pos) | ||
-- Hyphenate the affixes | -- Hyphenate the affixes | ||
for i, prefix in ipairs(prefixes) do | for i, prefix in ipairs(prefixes) do | ||
Line 576: | Line 713: | ||
local first_sort_base = nil | local first_sort_base = nil | ||
local categories = {} | local categories = {} | ||
if prefixes[2] then | |||
first_sort_base = make_entry_name_no_links(prefixes[2].lang or lang, prefixes[2].term) | |||
elseif base then | |||
first_sort_base = make_entry_name_no_links(base.lang or lang, base.term) | |||
end | |||
for i, prefix in ipairs(prefixes) do | for i, prefix in ipairs(prefixes) do | ||
table.insert(parts_formatted, link_term(prefix, prefix.term, lang, sc, sort_key)) | table.insert(parts_formatted, link_term(prefix, prefix.term, lang, sc, sort_key, force_cat)) | ||
insert_affix_category(categories, lang, pos, "prefix", prefix | insert_affix_category(categories, lang, pos, "prefix", prefix, sort_key, i == 1 and first_sort_base or nil) | ||
end | end | ||
if base then | if base then | ||
table.insert(parts_formatted, link_term(base, base.term, lang, sc, sort_key, force_cat)) | |||
table.insert(parts_formatted, link_term(base, base.term, lang, sc, sort_key)) | |||
else | else | ||
table.insert(parts_formatted, "") | table.insert(parts_formatted, "") | ||
end | end | ||
return concat_parts(lang, parts_formatted, categories, nocat, sort_key, lit, force_cat) | |||
end | end | ||
function export.show_suffixes(lang, sc, base, suffixes, pos, sort_key, nocat) | function export.show_suffixes(lang, sc, base, suffixes, pos, sort_key, nocat, lit, force_cat) | ||
local categories = {} | local categories = {} | ||
pos = pos or "word" | pos = pos or "word" | ||
pos = pluralize(pos) | pos = pluralize(pos) | ||
-- Hyphenate the affixes | -- Hyphenate the affixes | ||
for i, suffix in ipairs(suffixes) do | for i, suffix in ipairs(suffixes) do | ||
make_part_affix(suffix, lang, sc, "suffix") | make_part_affix(suffix, lang, sc, "suffix") | ||
end | end | ||
-- Make links out of all the parts | -- Make links out of all the parts | ||
local parts_formatted = {} | local parts_formatted = {} | ||
if base then | if base then | ||
table.insert(parts_formatted, link_term(base, base.term, lang, sc, sort_key)) | table.insert(parts_formatted, link_term(base, base.term, lang, sc, sort_key, force_cat)) | ||
else | else | ||
table.insert(parts_formatted, "") | table.insert(parts_formatted, "") | ||
end | end | ||
for i, suffix in ipairs(suffixes) do | for i, suffix in ipairs(suffixes) do | ||
table.insert(parts_formatted, link_term(suffix, suffix.term, lang, sc, sort_key)) | table.insert(parts_formatted, link_term(suffix, suffix.term, lang, sc, sort_key, force_cat)) | ||
end | end | ||
-- Insert the categories | -- Insert the categories | ||
for i, suffix in ipairs(suffixes) do | for i, suffix in ipairs(suffixes) do | ||
Line 630: | Line 764: | ||
insert_affix_category(categories, lang, pos, "suffix", suffix) | insert_affix_category(categories, lang, pos, "suffix", suffix) | ||
end | end | ||
if suffix.pos and rfind(suffix.pos, "patronym") then | if suffix.pos and rfind(suffix.pos, "patronym") then | ||
table.insert(categories, | table.insert(categories, "patronymics") | ||
end | end | ||
end | end | ||
return | return concat_parts(lang, parts_formatted, categories, nocat, sort_key, lit, force_cat) | ||
end | end | ||
function export.show_transfix(lang, sc, base, transfix, pos, sort_key, nocat) | function export.show_transfix(lang, sc, base, transfix, pos, sort_key, nocat, lit, force_cat) | ||
local categories = {} | local categories = {} | ||
pos = pos or "word" | pos = pos or "word" | ||
pos = pluralize(pos) | pos = pluralize(pos) | ||
-- Hyphenate the affixes | -- Hyphenate the affixes | ||
make_part_affix(transfix, lang, sc, "transfix") | make_part_affix(transfix, lang, sc, "transfix") | ||
-- Make links out of all the parts | -- Make links out of all the parts | ||
local parts_formatted = {} | local parts_formatted = {} | ||
table.insert(parts_formatted, link_term(base, base.term, lang, sc, sort_key)) | table.insert(parts_formatted, link_term(base, base.term, lang, sc, sort_key, force_cat)) | ||
table.insert(parts_formatted, link_term(transfix, transfix.term, lang, sc, sort_key)) | table.insert(parts_formatted, link_term(transfix, transfix.term, lang, sc, sort_key, force_cat)) | ||
-- Insert the categories | -- Insert the categories | ||
insert_affix_category(categories, lang, pos, "transfix", transfix) | insert_affix_category(categories, lang, pos, "transfix", transfix) | ||
return | return concat_parts(lang, parts_formatted, categories, nocat, sort_key, lit, force_cat) | ||
end | end | ||
Line 674: | Line 808: | ||
error("Internal error: Invalid affix type " .. (affix_type or "(nil)")) | error("Internal error: Invalid affix type " .. (affix_type or "(nil)")) | ||
end | end | ||
if not term then | if not term then | ||
return nil | return nil | ||
Line 683: | Line 817: | ||
return usub(term, 2) | return usub(term, 2) | ||
end | end | ||
if affix_type == "circumfix" or affix_type == "transfix" then | if affix_type == "circumfix" or affix_type == "transfix" then | ||
return term | return term | ||
Line 689: | Line 823: | ||
affix_type = "infix" | affix_type = "infix" | ||
end | end | ||
local scode, thyph, dhyph = get_template_and_display_hyphens(term, lang, sc) | local scode, thyph, dhyph = get_template_and_display_hyphens(term, lang, sc) | ||
thyph = "([" .. thyph .. "])" | thyph = "([" .. thyph .. "])" | ||
-- Remove an asterisk if the morpheme is reconstructed and add it in the end. | -- Remove an asterisk if the morpheme is reconstructed and add it in the end. | ||
local reconstructed = "" | local reconstructed = "" | ||
Line 699: | Line 833: | ||
term = term:gsub("^%*", "") | term = term:gsub("^%*", "") | ||
end | end | ||
local beginning_hyphen = rmatch(term, "^" .. thyph .. ".*$") | local beginning_hyphen = rmatch(term, "^" .. thyph .. ".*$") | ||
local ending_hyphen = rmatch(term, "^.*" .. thyph .. "$") | local ending_hyphen = rmatch(term, "^.*" .. thyph .. "$") | ||
Line 734: | Line 868: | ||
error("Internal error: Bad affix type " .. affix_type) | error("Internal error: Bad affix type " .. affix_type) | ||
end | end | ||
return reconstructed .. term | return reconstructed .. term | ||
end | end | ||
return export | return export | ||