Module:rad-pronunciation: Difference between revisions

ਕੋਈ ਸੋਧ ਸਾਰ ਨਹੀਂ
mNo edit summary
No edit summary
 
(82 intermediate revisions by the same user not shown)
Line 1: Line 1:
local export = {}
local export = {}
local getArgs = require('Module:Arguments').getArgs
local getArgs = require("Module:Arguments").getArgs


local m_rad_IPA = require("Module:rad-IPA")
local m_rad_IPA = require("Module:rad-IPA")
local m_rad_syllables = require("Module:rad-syllables")
local m_rad_syllables = require("Module:rad-syllables")
local m_syllables = require("Module:syllables")
local m_links = require("Module:links")
local m_links = require("Module:links")
local m_languages = require("Module:languages")
local m_languages = require("Module:languages")
local m_parameters = require("Module:parameters")
local m_rhymes = require("Module:rhymes")
local m_table = require("Module:table")


function table.contains(table, element)
function export.show(frame)
  for _, value in pairs(table) do
    local args = getArgs(frame)
     if value == element then
    local word = mw.title.getCurrentTitle().subpageText
      return true
    local p = 1
 
     if args["entry"] ~= nil then
        word = args["entry"]
     end
     end
  end
  return false
end


function export.show(frame)
    -- All possible "modes":
local args_frame = getArgs(frame)
    local parameter = {["IPA"] = "IPA", ["syllables"] = "syllables", ["homophones"] = "homophones"}
local args = {}
    local register = {["colloquial"] = "colloquial", ["formal"] = "formal", ["humorous"] = "humorous"}
local p = 1
    local dialect = {["hjádvanþs"] = "hjádvanþs", ["coastal"] = "coastal", ["insular"] = "insular"}
 
mw.log("——— Processing arguments ———")
    -- create data arrays --
while args_frame[p] do
    local IPA = {
if p == 2 and args_frame[p] == "" then break end
        ["standard"] = {
table.insert(args, args_frame[p])
            ["plain"] = {}
mw.log("Argument " .. p .. ": " .. args_frame[p])
        }
p = p + 1
    }
end
    for _, r in pairs(register) do
        IPA["standard"][r] = {}
-- All possible "modes":
    end
local parameter = {["IPA"] = "IPA", ["syllables"] = "syllables", ["homophones"] = "homophones"}
    for _, d in pairs(dialect) do
local register = {["colloquial"] = "colloquial", ["formal"] = "formal"}
        IPA[d] = {["plain"] = {}}
local dialect = {["hjádvanþs"] = "hjádvanþs", ["coastal"] = "coastal", ["insular"] = "insular"}
        for _, r in pairs(register) do
            IPA[d][r] = {}
local word = args[1]
        end
    end -- set up IPA
-- get automations --
 
local auto_IPA = m_rad_IPA.generate({word})
    local rhymes = {}
local auto_IPA_phon = m_rad_IPA.generate({word, "phon"})
    local syllables = {}
local auto_IPA_hj = m_rad_IPA.generate({word, "hj"})
    local homophones = {}
local auto_IPA_phon_hj = m_rad_IPA.generate({word, "hj", "phon"})
local auto_syllables = m_rad_syllables.generate({word})
-- create data arrays --
local IPA = {
["standard"] = {["plain"] = {}, ["colloquial"] = {}, ["formal"] = {},  },
["hjádvanþs"] = {["plain"] = {}, ["colloquial"] = {}, ["formal"] = {},  },
["coastal"] = {["plain"] = {}, ["colloquial"] = {}, ["formal"] = {},  },
["insular"] = {["plain"] = {}, ["colloquial"] = {}, ["formal"] = {},  },
}
local rhymes = {}
local syllables = {}
local homophones = {}


    -- get data --
local function insert_rhyme(input, pos)
    local IPA_no_auto = false
local new_rhyme = m_rad_IPA.get_rhyme(input)
    local syllables_no_auto = false
if not (new_rhyme == nil or table.contains(rhymes, new_rhyme)) then
    local show_rhymes = true
