Module:compound: Verskil tussen weergawes

Content deleted Content added
Pynappel (Besprekings | bydraes)
Nuwe bladsy geskep met 'local m_links = require("Module:links") local m_utilities = require("Module:utilities") local export = {} -- FIXME: should be script-based -- But we can't do that unles...'
 
Naudefj (Besprekings | bydraes)
Werk by vanaf en:
Lyn 4:
local export = {}
 
local u = mw.ustring.char
-- FIXME: should be script-based
local rsub = mw.ustring.gsub
-- But we can't do that unless we do script detection before linking.
local hyphensusub = {mw.ustring.sub
local ulen = mw.ustring.len
["ar"] = "ـ",
local rfind = mw.ustring.find
["fa"] = "ـ",
local rmatch = mw.ustring.match
["he"] = "־",
 
["ja"] = "",
-- ABOUT TEMPLATE AND DISPLAY HYPHENS:
["ko"] = "",
--
["yi"] = "־",
-- The "template hyphen" is the per-script hyphen character that is used in
["zh"] = "",
-- template calls to indicate that a term is an affix. This is always a single
-- Unicode char, but there may be multiple possible hyphens for a given script.
-- Normally this is just the regular hyphen character "-", but for some
-- non-Latin-script languages (currently only right-to-left languages), it
-- is different.
--
-- The "display hyphen" is the string (which might be an empty string) that
-- is added onto a term as displayed (and linked), to indicate that a term
-- is an affix. Currently this is always either the same as the template
-- hyphen or an empty string, but the code below is written generally enough
-- to handle arbitrary display hyphens. Specifically:
--
-- (1) For East Asian languages, the display hyphen is always blank.
-- (2) For Arabic-script languages, either tatweel (ـ) or ZWNJ (zero-width
-- non-joiner) are allowed as template hyphens, where ZWNJ is supported
-- primarily for Farsi, because some suffixes have non-joining behavior.
-- The display hyphen corresponding to tatweel is also tatweel, but the
-- display hyphen corresponding to ZWNJ is blank (tatweel is also the
-- default display hyphen, for calls to {{prefix}}/{{suffix}}/etc. that
-- don't include an explicit hyphen).
 
-- List of all Arabic scripts.
local arab_scripts = {
"Arab",
-- WTF? Why are there a zillion language-specific variants of the
-- Arabic script?
"fa-Arab",
"kk-Arab",
"ks-Arab",
"ku-Arab",
"ms-Arab",
"mzn-Arab",
"ota-Arab",
"pa-Arab",
"ps-Arab",
"sd-Arab",
"tt-Arab",
"ug-Arab",
"ur-Arab",
}
 
-- Per-script template hyphens. The template hyphen is what appears in the
-- {{affix}}/{{prefix}}/{{suffix}}/etc. template (in the wikicode). See below.
--
-- The value below is a string consisting of one or more hyphen characters.
-- If there is more than one character, a non-default function must be
-- specified for the script in display_hyphens[] so the correct display
-- hyphen will be specified when no template hyphen is given (in {{suffix}}/
-- {{prefix}}/etc.).
--
-- Script detection is normally done when linking, but we need to do it
-- earlier. However, under most circumstances we don't need to do script
-- detection. Specifically, we only need to do script detection for a given
-- language if
--
-- (a) the language has multiple scripts; and
-- (b) at least one of those scripts is listed below or in display_hyphens.
 
local ZWNJ = u(0x200C) -- zero-width non-joiner
local arab_hyphens = "ـ" .. ZWNJ .. "-"
local template_hyphens = {
-- Arabic scripts get added below
["Hebr"] = "־",
-- FIXME! What about the following right-to-left scripts?
-- Adlm (Adlam)
-- Armi (Imperial Aramaic)
-- Avst (Avestan)
-- Cprt (Cypriot)
-- Khar (Kharoshthi)
-- Mand (Mandaic/Mandaean)
-- Mani (Manichaean)
-- Mend (Mende/Mende Kikakui)
-- Narb (Old North Arabian)
-- Nbat (Nabataean/Nabatean)
-- Nkoo (N'Ko)
-- Orkh (Orkhon runes)
-- Phli (Inscriptional Pahlavi)
-- Phlp (Psalter Pahlavi)
-- Phlv (Book Pahlavi)
-- Phnx (Phoenician)
-- Prti (Inscriptional Parthian)
-- Rohg (Hanifi Rohingya)
-- Samr (Samaritan)
-- Sarb (Old South Arabian)
-- Sogd (Sogdian)
-- Sogo (Old Sogdian)
-- Syrc (Syriac)
-- Thaa (Thaana)
}
for _, script in ipairs(arab_scripts) do
template_hyphens[script] = arab_hyphens
end
 
-- Default display-hyphen funct
local function default_display_hyphen(script, hyph)
if not hyph then
return template_hyphens[script] or "-"
end
return hyph
end
 
local function no_display_hyphen(script, hyph)
return ""
end
 
local function arab_get_display_hyphen(script, hyph)
if not hyph then
return "ـ" -- tatweel
elseif hyph == ZWNJ then
return ""
else
return hyph
end
end
 
-- Per-script function to return the correct display hyphen given the
-- script and template hyphen. The function should also handle the case
-- where the passed-in template hyphen is nil, corresponding to the
-- situation in {{prefix}}/{{suffix}}/etc. where no template hyphen is
-- specified.
local display_hyphens = {
-- Arabic scripts get added below
["Hani"] = no_display_hyphen,
-- The following two are mixtures of several scripts. Hopefully
-- the specs here are correct!
["Jpan"] = no_display_hyphen,
["Kore"] = no_display_hyphen,
["Laoo"] = no_display_hyphen,
["Nshu"] = no_display_hyphen,
["Thai"] = no_display_hyphen,
}
for _, script in ipairs(arab_scripts) do
display_hyphens[script] = arab_get_display_hyphen
end
 
local function pluralize(pos)
if pos ~= "nouns" and mw.ustring.subusub(pos, -5) ~= "verbs" and mw.ustring.subusub(pos, -4) ~= "ives" then
if pos:find("[sx]$") then
pos = pos .. "es"
Line 27 ⟶ 160:
end
 
local function link_term(terminfo, display_term, lang, sc, sort_key)
local terminfo_new = {}require("Module:table").shallowcopy(terminfo)
local result
 
for key, val in pairs(terminfo) do
terminfo_new[key].term = valdisplay_term
end
if terminfo_new.lang then
returnresult = require("Module:etymology").format_borrowed(lang, terminfoterminfo_new, sort_key, false, true, "plain")
else
terminfo_new.lang = lang
terminfo_new.sc = terminfo_new.sc or sc
returnresult = m_links.full_link(terminfo_new, "term", false)
end
if terminfo_new.q then
result = result .. " " .. require("Module:qualifier").format_qualifier(terminfo_new.q)
end
return result
end
 
-- Figure out the appropriate script for the given affix and language (unless
 
-- the script is explicitly passed in), and return the values of
local function get_hyphen(lang, sc)
-- template_hyphens[] and display_hyphens[] for that script, substituting
--The script will be "Latn" for transliterations.
-- default values as appropriate. Three values are returned:
if sc and sc:getCode() == "Latn" then
-- DETECTED_SCRIPT, TEMPLATE_HYPHEN, DISPLAY_HYPHEN
return "-"
local function get_template_and_display_hyphens(text, lang, sc)
local scode
-- 1. If the script is explicitly passed in, use it.
if sc then
scode = sc:getCode()
else
lang = require("Module:languages").getNonEtymological(lang)
return hyphens[lang:getCode()] or "-"
-- If we don't call shallowClone here, #possible_scripts always == 0.
-- Something weird to do with the metatable that's set on the table,
-- coming from loadData.
local possible_scripts = require("Module:table").shallowClone(lang:getScriptCodes())
if #possible_scripts == 0 then
-- This shouldn't happen; if the language has no script codes,
-- the list {"None"} should be returned.
error("Something is majorly wrong! Language " .. lang:getCanonicalName() .. " has no script codes.")
end
if #possible_scripts == 1 then
-- 2. If the language has only one possible script, use it.
scode = possible_scripts[1]
else
-- 3. Check if any of the possible scripts for the language have
-- non-default values for template_hyphens[] or
-- display_hyphens[]. If so, we need to do script detection on
-- the text. If not, just use "Latn", which may not be
-- technically correct but produces the right results because
-- Latn has all default values for template_hyphens[] and
-- display_hyphens[].
local may_have_nondefault_hyphen = false
for _, script in ipairs(possible_scripts) do
if template_hyphens[script] or display_hyphens[script] then
may_have_nondefault_hyphen = true
break
end
end
if not may_have_nondefault_hyphen then
scode = "Latn"
else
scode = require("Module:scripts").findBestScript(text, lang):getCode()
end
end
end
local template_hyphen = template_hyphens[scode] or "-"
local display_hyphen = display_hyphens[scode] or default_display_hyphen
return scode, template_hyphen, display_hyphen
end
 
-- Find the type of affix ("prefix", "infix", "suffix", "circumfix" or nil
 
-- for non-affix). Return the affix type and the displayed/linked equivalent
-- of the part (normally the same as the part but will be different for some
-- East Asian languages that use a regular hyphen as an affix-signaling
-- hyphen but have no display hyphen).
local function get_affix_type(lang, sc, part)
if not part then
return nil, nil
end
local hyphenscode, thyph, dhyph = get_hyphenget_template_and_display_hyphens(part, lang, sc)
local hyphen_space_hyphenthyph = hyphen"([" .. " "thyph .. hyphen"])"
local hyphen_space_hyphen = thyph .. " " .. thyph
part = part:gsub("^*", "")
 
if mw.ustring.part:find(part, hyphen_space_hyphen, 1, true"^%^") then
-- If part begins with ^, it's not an affix no matter what.
return "circumfix"
-- Strip off the ^ and return "no affix".
elseif mw.ustring.sub(part, 1, 1) == hyphen and mw.ustring.sub(part, -1) == hyphen then
return "infix"nil, usub(part, 2)
elseif mw.ustring.sub(part, -1) == hyphen then
return "prefix"
elseif mw.ustring.sub(part, 1, 1) == hyphen then
return "suffix"
else
return nil
end
 
-- Remove an asterisk if the morpheme is reconstructed and add it in the end.
local reconstructed = ""
if part:find("^%*") then
reconstructed = "*"
part = part:gsub("^%*", "")
end
 
local affix_type = nil
 
local beginning_hyphen = rmatch(part, "^" .. thyph .. ".*$")
local ending_hyphen = rmatch(part, "^.*" .. thyph .. "$")
local beginning_dhyph = dhyph(scode, beginning_hyphen)
local ending_dhyph = dhyph(scode, ending_hyphen)
 
if rfind(part, hyphen_space_hyphen) then
affix_type = "circumfix"
-- FIXME! Change to display hyphens?
elseif beginning_hyphen and ending_hyphen then
affix_type = "infix"
-- Don't do anything if the part is a single hyphen.
-- This is probably correct.
if (beginning_hyphen ~= beginning_dhyph or
ending_hyphen ~= ending_dhyph) and ulen(part) > 1 then
part = beginning_dhyph .. rsub(part, "^.(.-).$", "%1") .. ending_dhyph
end
elseif ending_hyphen then
affix_type = "prefix"
if ending_hyphen ~= ending_dhyph then
part = rsub(part, "^(.-).$", "%1") .. ending_dhyph
end
elseif beginning_hyphen then
affix_type = "suffix"
if beginning_hyphen ~= beginning_dhyph then
part = beginning_dhyph .. usub(part, 2)
end
end
 
part = reconstructed .. part
return affix_type, part
end
 
 
-- Iterate an array up to the greatest integer index found.
local function ipairs_with_gaps(t)
local max_index = math.max(unpack(require("Module:table").numKeys(t)))
local i = 0
return function()
while i < max_index do
i = i + 1
return i, t[i]
end
end
end
 
export.ipairs_with_gaps = ipairs_with_gaps
 
 
Line 88 ⟶ 318:
local whole_words = 0
for i, part in ipairsipairs_with_gaps(parts) do
part = part or {}
-- Make a link for the part
local part_lang = part.lang or lang
table.insert(parts_formatted, link_term(part, lang, sc, sort_key))
local part_sc = part.sc or sc
-- Is it an affix, and if so, what type of affix?
local affix_type, display_term = get_affix_type(part.lang or langpart_lang, part.sc or scpart_sc, part.term)
-- Make a link for the part
if display_term == "" then
-- If a bare ^ was specified, then insert a blank string. A + will still
-- appear next to it. This lets us directly convert things such as
-- {{suffix|mul||idae}} to {{affix|mul|^|-idae}}.
table.insert(parts_formatted, "")
else
table.insert(parts_formatted, link_term(part, display_term, lang, sc, sort_key))
end
if affix_type then
Line 102 ⟶ 343:
if i == 1 and parts[2] and parts[2].term then
part_sort_baselocal part2_lang = lang:makeEntryName(parts[2].term)lang or lang
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)
part_sort_base = part2_lang:makeEntryName(part2_display_term)
end
if affix_type == "infix" then affix_type = "interfix" end
if part.pos and mw.ustring.matchrfind(part.pos, "patronym") then
table.insert(categories_formatted, m_utilities.format_categories({lang:getCanonicalName() .. " patronymics"}, lang, part_sort, part_sort_base))
end
if pos ~= "words" and part.pos and mw.ustring.matchrfind(part.pos, "diminutive") then
table.insert(categories_formatted, m_utilities.format_categories({lang:getCanonicalName() .. " diminutive " .. pos}, lang, part_sort, part_sort_base))
end
table.insert(categories_formatted, m_utilities.format_categories({lang:getCanonicalName() .. " " .. pos .. " " .. affix_type .. "ed with " .. langpart_lang:makeEntryName(part.termdisplay_term) .. (part.id and " (" .. part.id .. ")" or "")}, lang, part_sort, part_sort_base))
else
whole_words = whole_words + 1
Line 144 ⟶ 388:
local whole_words = 0
for i, part in ipairs(parts) do
local part_lang = part.lang or lang
table.insert(parts_formatted, link_term(part, lang, sc, sort_key))
local part_sc = part.sc or sc
local affix_type, display_term = get_affix_type(part.lang or langpart_lang, part.sc or scpart_sc, part.term)
 
-- If the word is an infix, recognize it as such (which means
-- e.g. that we will display the word without hyphens for
-- East Asian languages). Otherwise, ignore the fact that it
-- looks like an affix and display as specified in the template
-- (but pay attention to the detected affix type for certain
-- tracking purposes)
if affix_type == "infix" then
table.insert(categories_formatted, m_utilities.format_categories({lang:getCanonicalName() .. " " .. pos .. " interfixed with " .. langpart_lang:makeEntryName(part.termdisplay_term)}, lang, part.sort or sort_key))
elseif affix_type then
require("Module:debug").track{
"compound",
"compound/" .. affix_type,
"compound/" .. affix_type .. "/lang/" .. lang:getCode()
}
else
display_term = part.term
whole_words = whole_words + 1
if affix_type then
require("Module:debug").track{
"compound",
"compound/" .. affix_type,
"compound/" .. affix_type .. "/lang/" .. lang:getCode()
}
else
whole_words = whole_words + 1
end
end
table.insert(parts_formatted, link_term(part, display_term, lang, sc, sort_key))
end
 
Line 168 ⟶ 422:
return table.concat(parts_formatted, " +&lrm; ") .. (nocat and "" or table.concat(categories_formatted))
end
 
 
function export.show_compound_like(lang, sc, parts, sort_key, text, oftext, cat)
local parts_formatted = {}
local categories_formatted = {}
 
if cat then
table.insert(categories_formatted, m_utilities.format_categories({lang:getCanonicalName() .. " " .. cat}, lang, sort_key))
end
-- Make links out of all the parts
for i, part in ipairs(parts) do
table.insert(parts_formatted, link_term(part, part.term, lang, sc, sort_key))
end
 
local text_sections = {}
if text then
table.insert(text_sections, text)
end
if #parts > 0 and oftext then
table.insert(text_sections, " ")
table.insert(text_sections, oftext)
table.insert(text_sections, " ")
end
table.insert(text_sections, table.concat(parts_formatted, " +&lrm; "))
table.insert(text_sections, table.concat(categories_formatted, ""))
return table.concat(text_sections, "")
end
 
 
-- Make a given part into an affix of a specific type. For example, if the desired affix type
-- is "suffix", this will (in general) add a hyphen onto the beginning of the term, alt, tr and ts
-- components of the part if not already present. The hyphen that's added is the "display hyphen"
-- (see above) and may be language-specific. In the case of East Asian languages, the display
-- hyphen is an empty string whereas the template hyphen is the regular hyphen, meaning that any
-- regular hyphen at the beginning of the part will be effectively removed.
local function make_part_affix(part, lang, sc, affix_type)
local part_lang = part.lang or lang
local part_sc = part.sc or sc
 
part.term = export.make_affix(part.term, part_lang, part_sc, affix_type)
part.alt = export.make_affix(part.alt, part_lang, part_sc, affix_type)
part.tr = export.make_affix(part.tr, part_lang, require("Module:scripts").getByCode("Latn"), affix_type)
part.ts = export.make_affix(part.ts, part_lang, require("Module:scripts").getByCode("Latn"), affix_type)
end
 
 
local function track_wrong_affix_type(template, part, lang, sc, expected_affix_type, part_name)
if part then
local affix_type = get_affix_type(part.lang or lang, part.sc or sc, part.term)
if affix_type ~= expected_affix_type then
require("Module:debug").track{
template,
template .. "/" .. part_name,
template .. "/" .. part_name .. "/" .. (affix_type or "none"),
template .. "/" .. part_name .. "/" .. (affix_type or "none") .. "/lang/" .. lang:getCode()
}
end
end
end
 
 
local function insert_affix_category(categories, lang, pos, affix_type, part)
if part.term then
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 ""))
end
end
 
