Module:rhymes: Difference between revisions
Jump to navigation
Jump to search
TheNightAvl (talk | contribs) (Created page with "local export = {} local getArgs = require("Module:Arguments").getArgs local m_links = require("Module:links") local m_languages = require("Module:languages") local V = "aeiouyɑæɐəɵɛɜɪɨɔœɒøʊʉʌɯʏɤ" local from_secondary = { ["lfv"] = true } -- list of language codes which get rhyme from secondary stress as well as primary function de_onset(ipa) ipa = mw.ustring.gsub(ipa, "[ˈˌ]", "") ipa = mw.ustring.gsub(ipa, "^[^" .. V .. "]+", "") ipa = mw.ust...") |
TheNightAvl (talk | contribs) No edit summary |
||
(13 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
local getArgs = require("Module:Arguments").getArgs | local getArgs = require("Module:Arguments").getArgs | ||
local m_languages = require("Module:languages") | local m_languages = require("Module:languages") | ||
local m_IPA = require("Module:IPA") | |||
local V = "aeiouyɑæɐəɵɛɜɪɨɔœɒøʊʉʌɯʏɤ" | local V = "aeiouyɑæɐəɵɛɜɪɨɔœɒøʊʉʌɯʏɤ" | ||
local from_secondary = { | local from_secondary = { | ||
["lfv"] = true, | |||
["rad"] = true, | |||
} -- list of language codes which get rhyme from secondary stress as well as primary | |||
local no_primary_if_secondary = { | |||
["lfv"] = true | ["lfv"] = true | ||
} -- list of language codes which | } -- list of language codes which ignore primary stress if secondary stress is present | ||
function de_onset(ipa) | function de_onset(ipa) | ||
ipa = mw.ustring.gsub(ipa, "[ˈˌ]", "") | ipa = mw.ustring.gsub(ipa, "[ˈˌ]", "") | ||
ipa | -- mw.log(ipa) | ||
while true do | |||
if mw.ustring.find(ipa, "^[" .. V .. "]̯") then | |||
ipa = mw.ustring.sub(ipa, 3) | |||
elseif mw.ustring.find(ipa, "^[" .. V .. "]") or mw.ustring.find(ipa, "^%S̩") then | |||
break | |||
elseif #ipa < 2 then error("No syllabic element detected") | |||
else | |||
ipa = mw.ustring.sub(ipa, 2) | |||
end | |||
-- mw.log(ipa) | |||
end | |||
return ipa | return ipa | ||
end | end | ||
function export.generate(lang, rhymes, nopre) | function export.generate(lang, rhymes, nopre, nocat) | ||
local language = m_languages.get_by_code(lang) | local language = m_languages.get_by_code(lang) | ||
local rhymes_show = "" | local rhymes_show = "" | ||
if | if nopre ~= true then | ||
rhymes_show = " | rhymes_show = "Rhyme" | ||
if #rhymes > 1 then rhymes_show = rhymes_show .. "s" end | if #rhymes > 1 then rhymes_show = rhymes_show .. "s" end | ||
rhymes_show = rhymes_show .. ": " | rhymes_show = rhymes_show .. ": " | ||
Line 36: | Line 51: | ||
if rhyme_count < 2 then | if rhyme_count < 2 then | ||
rhymes_show = rhymes_show .. | rhymes_show = rhymes_show .. | ||
"<span class=\"IPA\">-" .. rhyme .. "</span> | "<span class=\"IPA\">-" .. rhyme .. "</span>" | ||
else | else | ||
rhymes_show = rhymes_show .. | rhymes_show = rhymes_show .. | ||
"<span class=\"IPA\">[[:Category:" .. rhyme_cat .. "|-" .. rhyme .. "]]</span> | "<span class=\"IPA\">[[:Category:" .. rhyme_cat .. "|-" .. rhyme .. "]]</span>" .. | ||
"<sup> (" .. rhyme_count .. ")</sup>" | "<sup> (" .. rhyme_count .. ")</sup>" | ||
end | end | ||
if nocat ~= true then | |||
rhymes_show = rhymes_show .. "[[Category:" .. rhyme_cat .. "]]" | |||
end | |||
end | end | ||
Line 55: | Line 73: | ||
for i, rhyme in ipairs(args) do | for i, rhyme in ipairs(args) do | ||
if i > 1 then | if i > 1 then | ||
rhyme = m_IPA.get_SAMPAd(rhyme) | |||
rhyme = mw.ustring.gsub(rhyme, "[%/%[%]]", "") | rhyme = mw.ustring.gsub(rhyme, "[%/%[%]]", "") | ||
local rhyme2 = mw.ustring.match(rhyme, "ˌ( | local rhyme2 | ||
if from_secondary[language.code] and mw.ustring.find(rhyme, "ˌ") then | |||
rhyme2 = mw.ustring.match(rhyme, "ˌ([^ˈˌ]*)$") | |||
end | |||
rhyme = mw.ustring.match(rhyme, "ˈ(.*)$") or rhyme | rhyme = mw.ustring.match(rhyme, "ˈ(.*)$") or rhyme | ||
table.insert(rhymes, de_onset(rhyme)) | if rhyme2 == nil or no_primary_if_secondary[language.code] ~= true then | ||
if rhyme2 then table.insert(rhymes, de_onset(rhyme2)) end | table.insert(rhymes, de_onset(rhyme)) | ||
end | |||
if rhyme2 then | |||
table.insert(rhymes, de_onset(rhyme2)) | |||
end | |||
end | end | ||
end | end | ||
mw.logObject(rhymes) | -- mw.logObject(rhymes) | ||
return export.generate(language.code, rhymes, args["nopre"] ~= nil) | return export.generate(language.code, rhymes, args["nopre"] ~= nil, args["nocat"] ~= nil) | ||
end | end | ||
Latest revision as of 15:27, 1 August 2024
Underlies {{rhymes}}
.
local export = {}
local getArgs = require("Module:Arguments").getArgs
local m_languages = require("Module:languages")
local m_IPA = require("Module:IPA")
local V = "aeiouyɑæɐəɵɛɜɪɨɔœɒøʊʉʌɯʏɤ"
local from_secondary = {
["lfv"] = true,
["rad"] = true,
} -- list of language codes which get rhyme from secondary stress as well as primary
local no_primary_if_secondary = {
["lfv"] = true
} -- list of language codes which ignore primary stress if secondary stress is present
function de_onset(ipa)
ipa = mw.ustring.gsub(ipa, "[ˈˌ]", "")
-- mw.log(ipa)
while true do
if mw.ustring.find(ipa, "^[" .. V .. "]̯") then
ipa = mw.ustring.sub(ipa, 3)
elseif mw.ustring.find(ipa, "^[" .. V .. "]") or mw.ustring.find(ipa, "^%S̩") then
break
elseif #ipa < 2 then error("No syllabic element detected")
else
ipa = mw.ustring.sub(ipa, 2)
end
-- mw.log(ipa)
end
return ipa
end
function export.generate(lang, rhymes, nopre, nocat)
local language = m_languages.get_by_code(lang)
local rhymes_show = ""
if nopre ~= true then
rhymes_show = "Rhyme"
if #rhymes > 1 then rhymes_show = rhymes_show .. "s" end
rhymes_show = rhymes_show .. ": "
end
for num, rhyme in ipairs(rhymes) do
local rhyme_cat = "Rhymes:" .. language.name .. "/" .. rhyme
local rhyme_count = mw.site.stats.pagesInCategory(rhyme_cat, "pages")
if num > 1 then
rhymes_show = rhymes_show .. ", "
end
if rhyme_count < 2 then
rhymes_show = rhymes_show ..
"<span class=\"IPA\">-" .. rhyme .. "</span>"
else
rhymes_show = rhymes_show ..
"<span class=\"IPA\">[[:Category:" .. rhyme_cat .. "|-" .. rhyme .. "]]</span>" ..
"<sup> (" .. rhyme_count .. ")</sup>"
end
if nocat ~= true then
rhymes_show = rhymes_show .. "[[Category:" .. rhyme_cat .. "]]"
end
end
return rhymes_show
end
function export.show(frame)
local args = getArgs(frame)
local language = m_languages.get_by_code(args[1])
local rhymes = {}
if args[2] == nil then error("At least one rhyme is required") end
for i, rhyme in ipairs(args) do
if i > 1 then
rhyme = m_IPA.get_SAMPAd(rhyme)
rhyme = mw.ustring.gsub(rhyme, "[%/%[%]]", "")
local rhyme2
if from_secondary[language.code] and mw.ustring.find(rhyme, "ˌ") then
rhyme2 = mw.ustring.match(rhyme, "ˌ([^ˈˌ]*)$")
end
rhyme = mw.ustring.match(rhyme, "ˈ(.*)$") or rhyme
if rhyme2 == nil or no_primary_if_secondary[language.code] ~= true then
table.insert(rhymes, de_onset(rhyme))
end
if rhyme2 then
table.insert(rhymes, de_onset(rhyme2))
end
end
end
-- mw.logObject(rhymes)
return export.generate(language.code, rhymes, args["nopre"] ~= nil, args["nocat"] ~= nil)
end
return export
--[[
=p.show(mw.getCurrentFrame():newChild{title="parent", args={"lfv", "/ˈvydɛ/"}}:newChild{title="child"})
]]--