if pos == nil then
    local mode = "IPA"
table.insert(rhymes, new_rhyme)
    local mode_dialect = "standard"
else
    local mode_register = "plain"
table.insert(rhymes, pos, new_rhyme)
    local working_syllables = ""
end
    local manual_entry = false
mw.log("Rhyme registered: " .. new_rhyme)
   
end
    -- account for acronyms
    if mw.ustring.find(word, "[A-ZÀÁẢÂÈÌÍỈÒØÙÛÚỦÝỶỲŪ][A-ZÀÁẢÂÈÌÍỈÒØÙÛÚỦÝỶỲŪ]+") then
    syllables_no_auto = true
end
end
 
-- get data --
    -- turn off rhymes if affix
local IPA_no_auto = false
    if mw.ustring.find(word, "^[%-·]") or mw.ustring.find(word, "[%-·]$") then
local syllables_no_auto = false
        show_rhymes = false
local mode = "IPA"
    end
local mode_dialect = "standard"
 
local mode_register = "plain"
    local function insert_rhyme(input, pos)
local working_syllables = ""
    if show_rhymes then
        local function insert_to_rhymes(rhyme)
for i = 2, #args do
        if not (rhyme == nil or m_table.contains(rhymes, rhyme)) then
mw.log("Processing argument " .. i .. ".")
            if pos == nil then
if parameter[args[i]] then -- mode changer
                table.insert(rhymes, rhyme)
mode = args[i]
            else
mode_dialect = "standard"
                table.insert(rhymes, pos, rhyme)
mode_register = "plain"
                pos = pos + 1
elseif dialect[args[i]] then
            end
mode_dialect = args[i]
        -- mw.log("Rhyme registered: " .. rhyme)
mode_register = "plain"
        end
elseif register[args[i]] then
        end
mode_register = args[i]
insert_to_rhymes(m_rad_IPA.get_rhyme(input))
local weak_rhymes = m_rad_IPA.get_weak_rhyme(input)
-- begin adding data to tables --
if weak_rhymes ~= nil and type(weak_rhymes) == "table" then
elseif mode == "IPA" then
for _, weak_rhyme in ipairs(weak_rhymes) do
if args[i] == "no auto" then
insert_to_rhymes(weak_rhyme)
IPA_no_auto = true
else
table.insert(IPA[mode_dialect][mode_register], args[i])
mw.log("IPA: added '" .. args[i] .. "' to IPA[" .. mode_dialect .. "][" .. mode_register .. "]")
if mode_dialect == "standard" or mode_dialect == "hjádvanþs" then
local just_phonemic = mw.ustring.gmatch(args[i], "%/(.*)%/")
insert_rhyme(just_phonemic)
end
end
end
end
elseif mode == "syllables" then
if args[i] == "no auto" then
syllables_no_auto = true
elseif args[i] == "" then
if mw.ustring.find(working_syllables, "(%|)") then
table.insert(syllables, working_syllables)
mw.log("Syllables: " .. working_syllables .. " registered.")
end
working_syllables = ""
elseif args[i+1] == nil then
working_syllables = working_syllables .. "|" .. args[i]
if mw.ustring.find(working_syllables, "(%|)") then
table.insert(syllables, working_syllables)
mw.log("Syllables: " .. working_syllables .. " registered.")
end
else
working_syllables = working_syllables .. "|" .. args[i]
end
elseif mode == "homophones" then
table.insert(homophones, args[i])
mw.log("Homophones: " .. args[i] .. " registered.")
end
end
end
    end
 
-- add auto values --
    local i = 1
if IPA_no_auto == false then
 
table.insert(IPA["standard"]["plain"], 1, "/" .. auto_IPA .. "/")
    while args[i] ~= nil or args[i + 1] ~= nil do
insert_rhyme(auto_IPA, 1)
        -- mw.log("Processing argument " .. i .. ".")
        if parameter[args[i]] ~= nil then -- mode changer
if auto_IPA_phon ~= auto_IPA then
            mode = args[i]
