|
|
| (22 intermediate revisions by the same user not shown) |
| Line 7: |
Line 7: |
| local m_utils = require("Module:utilities") | | local m_utils = require("Module:utilities") |
| local m_etym = require("Module:etymology") | | local m_etym = require("Module:etymology") |
| | local m_etym_specialized = require("Module:etymology/specialized") |
| local m_links = require("Module:links") | | local m_links = require("Module:links") |
| local m_table = require("Module:table") | | local m_table = require("Module:table") |
|
| |
|
| local gsub = mw.ustring.gsub | | local gsub = mw.ustring.gsub |
| local PAGENAME = gsub(mw.title.getCurrentTitle().text, "%s", " ")
| |
| local NAMESPACE = mw.title.getCurrentTitle().nsText
| |
| local match = mw.ustring.match | | local match = mw.ustring.match |
| local gmatch = mw.ustring.gmatch
| |
|
| |
|
| local export = {} | | local export = {} |
|
| |
|
| local wasc_suffixes = m_table.listToSet { | | local wasc_suffixes = m_table.listToSet { |
| "ati", "cosc", "e", "ekan", "i", "ila", | | "-ati", "-cosc", "-e", "-ekan", "-i", "-ila", "-kan", |
| "kan", "la", "osc", "otl", "que", "scati", "si"
| | "-la", "-osc", "-otl", "-que", "-scati", "-si", "-tl", |
| } | | } |
|
| |
| local function ncategories(categories)
| |
| local out_categories = {}
| |
| for key, cat in ipairs(categories) do
| |
| out_categories[key] = "[[Category:" .. cat .. "]]"
| |
| end
| |
|
| |
| return NAMESPACE == "Template" and "" or table.concat(out_categories, "")
| |
| end
| |
|
| |
| local function link(lang, term, alt)
| |
| local natlang = lang:getWikidataItem() or false
| |
| -- true if the language declaration has a wikidata item, a marginal amount of conlangs have it
| |
|
| |
| if lang:hasType("reconstructed") and not term:match("^%*") then
| |
| term = "*" .. term
| |
| end
| |
| local data = {term = term, alt = alt or term, lang = lang, to_wikt = natlang}
| |
| return m_links.full_link(data, "term")
| |
| end
| |
|
| |
| function export.getLink(frame)
| |
| local params = {}
| |
| local a = 0
| |
|
| |
| if frame.args["offset"] or (frame.args["old"] or frame.args["older"]) then
| |
| local offset = frame.args["old"] and 1 or frame.args["older"] and 2 or tonumber(frame.args["offset"])
| |
|
| |
| for i=1,offset do
| |
| params[i] = {}
| |
| end
| |
| params[offset+1] = {list = true}
| |
| a = offset + 1
| |
| else
| |
| params[1] = {list = true}
| |
| a = 1
| |
| end
| |
|
| |
| -- exceptions
| |
| params["and"], params["see"] = {}, {}
| |
|
| |
| local args = require("Module:parameters").process(frame:getParent().args, params)
| |
|
| |
| local fam, lang = m_families.getByCode(frame.args[1]), require("Module:languages").getByCode(frame.args[2])
| |
| local proto = fam:getProtoLanguage()
| |
|
| |
| local links = {}; local categories = {}; local alts = {};
| |
| -- WIP
| |
| for i, item in ipairs(args[a]) do
| |
| if item == "+" then
| |
| table.insert(links," ")
| |
| elseif item == "-" then
| |
| table.insert(links, item)
| |
| elseif item:find("<") and not item:find("^[^<]*<[a-z]*[^a-z:]") then
| |
| local run = m_put.parse_balanced_segment_run(item, "<", ">")
| |
| local orig_param = a + i - 1
| |
| local function parse_err(msg)
| |
| error(msg .. ": " .. orig_param .. "= " .. table.concat(run))
| |
| end
| |
| local term = run[1]:gsub("%*","")
| |
|
| |
| for j = 2, #run - 1, 2 do
| |
| local modtext = run[j]:match("^<(.*)>$")
| |
| local prefix, arg = modtext:match("^([a-z]+):(.*)$")
| |
|
| |
| if item:match("><") then
| |
| if prefix == "a" then
| |
| table.insert(links, link(proto, term, arg))
| |
| table.insert(alts, arg)
| |
| elseif prefix == "c" then
| |
| table.insert(categories, lang:getCanonicalName() .. " terms from " .. proto:getCanonicalName() .. " *" .. arg)
| |
| table.insert(alts, term)
| |
| end
| |
| elseif prefix == "a" then
| |
| table.insert(links, link(proto, term, arg))
| |
| table.insert(categories, lang:getCanonicalName() .. " terms from " .. proto:getCanonicalName() .. " *" .. term)
| |
| table.insert(alts, arg)
| |
| elseif prefix == "c" then
| |
| table.insert(links, link(proto, term))
| |
| table.insert(categories, lang:getCanonicalName() .. " terms from " .. proto:getCanonicalName() .. " *" .. arg)
| |
| table.insert(alts, term)
| |
| end
| |
| end
| |
| else
| |
| table.insert(links, link(proto, args[a][i]))
| |
| table.insert(categories, lang:getCanonicalName() .. " terms from " .. proto:getCanonicalName() .. " *" .. args[a][i])
| |
| table.insert(alts, args[a][i])
| |
| end
| |
|
| |
| if i~=1 and links[i-1] == "-" then alts[i] = links[i]:gsub("^%*","") end
| |
| --if i~=1 and links[i-1] ~= " " then links[i] = links[i]:gsub("(%|?)%*%-","%1-") end
| |
| --if i~=1 and alts[i-1]:match("%-$") then links[i] = links[i]:gsub("%|%*","|") end
| |
| end
| |
|
| |
| return table.concat(links) .. ncategories(categories)
| |
| end
| |
|
| |
|
| local function get_single_args(args, index) | | local function get_single_args(args, index) |
| Line 133: |
Line 35: |
| end | | end |
|
| |
|
| local function parse_args(parent_args, dest_code, ancestor_codes, extra_params)
| | function export.parse_args(parent_args, dest_code, ancestor_codes, extra_params) |
| local param_mods = m_param_utils.construct_param_mods({{group = {"link", "q", "l"}}}) | | local param_mods = m_param_utils.construct_param_mods({{group = {"link", "q", "l"}}}) |
| | | |
| local params = extra_params or {} | | local params = extra_params or {} |
| params.nocap = {type = "boolean"} | | params.nocap = {type = "boolean"} -- no capital letter |
| params.nocat = {type = "boolean"} | | params.nocat = {type = "boolean"} -- no categories |
| | params.p = {} -- borrowing process |
| | |
| | local termarg_index |
| | if parent_args.borrowing then |
| | termarg_index = 2 |
| | params[1] = { |
| | type = "language", |
| | required = true, |
| | } |
| | else |
| | termarg_index = 1 |
| | end |
| | | |
| local termarg_index = 1
| |
| for _, ancestor in ipairs(ancestor_codes) do | | for _, ancestor in ipairs(ancestor_codes) do |
| local lang_options = ancestor.options or {} | | local lang_options = ancestor.options or {} |
| Line 175: |
Line 88: |
| local etymologies = {} | | local etymologies = {} |
| | | |
| termarg_index = 1 | | termarg_index = parent_args.borrowing and 2 or 1 |
| local cats = {} | | local cats = {} |
| for _, ancestor in ipairs(ancestor_codes) do | | for _, ancestor in ipairs(ancestor_codes) do |
| Line 199: |
Line 112: |
| terms = {} | | terms = {} |
| local root_index = 1 | | local root_index = 1 |
| | local last_term = "" |
| for _, item in ipairs(items) do | | for _, item in ipairs(items) do |
| if item.alt and not match(item.alt, "^%*") and ancestor_lang:hasType("reconstructed") then | | if item.alt and not match(item.alt, "^%*") and ancestor_lang:hasType("reconstructed") then |
| Line 207: |
Line 121: |
| separator = item.term | | separator = item.term |
| elseif item.term then | | elseif item.term then |
| if root_index > 1 and separator ~= "+" and match(items[root_index - 1].term, "%-$") then -- no asterisk after hyphen | | if root_index > 1 and last_term ~= "+" then -- only subsequent asterisks afer space |
| if not item.alt then | | item.alt = gsub(item.alt or item.term, "^%*", "") |
| item.alt = item.term:gsub("^%*", "")
| |
| else
| |
| item.alt = item.alt:gsub("^%*", "")
| |
| end
| |
| end | | end |
| table.insert(terms, item) | | table.insert(terms, item) |
| | | |
| local cat_term = args.c[root_index] or item.term | | local function one_asterisk(str) |
| cat_term = "*" .. gsub(cat_term, "^*+", "") -- ensure only one asterisk
| | return "*" .. gsub(str, "^*+", "") |
| if code == "wasc" and cat_term ~= item.term then -- Wascotl root and suffix handling | | end |
| local suffix = match(cat_term, "^*%w+%-(%w+)$") | | |
| | local cat_term = one_asterisk(args.c[root_index] or item.term) |
| | if code == "wasc" then -- Wascotl root and suffix handling |
| | local suffix = match(cat_term, "^*[%w']+(%-[%w']+)$") |
| | | |
| if wasc_suffixes[suffix] then | | if wasc_suffixes[suffix] then |
| cat_term = gsub(cat_term, suffix, "") | | cat_term = gsub(cat_term, suffix, "-") |
| end | | end |
| end | | end |
| | | |
| table.insert(cats, dest_lang:getCanonicalName() .. " terms from " .. ancestor_lang:getCanonicalName() .. " " .. cat_term) | | table.insert(cats, dest_lang:getCanonicalName() .. " terms derived from the " .. ancestor_lang:getCanonicalName() .. " root " .. cat_term) |
| | | |
| root_index = root_index + 1 | | root_index = root_index + 1 |
| end | | end |
| | |
| | last_term = item.term |
| end | | end |
| | | |
| Line 255: |
Line 170: |
| end | | end |
| end | | end |
| | | |
| local etymology = m_etym.format_inherited{ | | local etymology |
| lang = dest_lang,
| | if lang_options.borrowed then |
| terms = terms,
| | etymology = m_etym_specialized.specialized_borrowing{ |
| sort_key = args.sort,
| | bortype = args.p or "b", |
| nocat = args.nocat,
| | lang = dest_lang, |
| conj = lang_options.roots and separator or nil,
| | sources = {ancestor_lang}, |
| } | | terms = terms, |
| | sort_key = args.sort, |
| | nocat = args.nocat, |
| | conj = lang_options.roots and separator or nil, |
| | nocap = args.mid or args.old or args.nocap, |
| | } |
| | else |
| | etymology = m_etym.format_inherited{ |
| | lang = dest_lang, |
| | terms = terms, |
| | sort_key = args.sort, |
| | nocat = args.nocat, |
| | conj = lang_options.roots and separator or nil, |
| | } |
| | etymology = "from " .. etymology |
| | end |
| | | |
| if lang_options.annotated and args.parts then | | if lang_options.annotated and args.parts then |
| Line 284: |
Line 214: |
| end | | end |
| | | |
| local categories = {} | | local categories = m_utils.format_categories(cats, dest_lang) |
| if not parent_args.nocat then
| |
| categories = m_utils.format_categories(cats, dest_lang)
| |
| end
| |
|
| |
| return etymologies, args, categories
| |
| end
| |
| | |
| local function concat_etymologies(args, etymologies)
| |
| local capital = args.nocap and "f" or "F"
| |
| return capital .. "rom " .. table.concat(etymologies, ", from ") .. "."
| |
| end
| |
| | |
| function export.qsc(frame)
| |
| local parent_args = frame:getParent().args
| |
|
| |
| local ancestor_codes = {
| |
| { code = "sekh" },
| |
| { code = "wasc", options = {optional = true, roots = true } }
| |
| }
| |
|
| |
| local evolution, args, categories = parse_args(parent_args, "qsc", ancestor_codes)
| |
|
| |
| return concat_etymologies(args, evolution) .. categories
| |
| end
| |
| | |
| function export.lyti_inh(frame)
| |
| local parent_args = frame:getParent().args
| |
|
| |
| local ancestor_codes = {
| |
| { code = "lyti-mid", options = {} },
| |
| { code = "lyti-old", options = {} },
| |
| { code = "cel-pro", options = {annotated = true} },
| |
| { code = "ine-pro", options = {roots = true} },
| |
| }
| |
|
| |
| local extra_params = {
| |
| mid = {type = "boolean"},
| |
| old = {type = "boolean"},
| |
| source = {},
| |
| }
| |
|
| |
| local evolution, args, categories = parse_args(parent_args, "lyti", ancestor_codes)
| |
|
| |
| return concat_etymologies(args, evolution) .. categories
| |
| end
| |
| | |
| function export.lyti_loan(frame)
| |
| local parent_args = frame:getParent().args
| |
| local source_code = parent_args.source or "und"
| |
|
| |
| local ancestor_codes = {
| |
| { code = "lyti-mid", options = {optional = not parent_args.mid} },
| |
| { code = "lyti-old", options = {optional = not parent_args.old} },
| |
| { code = source_code, options = {} },
| |
| }
| |
|
| |
| local extra_params = {
| |
| mid = {type = "boolean"},
| |
| old = {type = "boolean"},
| |
| source = {},
| |
| }
| |
|
| |
| local evolution, args, categories = parse_args(parent_args, "lyti", ancestor_codes)
| |
| | | |
| return concat_etymologies(args, evolution) .. categories | | return etymologies, args, parent_args.nocat and "" or categories |
| end | | end |
|
| |
|
| return export | | return export |