Implements {{amf-new}}
.
local export = {}
local m_str_utils = require("Module:string utilities")
local upper = m_str_utils.upper
local sub = m_str_utils.sub
function export.new(frame)
local parent_args = frame:getParent().args
local params = {
= { allow_empty = true }, -- part of speech 1
= { required = true }, -- definition 1
= true, -- part of speech 2
= true, -- definition 2
= true, -- part of speech 3
= true, -- definition 3
= { alias_of = "etym" },
= true,
= true,
= true,
= true, -- categories without namespace prefix separated by ;
= true, -- include caption; e.g. input ];caption
= true, -- affix with ;<part of speech number>
= true, -- same here
= true, -- alt forms separated by ;
= { type = "boolean", default = false }, -- suppress automatic addition of Petrollino, 2016
= true,
}
local args = require("Module:parameters").process(parent_args, params)
local results = "==Hamer-Banna==\n"
local function processCat(text)
categories = {}
text = text:gsub(":(+)(?)", "{{c|amf|%1}}%2")
:gsub("(^|;)(+)(?)", "{{cln|amf|%1}}%2")
for i in text:gmatch("+") do
table.insert(categories, i)
end
return categories
end
local function genTitle(text)
local pos_title = {
= "Noun", = "Noun", = "Proper noun", = "Proper noun", = "Pronoun",
= "Verb", = "Adjective", = "Adjective", = "Adverb",
= "Preposition", = "Conjunction",
= "Particle", = "Suffix",
= "Proverb", = "Idiom", = "Phrase", = "Ideophone", = "Interjection",
= "Interjection", = "Numeral", = "Determiner",
= "Noun", = "Verb",
};
return pos_title or upper(sub(text, 1, 1)) .. sub(text, 2, -1)
end
local function genHead(text)
local pos_head = {
= "noun", = "noun", = "proper noun", = "proper noun", = "verb", = "adj",
= "con", = "particle", = "pronoun",
= "proverb", = "idiom", = "ideophone", = "phrase",
= "interj", = "det", = "noun form",
= "verb form",
};
return pos_head or text
end
if args then
pic = {}
for i in args:gmatch("+") do
table.insert(pic, i)
end
pic = " .. "|thumb|right]]\n"
if pic then pic = "" .. pic:gsub("%]%]", "%|" .. pic .. "%]%]") end
results = results .. pic
end
if args then
args = args:gsub("(+);?", "* {{alt|amf|%1}}\n")
results = results .. "===Alternative forms===\n" .. args:gsub(";", "\n")
end
if args then results = results .. "\n===Etymology===\n"
.. args .. "\n" end
results = results .. "\n===Pronunciation===\n* {{amf-IPA}}\n\n==="
.. genTitle(args) .. "===\n{{head|amf|" .. genHead(args) ..
"}}\n\n# " .. args
if args then results = results:gsub("{{head%|amf%|+", "%0|head=" .. args) end
if genHead(args) == "noun" then
results = results:gsub("{{head|amf|noun", "{{amf-noun")
:gsub("%|head=(+)", "|%1")
end
for i=1,4,1 do
if args and (i+2) % 2 ~= 0 then
results = results .. "\n\n===" .. genTitle(args)
.. "===\n{{head|amf|" .. genHead(args) .. "}}\n"
elseif args and (i+2) % 2 == 0 then
results = results .. "\n# " .. args
end
end
if args then
pas = {}
for i in args:gmatch("+") do
table.insert(pas, i)
end
if pas == "1" then
results = results:gsub("(===" .. genTitle(args) .. "===\n{{head|amf|.+)}}",
"%1|passive|" .. pas .. "}}")
elseif pas == "2" or "3" then
results = results:gsub("(===" .. genTitle(args) .. "===\n{{head|amf|.+)}}",
"%1|passive|" .. pas .. "}}")
elseif pas == "4" or "5" then
results = results:gsub("(===" .. genTitle(args) .. "===\n{{head|amf|.+)}}",
"%1|passive|" .. pas .. "}}")
end
end
if args then
cau = {}
for i in args:gmatch("+") do
table.insert(cau, i)
end
if pas == "1" then
results = results:gsub("(===" .. genTitle(args) .. "===\n{{head|amf|.+)}}",
"%1|causative|" .. cau .. "}}")
elseif pas == "2" or "3" then
results = results:gsub("(===" .. genTitle(args) .. "===\n{{head|amf|.+)}}",
"%1|causative|" .. cau .. "}}")
elseif pas == "4" or "5" then
results = results:gsub("(===" .. genTitle(args) .. "===\n{{head|amf|.+)}}",
"%1|causative|" .. cau .. "}}")
end
end
if args ~= true then
results = results .. "\n\n===References===\n* {{R:amf:Petrollino:2016}}"
end
if args then
results = results:gsub("2016%}%}", "2016|page=" .. args .. "}}")
end
if args then
results = results:gsub("2016%}%}", "2016|pages=" .. args .. "}}")
end
if args then
results = results .. "\n"
for _,cat in ipairs(processCat(args)) do
results = results .. "\n" .. cat
end
end
return results
end
return export