Line 178 ⟶ 500:
-- Hyphenate the affixes
prefix.term = export.make_affixmake_part_affix(prefix.term, prefix.lang or lang, prefix.sc or sc, "prefix")
make_part_affix(suffix, lang, sc, "suffix")
prefix.alt = export.make_affix(prefix.alt, prefix.lang or lang, prefix.sc or sc, "prefix")
track_wrong_affix_type("circumfix", prefix, lang, sc, "prefix", "prefix")
if prefix.annotations then
track_wrong_affix_type("circumfix", base, lang, sc, nil, "base")
prefix.annotations.tr = export.make_affix(prefix.annotations.tr, prefix.lang or lang, require("Module:scripts").getByCode("Latn"), "prefix")
track_wrong_affix_type("circumfix", suffix, lang, sc, "suffix", "suffix")
end
suffix.term = export.make_affix(suffix.term, suffix.lang or lang, suffix.sc or sc, "suffix")
suffix.alt = export.make_affix(suffix.alt, suffix.lang or lang, suffix.sc or sc, "suffix")
if suffix.annotations then
suffix.annotations.tr = export.make_affix(suffix.annotations.tr, suffix.lang or lang, require("Module:scripts").getByCode("Latn"), "suffix")
end
local prefix_affix_type = get_affix_type(prefix.lang or lang, prefix.sc or sc, prefix.term)
if prefix_affix_type ~= "prefix" then
require("Module:debug").track{
"circumfix",
"circumfix/prefix",
"circumfix/prefix/" .. (prefix_affix_type or "none"),
"circumfix/prefix/" .. (prefix_affix_type or "none") .. "/lang/" .. lang:getCode()
}
end
local base_affix_type = get_affix_type(base.lang or lang, base.sc or sc, base.term)
if base_affix_type then
require("Module:debug").track{
"circumfix",
"circumfix/base",
"circumfix/base/" .. base_affix_type,
"circumfix/base/" .. base_affix_type .. "/lang/" .. lang:getCode()
}
end
local suffix_affix_type = get_affix_type(suffix.lang or lang, suffix.sc or sc, suffix.term)
if suffix_affix_type ~= "suffix" then
require("Module:debug").track{
"circumfix",
"circumfix/suffix",
"circumfix/suffix/" .. (suffix_affix_type or "none"),
"circumfix/suffix/" .. (suffix_affix_type or "none") .. "/lang/" .. lang:getCode()
}
end
-- Create circumfix term
Line 235 ⟶ 520:
-- Make links out of all the parts
local parts_formatted = {}
local sort_base = (base.lang or lang):makeEntryName(base.term)
table.insert(parts_formatted, link_term(prefix, prefix.term, lang, sc, sort_key))
table.insert(parts_formatted, link_term(base, base.term, lang, sc, sort_key))
table.insert(parts_formatted, link_term(suffix, suffix.term, lang, sc, sort_key))
-- Insert the categories
table.insert(categories, lang:getCanonicalName() .. " " .. pos .. " circumfixed with " .. (prefix.lang or lang):makeEntryName(circumfix, lang))
return table.concat(parts_formatted, " +&lrm; ") .. (nocat and "" or m_utilities.format_categories(categories, lang, sort_key, sort_base))
Line 254 ⟶ 539:
-- Hyphenate the affixes
prefix.term = export.make_affixmake_part_affix(prefix.term, prefix.lang or lang, prefix.sc or sc, "prefix")
make_part_affix(suffix, lang, sc, "suffix")
prefix.alt = export.make_affix(prefix.alt, prefix.lang or lang, prefix.sc or sc, "prefix")
track_wrong_affix_type("confix", prefix, lang, sc, "prefix", "prefix")
if prefix.annotations then
track_wrong_affix_type("confix", base, lang, sc, nil, "base")
prefix.annotations.tr = export.make_affix(prefix.annotations.tr, prefix.lang or lang, require("Module:scripts").getByCode("Latn"), "prefix")
track_wrong_affix_type("confix", suffix, lang, sc, "suffix", "suffix")
end
suffix.term = export.make_affix(suffix.term, suffix.lang or lang, suffix.sc or sc, "suffix")
suffix.alt = export.make_affix(suffix.alt, suffix.lang or lang, suffix.sc or sc, "suffix")
if suffix.annotations then
suffix.annotations.tr = export.make_affix(suffix.annotations.tr, suffix.lang or lang, require("Module:scripts").getByCode("Latn"), "suffix")
end
local prefix_affix_type = get_affix_type(prefix.lang or lang, prefix.sc or sc, prefix.term)
if prefix_affix_type ~= "prefix" then
require("Module:debug").track{
"confix",
"confix/prefix",
"confix/prefix/" .. (prefix_affix_type or "none"),
"confix/prefix/" .. (prefix_affix_type or "none") .. "/lang/" .. lang:getCode()
}
end
if base then
local base_affix_type = get_affix_type(base.lang or lang, base.sc or sc, base.term)
if base_affix_type then
require("Module:debug").track{
"confix",
"confix/base",
"confix/base/" .. base_affix_type,
"confix/base/" .. base_affix_type .. "/lang/" .. lang:getCode()
}
end
end
local suffix_affix_type = get_affix_type(suffix.lang or lang, suffix.sc or sc, suffix.term)
if suffix_affix_type ~= "suffix" then
require("Module:debug").track{
"confix",
"confix/suffix",
"confix/suffix/" .. (suffix_affix_type or "none"),
"confix/suffix/" .. (suffix_affix_type or "none") .. "/lang/" .. lang:getCode()
}
end
-- Make links out of all the parts
local parts_formatted = {}
local prefix_sort_base = lang:makeEntryName(suffix.term)
if suffix.term then
prefix_sort_base = (suffix.lang or lang):makeEntryName(suffix.term)
end
local prefix_categories = {}
local suffix_categories = {}
table.insert(parts_formatted, link_term(prefix, prefix.term, lang, sc, sort_key))
table.insertinsert_affix_category(prefix_categories, lang:getCanonicalName() .. " " .., pos .., " prefixed with prefix", .. lang:makeEntryName(prefix.term, lang))
if base then
prefix_sort_baseif = lang:makeEntryName(base.term) then
prefix_sort_base = (base.lang or lang):makeEntryName(base.term)
table.insert(parts_formatted, link_term(base, lang, sc, sort_key))
end
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.insertinsert_affix_category(suffix_categories, lang:getCanonicalName() .. " " .., pos .., " suffixed with suffix", .. lang:makeEntryName(suffix.term, lang))
return table.concat(parts_formatted, " +&lrm; ") .. (nocat and "" or m_utilities.format_categories(prefix_categories, lang, sort_key, prefix_sort_base) .. m_utilities.format_categories(suffix_categories, lang, sort_key))
Line 328 ⟶ 579:
-- Hyphenate the affixes
infix.term = export.make_affixmake_part_affix(infix.term, infix.lang or lang, infix.sc or sc, "infix")
infix.alt = export.make_affix(infix.alt, infix.lang or lang, infix.sc or sc, "infix")
track_wrong_affix_type("infix", base, lang, sc, nil, "base")
if infix.annotations then
infix.annotations.tr = export.make_affix track_wrong_affix_type("infix.annotations.tr", infix.lang or, lang, require(sc, "Module:scripts").getByCode("Latninfix"), "infix")
end
local base_affix_type = get_affix_type(base.lang or lang, base.sc or sc, base.term)
if base_affix_type then
require("Module:debug").track{
"infix",
"infix/base"
}
require("Module:debug").track{
"infix/base/" .. base_affix_type,
"infix/base/" .. base_affix_type .. "/lang/" .. lang:getCode()
}
end
local infix_affix_type = get_affix_type(infix.lang or lang, infix.sc or sc, infix.term)
if infix_affix_type ~= "infix" then
require("Module:debug").track{
"infix",
"infix/infix",
"infix/infix/" .. (infix_affix_type or "none"),
"infix/infix/" .. (infix_affix_type or "none") .. "/lang/" .. lang:getCode()
}
end
-- Make links out of all the parts
local parts_formatted = {}
table.insert(parts_formatted, link_term(base, base.term, lang, sc, sort_key))
table.insert(parts_formatted, link_term(infix, infix.term, lang, sc, sort_key))
-- Insert the categories
table.insertinsert_affix_category(categories, lang:getCanonicalName() .. " " .., pos .., " infixed with infix", .. lang:makeEntryName(infix.term))
return table.concat(parts_formatted, " +&lrm; ") .. (nocat and "" or m_utilities.format_categories(categories, lang, sort_key))
Line 377 ⟶ 604:
-- Hyphenate the affixes
for i, prefix in ipairs(prefixes) do
prefixes[i].term = export.make_affixmake_part_affix(prefix.term, prefix.lang or lang, prefix.sc or sc, "prefix")
prefixes[i].alt = export.make_affix(prefix.alt, prefix.lang or lang, prefix.sc or sc, "prefix")
if prefix.annotations then
prefixes[i].annotations.tr = export.make_affix(prefix.annotations.tr, prefix.lang or lang, require("Module:scripts").getByCode("Latn"), "prefix")
end
end
for i, prefix in ipairs(prefixes) do
local prefix_affix_type = get_affix_typetrack_wrong_affix_type("prefix.lang", orprefix, lang, prefix.sc, or sc"prefix", "prefix.term")
if prefix_affix_type ~= "prefix" then
require("Module:debug").track{
"prefix",
"prefix/prefix",
"prefix/prefix/" .. (prefix_affix_type or "none"),
"prefix/prefix/" .. (prefix_affix_type or "none") .. "/lang/" .. lang:getCode()
}
end
end
 
