Module:compound: Difference between revisions

Jump to navigation Jump to search
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 two are mixtures of several scripts. Hopefully
-- 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,
["Kore"] = 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 = require("Module:languages").getNonEtymological(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 max_index = math.max(unpack(require("Module:table").numKeys(t)))
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 categories_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:makeEntryName(part2_display_term)
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(categories_formatted, m_utilities.format_categories({lang:getCanonicalName() .. " patronymics"}, lang, part_sort, part_sort_base))
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(categories_formatted, m_utilities.format_categories({lang:getCanonicalName() .. " diminutive " .. pos}, lang, part_sort, part_sort_base))
table.insert(categories, {cat="diminutive " .. pos, sort_key=part_sort, sort_base=part_sort_base})
end
end
 
table.insert(categories_formatted, m_utilities.format_categories({lang:getCanonicalName() .. " " .. pos .. " " .. affix_type .. "ed with " .. part_lang:makeEntryName(display_term) .. (part.id and " (" .. part.id .. ")" or "")}, lang, part_sort, part_sort_base))
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(categories_formatted, m_utilities.format_categories({lang:getCanonicalName() .. " compound " .. pos}, lang, sort_key))
table.insert(categories, "compound " .. pos)
end
end
end
end
end
end
 
-- If there are no categories, then there were no actual affixes, only regular words.
-- If there are no categories, then there were no actual affixes, only a single regular word.
-- This function does not support compounds (yet?), so show an error.
if #categories == 0 then
if #categories_formatted == 0 then
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
 
return table.concat(parts_formatted, " +‎ ") .. (nocat and "" or table.concat(categories_formatted))
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 "words"
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 = {}
local categories_formatted = {}
table.insert(categories, "compound " .. pos)
table.insert(categories_formatted, m_utilities.format_categories({lang:getCanonicalName() .. " compound words"}, lang, sort_key))
 
-- 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(categories_formatted, m_utilities.format_categories({lang:getCanonicalName() .. " " .. pos .. " interfixed with " .. part_lang:makeEntryName(display_term)}, lang, part.sort or sort_key))
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
 
return table.concat(parts_formatted, " +‎ ") .. (nocat and "" or table.concat(categories_formatted))
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 categories_formatted = {}
local categories = {}


if cat then
if cat then
table.insert(categories_formatted, m_utilities.format_categories({lang:getCanonicalName() .. " " .. cat}, lang, sort_key))
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, table.concat(parts_formatted, " +‎ "))
-- FIXME, should support nocat=
table.insert(text_sections, table.concat(categories_formatted, ""))
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
table.insert(categories, lang:getCanonicalName() .. " " .. pos .. " " .. affix_type .. "ed with " .. part_lang:makeEntryName(part.term) .. (part.id and " (" .. part.id .. ")" or ""))
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):makeEntryName(base.term)
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, lang:getCanonicalName() .. " " .. pos .. " circumfixed with " .. (prefix.lang or lang):makeEntryName(circumfix))
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 table.concat(parts_formatted, " +‎ ") .. (nocat and "" or m_utilities.format_categories(categories, lang, sort_key, sort_base))
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):makeEntryName(suffix.term)
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 prefix_categories = {}
local categories = {}
local suffix_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(prefix_categories, lang, pos, "prefix", prefix)
 
if base then
if base then
if base.term then
table.insert(parts_formatted, link_term(base, base.term, lang, sc, sort_key, force_cat))
prefix_sort_base = (base.lang or lang):makeEntryName(base.term)
end
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(suffix_categories, lang, pos, "suffix", suffix)
insert_affix_category(categories, lang, pos, "suffix", suffix)
 
return table.concat(parts_formatted, " +‎ ") .. (nocat and "" or m_utilities.format_categories(prefix_categories, lang, sort_key, prefix_sort_base) .. m_utilities.format_categories(suffix_categories, lang, sort_key))
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 table.concat(parts_formatted, " +‎ ") .. (nocat and "" or m_utilities.format_categories(categories, lang, sort_key))
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)
if i > 1 and first_sort_base == nil then
first_sort_base = (prefix.lang or lang):makeEntryName(prefix.term)
end
end
end
 
if base then
if base then
if first_sort_base == nil then
table.insert(parts_formatted, link_term(base, base.term, lang, sc, sort_key, force_cat))
first_sort_base = (base.lang or lang):makeEntryName(base.term)
end
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
 
local first_category = table.remove(categories, 1)
return concat_parts(lang, parts_formatted, categories, nocat, sort_key, lit, force_cat)
return table.concat(parts_formatted, " +‎ ") .. (nocat and "" or m_utilities.format_categories({first_category}, lang, sort_key, first_sort_base) .. m_utilities.format_categories(categories, lang, sort_key))
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, lang:getCanonicalName() .. " patronymics")
table.insert(categories, "patronymics")
end
end
end
end
 
return table.concat(parts_formatted, " +‎ ") .. (nocat and "" or m_utilities.format_categories(categories, lang, sort_key))
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 table.concat(parts_formatted, " +‎ ") .. (nocat and "" or m_utilities.format_categories(categories, lang, sort_key))
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
-- For Vim, so we get 4-space tabs
-- vim: set ts=4 sw=4 noet: