Module:stems

Από Βικιλεξικό
Μετάβαση στην πλοήγηση Πήδηση στην αναζήτηση

Module:stems >> Module:stems/τεκμηρίωση (documentation)

  • Πρότυπο:word-1 λέξη μείον το τελευταίο γράμμα, οποιασδήποτε γλώσσας
  • Πρότυπο:word-2 λέξη μείον 2 τελευταία γράμματα, οποιασδήποτε γλώσσας
  • Πρότυπο:word-3 λέξη μείον 3 τελευταία γράμματα, οποιασδήποτε γλώσσας
  • Πρότυπο:word2- λέξη μείον το 1ο γράμμα, αρχίζουμε από το 2ο γράμμα, σε οποιαδήποτε γλώσσα

-- 2020.04.11. Sarri.greek
--[=[
ΠΑΡΑΓΩΓΗ ΘΕΜΑΤΩΝ - STEM PRODUCTION
1) minus letters from end. Templates like word-1, word-2 etc.
	χρήσιμα σε πίνακες κλίσης - for inflection tables
	από το λήμμα ή δοσμένο λήμμα=ωωωω - from lemma or a given λήμμα=xxxx, minus letters from the end
	word_0 = μείον 0 γράμματα από το τέλος ([[Πρότυπο:word-0]])
	word_1 = μείον 1 γράμμα από το τέλος  ([[Πρότυπο:word-1]])
	word_2 = μείον 2 γράμματα από το τέλος  ([[Πρότυπο:word-2]])
	word_3 = μείον 3 γράμματα από το τέλος  ([[Πρότυπο:word-3]])
	word_4 = μείον 4 γράμματα από το τέλος  ([[Πρότυπο:word-4]])
2) minus letters from beginning. Templates like word2- (starts from 2nd letter)
	word2- = μείον 1ος χαρακτήρας από την αρχή, όπως ο αστερίσκος σε υποθετικούς τύπους
			= minus 1st character from beginning, e.g. the asterisc of hypthetical forms
3) write the 1st letter of lemma or word ([[Πρότυπο:letter1]])
	write the last letter of lemma or word ([[Πρότυπο:letter_last]])
4) German Umlauts
*) all TESTS at the end
]=]--

local export = {}

--------------------------------------------------------------------------
--         lemma minus letters from the end for templates               --
--                 plus i variants for direct invoke                    --
--------------------------------------------------------------------------

-- no need for this one
-- ============= word_0 =============== --
-- lemma minus 0 letters from the end for Template [[Πρότυπο:word-0]]
function export.word_0(arg)
	if type(arg) == 'table' and type(arg.getParent) == 'function' then
		local frame = arg
		local args = frame:getParent().args
		term = args['λήμμα'] or args['lemma'] or ''
	else
		term = arg
	end
    PAGENAME = mw.title.getCurrentTitle().text
    lemma = PAGENAME:match( "^%s*(.-)%s*$" )
	if term ~= '' then lemma = term end
    if lemma == '' then lemma = PAGENAME:match( "^%s*(.-)%s*$" ) end
return mw.ustring.sub(lemma,1,-1)	
end


-- ============= wordi_0 =============== --
-- wordi= word invoked
-- lemma minus 0 letters, direct invoke
function export.wordi_0(frame)
--	myarg = frame:getParent().args --  for Template only
	myarg = frame.args -- for invoke only
    PAGENAME = mw.title.getCurrentTitle().text
    lemma = PAGENAME:match( "^%s*(.-)%s*$" )
	lemma_target = myarg['lemma'] or myarg['λήμμα'] or ''
	if lemma_target ~= '' then lemma = lemma_target end
    if lemma == '' then lemma = PAGENAME:match( "^%s*(.-)%s*$" ) end
return mw.ustring.sub(lemma,1,-1)
end


-- ============= word_1 =============== --
-- lemma minus 1 letter from the end for Template [[Πρότυπο:word-1]]
function export.word_1(arg)
	if type(arg) == 'table' and type(arg.getParent) == 'function' then
		local frame = arg
		local args = frame:getParent().args
		term = args['λήμμα'] or args['lemma'] or ''
	else
		term = arg
	end
    PAGENAME = mw.title.getCurrentTitle().text
    lemma = PAGENAME:match( "^%s*(.-)%s*$" )
	if term ~= '' then lemma = term end
    if lemma == '' then lemma = PAGENAME:match( "^%s*(.-)%s*$" ) end
return mw.ustring.sub(lemma,1,-2)	
end


-- ============= wordi_1 =============== --
-- wordi= word invoked
-- lemma minus 1 letter, direct invoke
function export.wordi_1(frame)
--	myarg = frame:getParent().args --  for Template only
	myarg = frame.args -- for invoke only
    PAGENAME = mw.title.getCurrentTitle().text
    lemma = PAGENAME:match( "^%s*(.-)%s*$" )
	lemma_target = myarg['lemma'] or myarg['λήμμα'] or ''
	if lemma_target ~= '' then lemma = lemma_target end
    if lemma == '' then lemma = PAGENAME:match( "^%s*(.-)%s*$" ) end
return mw.ustring.sub(lemma,1,-2)
end


