Module:User:AmazingJus/tr

local export = {}

local U = require("Module:string/char") local m_IPA = require("Module:IPA") local tbl = require("Module:table")

local gmatch = mw.ustring.gmatch local gsub = mw.ustring.gsub local split = mw.text.split local len = mw.ustring.len local match = mw.ustring.match local sub = mw.ustring.sub local lc = mw.ustring.lower

local breve = U(0x361) local stress = "ˈ"

local chars = { b = "aıou", c = "bcçdfgğhjklmnprsştvyz", f = "âeiîöûü", v = "aâeıiîoöuûü" }

local phons = { ["cons"] = { ["c"] = "ʤ", ["ç"] = "ʧ", ["g"] = "ɡ", ["ğ"] = "ɰ", ["j"] = "ʒ", ["l"] = "ɫ", ["r"] = "ɾ", ["ş"] = "ʃ", ["y"] = "j" },	["vowels"] = { ["â"] = "aː", ["ı"] = "ɯ", ["î"] = "iː", ["ö"] = "ø", ["û"] = "uː", ["ü"] = "y" },	["decomp"] = { ["ʤ"] = "d" .. breve .. "ʒ", ["ʧ"] = "t" .. breve .. "ʃ" } }

local allophs = { ["devoicing"] = { ["b"] = "p", ["c"] = "ç", ["d"] = "t", ["g"] = "k", },	["front"] = { -- operates in IPA ["ɡ"] = "ɟ", ["k"] = "c", ["ɫ"] = "l" } }

--	Creates tables to determine whether something is a consonant or a vowel	Format: { a = true, â = true, e = true, ... } -- local vowelTable = tbl.listToSet(chars.v) local consonantTable = tbl.listToSet(chars.c)

local function insert(str, i, thing) if i > len(str) then error("Index " .. i .. " is greater than the length of the string.") end return sub(str, 1, i - 1) .. thing .. sub(str, i, len(str)) end

--	Syllabifies given text by inserting a dot before a consonant,	or if there are multiple consonants, before the last one. -- local function syllabify(text) text = gsub(text, "([^" .. chars.c .. "]-)([" .. chars.c .. "]?[" .. chars.v .. "])", "%1‧%2")	text = gsub(text, "#([^" .. vowels .. "]*)‧", "#%1") -- remove leading dots text = gsub(text, "‧+", "‧") -- remove consecutive excess dots return split(text, "‧") -- return syllables as a table end

--	Normalises text by making it lowercase, marking word	boundaries with local function normalise(text) text = lc(text) -- make text lowercase text = gsub(text, "([^ ]+)", "#%1#") -- mark word boundaries with # text = syllabify(text) -- syllabify text end

--[[	Determines the stress of proper nouns according to the Sezer rule.	Operates on a word in Turkish orthography, not IPA. Gets syllabfied word	and checks the last two or three syllables (in the order ultima, penult,	antepenult), and the following consonants of the penult and antepenult (in	that order), in order to apply the Sezer stress rule.

Places stress before vowel. A later rule will have to move it to the correct position. --]] function export.sezer(text) -- get syllabification of text local syllables = syllabify(text)

-- rule only applies in words of two or more syllables if #syllables < 2 then return nil end

-- for words with two syllables, stress the first syllable if #syllables == 2 then return stress .. syllables[1] .. "‧" .. syllables[2] end

-- for words with three or more syllables if #syllables >= 3 then local antepenult = syllables[#syllables - 2] local penult = syllables[#syllables - 1]

-- check if antepenult ends with two consonants and penult with at most one local antepenult_cons = match(antepenult, "[" .. chars.c .. "]+$") or "" local penult_cons = match(penult, "[" .. chars.c .. "]+$") or ""

if #antepenult_cons >= 2 and #penult_cons <= 1 then -- stress the antepenultimate syllable syllables[#syllables - 2] = stress .. syllables[#syllables - 2] else -- otherwise stress the penultimate syllable syllables[#syllables - 1] = stress .. syllables[#syllables - 1] end

return table.concat(syllables, "‧") end

error("The function Sezer failed to add a stress mark.") end

--	Converts entries from the Turkish orthography	to a phonemic IPA transcription. -- function export.phonemic(text) if type(text) == "table" then text = text.args[1] end

-- text = normalise(text)

text = gsub(text, "([bcdg]+)([çfhkpsşt])", function(prev_cons, next_cons)		return allophs.devoicing[prev_cons] .. next_cons	end)

text = gsub(text, ".", phons.cons)

text = gsub(text, "([" .. chars.f .. "])[ɡkɫ]", function(char, next_char)		return char .. allophs.front[next_char]	end) text = gsub(text, "[ɡkɫ]([" .. chars.f .. "])", function(prev_char, char)		return allophs.front[prev_char] .. char	end)

text = gsub(text, "ck", "cc") text = gsub(text, "kc", "cc") text = gsub(text, "ɡɟ", "ɟɟ") text = gsub(text, "ɟɡ", "ɟɟ") text = gsub(text, "lɫ", "ll") text = gsub(text, "ɫl", "ll")

text = gsub(text, ".", phons.decomp) text = gsub(text, ".", phons.vowels) text = gsub(text, "‧", ".") return gsub(text, "#", "") end

return export