Module:ja-compound
Itsura
- This module lacks a documentation subpage. Please create it.
- Useful links: subpage list • links • transclusions • testcases • sandbox
local export = {}
local link = require("Module:ja-link").link
local concat = table.concat
local insert = table.insert
-- [[Module:parameters]]
function export.show(frame)
local list_allow_holes = {list = true, allow_holes = true}
local boolean_param = {type = "boolean"}
local args = require("Module:parameters").process(frame:getParent().args, {
[1] = {required = true, list = true, allow_holes = true},
t = list_allow_holes,
rom = list_allow_holes,
pos = list_allow_holes,
lit = list_allow_holes,
linkto = list_allow_holes,
s = list_allow_holes,
sort = true,
nocat = boolean_param,
nocap = boolean_param, -- required for use with {{surf}} but ignored
})
local len = (args[1].maxindex + 1) / 2
local result = {}
local categories, sort = {"Japanese compound terms"}, {}
local function format_label(labels)
local labels_f = {}
for lb in labels:gmatch"[^,]+" do
local rl = ({
rendaku = {"[[Appendix:Japanese glossary#rendaku|rendaku]]", "Japanese terms with rendaku"},
renjo = {"[[Appendix:Japanese glossary#renjō|renjō]]", "Japanese terms with renjō"},
})[lb]
if rl then
insert(labels_f, rl[1])
insert(categories, rl[2])
else
insert(labels_f, lb)
end
end
return concat(labels_f, ", ") .. " form "
end
for i = 1, len do
local kana_this = args[1][i * 2] or args[1][i * 2 - 1]
local kana_this_raw = kana_this:gsub("[ ^%.%%%-]", "")
local b_pre, b_suf = kana_this:match"%-$", kana_this:match"^%-"
local cat_form = args[1][i * 2 - 1] and args[1][i * 2 - 1]:gsub("[ ^%.%%%-]", "") or kana_this_raw
if b_pre then
if b_suf then
if kana_this_raw ~= cat_form then
insert(categories, "Japanese terms infixed with " .. cat_form .. " read as " .. kana_this_raw)
else
insert(categories, "Japanese terms infixed with " .. cat_form)
end
else
if kana_this_raw ~= cat_form then
insert(categories, "Japanese terms prefixed with " .. cat_form .. " read as " .. kana_this_raw)
else
insert(categories, "Japanese terms prefixed with " .. cat_form)
end
end
elseif b_suf then
if kana_this_raw ~= cat_form then
insert(categories, "Japanese terms suffixed with " .. cat_form .. " read as " .. kana_this_raw)
else
insert(categories, "Japanese terms suffixed with " .. cat_form)
end
end
local data_pos
if args.s[i] then
local sandhi_lemma, sandhi_kana, sandhi_label, _s
_s, sandhi_label = args.s[i]:match"^(.-)%?(.-)$"
_s = _s or args.s[i]
sandhi_lemma, sandhi_kana = _s:match"^(.-):(.-)$"
if sandhi_lemma == "" then
sandhi_lemma = args[1][i * 2 - 1]
elseif sandhi_lemma == nil then
sandhi_lemma = _s
end
data_pos = concat{
args.pos[i] and args.pos[i] .. ", " or "",
sandhi_label and format_label(sandhi_label) or "as ",
link{
lemma = sandhi_lemma,
kana = sandhi_kana,
linkto = "-",
},
}
insert(sort, ((sandhi_kana or sandhi_lemma):gsub("[%^%-%% ]", "")))
else
data_pos = args.pos[i]
insert(sort, (kana_this_raw:gsub("[%^%% ]", "")))
end
insert(result, link{
lemma = args[1][i * 2 - 1],
kana = args[1][i * 2],
gloss = args.t[i],
tr = args.rom[i],
lit = args.lit[i],
linkto = args.linkto[i],
pos = data_pos,
})
end
result = concat(result, " + ")
local lang = require("Module:languages").getByCode("ja")
sort = lang:makeSortKey(args.sort or concat(sort))
if args.nocat then
categories = ""
else
categories = require("Module:utilities").format_categories(categories, lang, sort)
end
return result .. categories
end
return export