-- ============= word_2 =============== --
-- lemma minus 2 letters, for [[Template:word-2]]
function export.word_2(arg)
	if type(arg) == 'table' and type(arg.getParent) == 'function' then
		local frame = arg
		local args = frame:getParent().args
		term = args['λήμμα'] or args['lemma'] or ''
	else
		term = arg
	end
    PAGENAME = mw.title.getCurrentTitle().text
    lemma = PAGENAME:match( "^%s*(.-)%s*$" )
	if term ~= '' then lemma = term end
    if lemma == '' then lemma = PAGENAME:match( "^%s*(.-)%s*$" ) end
return mw.ustring.sub(lemma,1,-3)	
end


-- ============= wordi_2 =============== --
-- lemma minus 2 letters, direct invoke
function export.wordi_2(frame)
--	myarg = frame:getParent().args --  for Template only
	myarg = frame.args -- for invoke only
    PAGENAME = mw.title.getCurrentTitle().text
    lemma = PAGENAME:match( "^%s*(.-)%s*$" )
	lemma_target = myarg['lemma'] or myarg['λήμμα'] or ''
	if lemma_target ~= '' then lemma = lemma_target end
    if lemma == '' then lemma = PAGENAME:match( "^%s*(.-)%s*$" ) end
return mw.ustring.sub(lemma,1,-3)
end


-- ============= word_3 =============== --
-- lemma minus 3 letters, for Template [[Πρότυπο:word-3]]
function export.word_3(arg)
	if type(arg) == 'table' and type(arg.getParent) == 'function' then
		local frame = arg
		local args = frame:getParent().args
		term = args['λήμμα'] or args['lemma'] or ''
	else
		term = arg
	end
    PAGENAME = mw.title.getCurrentTitle().text
    lemma = PAGENAME:match( "^%s*(.-)%s*$" )
	if term ~= '' then lemma = term end
    if lemma == '' then lemma = PAGENAME:match( "^%s*(.-)%s*$" ) end
return mw.ustring.sub(lemma,1,-4)	
end


-- ============= wordi_3 =============== --
-- lemma minus 3 letters, direct invoke
function export.wordi_3(frame)
--	myarg = frame:getParent().args --  for Template only
	myarg = frame.args -- for invoke only
    PAGENAME = mw.title.getCurrentTitle().text
    lemma = PAGENAME:match( "^%s*(.-)%s*$" )
	lemma_target = myarg['lemma'] or myarg['λήμμα'] or ''
	if lemma_target ~= '' then lemma = lemma_target end
    if lemma == '' then lemma = PAGENAME:match( "^%s*(.-)%s*$" ) end
return mw.ustring.sub(lemma,1,-4)
end


-- ============= word_4 =============== --
-- lemma minus 4 letters, for Template [[Πρότυπο:word-4]] -- e.g. λύ-ομαι
function export.word_4(arg)
	if type(arg) == 'table' and type(arg.getParent) == 'function' then
		local frame = arg
		local args = frame:getParent().args
		term = args['λήμμα'] or args['lemma'] or ''
	else
		term = arg
	end
    PAGENAME = mw.title.getCurrentTitle().text
    lemma = PAGENAME:match( "^%s*(.-)%s*$" )
	if term ~= '' then lemma = term end
    if lemma == '' then lemma = PAGENAME:match( "^%s*(.-)%s*$" ) end
return mw.ustring.sub(lemma,1,-5)	
end


-- ============= wordi_4 =============== --
-- lemma minus 4 letters, direct invoke
function export.wordi_3(frame)
--	myarg = frame:getParent().args --  for Template only
	myarg = frame.args -- for invoke only
    PAGENAME = mw.title.getCurrentTitle().text
    lemma = PAGENAME:match( "^%s*(.-)%s*$" )
	lemma_target = myarg['lemma'] or myarg['λήμμα'] or ''
	if lemma_target ~= '' then lemma = lemma_target end
    if lemma == '' then lemma = PAGENAME:match( "^%s*(.-)%s*$" ) end
return mw.ustring.sub(lemma,1,-5)
end

--------------------------------------------------------------------------
--        lemma minus letters from beginning for templates              --
--                 plus i variants for direct invoke                    --
--------------------------------------------------------------------------


-- ============= word2- =============== --
-- lemma minus 1 letter from the beginning, start from 2nd letter. For Template [[Πρότυπο:word2-]]
-- used e.g. to omit asterisc for hypothetical forms as in [[wikt:el:Template:enWIKT PIE]]
function export.word2_(arg)
	if type(arg) == 'table' and type(arg.getParent) == 'function' then
		local frame = arg
		local args = frame:getParent().args
		term = args['λήμμα'] or args['lemma'] or ''
	else
		term = arg
	end
    PAGENAME = mw.title.getCurrentTitle().text
    lemma = PAGENAME:match( "^%s*(.-)%s*$" )
	if term ~= '' then lemma = term end
    if lemma == '' then lemma = PAGENAME:match( "^%s*(.-)%s*$" ) end
return mw.ustring.sub(lemma,2,-1)	
end