IPA["standard"]["plain"][1] = IPA["standard"]["plain"][1] .. " [" .. auto_IPA_phon .. "]"
            mode_dialect = "standard"
end
            mode_register = "plain"
        elseif dialect[args[i]] ~= nil then
if auto_IPA_hj ~= auto_IPA then
            if mode ~= "IPA" then
table.insert(IPA["hjádvanþs"]["plain"], 1, "/" .. auto_IPA_hj .. "/")
                mode = "IPA"
insert_rhyme(auto_IPA_hj, 2)
                mode_dialect = "standard"
                mode_register = "plain"
if auto_IPA_phon_hj ~= auto_IPA_hj then
            end
IPA["hjádvanþs"]["plain"][1] = IPA["hjádvanþs"]["plain"][1] .. " [" .. auto_IPA_phon_hj .. "]"
            mode_dialect = args[i]
end
            mode_register = "plain"
end
        elseif register[args[i]] ~= nil then
end
            -- begin adding data to tables --
            if mode ~= "IPA" then
if syllables_no_auto == false and mw.ustring.find(auto_syllables, "(%|)") then
                mode = "IPA"
table.insert(syllables, 1, auto_syllables)
                mode_dialect = "standard"
end
                mode_register = "plain"
            end
-- format --
            mode_register = args[i]
        elseif mode == "IPA" then
if #IPA["standard"]["plain"] == 0 then
            if args[i] == "no auto" or args[i] == "noauto" then
error("Missing IPA input.")
                IPA_no_auto = true
end
            elseif args[i] ~= nil then
                local temp_arg = args[i]
local args_temp = {}
               
local accent_temp = {}
                temp_arg = mw.ustring.gsub(temp_arg, "%*%(''(.*)''%)%*", "(%1)")
                local temp_note = mw.ustring.match(temp_arg, "%s*%*?%(.*%)%*?%s*")
args_temp = IPA["standard"]["plain"]
                if temp_note then
table.insert(args_temp, 1, "rad")
                temp_arg = mw.ustring.gsub(temp_arg, "%s*%*?%(.*%)%*?%s*", "")
local IPA_show = "* " .. frame:expandTemplate{ title = "IPA", args = args_temp }
                temp_note = mw.ustring.match(temp_note, "%((.*)%)")
            end
for r, _ in pairs(register) do
 
if #IPA["standard"][r] > 0 then
                if not mw.ustring.find(temp_arg, "%/(.*)%/") then
args_temp = IPA["standard"][r]
                    if mw.ustring.find(temp_arg, "%[(.*)%]") then
table.insert(args_temp, 1, "")
                        if mw.ustring.find(temp_arg, "(.*) %[") then
IPA_show = IPA_show .. "\n** (<i>" .. r .. "</i>) " .. frame:expandTemplate{ title = "IPA", args = args_temp }
                            temp_arg =
end
                                "/" ..
end
                                mw.ustring.match(temp_arg, "(.*) %[") .. "/ " .. mw.ustring.match(temp_arg, "(%[.*%])")
                        else
if #IPA["hjádvanþs"]["plain"] > 0 then
                            temp_arg = mw.ustring.match(temp_arg, "(%[.*%])")
args_temp = IPA["hjádvanþs"]["plain"]
                        end
table.insert(args_temp, 1, "")
                    elseif mw.ustring.find(temp_arg, "^%<(.*)%>$") and mode_dialect == "standard" then
IPA_show = IPA_show .. "\n** " .. frame:expandTemplate{ title = "accent", args = { "rad", "hjádvanþs" } } .. " " .. frame:expandTemplate{ title = "IPA", args = args_temp }
                        temp_arg_match = mw.ustring.match(temp_arg, "^%<(.*)%>$")
end
                        temp_arg_ipa = m_rad_IPA.generate({temp_arg_match})
for r, _ in pairs(register) do
                        temp_arg_ipa_phon = m_rad_IPA.generate({temp_arg_match, "phon"})
if #IPA["hjádvanþs"][r] > 0 then
                        temp_arg_ipa_hj = m_rad_IPA.generate({temp_arg_match, "hj"})
