Module:vi-adj

local p = {}

local m_links = require("Module:links") local m_utils = require("Module:utilities") local lang = require("Module:languages").getByCode("vi")

local tone_diacritics = { ["̀"] = "̀", ["́"] = "", ["̉"] = "", ["̃"] = "̀", ["̣"] = "̀" }

local checked_finals = { ["p$"] = "m", ["t$"] = "n", ["ch$"] = "nh", ["c$"] = "ng" }

function p.rdp_one(frame) local lemma = frame.args[1] or mw.title.getCurrentTitle.text local rdp_syll_normed = mw.ustring.toNFD(lemma) rdp_syll_normed = mw.ustring.gsub(rdp_syll_normed, "̣̂", "̂̀") -- dot-below is put before circumflex, which causes problems later on	rdp_syll_normed = mw.ustring.gsub(rdp_syll_normed, "̣̆", "̆̀") -- same with breve for orig, modif in pairs(tone_diacritics) do		rdp_syll_normed = mw.ustring.gsub(rdp_syll_normed, orig, modif) end for orig, modif in pairs(checked_finals) do		rdp_syll_normed = mw.ustring.gsub(rdp_syll_normed, orig, modif) end return mw.ustring.toNFC(rdp_syll_normed) .. " " .. lemma end

local function a_rdp(syllable) local syllable_normed = mw.ustring.toNFD(syllable) local a_with_tone = "a" if mw.ustring.find(syllable_normed, "[̣̀̃]") ~= nil then a_with_tone = "à" end local initial = mw.ustring.match(syllable_normed, "([^aăâeêioôơuưyAĂÂEÊIOÔƠUƯY]+)") if mw.ustring.find(syllable_normed, "([aăâeêioôơuưyAĂÂEÊIOÔƠUƯY]+)")==1 then initial = "" end -- in case the syllable starts with a vowel if initial == "gh" then initial = "g" end -- in case the syllable was ghi, ghê, ghe return mw.ustring.toNFC(initial .. a_with_tone) end

function p.rdp_two(frame) local lemma = frame.args[1] or mw.title.getCurrentTitle.text local syllables = {} for w in string.gmatch(lemma, "([^ ]+)") do		table.insert(syllables, w)	end return syllables[1] .. " " .. a_rdp(syllables[2]) .. " " .. lemma end

function p.rdp_two_var(frame) local lemma = frame.args[1] or mw.title.getCurrentTitle.text local syllables = {} for w in string.gmatch(lemma, "([^ ]+)") do		table.insert(syllables, w)	end return lemma .. " " .. a_rdp(syllables[1]) .. " " .. a_rdp(syllables[2]) end

function p.rdp_AABB(frame) local lemma = frame.args[1] or mw.title.getCurrentTitle.text local syllables = {} for w in string.gmatch(lemma, "([^ ]+)") do		table.insert(syllables, w)	end return syllables[1] .. " " .. syllables[1] .. " " .. syllables[2] .. " " .. syllables[2] end

function p.rdp_type(frame) local type_of_rdp = {[1] = "dim", [3] = "aug"} local lemma = frame.args[1] local s, number_of_spaces = string.gsub(lemma," "," ") return type_of_rdp[number_of_spaces] end

return p