track_wrong_affix_type("prefix", base, lang, sc, nil, "base")
if base then
 
local base_affix_type = get_affix_type(base.lang or lang, base.sc or sc, base.term)
if base_affix_type then
require("Module:debug").track{
"prefix",
"prefix/base",
"prefix/base/" .. base_affix_type,
"prefix/base/" .. base_affix_type .. "/lang/" .. lang:getCode()
}
end
end
-- Make links out of all the parts
local parts_formatted = {}
Line 415 ⟶ 619:
for i, prefix in ipairs(prefixes) do
table.insert(parts_formatted, link_term(prefix, prefix.term, lang, sc, sort_key))
insert_affix_category(categories, lang, pos, "prefix", prefix)
table.insert(categories, lang:getCanonicalName() .. " " .. pos .. " prefixed with " .. lang:makeEntryName(prefix.term, lang) .. (prefix.id and " (" .. prefix.id .. ")" or ""))
if i > 1 and first_sort_base == nil then
first_sort_base = (prefix.lang or lang):makeEntryName(prefix.term)
end
end
Line 425 ⟶ 629:
if base then
if first_sort_base == nil then
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
table.insert(parts_formatted, "")
Line 446 ⟶ 650:
-- Hyphenate the affixes
for i, suffix in ipairs(suffixes) do
suffixes[i].term = export.make_affixmake_part_affix(suffix.term, suffix.lang or lang, suffix.sc or sc, "suffix")
suffixes[i].alt = export.make_affix(suffix.alt, suffix.lang or lang, suffix.sc or sc, "suffix")
if suffix.annotations then
suffixes[i].annotations.tr = export.make_affix(suffix.annotations.tr, suffix.lang or lang, require("Module:scripts").getByCode("Latn"), "suffix")
end
end
if base then
local base_affix_type = get_affix_type(base.lang or lang, base.sc or sc, base.term)
if base_affix_type then
require("Module:debug").track{
"suffix",
"suffix/base",
"suffix/base/" .. base_affix_type,
"suffix/base/" .. base_affix_type .. "/lang/" .. lang:getCode()
}
end
end
track_wrong_affix_type("suffix", base, lang, sc, nil, "base")
 