args_temp = IPA["hjádvanþs"][r]
                        temp_arg_ipa_hj_phon = m_rad_IPA.generate({temp_arg_match, "hj", "phon"})
table.insert(args_temp, 1, "")
 
IPA_show = IPA_show .. "\n** " .. frame:expandTemplate{ title = "accent", args = { "rad", "hjádvanþs", r } } .. " " .. frame:expandTemplate{ title = "IPA", args = args_temp }
                        temp_arg = "/" .. temp_arg_ipa .. "/"
end
                        if temp_arg_ipa_phon ~= temp_arg_ipa then
end
                            temp_arg = temp_arg .. " [" .. temp_arg_ipa_phon .. "]"
                        end
dialect["hjádvanþs"] = nil
                        if temp_arg_ipa_hj ~= temp_arg_ipa then
                            temp_arg_hj = "/" .. temp_arg_ipa_hj .. "/"
for d, _ in pairs(dialect) do
                            if temp_arg_ipa_hj_phon ~= temp_arg_hj_ipa then
                                temp_arg_hj = temp_arg_hj .. " [" .. temp_arg_ipa_hj_phon .. "]"
if #IPA[d]["plain"] > 0 then
                            end
args_temp = IPA[d]["plain"]
                            table.insert(IPA["hjádvanþs"][mode_register], temp_arg_hj)
table.insert(args_temp, 1, "")
                        end
IPA_show = IPA_show .. "\n** " .. frame:expandTemplate{ title = "accent", args = { "rad", d } } .. " " .. frame:expandTemplate{ title = "IPA", args = args_temp }
                    else
end
                        temp_arg = "/" .. temp_arg .. "/"
                    end
for r, _ in pairs(register) do
                end
if #IPA[d][r] > 0 then
 
args_temp = IPA[d][r]
if temp_note then
table.insert(args_temp, 1, "")
temp_arg = temp_arg .. " *(''" .. temp_note .. "'')*"
IPA_show = IPA_show .. "\n** " .. frame:expandTemplate{ title = "accent", args = { "rad", d, r } } .. " " .. frame:expandTemplate{ title = "IPA", args = args_temp }
end
end
end
end
                table.insert(IPA[mode_dialect][mode_register], temp_arg)
                -- mw.log("IPA: added '" .. temp_arg .. "' to IPA[" .. mode_dialect .. "][" .. mode_register .. "]")
local homophones_show = ""
                manual_entry = true
 
if #homophones  > 0 then
                if mode_dialect == "standard" or mode_dialect == "hjádvanþs" then
homophones_show = "\n* Homophones:"
                    local just_phonemic = mw.ustring.match(temp_arg, "%/(.*)%/")
for _, item in ipairs(table.sort(homophones)) do
                    insert_rhyme(just_phonemic)
homophones_show = homophones_show .. ", " .. m_links.full_link{ term = item, language = m_languages.get_by_code("rad") }
                end
end
            end
homophones_show = mw.ustring.gsub(homophones_show, "(%:%,)", "%:")
        elseif mode == "syllables" then
end
            if args[i] == "no auto" or args[i] == "noauto" then
                syllables_no_auto = true
local rhymes_show = ""
            elseif args[i] == "" or args[i] == nil then
                if mw.ustring.find(working_syllables, "(%|)") then
if #rhymes > 0 then
                    table.insert(syllables, working_syllables)
rhymes_show = "\n* Rhymes:"
                    -- mw.log("Syllables: " .. working_syllables .. " registered.")
                end
for _, rhyme in ipairs(rhymes) do
                working_syllables = ""
rhymes_show = rhymes_show .. " <span class=\"IPA\">[[:Category:Rhymes:Radestrian/" .. rhyme .. "|-" .. rhyme .. "]]</span>[[Category:Rhymes:Radestrian/" .. rhyme .. "]]"
            elseif args[i + 1] == nil then
end
                working_syllables = working_syllables .. "|" .. args[i]
end
                table.insert(syllables, working_syllables)
                -- mw.log("Syllables: " .. working_syllables .. " registered.")
local syllables_show = ""
                working_syllables = ""
            else
