Module:Riscrijhaedje

Èn årtike di Wiccionaire.
Aller à la navigation Aller à la recherche
Notule d' esplikêyes

Ci module ci est eployî pa d' ôtes modules ou modeles po riscrire pus åjheymint des loyéns eviè des pådjes do wiccionaire.

Tcherdjaedje

Po poleur eployî ci module ci dins èn ôte, i l' fåt tcherdjî :

cat = require("Module:Riscrijhaedje")

Fonccions po les modules

p.starts_with_vowel(w)

Ritoûne vraiy si l' mot w kimint pa ene voyale.

p.ends_with_vowel(w)

Ritoûne vraiy si l' mot w finixh pa ene oyvåve voyale.

p.aclape_bodje_cawe(bdj, caw)

Ritoûne on tecse fwait pa aclapaedje des deus parametes, tot candjant s' i fåt l' fén do prumî ou l' kimince do deujhinme, po rispecter les rîles d' ortografeye do rfondou walon.

p.betchete_cogne_motli(mot)

Ritoûne li mot passe e paramete, ki pout mostrer des spotchåvès voyales etur atchetes, riscrît dins si mwaisse cogne (metans « r(i)fé « -> « rifé », « s(i)crire » -> « scrire » ).

p.get_anchor(croejh, ling)

Cisse fonccion co eploye divintrinnmint les modules Hagnon eyet Lingaedje po constrûre ene etikete (anchor) del minme manire ki l' module Hagno el fwait po les tites.
  • croejh ene croejhete, emey les cenes eployeyes dins les tites di hagnons
  • ling on côde di lingaedje

p.get_article_link_anchor(tite, croejh, ling, anke)

