Module:stems
Μετάβαση στην πλοήγηση
Πήδηση στην αναζήτηση
Module:stems >> Module:stems/τεκμηρίωση (documentation)
- Πρότυπο:word-1 λέξη μείον το τελευταίο γράμμα, οποιασδήποτε γλώσσας
- Πρότυπο:word-2 λέξη μείον 2 τελευταία γράμματα, οποιασδήποτε γλώσσας
- Πρότυπο:word-3 λέξη μείον 3 τελευταία γράμματα, οποιασδήποτε γλώσσας
- Πρότυπο:word2- λέξη μείον το 1ο γράμμα, αρχίζουμε από το 2ο γράμμα, σε οποιαδήποτε γλώσσα
-- 2020.04.11. Sarri.greek
-- cf [[wikt:en:Module:User:Sarri.greek/stems]]
--[=[
ΠΑΡΑΓΩΓΗ ΘΕΜΑΤΩΝ - 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) word_minus_hyphen & word_minus_hyphen_i μείον ενωτικά (take away hyphen from affixes. Use for Reverse index searches)
5) 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 from the end, 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 from the end, 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 from the end, 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 from the end, 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 from the end, 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 from the end, 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 from the end, 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 from the end, 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
--------------------------------------------------------------------------
-- word_minus_hyphen & word_minus_hyphen_i --
-- μείον τα ενωτικά --take away hyphen from affixes.
--------------------------------------------------------------------------
-- Use the 'invoke' version for Reverse index searches)
-- ============= word_minus_hyphens for Templates =============== --
-- PAGENAME or lemma minus hyphen at beginning or at end or both
-- Use the 'invoke' version below
function export.word_minus_hyphen(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 ''
-- can i please also have args['1'] too ??
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
--?? WHATttt must I write for him to understand that lemma = args['lemma']??
-- careful: DO NOT write ????????????? this works only for lemma= NOT for PAGENAMES
-- ^ means: at beginning $ means: at end
-- 1 start at 1st letter / -2 stop at 2nd letter from end (cut off the last, which is a hyphen)
if mw.ustring.find(lemma, '[-]$') and not mw.ustring.find(lemma, '^[-]')
then result = mw.ustring.sub(lemma,1,-2) end
-- 2 start at 2nd letter / -1 stop at 1st letter from end
if mw.ustring.find(lemma, '^[-]') and not mw.ustring.find(lemma, '[-]$')
then result = mw.ustring.sub(lemma,2,-1) end
-- both
if mw.ustring.find(lemma, '^[-]') and mw.ustring.find(lemma, '[-]$')
then result = mw.ustring.sub(lemma,2,-2) end
-- neither (no change, produce the lemma as it is)
if not mw.ustring.find(lemma, '^[-]') and not mw.ustring.find(lemma, '[-]$')
then result = mw.ustring.sub(lemma,1,-1) end
return result
end -- close function
-- ============= word_minus_hyphens_i to invoke =============== --
-- PAGENAME or lemma minus hyphen at beginning or at end or both, direct invoke
-- Used at [[Πρότυπο:Π:ΑΛΝΕ]], [[wikt:en:Template:R:el:Reverse]]
function export.word_minus_hyphen_i(frame)
-- local args = frame:getParent().args -- for Templates
local args = frame.args -- invoke
-- lemma
local lemma = args['λήμμα'] or args['lemma'] or ''
-- can i please also have args['1'] too ??
PAGENAME = mw.title.getCurrentTitle().text
if lemma == '' or lemma == nil then args['lemma'] = PAGENAME:match( "^%s*(.-)%s*$" )
-- trim empty spaces ( "^%s*(.-)%s*$" ) from beginning and end. Found at all Modules.
else lemma = args['lemma']
end
-- the same as above
if mw.ustring.find(lemma, '[-]$') and not mw.ustring.find(lemma, '^[-]')
then result = mw.ustring.sub(lemma,1,-2) end
if mw.ustring.find(lemma, '^[-]') and not mw.ustring.find(lemma, '[-]$')
then result = mw.ustring.sub(lemma,2,-1) end
if mw.ustring.find(lemma, '^[-]') and mw.ustring.find(lemma, '[-]$')
then result = mw.ustring.sub(lemma,2,-2) end
if not mw.ustring.find(lemma, '^[-]') and not mw.ustring.find(lemma, '[-]$')
then result = mw.ustring.sub(lemma,1,-1) end
return result
end -- close function
--------------------------------------------------------------------------
-- 5) 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