local function split_syllables(input)
                working_syllables = working_syllables .. "|" .. args[i]
            end
        elseif mode == "homophones" then
            if args[i] ~= nil then
                table.insert(homophones, args[i])
                mw.log("Homophones: " .. args[i] .. " registered.")
            end
        end
 
        i = i + 1
    end
 
    -- get automations --
    local auto_IPA = IPA_no_auto == false and m_rad_IPA.generate({word})
    local auto_IPA_phon = IPA_no_auto == false and m_rad_IPA.generate({word, "phon"})
    local auto_IPA_hj = IPA_no_auto == false and m_rad_IPA.generate({word, "hj"})
    local auto_IPA_phon_hj = IPA_no_auto == false and m_rad_IPA.generate({word, "hj", "phon"})
    local auto_syllables = syllables_no_auto == false and m_rad_syllables.generate({word})
 
    -- add auto values --
    if IPA_no_auto == false then
        table.insert(IPA["standard"]["plain"], 1, "/" .. auto_IPA .. "/")
        insert_rhyme(auto_IPA, 1)
 
        if auto_IPA_phon ~= auto_IPA then
            IPA["standard"]["plain"][1] = IPA["standard"]["plain"][1] .. " [" .. auto_IPA_phon .. "]"
        end
 
        if auto_IPA_hj ~= auto_IPA then
            table.insert(IPA["hjádvanþs"]["plain"], 1, "/" .. auto_IPA_hj .. "/")
            insert_rhyme(auto_IPA_hj, 2)
 
            if auto_IPA_phon_hj ~= auto_IPA_hj then
                IPA["hjádvanþs"]["plain"][1] = IPA["hjádvanþs"]["plain"][1] .. " [" .. auto_IPA_phon_hj .. "]"
            end
        end
    end
 
    if syllables_no_auto == false and mw.ustring.find(auto_syllables, "(%|)") then
        table.insert(syllables, 1, auto_syllables)
    end
 
    -- format --
 
    if #IPA["standard"]["plain"] == 0 then
        error("Missing IPA input")
    end
 
    local args_temp = {}
    local accent_temp = {}
 
    args_temp = IPA["standard"]["plain"]
    table.insert(args_temp, 1, "rad")
    local IPA_show = "* " .. frame:expandTemplate {title = "IPA", args = args_temp}
    if manual_entry == true then
        IPA_show = IPA_show .. "[[Category:Radestrian terms with manually entered pronunciation]]"
    end
 
    for r, _ in pairs(register) do
        if #IPA["standard"][r] > 0 then
            args_temp = IPA["standard"][r]
            table.insert(args_temp, 1, "rad")
            args_temp["nopre"] = 1
            IPA_show =
                IPA_show .. "\n** (<i>" .. r .. "</i>) " .. frame:expandTemplate {title = "IPA", args = args_temp}
        end
    end
 
    if #IPA["hjádvanþs"]["plain"] > 0 then
        args_temp = IPA["hjádvanþs"]["plain"]
        table.insert(args_temp, 1, "rad")
        args_temp["nopre"] = 1
        IPA_show =
            IPA_show ..
            "\n** " ..
                frame:expandTemplate {title = "accent", args = {"rad", "hjádvanþs"}} ..
                    " " ..
                        frame:expandTemplate {title = "IPA", args = args_temp} ..
                            "[[Category:Radestrian terms with hjádvanþs dialect pronunciation]]"
    end
    for r, _ in pairs(register) do
        if #IPA["hjádvanþs"][r] > 0 then
            args_temp = IPA["hjádvanþs"][r]
            table.insert(args_temp, 1, "rad")
            args_temp["nopre"] = 1
            IPA_show =
                IPA_show ..
                "\n** " ..
                    frame:expandTemplate {title = "accent", args = {"rad", "hjádvanþs", r}} ..
                        " " ..
                            frame:expandTemplate {title = "IPA", args = args_temp} ..
                                "[[Category:Radestrian terms with hjádvanþs dialect pronunciation]]"
        end
    end
 
    dialect["hjádvanþs"] = nil
 
    for d, _ in pairs(dialect) do
        if #IPA[d]["plain"] > 0 then
            args_temp = IPA[d]["plain"]
            table.insert(args_temp, 1, "rad")
            args_temp["nopre"] = 1
            IPA_show =
                IPA_show ..
                "\n** " ..
                    frame:expandTemplate {title = "accent", args = {"rad", d}} ..
                        " " ..
                            frame:expandTemplate {title = "IPA", args = args_temp} ..
                                "[[Category:Radestrian terms with " .. d .. " dialect pronunciation]]"
        end
 
        for r, _ in pairs(register) do
            if #IPA[d][r] > 0 then
                args_temp = IPA[d][r]
                table.insert(args_temp, 1, "rad")
                args_temp["nopre"] = 1
                IPA_show =
                    IPA_show ..
                    "\n** " ..
                        frame:expandTemplate {title = "accent", args = {"rad", d, r}} ..
                            " " ..
                                frame:expandTemplate {title = "IPA", args = args_temp} ..
                                    "[[Category:Radestrian terms with " .. d .. " dialect pronunciation]]"
            end
        end
    end
 
    if mw.ustring.match(IPA_show, "%>%, ") or mw.ustring.match(IPA_show, "%*.*%*") then
        IPA_show = IPA_show .. "[[Category:Radestrian terms with multiple pronunciations]]"
    end
 
    local homophones_show = ""
 
    if #homophones > 0 then
        homophones_show = "\n* Homophones:"
        table.sort(homophones)
        for _, item in ipairs(homophones) do
            homophones_show =
                homophones_show .. ", " .. m_links.full_link {term = item, language = m_languages.get_by_code("rad")}
        end
        homophones_show = mw.ustring.gsub(homophones_show, "(%:%,)", ":") .. "[[Category:Radestrian homophones]]"
    end
 
    local rhymes_show = ""
 
    if #rhymes > 0 and show_rhymes then
    rhymes_show = "\n* " .. m_rhymes.generate("rad", rhymes)
    end
 
    local syllables_show = ""
 
    local function split_syllables(input)
         local syllables = {}
         local syllables = {}
         for syl in mw.ustring.gmatch(input, "([^%|]+)") do
         for syl in mw.ustring.gmatch(input, "([^%|]+)") do
                table.insert(syllables, syl)
            table.insert(syllables, syl)
         end
         end
         return syllables
         return syllables