Fwait on loyén wikicôde eviè l' pådje « tite », tot radjoutant ene etikete po-z aler al boune seccion. Elle eploye divintrinnmint betchete_cogne_motli() eyet get_anchor()
  • tite c' est l' tite del pådje. Asteme : li tite est sinsibe ås grandes et pititès letes : « mots » n' est nén l' minme ki « Mots ». Si l' tecse contént ddja do wikicôde di loyéns (s' i gn a « [[ ») li fonccion nel candjrè nén.
  • croejh ene croejhete, emey les cenes eployeyes dins les tites di hagnons (vey Module:Hagnon
  • ling on côde di lingaedje. Il est eployî, avou croejhete si defineye, po fé on loyén viè l' seccion corespondante del pådje
  • anke si defini, adon croejhete et lingaedje sont-st ignorés; et anke dene l' etikete egzacte a-z eployî (ça permete di dispårti des omonimes)

p.split_article_link(w)

Si w est on loyén wikicôde, avou « / » (espåce-båre di clintchî-espåce) dins l' no do loyén, adon l' fonccion ritoûnrè ostant ene tchinne avou ostant d' loyéns wikicôde dispårtis pa « / » (metans [[aveur / awè]] -> [[aveur]] / [[awè]]). Si l' loyén a-st ene anke, ele serè-st wårdêye dins les loyéns riscrîts.

Egzimpe

Ene môdeye simplifieye do côde eployî dins l' module Module:Ortografeyes

local p = {}
local riscr = require("Module:Riscrijhaedje");

...
	-- ("word" c' est l' tchinne dins l' côde wiki del pådje,
    -- "lw" c' est come on l' vout riscrire
    -- "fw", "strbegin", "strend" des variåves timporaires d' ovraedje)

	-- handle things like: "r(i)gon (rigon / r'gon)"
	fw = string.find(word, " %(") -- drovante åtchete avou on blanc pa dvant: r(i)gon » («rigon / r'gon)"
	if fw then
		local strbegin = string.sub(word, 1, fw - 1)
        -- get_article_link("r(i)gon", "", "wa") --> "[[rigon#Walon|r(i)gon]]"
		strbegin = riscr.get_article_link(strbegin, "", ling)
		local strend = string.sub(word, fw + 2)
		strend = string.gsub(strend, "%)$", "")
		-- if "/text/" then it is a phonetic transcription, keep unchanged
		-- else we linkify it
		if not string.match(strend, "/[^ ][^/]+[^ ]/") then
        	-- get_article_link("rigon / r'gon", "", "wa") -> "[[rigon / r'gon#Walon|rigon / r'gon]]"
			strend = riscr.get_article_link(strend, "", ling)
			if string.match(strend, " / ") then
				-- split_article_link("[[rigon / r'gon#Walon|rigon / r'gon]]")
                -- -> "[[rigon#Walon|rigon]] / [[r'gon#Walon|r'gon]]"
				strend = riscr.split_article_link( strend )
			end
		end
		lw = strbegin .. " ( " .. strend .. " )"
	else
		lw = riscr.get_article_link(word, "", ling)
		if string.match(word, " / ") then
			lw = riscr.split_article_link( lw )
		end
	end

---


Fonccions po les modeles

A-z eployî dins on modele, avou {{#invoke:Riscrijhaedje|<fonccion>|<parametes>}}.

starts_with_vowel_template

hoûke p.starts_with_vowel
parametes: on paramete nén lomé: {{#invoke:Riscrijhaedje|starts_with_vowel_template|<mot>}}

ends_with_vowel_template

hoûke p.ends_with_vowel
parametes: on paramete nén lomé: {{#invoke:Riscrijhaedje|ends_with_vowel_template|<mot>}}

aclape_bodje_cawe_template

hoûke p.aclape_bodje_cawe
parametes: deus parametes nén lomés: {{#invoke:Riscrijhaedje|aclape_bodje_cawe_template|<bodje>|<cawete>}}

get_article_link_template

hoûke p.get_article_link_anchor
parametes: di onk a cwate parametes nén lomés:
  • {{#invoke:Riscrijhaedje|get_article_link_template|<mot>}}
  • {{#invoke:Riscrijhaedje|get_article_link_template|<mot>|<croejhete>|<côde lingaedje>}}
  • {{#invoke:Riscrijhaedje|get_article_link_template|<mot>||<côde lingaedje>}}
  • {{#invoke:Riscrijhaedje|get_article_link_template|<mot>|||<anke>}}

split_article_link_template

hoûke p.split_article_link
parametes: on paramete nén lomé: {{#invoke:Riscrijhaedje|split_article_link_template|<loyén wikicôde>}}

Egzimpe

Egzimpe d' eployaedje dins l' Modele:riscr-loyén-viebe (eployî dins les grands tåvleas d' codjowaedje fwaits pa Modele:Codjowaedje do walon)

<includeonly>{{#invoke:Riscrijhaedje|split_article_link_template|{{#invoke:Riscrijhaedje|get_article_link_template
|1={{{1|}}}
|2={{#switch:{{{2|}}}
 |INF=Vi
 |PP=PP
 |PE=PE
 |PEf=PE
 |Vi=Vi
 |#default=Codjowa}}
|3={{{3|wa}}}
}}}}</includeonly><noinclude>{{doc}}</noinclude>

Dj' ô bén, li codjowa est d' aprume candjî a on loyén wikicôde, avou ene etikete fwait del croejhete (avou on riscrijhaedje des croejhetes di codjowaedje eployeyes pa Modele:Codjowaedje do walon eyet les cenes di Modele:H) eeyt do lingaedje (prémetou a « wa »); et poy on houke split_article_link_template po dispårti, s' i fåt, les variantes.

Çou ki dene, avou INF = aveur / awè dins on tåvlea di codjowaedje, on loyén come çoucial:

[[aveur#Walon Viebe|aveur]] / [[awè#Walon Viebe|awè]]

local p = {}
local builder = require("Module:Builder")

-- Return true if the word starts with a spoken vowel
function p.starts_with_vowel(w)
    -- if no word given, return false
    if (w == nil) then return false end
    -- trim word
    w = mw.text.trim(w)
    -- lower case
    w = mw.ustring.lower(w)
    
    if mw.ustring.match( w,  "^[aåâäeéèêëiìîoóòôöuúùûü]" )
    then
        return true
    else
        return false
    end
end

-- Return true if the word ends with a spoken vowel
function p.ends_with_vowel(w)
    -- if no word given, return false ??
    if (w == nil) then return false end
    -- trim word
    w = mw.text.trim(w)
    -- lower case
    w = mw.ustring.lower(w)
    
    wtest = w

	-- ending "s" is always silent (to be heard it must be -ss or -se)    
    if string.match( wtest, "s$") -- wtest.endswith( "s" )
    then
    	wtest =  string.sub(wtest, 1, -2) -- strip trailing s (plural mark)
    end
    -- ending "e" is silent and is for a spoken consonant, unless if it is a betchfessî
    if string.match( wtest, "e$") -- wtest.endswith("e")
    then
    	if string.match( wtest, "[qg]ue$")
    	then
    		return false
    	end
    	if mw.ustring.match( wtest, "[aiéou]e$") -- betchfessîs "ae", "oe"; "ée", ie", ue" c'est e Feller
    	then
    		return true
    	else
    		return false
    	end
    end

	-- ending "t" is very often (but not always) unspoken    
    if string.match( wtest, "t$")
    then
	    if wtest == "èt"
	    then
	    	return false -- FIXME : in Feller it is true
	    end
	    if string.match( wtest, "èt$")
	    then
	    	return true
	    end
	    -- FIXME : no exceptions ?
		wtest = wtest:sub(1, -2) -- strip trailing "t"
    end

    if string.match( wtest, "c$")
    then
    	if string.match( wtest,  "[ao]nc$" )
    	then
        	return true
    	else
        	return false
        end
    end
    
	-- FIXME : to improve    
    if mw.ustring.match( wtest,  "[aåâäeéèêëiìîoóòôöuúùûü]$" ) or 
    	mw.ustring.match( wtest,  "[aéiou]n$" )
    then
        return true
    else
        return false
    end
end

-- Returns a strings from the concatenation of two strings, applying needed orthographic rules
function p.aclape_bodje_cawe(bdj, caw)
    if (bdj == nil) then bdj = "" end
    if (caw == nil) then caw = "" end
    -- trim word
    caw = mw.text.trim(caw)
    bdj = mw.text.trim(bdj)

	-- some normalization just in case
	if string.match( bdj, "ss$")
	then
		bdj = string.gsub( bdj, "ss$", "s")
	end

	-- this is ambiguous; use "-k" or "-ç" is preferred
	-- si caw -el... ou -l..  c' est motoit bén on viebe avou -cler / -kele => -k
	-- ôtrumint, c' est surmint come "apicî" => -ç
	if string.match( bdj, "c$")
	then
		if string.match( caw, "^el") or string.match( caw, "^l")
		then
			bdj = string.gsub( bdj, "c$", "k")
		else
			bdj = string.gsub( bdj, "c$", "ç")
		end
	end

    mot = bdj .. "_" .. caw

	if mw.ustring.match( mot, "k_[^eêéèiîy\()]")
	then
		return string.gsub(mot, "k_", "c")
	end
	if mw.ustring.match( mot, "ç_[eêéèiîy\()]")
	then
		return string.gsub(mot, "ç_", "c")
	end
	if mw.ustring.match( mot, "g_[eêéèiî]")
	then
		return string.gsub(mot, "g_", "gu")
	end
	if mw.ustring.match( mot, "[aâåeêéèiîoôuû]s_[aâåeêéèiîoôuû]")
	then
		return string.gsub(mot, "s_", "ss")
	end
	if mw.ustring.match( mot, "[aâåeêéèiîoôuû]_s[aâåeêéèiîoôuû]")
	then
		return string.gsub(mot, "_s", "ss")
	end
	if mw.ustring.match( mot, "[aâåeêéèiîoôuû]s_y[aâåeêéèiîoôuû]")
	then
		return string.gsub(mot, "s_", "ss")
	end
	-- special case; only used by some modules to build the radix flexion of 
	-- verbs of the kind of "netyî" (A=net+y, B=net+ey); so that it works for
	-- the likes of "scussyî"
	if mw.ustring.match( mot, "[aâåeêéèiîoôuû]s_y$")
	then
		return string.gsub(mot, "s_", "ss")
	end
	if mw.ustring.match( mot, "[aâåeêéèiîoôuû]_sy[aâåeêéèiîoôuû]")
	then
		return string.gsub(mot, "_s", "ss")
	end
	if mw.ustring.match( mot, "[^aâåeêéègiîoôuû ]y_([aâåeêéèoôuû])")
	then
		return string.gsub(mot, "y_", "i")
	end
	if mw.ustring.match( mot, "gy_[aâåeêéèoôuû]")
	then
		return string.gsub(mot, "gy_", "gui")
	end
	if string.match( mot, "n_[bp]")
	then
		return string.gsub(mot, "n_", "m")
	end
	if string.match( mot, "â_[rbdgjvz]")
	then
		return string.gsub(mot, "â_", "a")
	end
	if string.match( mot, "ê_[rbdgjvz]")
	then
		return string.gsub(mot, "ê_", "e")
	end
	if string.match( mot, "î_[rbdgjvz]")
	then
		return string.gsub(mot, "î_", "i")
	end
	if string.match( mot, "ô_[y]")
	then
		return string.gsub(mot, "ô_", "o")
	end
	if string.match( mot, "û_[rbdgjvz]")
	then
		return string.gsub(mot, "û_", "u")
	end
	if string.match( mot, "c_h")
	then
		return string.gsub(mot, "c_", "k")
	end

    return bdj .. caw
   
end

function p.betchete_cogne_motli(mot)
    if (mot == nil) then mot = "" end
    mot = mw.text.trim(mot)

	-- sipotchaedje coûtchantrece, on ritoûne li cogne plinne	
    if mw.ustring.match(mot, "^%([eèEÈ]s%)s" )
    then
    	return mw.ustring.sub(mot, 2, 3) .. mw.ustring.sub(mot, 5 )
    end
    --[[
    if mw.ustring.match(mot, "^%([eèEÈ]%)ss" )
    then
    	return mw.ustring.sub(mot, 2, 2) .. mw.ustring.sub(mot, 4 )
    end
    ]]--
    if mw.ustring.match(mot, "^%([eèEÈ]%)s" )
    then
    	return mw.ustring.sub(mot, 2, 2) .. mw.ustring.sub(mot, 4 )
    end
    if mw.ustring.match(mot, "^%([eèEÈ]%)r" )
    then
    	return mw.ustring.sub(mot, 2, 2) .. mw.ustring.sub(mot, 4 )
    end
    if mw.ustring.match(mot, "^%([eèEÈ]%)n[nd]" )
    then
    	return mw.ustring.sub(mot, 2, 2) .. mw.ustring.sub(mot, 4 )
    end

	-- sipotchaedhe ene lete pa dvant
    if string.match(mot, "^[sS]%([iu]%)" )
    then
    	return p.aclape_bodje_cawe(
    		string.sub(mot, 1, 1),
    		string.sub(mot, 5 ) )
    end
    if string.match(mot, "^[bBcCdDfFkKlLmMpPrRsStTvV]%([eiuo]%)" )
    then
    	return p.aclape_bodje_cawe(
    		string.sub(mot, 1, 1) .. string.sub(mot, 3, 3),
    		string.sub(mot, 5 ) )
    end
    if string.match(mot, "^[bBcCdDfFkKlLmMpPrRsStTvV]%([eiuo]s%)" )
    then
    	return 
    		string.sub(mot, 1, 1) .. string.sub(mot, 3, 4) ..
    		string.sub(mot, 6 )
    end

    if string.match(mot, "^[dD]j%([iu]%)" )
    then
    	return p.aclape_bodje_cawe(
    		string.sub(mot, 1, 2) .. string.sub(mot, 4, 4),
    		string.sub(mot, 6 ) )
    end
    if string.match(mot, "^[tT]ch%([iu]%)" )
    then
    	return p.aclape_bodje_cawe(
    		string.sub(mot, 1, 3) .. string.sub(mot, 5, 5),
    		string.sub(mot, 7 ) )
    end
    if string.match(mot, "^[sS]ch%([iu]%)" )
    then
    	return p.aclape_bodje_cawe(
    		string.sub(mot, 1, 3) .. string.sub(mot, 5, 5),
    		string.sub(mot, 7 ) )
    end
    
    return mot
end

-- Returns an anchor corresponding to a given grammer and language
function p.get_anchor(croejh, ling)
    if (croejh == nil) then croejh = "" end
    if (ling == nil) then ling = "wa" end
	local langObj = mw.language.new("wa")
	
    anchor = ""
    
    if croejh ~= ""
    then
		local h = require("Module:Hagnon")
		local title = mw.ustring.lower( croejh )
		local titles = mw.loadData("Module:Hagnon/data")
		local id_title = ""

		if h.is_title(title) then
			if h.is_alias(title) then
				title = titles['alias'][title]
			elseif titles['text'][title] ~= nil then
				title = titles['text'][title]
			end
		else
			-- unknown grammar, return just the languag name as anchor
	    	title = ""
		end
	
		if ling ~=nil then
	   		local l = require("Module:Lingaedje")
			local lang = l.get_name( ling )
			if lang ~=nil then
				id_title = langObj:ucfirst(lang)
	    		if ling == "wa-fel" then
	    			id_title = id_title .. "-Feller"
	    		elseif ling == "wa-vsis" then
	    			id_title = id_title .. " (vîs sistinmes)"
	    		elseif ling == "wa-vrif" then
	    			id_title = id_title .. " (viye rifondowe)"
	    		end
			
				if title.name ~=nil then
					if title.name ~= "etimolodjeye" then
						id_title = id_title ..' '.. langObj:ucfirst(title.name)
					end
				else
					id_title = id_title ..' '.. langObj:ucfirst(title)
				end
			end
		end
	
		if id_title ~= ""
		then
			anchor = "#" .. langObj:ucfirst(id_title)
		end
	
    else
    	if ling ~= ""
    	then
    		local l = require("Module:Lingaedje")
    		local lang = l.get_name( ling )
    		if lang ~=nil then
	    		anchor = "#" .. langObj:ucfirst( lang )
	    		-- special cases
	    		if ling == "wa-fel" then
	    			anchor = anchor .. "-Feller"
	    		elseif ling == "wa-vsis" then
	    			anchor = anchor .. " (vîs sistinmes)"
	    		elseif ling == "wa-vrif" then
	    			anchor = anchor .. " (viye rifondowe)"
	    		end
	    	end
    	end
    end
    
    return anchor
end

-- Returns a wikicode link with article name beginning rewritten to point to main one
function p.get_article_link(mot, croejh, ling)
	return p.get_article_link_anchor(mot, croejh, ling, nil)
end
function p.get_article_link_anchor(mot, croejh, ling, anchor)
    if (mot == nil) then mot = "" end
    if (croejh == nil) then croejh = "" end
    if (ling == nil or ling == "") then ling = "wa" end
    if (anchor == nil) then anchor = "" end

	-- already linkified, do nothing
	if string.match( mot, "%[%[")
	then
		return mot
	end

    -- trim
    mot = mw.text.trim(mot)
    croejh = mw.text.trim(croejh)
    ling = mw.text.trim(ling)

	local link = ""
	if anchor ~= "" then anchor = "#"..anchor end
 
	if mot ~= ""
	then
		local artike = mot
		
		if string.match( mot, "%(") and (ling == "wa" or ling == "wa-fel" or ling == "wa-vsis")
		then
			artike = p.betchete_cogne_motli(mot)
		end
		
		if anchor == "" and (croejh ~= "" or ling ~= "")
		then
			anchor = p.get_anchor(croejh, ling)
		end
		
		link = "[[" .. artike
		
		if anchor ~= ""
		then
			link = link .. anchor
		end
		
		if artike ~= mot or anchor ~= ""
		then 
			link = link .. "|" .. mot
		end
		
		link = link .. "]]"
	end
	
	return link
end

-- takes a wikicode link and if it has " / " or " u " in the article name, split it
-- to several wikicode links
function p.split_article_link(w)
    if (w == nil) then w = "" end
    local sep = " / "
    local sep2 = ", "
    local regsep = " [u/] "

    if string.match(w, regsep ) or string.match(w, sep2 )
    then
    	-- first check if the parts aren't already separate links
    	if string.match(w, "%]%]"..regsep.."%[%[" ) or
    			string.match(w, "%]%]"..sep2.."%[%[" ) then
    		return w
    	end
    	
    	local anchor = ""
    	local display = ""
    	local linkstart = ""
    	local linkend = ""
    	local pos = 0
    	local pos2 = 0
    	local splititems = ""
    	
    	-- look for anchor and display part
    	pos = mw.ustring.find (w, "#")
    	pos2 = mw.ustring.find (w, "|")

    	if (pos2 ~= nil)
    	then
    		display = mw.ustring.sub (w, pos2 + 1, -3)
    	end
    	
    	if (pos ~= nil)
    	then
    		if (pos2 ~= nil)
    		then
    			anchor = mw.ustring.sub (w, pos, pos2 - 1)
    		else
    			anchor = mw.ustring.sub (w, pos, -3)
    		end
    	else
    		pos = pos2
    	end

    	if (pos == nil)
    	then
    		pos = mw.ustring.find (w, "]]", 1, true)
    	end
    	
    	if (pos ~= nil)
    	then
    		linkstart = "[["
    		linkend = "]]"
    		w = mw.ustring.sub (w, 3, pos - 1)
    	end

		pos = 1
		pos2 = 1
		local tpos = 1
		local s = ""
		local artike = ""
		local dpos = 1
		local dpos2 = 1
		local d = ""
		while (pos2 ~= nil)
		do
			pos2 = mw.ustring.find (w, regsep, pos)
			if (pos2 ~= nil) then lsep = mw.ustring.len(sep) end
			tpos = mw.ustring.find (w, sep2, pos)
			if (tpos ~= nil) then
				if ((pos2 == nil) or (tpos < pos2)) then
					pos2 = tpos
					lsep = mw.ustring.len(sep2)
				end
			end
			
			if (pos2 ~= nil)
			then
				s = mw.ustring.sub (w, pos, pos2 - 1)
				pos = pos2 + lsep
			else
				s = mw.ustring.sub (w, pos)
			end
			
			if string.match( s, "%(") -- and (ling == "wa" or ling == "wa-fel" or ling == "wa-vsis")
			then
				artike = p.betchete_cogne_motli(s)
			else
				artike = s
			end

			if display ~= ""
			then
				dpos2 = mw.ustring.find (display, regsep, dpos)
				if (dpos2 ~= nil) then lsep = mw.ustring.len(sep) end
				tpos = mw.ustring.find (display, sep2, dpos)
				if (tpos ~= nil) then
					if ((dpos2 == nil) or (tpos < dpos2)) then
						dpos2 = tpos
						lsep = mw.ustring.len(sep2)
					end
				end
				
				if (dpos2 ~= nil)
				then
					d = "|" .. mw.ustring.sub (display, dpos, dpos2 - 1)
					dpos = dpos2 + lsep
				else
					d = "|" .. mw.ustring.sub (display, dpos)
				end
			end

			if d ~= "|"
			then
				splititems = splititems .. linkstart .. artike .. anchor .. d .. linkend
			else
				splititems = splititems .. linkstart .. artike .. anchor .. d .. s .. linkend
			end

			if (pos2 ~= nil)
			then
				splititems = splititems .. mw.ustring.sub (w, pos2, pos - 1)
			end
		end

    	return splititems
    else
    	return w
    end

end

-- Function to use from template
function p.starts_with_vowel_template(frame)
    local args
    if frame.args ~= nil and frame.args[1] ~= nil then
        args = frame.args
    else
        args = frame:getParent().args
    end
    local w = args[1]
    
    local ret = p.starts_with_vowel(w)
    if ret == true then return "voyale" else return "cossoune" end
end
function p.ends_with_vowel_template(frame)
    local args
    if frame.args ~= nil and frame.args[1] ~= nil then
        args = frame.args
    else
        args = frame:getParent().args
    end
    local w = args[1]
    
    local ret = p.ends_with_vowel(w)
    if ret == true then return "voyale" else return "cossoune" end
end
function p.aclape_bodje_cawe_template(frame)
    local args
    if frame.args ~= nil and frame.args[1] ~= nil then
        args = frame.args
    else
        args = frame:getParent().args
    end
    local bdj = args[1]
    local caw = args[2]

    local mot = p.aclape_bodje_cawe(bdj, caw)
    return mot
end
function p.get_article_link_template(frame)
    local args
    if frame.args ~= nil and frame.args[1] ~= nil then
        args = frame.args
    else
        args = frame:getParent().args
    end
    local mot = args[1]
    local croejh = args[2]
    local ling = args[3]
    local anchor = args[4]

    local mot = p.get_article_link_anchor(mot, croejh, ling, anchor)
    return mot
end
function p.split_article_link_template(frame)
    local args
    if frame.args ~= nil and frame.args[1] ~= nil then
        args = frame.args
    else
        args = frame:getParent().args
    end
    local w = args[1]

    local splitw = p.split_article_link(w)
    return splitw
end

return p