-- ============= wordi2- =============== --
-- wordi= word invoked
-- lemma minus 1 letter from beginning, start from 2nd letter. For direct invoke
function export.wordi2_(frame)
--	myarg = frame:getParent().args --  for Template only
	myarg = frame.args -- for invoke only
    PAGENAME = mw.title.getCurrentTitle().text
    lemma = PAGENAME:match( "^%s*(.-)%s*$" )
	lemma_target = myarg['lemma'] or myarg['λήμμα'] or ''
	if lemma_target ~= '' then lemma = lemma_target end
    if lemma == '' then lemma = PAGENAME:match( "^%s*(.-)%s*$" ) end
return mw.ustring.sub(lemma,2,-1)
end


--------------------------------------------------------------------------
--                      3)  write a letter of a word                    --
--------------------------------------------------------------------------

-- ============= letter1 =============== --
-- output = the 1st letter of lemma, or word. For Template [[Πρότυπο:letter1]]
-- used e.g. ancient perfect tense with reduplication λ-ε-λ.. of [[λύω]]
function export.letter1(arg)
	if type(arg) == 'table' and type(arg.getParent) == 'function' then
		local frame = arg
		local args = frame:getParent().args
		term = args['λήμμα'] or args['lemma'] or ''
	else
		term = arg
	end
    PAGENAME = mw.title.getCurrentTitle().text
    lemma = PAGENAME:match( "^%s*(.-)%s*$" )
	if term ~= '' then lemma = term end
    if lemma == '' then lemma = PAGENAME:match( "^%s*(.-)%s*$" ) end
return mw.ustring.sub(lemma,1,1)	
end



-- ============= letter_last =============== --
-- output = the last letter of lemma, or word. For Template [[Πρότυπο:letter-last]]
-- used e.g. at paste tense of [[stop]], stopped
function export.letter_last(arg)
	if type(arg) == 'table' and type(arg.getParent) == 'function' then
		local frame = arg
		local args = frame:getParent().args
		term = args['λήμμα'] or args['lemma'] or ''
	else
		term = arg
	end
    PAGENAME = mw.title.getCurrentTitle().text
    lemma = PAGENAME:match( "^%s*(.-)%s*$" )
	if term ~= '' then lemma = term end
    if lemma == '' then lemma = PAGENAME:match( "^%s*(.-)%s*$" ) end
return mw.ustring.sub(lemma,-1,-1)	
end

--------------------------------------------------------------------------
--                    4)   german (de) Umlauts                          --
-- originally by Benwin2 at https://en.wiktionary.org/wiki/Module:de-common
--------------------------------------------------------------------------
-- to invoke directly with #invoke:stems|toUmlaut|<word>

function export.apply_umlaut(term, origterm)

local vowels = "aeiouyäöüAEIOUYÄÖÜ"
local capletters = "A-ZÄÖÜ"
local umlaut = {
	["a"] = "ä",
	["A"] = "Ä",
	["o"] = "ö",
	["O"] = "Ö",
	["u"] = "ü",
	["U"] = "Ü",
}

	local stem, after = term:match("^(.*[^e])(e[lmnr]?)$")
	if stem then
		-- Nagel -> Nägel, Garten -> Gärten
		return export.apply_umlaut(stem, term) .. after
	end

	-- Haus -> Häuschen
	local before_v, v, after_v = mw.ustring.match(term, "^(.*)([Aa])([Uu]" .. "[^aeiouyäöüAEIOUYÄÖÜ]" .. "-)$")
	if not before_v then
		-- Haar -> Härchen
		before_v, v, after_v = mw.ustring.match(term, "^(.*)([Aa])[Aa](" .. "[^aeiouyäöüAEIOUYÄÖÜ]" .. "-)$")
	end

	if not before_v then
		-- Boot -> Bötchen
		before_v, v, after_v = mw.ustring.match(term, "^(.*)([Oo])[Oo](" .. "[^aeiouyäöüAEIOUYÄÖÜ]" .. "-)$")
	end
	
	if not before_v then
		-- regular umlaut
		before_v, v, after_v = mw.ustring.match(term, "^(.*)([AaOouU])(" .. "[^aeiouyäöüAEIOUYÄÖÜ]" .. "-)$")
	end
	
	if before_v then
		return before_v .. umlaut[v] .. after_v
	end
	
	error("Δεν υπάρχει Umlaut στο " .. (originalterm or term) .. " επειδή το τελευταίο φωνήεν δεν είναι  a, o, u ή au")
	

end
function export.toUmlaut(frame)
--	myarg = frame:getParent().args --  for Template only
	myarg = frame.args -- for invoke only
    PAGENAME = mw.title.getCurrentTitle().text
    lemma = PAGENAME:match( "^%s*(.-)%s*$" )
	lemma_target = myarg['lemma'] or myarg['λήμμα'] or ''
	if lemma_target ~= '' then lemma = lemma_target end
    if lemma == '' then lemma = PAGENAME:match( "^%s*(.-)%s*$" ) end
    
    local term = myarg[1] or ''
  
return export.apply_umlaut(term, origterm)
end


--------------------------------------------------------------------------
--                                   TESTS                             --
--------------------------------------------------------------------------


return export