end
    end
 
if #syllables > 0 then
    if #syllables > 0 then
syllables_show = "\n* "
        syllables_show = "\n* "
args_temp = { "rad" }
        args_temp = {"rad"}
for set = 1, #syllables do
        for set = 1, #syllables do
if set > 1 then
            if set > 1 then
table.insert(args_temp, "")
                table.insert(args_temp, "")
end
            end
local working_syllables = split_syllables(syllables[set])
            local working_syllables = split_syllables(syllables[set])
for syl = 1, #working_syllables do
            for syl = 1, #working_syllables do
table.insert(args_temp, working_syllables[syl])
                table.insert(args_temp, working_syllables[syl])
end
            end
end
        end
syllables_show = syllables_show .. frame:expandTemplate{ title = "syllables", args = args_temp }
        args_temp["delimiter"] = "–"
end
 
        syllables_show = syllables_show .. frame:expandTemplate {title = "syllables", args = args_temp}
return IPA_show .. homophones_show .. rhymes_show .. syllables_show
    end
 
    local to_Return = IPA_show .. homophones_show .. rhymes_show .. syllables_show
 
    if args["entry"] ~= nil then
        to_Return = mw.ustring.gsub(to_Return, "%[%[Category[^%]]+%]%]", "")
    end
 
    return to_Return
end
end


Line 255: Line 372:
--[[
--[[
Debug console test string:
Debug console test string:
=p.show(mw.getCurrentFrame():newChild{title="whatever",args={"rjaovs"}})
=p.show(mw.getCurrentFrame():newChild{title="whatever",args={["entry"] = "rjaovs"}})
]]
]]