for i, suffix in ipairs(suffixes) do
local suffix_affix_type = get_affix_typetrack_wrong_affix_type("suffix.lang", orsuffix, lang, suffix.sc, or sc"suffix", "suffix.term")
if suffix_affix_type ~= "suffix" then
require("Module:debug").track{
"suffix",
"suffix/suffix",
"suffix/suffix/" .. (suffix_affix_type or "none"),
"suffix/suffix/" .. (suffix_affix_type or "none") .. "/lang/" .. lang:getCode()
}
end
end
Line 482 ⟶ 663:
if base then
table.insert(parts_formatted, link_term(base, base.term, lang, sc, sort_key))
else
table.insert(parts_formatted, "")
Line 488 ⟶ 669:
for i, suffix in ipairs(suffixes) do
table.insert(parts_formatted, link_term(suffix, suffix.term, lang, sc, sort_key))
end
-- Insert the categories
for i, suffix in ipairs(suffixes) do
if suffix.term then
table.insert(categories, lang:getCanonicalName() .. " " .. pos .. " suffixed with " .. lang:makeEntryName(suffix.term) .. (suffix.id and " (" .. suffix.id .. ")" or ""))
insert_affix_category(categories, lang, pos, "suffix", suffix)
end
if suffix.pos and mw.ustring.matchrfind(suffix.pos, "patronym") then
table.insert(categories, lang:getCanonicalName() .. " patronymics")
end
Line 511 ⟶ 694:
-- Hyphenate the affixes
transfix.term = export.make_affixmake_part_affix(transfix.term, transfix.lang or lang, transfix.sc or sc, "transfix")
transfix.alt = export.make_affix(transfix.alt, transfix.lang or lang, transfix.sc or sc, "transfix")
transfix.tr = export.make_affix(transfix.tr, transfix.lang or lang, require("Module:scripts").getByCode("Latn"), "transfix")
-- Make links out of all the parts
local parts_formatted = {}
table.insert(parts_formatted, link_term(base, base.term, lang, sc, sort_key))
table.insert(parts_formatted, link_term(transfix, transfix.term, lang, sc, sort_key))
-- Insert the categories
table.insertinsert_affix_category(categories, lang:getCanonicalName() .. " " .., pos .., " transfixed with transfix", .. lang:makeEntryName(transfix.term))
return table.concat(parts_formatted, " +&lrm; ") .. (nocat and "" or m_utilities.format_categories(categories, lang, sort_key))
Line 528 ⟶ 709:
 
 
-- AddsAdd a hyphen to a word in the appropriate place, based on the specified
-- affix type. For example, if `affix_type` == "prefix", we'll add a hyphen
function export.make_affix(term, lang, sc, affixtype)
-- onto the end if it's not already there. In general, if the template and
if not (affixtype == "prefix" or affixtype == "suffix" or affixtype == "circumfix" or affixtype == "infix" or affixtype == "interfix" or affixtype == "transfix") then
-- display hyphens are the same and the appropriate hyphen is already
error("Invalid affix type")
-- present, we leave it, else we strip off the template hyphen if present
-- and add the display hyphen.
function export.make_affix(term, lang, sc, affix_type)
if not (affix_type == "prefix" or affix_type == "suffix" or
affix_type == "circumfix" or affix_type == "infix" or
affix_type == "interfix" or affix_type == "transfix") then
error("Internal error: Invalid affix type " .. (affix_type or "(nil)"))
end
if not term then
return nil
elseif affixtype == "circumfix" or affixtype == "transfix" then
return term
elseif affixtype == "interfix" then
affixtype = "infix"
end
 
