User:Sarri.greek (CAT) » Module stems doc :: Temp:...word-minus-2end
-- 2024.03.04. ] from ]
--[=[
STEM PRODUCTION for any language
Create stems or other parts of PAGENAMEs of any words
to invoke directly from other modules or from templates
NOT recommended: DO NOT create Templates.
To use e.g. at inflection tables. For languages with changing ]]s
further changes may be handled in language-specific modules.
What is?
lemma,1,-3 = for lemma START at 1st letter and STOP at 3rd letter from the end = cut off 2 letters form end.
USE with invoke + function name. Examples:
From Templates or any page, write
* if you need the PAGENAME: {{#invoke:User:Sarri.greek/stems|word_minus_1end}}
* if you need a different word: {{#invoke:User:Sarri.greek/stems|word_minus_1end|lemma=yourword}}
From other modules, write
* if you need a PAGENAME: require("Module:User:Sarri.greek/stems").word_minus_1end
* if you need a different word: ??
NOT recommended: Create Templates with the functions marked with -t
* word-minus-1last-t, ...
CONTENTS
1) minus letters from end
* word_minus_0.... may use PAGENAME or lemma= instead.
* word_minus_1end_t (for a Template, not recommended)
* word_minus_1end (to inovke) = word (lemma or PAGENAME) minus 1 letter from the end
* word_minus_2end... etc minus 2 letters from end, -3, -4, -5, -6
2) word_minus_hyphen & word_minus_hyphen_i (take away hyphen from affixes. Use for Reverse index searches)
--) ... may add: minus letters from beginning. Like word-minus-1first
--) ... may add: write letters from beginning. Like word-write-1first
]=]--
local export = {}
--------------------------------------------------------------------------
-- 1) PAGENAME or lemma minus letters from the end --
--------------------------------------------------------------------------
-- minus 0 letters from end: use {{PAGENAME}} or lemma=
-- ============= word_minus_0 for Templates =============== --
-- PAGENAME or lemma minus 0 letters for Template:word-0
function export.word_minus_0(arg)
if type(arg) == 'table' and type(arg.getParent) == 'function' then
local frame = arg
local args = frame:getParent().args
term = args or '' -- add for your language: args 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_0_i to invoke =============== --
-- PAGENAME or lemma minus 0 letters, direct invoke
function export.word_minus_0_i(frame)
-- local args = frame:getParent().args -- for Templates
local args = frame.args -- invoke
-- lemma
local lemma = args or ''
PAGENAME = mw.title.getCurrentTitle().text
if lemma == '' or lemma == nil then args = PAGENAME:match( "^%s*(.-)%s*$" )
-- trim empty spaces ( "^%s*(.-)%s*$" ) from beginning and end. Found at all Modules.
else lemma = args
end
return mw.ustring.sub(lemma,1,-1)
end
-- ============= word_minus_1end for Templates =============== --
-- PAGENAME or lemma minus 1 letter from the end for Template:word-1
function export.word_minus_1end(arg)
if type(arg) == 'table' and type(arg.getParent) == 'function' then
local frame = arg
local args = frame:getParent().args
term = args or '' -- add for your language: args 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
-- ============= word_minus_1end_i to invoke =============== --
-- PAGENAME or lemma minus 1 letter from the end, direct invoke
function export.word_minus_1end_i(frame)
-- local args = frame:getParent().args -- for Templates
local args = frame.args -- invoke
-- lemma
local lemma = args or ''
PAGENAME = mw.title.getCurrentTitle().text
if lemma == '' or lemma == nil then args = PAGENAME:match( "^%s*(.-)%s*$" )
-- trim empty spaces ( "^%s*(.-)%s*$" ) from beginning and end. Found at all Modules.
else lemma = args
end
return mw.ustring.sub(lemma,1,-2)
-- 1 = start at 1st letter
-- -2 = stop at the 2nd letter from the end = cut of the 1st from the end
end
-- ============= word_minus_2end for Templates =============== --
-- PAGENAME or lemma minus 2 letters from the end, for Template:word-2 ]
function export.word_minus_2end(arg)
if type(arg) == 'table' and type(arg.getParent) == 'function' then
local frame = arg
local args = frame:getParent().args
term = args 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
-- ============= word_minus_2end_i to invoke =============== --
-- PAGENAME or lemma minus 2 letters from the end, direct invoke
function export.word_minus_2end_i(frame)
-- local args = frame:getParent().args -- for Templates
local args = frame.args -- invoke
-- lemma
local lemma = args or ''
PAGENAME = mw.title.getCurrentTitle().text
if lemma == '' or lemma == nil then args = PAGENAME:match( "^%s*(.-)%s*$" )
-- trim empty spaces ( "^%s*(.-)%s*$" ) from beginning and end. Found at all Modules.
else lemma = args
end
return mw.ustring.sub(lemma,1,-3)
end
-- ============= word_minus_3end for Templates =============== --
-- PAGENAME or lemma minus 3 letters from the end for Template:word-3
function export.word_minus_3end(arg)
if type(arg) == 'table' and type(arg.getParent) == 'function' then
local frame = arg
local args = frame:getParent().args
term = args 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
-- ============= word_minus_3end_i to invoke =============== --
-- PAGENAME or lemma minus 3 letters from the end, direct invoke
function export.word_minus_3end_i(frame)
-- local args = frame:getParent().args -- for Templates
local args = frame.args -- invoke
-- lemma
local lemma = args or ''
PAGENAME = mw.title.getCurrentTitle().text
if lemma == '' or lemma == nil then args = PAGENAME:match( "^%s*(.-)%s*$" )
-- trim empty spaces ( "^%s*(.-)%s*$" ) from beginning and end. Found at all Modules.
else lemma = args
end
return mw.ustring.sub(lemma,1,-4)
end
-- ============= word_minus_4end for Templates =============== --
-- PAGENAME or lemma minus 4 letters from the end, for Template:word-4
function export.word_minus_4end(arg)
if type(arg) == 'table' and type(arg.getParent) == 'function' then
local frame = arg
local args = frame:getParent().args
term = args or args 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
-- ============= word_minus_4end_i to invoke =============== --
-- PAGENAME or lemma minus 4 letters from the end, direct invoke
function export.word_minus_4end_i(frame)
-- local args = frame:getParent().args -- for Templates
local args = frame.args -- invoke
-- lemma
local lemma = args or ''
PAGENAME = mw.title.getCurrentTitle().text
if lemma == '' or lemma == nil then args = PAGENAME:match( "^%s*(.-)%s*$" )
-- trim empty spaces ( "^%s*(.-)%s*$" ) from beginning and end. Found at all Modules.
else lemma = args
end
return mw.ustring.sub(lemma,1,-5)
end
-- ============= word_minus_5end for Templates =============== --
-- PAGENAME or lemma minus 5 letters from the end, for Template:word-5
function export.word_minus_5end(arg)
if type(arg) == 'table' and type(arg.getParent) == 'function' then
local frame = arg
local args = frame:getParent().args
term = args 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,-6)
end
-- ============= word_minus_5end_i to invoke =============== --
-- PAGENAME or lemma minus 5 letters from the end, direct invoke
function export.word_minus_5end_i(frame)
-- local args = frame:getParent().args -- for Templates
local args = frame.args -- invoke
-- lemma
local lemma = args or ''
PAGENAME = mw.title.getCurrentTitle().text
if lemma == '' or lemma == nil then args = PAGENAME:match( "^%s*(.-)%s*$" )
-- trim empty spaces ( "^%s*(.-)%s*$" ) from beginning and end. Found at all Modules.
else lemma = args
end
return mw.ustring.sub(lemma,1,-6)
end
-- ============= word_minus_6end for Templates =============== --
-- PAGENAME or lemma minus 6 letters from the end, for Template:word-6
function export.word_minus_6end(arg)
if type(arg) == 'table' and type(arg.getParent) == 'function' then
local frame = arg
local args = frame:getParent().args
term = args 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,-7)
end
-- ============= word_minus_6end_i to invoke =============== --
-- PAGENAME or lemma minus 6 letters from the end, direct invoke
function export.word_minus_6end_i(frame)
-- local args = frame:getParent().args -- for Templates
local args = frame.args -- invoke
-- lemma
local lemma = args or ''
PAGENAME = mw.title.getCurrentTitle().text
if lemma == '' or lemma == nil then args = PAGENAME:match( "^%s*(.-)%s*$" )
-- trim empty spaces ( "^%s*(.-)%s*$" ) from beginning and end. Found at all Modules.
else lemma = args
end
return mw.ustring.sub(lemma,1,-7)
end
--------------------------------------------------------------------------
-- 2) PAGENAME or lemma minus hyphen --
-- tests at ]
--------------------------------------------------------------------------
-- ============= 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 ''
-- can i please also have args 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??
-- 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 ]
function export.word_minus_hyphen_i(frame)
-- local args = frame:getParent().args -- for Templates
local args = frame.args -- invoke
-- lemma
local lemma = args or ''
-- can i please also have args too ??
PAGENAME = mw.title.getCurrentTitle().text
if lemma == '' or lemma == nil then args = PAGENAME:match( "^%s*(.-)%s*$" )
-- trim empty spaces ( "^%s*(.-)%s*$" ) from beginning and end. Found at all Modules.
else lemma = args
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
return export