Module:User:Sarri.greek/grk-stems-test

--[=[ 
How to use
* [[Module:User:Sarri.greek/grk-stems]] (for changing diacritics for Greek) 
* and the [[Module:User:Sarri.greek/stems]] for any language, to cut off last letters from a PAGENAME or lemma=

1. extract the desired stem from a word by cutting off end-letters
	For this, use [[Module:User:Sarri.greek/stems]], choose a function minus-Xend_i 
2. remove its accents
	For this, use [[Module:User:Sarri.greek/grk-stems]] function stem0_i
3. handle by adding different accents.
	Like stem1_i (put oksia at last syllable), stem2_i (put oksia at 2nd last syllable)

Examaple: the word [[δημοκρατικός]] ("democrat, not USA Democrat")  get the unaccented stem δημοκρατικ

If you go to lemma [[δημοκρατικός]] write
{{#invoke:User:Sarri.greek/grk-stems|stem0_i|lemma={{#invoke:User:Sarri.greek/stems|word_minus_2end_i|lemma=δημοκρατικός}}}}
	We have to write the pagename at the 2nd invoke
	
You may use the [[Template:User:Sarri.greek/word-minus-2end]]
{{#invoke:User:Sarri.greek/grk-stems|stem0_i|lemma={{Template:User:Sarri.greek/word-minus-2end}}}}
Because you are looking at a PAGENAME, you don't need to write the lemma word like this:
{{#invoke:User:Sarri.greek/grk-stems|stem0_i|lemma={{Template:User:Sarri.greek/word-minus-2end|lemma=δημοκρατικός}}}}

If you go to any other page, must write what your lemma is
{{#invoke:User:Sarri.greek/grk-stems|stem0_i|lemma={{#invoke:User:Sarri.greek/stems|word_minus_1end_i|lemma=δημοκρατικός}}}}
or use the above Template

To make a Template with such functions, write
* for a template like '[[Template:User:Sarri.greek/word-minus-2end]] 
	 {{#invoke:User:Sarri.greek/grk-stems|word_minus_2end}} (at modules, we cannot put hyphens, only _ such lines )
* for a 'Template:accent0' to remove accents: 
	{{#invoke:User:Sarri.greek/grk-stems|stem0}}

From another Module, call it with
1) get the stem. my_stem_is = require("Module:User:Sarri.greek/stems").word_minus_1end('δημοκρατικός')
2) remove accents: my_stem0_is = require("Module:User:Sarri.greek/grk-stems").stem0(my_stem_is)
3) make any other change using the unaccented my_stem0_is 
	The unaccented stem is best to apply on it all kinds of alterations
Also, we may make a special require-abbreviation to use later, with
whatevername you like, or, m_ for module, m_stems = require("Module:User:Sarri.greek/grk-stems")
]=]--


export = {}

-- for handling Greek:
m_grk_stems = require("Module:User:Sarri.greek/grk-stems") 

-- ================= stem for Templates =============== --
-- stem as extracted from a PAGENAME or from a whole word of our choice (lemma=)
export['stem'] = function(frame)		-- for a template
	local args = frame:getParent().args	-- for Templates
--	local args = frame.args				-- invoke
-- lemma
	local lemma = args['lemma'] or ''
	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

	local minusletters = args['minus'] or  ''
		-- make empty if editor writes nothing
		args['minus'] = args['minus'] or ''
		-- But give some number, or Lua error : attempt to perform arithmetic on field 'minus' (a string value)
		if args['minus'] == '' or args['minus'] == nil then args['minus'] = '0' or '' end
local result -- is this needed?
result =  mw.ustring.sub(args['lemma'],1,-(args['minus']+1)) -- do not write: minusletters
    	-- exmple if editor writes |minus=2 (cut off 2 letters from end)
    	-- 1, -3 = start at 1st letter, stop at 2nd letter from end - stempoint is 3
return result
end -- close function


-- ================= stemi to invoke =============== -- stem_i would be more corret...
-- at any page write:
-- {{#invoke:User:Sarri.greek/grk-stems-test/stemi}} (for PAGNEMAE)
-- (lemma= of your choice, minus= a number for letter to cut)
-- at any Module write:
function export.stemi(frame)
--export['stem-i'] = function(frame) -- this DOES NOT WORK
--	local args = frame:getParent().args	-- for Templates
	local args = frame.args				-- invoke
-- lemma
	local lemma = args['lemma'] or ''
	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
	
	local minusletters = args['minus'] or  ''
		args['minus'] = args['minus'] or ''
		if args['minus'] == '' or args['minus'] == nil then args['minus'] = '0' or '' end
local result -- is this needed?
result =  mw.ustring.sub(args['lemma'],1,-(args['minus']+1)) -- do not write: minusletters
    	-- exmple if editor writes |minus=2 (cut off 2 letters from end)
    	-- 1, -3 = start at 1st letter, stop at 2nd letter from end - stempoint is 3
return result
end -- close function



-- Suppose, you have a GREEK stem. You can

-- ================= stem0 for Templates =============== --
-- REMOVE ACCENTS from a word, stem or a PAGENAME
export['stem0'] = function(frame)		-- for a template
	local args = frame:getParent().args	-- for Templates
--	local args = frame.args				-- invoke
-- lemma
	local lemma = args['lemma'] or ''
	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

-- REMOVE ACCENTS with function stem0
	local result1
	result1= require("Module:User:Sarri.greek/grk-stems").stem0(args['lemma'])
	
-- CUT OFF last letters from result1 TESTWORDS κορόιδο Άλπεις
    	-- exmple if editor writes |minus=2 (cut off 2 letters from end)
    	-- 1, -3 = start at 1st letter, stop at 2nd letter from end - stempoint is 3
	local minusletters = args['minus'] or  ''
		args['minus'] = args['minus'] or ''
		if args['minus'] == '' or args['minus'] == nil then args['minus'] = '0' or '' end
local result -- is this needed?
result =  mw.ustring.sub(result1,1,-(args['minus']+1))
return result
end -- close function


return export