Module:Doth-head: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
(8 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
local lang = require("Module:languages").getByCode("doth") | local lang = require("Module:languages").getByCode("doth") | ||
local vowels = " | local vowels = "aeioAEIO" | ||
local consonants = " | local consonants = "chdfghijkkhlmnqrsshtthvwyzzhCHDFGHIJKKHLMNQRSSHTTHVWYZZH" | ||
function export.isVowelFirst(term) | function export.isVowelFirst(term) | ||
Line 53: | Line 53: | ||
if (args[1] == nil or args[1] == "~") then | if (args[1] == nil or args[1] == "~") then | ||
stem = PAGENAME | stem = string.lower(PAGENAME) | ||
else | else | ||
stem = args[1] | stem = args[1] | ||
Line 83: | Line 83: | ||
local negative = "" | local negative = "" | ||
if (isFirst == true) then | if (isFirst == true) then | ||
positive = "as"..stem | positive = "as"..string.lower(stem) | ||
else | else | ||
positive = "a"..stem | positive = "a"..string.lower(stem) | ||
end | end | ||
if (isFirst == true) then | if (isFirst == true) then | ||
negative = "os"..stem | negative = "os"..string.lower(stem) | ||
else | else | ||
negative = "o"..stem | negative = "o"..string.lower(stem) | ||
end | end | ||
Line 139: | Line 139: | ||
local data = {lang = lang, pos_category = "nouns", categories = {}, sort_key = args["sort"], heads = {args["head"]}, genders = {}, inflections = {}} | local data = {lang = lang, pos_category = "nouns", categories = {}, sort_key = args["sort"], heads = {args["head"]}, genders = {}, inflections = {}} | ||
-- Plural | -- Plural | ||
local plural = args[2][1] | local plural = args[2][1] | ||
Line 173: | Line 162: | ||
args[2].label = "plural" | args[2].label = "plural" | ||
table.insert(data.inflections, args[2]) | table.insert(data.inflections, args[2]) | ||
end | end | ||
Line 220: | Line 191: | ||
end | end | ||
return word | return word | ||
end | end | ||
Line 254: | Line 216: | ||
break | break | ||
end | end | ||
end | end | ||
Latest revision as of 23:44, 8 January 2020
Documentation for this module may be created at Module:Doth-head/documentation
-- This module contains code for Dothraki headword templates.
local export = {}
local lang = require("Module:languages").getByCode("doth")
local vowels = "aeioAEIO"
local consonants = "chdfghijkkhlmnqrsshtthvwyzzhCHDFGHIJKKHLMNQRSSHTTHVWYZZH"
function export.isVowelFirst(term)
local first = string.sub(term,1,1)
if (string.match(vowels,first) == nil) then
return false
else
return true
end
end
function export.isVowelLast(term)
local last = string.sub(term,-1)
if (string.match(vowels,last) == nil) then
return false
else
return true
end
end
function export.dothadj(frame)
local params = {
[1] = {},
[2] = {},
[3] = {},
[4] = {},
[5] = {},
[6] = {},
[7] = {},
["head"] = {},
["sort"] = {},
}
local PAGENAME = mw.title.getCurrentTitle().text
local args = require("Module:parameters").process(frame:getParent().args, params)
local data = {lang = lang, pos_category = "adjectives", categories = {}, sort_key = args["sort"], inflections = {}, heads = args["head"]}
local stem = ""
if (args[1] == nil or args[1] == "~") then
stem = string.lower(PAGENAME)
else
stem = args[1]
end
-- local end1 = args[2]
local isFirst = export.isVowelFirst(stem)
local isLast = export.isVowelLast(stem)
if not stem then -- all specified
data.heads = args[2]
data.inflections = {
{label = "positive", args[3]},
{label = "comparative", args[4]},
{label = "superlative", args[5]},
{label = "negative", args[6]},
{label = "contrastitive", args[7]},
{label = "sublative", args[8]}
}
else
if (args["head"] == nil) then
data.heads = {stem}
else
data.heads = {args["head"]}
end
if (args[1] ~= "~") then
local positive = ""
local negative = ""
if (isFirst == true) then
positive = "as"..string.lower(stem)
else
positive = "a"..string.lower(stem)
end
if (isFirst == true) then
negative = "os"..string.lower(stem)
else
negative = "o"..string.lower(stem)
end
local comparative = ""
local superlative = ""
local contrastive = ""
local sublative = ""
if (isLast == true) then
comparative = positive.."n"
superlative = positive.."naz"
contrastive = negative.."n"
sublative = positive.."noz"
else
comparative = positive.."an"
superlative = positive.."anaz"
contrastive = negative.."an"
sublative = positive.."anoz"
end
data.inflections = {
{label = "comparative", comparative},
{label = "superlative", superlative},
{label = "negative", negative},
{label = "contrastive", contrastive},
{label = "sublative", sublative}
}
end
end
return require("Module:headword").full_headword(data)
end
function export.itnoun(frame)
PAGENAME = mw.title.getCurrentTitle().text
local params = {
[1] = {list = "g", default = "?"},
[2] = {list = "pl"},
["f"] = {},
["head"] = {},
["m"] = {},
["sort"] = {},
}
local args = require("Module:parameters").process(frame:getParent().args, params)
local data = {lang = lang, pos_category = "nouns", categories = {}, sort_key = args["sort"], heads = {args["head"]}, genders = {}, inflections = {}}
-- Plural
local plural = args[2][1]
if not plural then
args[2][1] = make_plural(PAGENAME, data.genders[1])
end
if plural == "~" then
table.insert(data.inflections, {label = "[[Appendix:Glossary#uncountable|uncountable]]"})
table.insert(data.categories, "Italian uncountable nouns")
else
table.insert(data.categories, "Italian countable nouns")
end
if plural == "-" then
table.insert(data.inflections, {label = "[[Appendix:Glossary#invariable|invariable]]"})
end
if plural == "-" or plural == "~" then
else
args[2].label = "plural"
table.insert(data.inflections, args[2])
end
return require("Module:headword").full_headword(data)
end
-- Generate a default plural form, which is correct for most regular nouns
function make_plural(word, gender)
-- If there are spaces in the term, then we can't reliably form the plural.
-- Return nothing instead.
if word:find(" ") then
return nil
elseif word:find("io$") then
word = word:gsub("io$", "i")
elseif word:find("ologo$") then
word = word:gsub("o$", "i")
elseif word:find("[cg]o$") then
word = word:gsub("o$", "hi")
elseif word:find("o$") then
word = word:gsub("o$", "i")
elseif word:find("[cg]a$") then
word = word:gsub("a$", (gender == "m" and "hi" or "he"))
elseif word:find("[cg]ia$") then
word = word:gsub("ia$", "e")
elseif word:find("a$") then
word = word:gsub("a$", (gender == "m" and "i" or "e"))
elseif word:find("e$") then
word = word:gsub("e$", "i")
end
return word
end
function export.itprop(frame)
local params = {
[1] = {list = "g", default = "?"},
["f"] = {},
["head"] = {},
["m"] = {},
["sort"] = {},
}
local args = require("Module:parameters").process(frame:getParent().args, params)
local data = {lang = lang, pos_category = "proper nouns", categories = {}, sort_key = args["sort"], heads = {args["head"]}, genders = args[1], inflections = {}}
for i, g in ipairs(data.genders) do
if g == "p" then
data.genders[i] = "?-p"
end
if g == "m-p" or g == "f-p" or g == "?-p" or g == "p" then
table.insert(data.inflections, {label = "[[Appendix:Glossary#plural only|plural only]]"})
table.insert(data.categories, lang:getCanonicalName() .. " pluralia tantum")
break
end
end
return require("Module:headword").full_headword(data)
end
return export