10,731
edits
No edit summary |
TheNightAvl (talk | contribs) No edit summary Tag: Reverted |
||
Line 1: | Line 1: | ||
local export = {} | local export = {} | ||
local d_languages = mw.loadData("Module:languages/data") | local d_languages = mw.loadData("Module:languages/data") | ||
local d_pos = { | |||
"adjectives", | |||
"adverbs", | |||
"articles", | |||
"conjunctions", | |||
"determiners", | |||
"interjections", | |||
"nouns", | |||
"numerals", | |||
"particles", | |||
"phrases", | |||
"postpositions", | |||
"prepositions", | |||
"pronouns", | |||
"proper nouns", | |||
"symbols", | |||
"verbs", | |||
} | |||
-- Alternative to mw.ustring.gsub that is neater to call in code | -- Alternative to mw.ustring.gsub that is neater to call in code | ||
Line 26: | Line 44: | ||
local function to_pattern(pattern, categories) | local function to_pattern(pattern, categories) | ||
return {"^" .. pattern .. "$", categories} | return {"^" .. pattern .. "$", categories} | ||
end | |||
-- provides initial capitalisation | |||
local function capitalise(word) | |||
if mw.ustring.len(word) > 1 then | |||
return mw.ustring.upper(mw.ustring.sub(word, 1, 1)) .. mw.ustring.sub(word, 2) | |||
elseif mw.ustring.len(word) == 1 then | |||
return mw.ustring.upper(word) | |||
end | |||
error("Empty input for capitalisation") | |||
end | end | ||
Line 59: | Line 87: | ||
end | end | ||
table.insert(out_patterns, to_pattern(replace(p_lua, "%%c", l_code), p_out_cats)) | table.insert(out_patterns, to_pattern(replace(p_lua, "%%c", l_code), p_out_cats)) | ||
end | |||
end | |||
local function hydrate_pattern_pos(out_patterns, p_lua, p_categories) | |||
for _, pos in ipairs(d_pos) do | |||
local p_out_cats = {} | |||
for _, p_cat in ipairs(p_categories) do | |||
table.insert(p_out_cats, replace(p_cat, "%%pos", pos)) | |||
end | |||
table.insert(out_patterns, to_pattern(replace(p_lua, "%%pos", pos), p_out_cats)) | |||
end | end | ||
end | end | ||
Line 71: | Line 109: | ||
elseif mw.ustring.find(p_template, "%%c") ~= nil then | elseif mw.ustring.find(p_template, "%%c") ~= nil then | ||
hydrate_pattern_c(out_patterns, p_lua, p_categories) | hydrate_pattern_c(out_patterns, p_lua, p_categories) | ||
elseif mw.ustring.find(p_template, "%%pos") ~= nil then | |||
hydrate_pattern_pos(out_patterns, p_lua, p_categories) | |||
else | else | ||
table.insert(out_patterns, to_pattern(p_lua, p_categories)) | table.insert(out_patterns, to_pattern(p_lua, p_categories)) |