Module:pine-noun: Difference between revisions

From Linguifex
Jump to navigation Jump to search
No edit summary
No edit summary
Line 70: Line 70:
local last_syllable = syllables[syll_count]
local last_syllable = syllables[syll_count]
local nucleus = match(stressed_syllable, "^" .. consonants .. "*(" .. vowels .. "+)")
local nucleus = match(stressed_syllable, "^" .. consonants .. "*į?(" .. vowels .. "+)")
local last_vowel = match(last_syllable, "(" .. vowels .. "+)$") -- nil if consonant-final
local last_vowel = match(last_syllable, "(" .. vowels .. "+)$") -- nil if consonant-final
if syll_count == 1 then
--[[if syll_count == 1 then
nucleus = sub(gsub(nucleus, "į",""), 1, 1)
nucleus = sub(gsub(nucleus, "į",""), 1, 1)
if last_vowel then
if last_vowel then
last_vowel = sub(last_vowel, -1, -1)
last_vowel = sub(last_vowel, -1, -1)
end
end
end
end]]
local polarity = {front, back}
local polarity = {front, back}

Revision as of 16:29, 27 November 2025



local export = {}

local m_u = require('Module:utilities')
local m_l = require('Module:links')
local m_t = require('Module:table')
local m_pron = require('Module:pine-pron')
local m_data = require('Module:pine-noun/data')
local lang = require('Module:languages').getByCode("pine")

local sub = mw.ustring.sub
local find = mw.ustring.find
local match = mw.ustring.match
local gmatch = mw.ustring.gmatch
local gsub = mw.ustring.gsub
local u = mw.ustring.char
local split = mw.text.split
local gsplit = mw.text.gsplit

local PAGENAME = mw.loadData("Module:headword/data").pagename
--local NAMESPACE = mw.title.getCurrentTitle().nsText

local vowels = "[aeiouyůảẻỉỏủỷį]"
local consonants = "[rṛtpsṡdḍgġhḥkḳlḷƛvbnṇmṃ]"

local labial = m_t.listToSet({
	"m", "ṃ", "p", "b", "v"
}, "labial")

local coronal = m_t.listToSet({
	"t", "d", "ḍ", "s", "ṡ", "r", "ṛ", "l", "ḷ", "ƛ", "n", "ṇ",
	"ts", "tṡ", "lį", "ḷį", "nį", "ṇį", "dn", "ng", "kn"
}, "coronal")

local dorsal = m_t.listToSet({
	"k", "g", "ġ", "h", "ḥ",
	"hį", "kṇ", "tġ"
}, "dorsal")

local front = m_t.listToSet({
	"e", "i", "ů", "y", "ả", "ẻ", "ỉ", "ỷ",
	"ai", "ůa"
}, "front")

local back = m_t.listToSet({
	"a", "o", "u", "ỏ", "ủ",
	"oa", "oi",
}, "back")

local function quality_lookup(segment, tables)
    if not segment then return nil end
    
    for _, tbl in ipairs(tables) do
        if tbl[segment] then return tbl[segment] end
    end
    -- fallback to first letter
    local first = segment:sub(1,1)
    for _, tbl in ipairs(tables) do
        if tbl[first] then return tbl[first] end
    end
end

local function detect_decl(word, schiz)
	local syllabified = m_pron.syllabify_from_spelling(word)
	--syllabified = gsub(syllabified, "·(" .. consonants .. ")%1", "%1·%1")
	--syllabified = gsub(syllabified, "t·(t[sṡ])", "%1·%1")
	
	local syllables = split(syllabified, "·")
	local syll_count = #syllables
	local stressed_syllable = syllables[1]
	local last_syllable = syllables[syll_count]
	
	local nucleus = match(stressed_syllable, "^" .. consonants .. "*į?(" .. vowels .. "+)")
	local last_vowel = match(last_syllable, "(" .. vowels .. "+)$") -- nil if consonant-final
	--[[if syll_count == 1 then
		nucleus = sub(gsub(nucleus, "į",""), 1, 1)
		if last_vowel then
			last_vowel = sub(last_vowel, -1, -1)
		end
	end]]
	
	local polarity = {front, back}
	local pol_nucleus = quality_lookup(nucleus, polarity)
	local pol_last  = quality_lookup(last_vowel, polarity)
	local phonicity = not last_vowel and "consonantal" or pol_nucleus == pol_last and "symphonic" or "antiphonic"
	
	if m_data.teleutophonic_ending(word) then
		return "teleutophonic-" .. teleuphonic_ending
	elseif syll_count == 1 then --monosyllabic
		-- "There is unfortunately no way to tell whether a monosyllabic noun ending in a consonant belongs to
		-- the consonantal declension group of the schizaphonic declension group" (p. 119)
		if phoniticy == "consonantal" then
			if args.schiz ~= nil then
				return "monosyllabic-" .. (schiz .. "schizophonic" or "consonantal")
			else
				error(word .. " is a monosyllabic noun ending in a consonant. Disambiguation is needed between consonantal and schizophonic declensions.")
			end
		else
			return "monosyllabic-diphthongal-" .. phonicity
		end
	else
		local onset = match(stressed_syllable, "^" .. consonants .. "+") -- nil if vowel-initial
		local coda = match(stressed_syllable, consonants .. "$") or match(syllables[2], "^" .. consonants .. "+")
		local poas = {labial, coronal, dorsal}
		local poa_onset = quality_lookup(onset, poas)
		local poa_coda  = quality_lookup(coda, poas)
		
		local aphonicity = onset and "archeaphonic" or "enteraphonic"
		local organicity = poa_onset and (poa_onset == poa_coda and "homorganic" or "heterorganic") or nil
		
		if syll_count == 2 then --bisyllabic
			return "bisyllabic-" .. (phonicity == "consonantal" and phonicity or aphonicity .. "-" .. (onset and organicity .. "-" or "") .. phonicity)
		elseif syll_count == 3 then --trisyllabic
			
		end
	end
end

local function make_table(data)
	return data.decl
end

-- The main entry point.
function export.show(frame)
	local params = {
		[1] = {default = pagename, template_default = "goka"},
		["decl"] = {},
		["schiz"] = {},
	}

	local parent_args = frame:getParent().args
	local args = require("Module:parameters").process(parent_args, params)
	
	local data = {}
	data.decl = args.decl or detect_decl(args[1], args.schiz)
	
	-- make the table
	return make_table(data)
end



return export