-- If the term begins with ^, leave it exactly as-is except for removing the ^.
local detected_type = get_affix_type(lang, sc, term)
if usub(term, 1, 1) == "^" then
return usub(term, 2)
if affixtype and detected_type == affixtype or (detected_type == "infix" and affixtype == "prefix") or (detected_type == "infix" and affixtype == "suffix") then
end
if affix_type == "circumfix" or affix_type == "transfix" then
return term
elseif affix_type == "interfix" then
affix_type = "infix"
end
local scode, thyph, dhyph = get_template_and_display_hyphens(term, lang, sc)
--remove an asterisk if the morpheme is reconstructed and add it in the end
thyph = "([" .. thyph .. "])"
-- Remove an asterisk if the morpheme is reconstructed and add it in the end.
local reconstructed = ""
if term:find("^%*") then
reconstructed = "*"
term = term:gsub("^%*", "")
end
local hyphenbeginning_hyphen = get_hyphenrmatch(langterm, sc"^" .. thyph .. ".*$")
local ending_hyphen = rmatch(term, "^.*" .. thyph .. "$")
local beginning_dhyph = dhyph(scode, beginning_hyphen)
if affixtype == "suffix" then
local ending_dhyph = dhyph(scode, ending_hyphen)
term = hyphen .. term
 
elseif affixtype == "prefix" then
if affix_type == "suffix" then
term = term .. hyphen
if beginning_hyphen and beginning_hyphen == beginning_dhyph then
elseif affixtype == "infix" then
term -- = hyphen ..leave term .. hyphenalone
else
local term_no_hyphen = beginning_hyphen and usub(term, 2) or term
term = beginning_dhyph .. term_no_hyphen
end
elseif affix_type == "prefix" then
if ending_hyphen and ending_hyphen == ending_dhyph then
-- leave term alone
else
local term_no_hyphen = ending_hyphen and rsub(term, "^(.-).$", "%1") or term
term = term_no_hyphen .. ending_dhyph
end
elseif affix_type == "infix" then
if (beginning_hyphen and ending_hyphen and
beginning_hyphen == beginning_dhyph and
ending_hyphen == ending_dhyph) then
-- leave term alone
elseif term == beginning_hyphen or term == ending_hyphen then
-- term is a single hyphen; should probably leave alone
else
local term_no_hyphen = beginning_hyphen and usub(term, 2) or term
term_no_hyphen = ending_hyphen and rsub(term_no_hyphen, "^(.-).$", "%1") or term_no_hyphen
term = beginning_dhyph .. term_no_hyphen .. ending_dhyph
end
else
error("InvalidInternal error: Bad affix type " .. affix_type)
end
Line 571 ⟶ 786:
 
return export
 
-- For Vim, so we get 4-space tabs
-- vim: set ts=4 sw=4 noet: