User:Sarri.greek/modules

Definition from Wiktionary, the free dictionary
Jump to navigation Jump to search

SarriTALKreferencequestionsmodulesaudionounsverbslemmataαβγό scholiaαἴρω & αἱρῶGreek holisticΤ' αστέρι του βοριά (song)
LABtest1commands samplerfontsthoughtswordsverbsT1 · aT2· a· bT3, T4, ... — menuhelp@el.wikt


intro[edit]

Lessons LUA for άσχετους

recognize hyphen[edit]

By User:Erutuon. I am so thankful! sarri.greek (talk) 02:14, 14 February 2019 (UTC)

local p = {}

local function p.affix() --not'local'. it gives error '(' expected near '.'
	local lexiaargs = frame:getParent().args
	local term = lexiaargs[1] -- that is, {{#invoke:module name|affix|<term>}}

	if term:sub(1, 1) == '-' then
		if term:sub(-1) == '-' then
			return 'infix'
		else
			return 'suffix'
		end
	elseif term:sub(-1) == '-' then
		return 'prefix'
	else
		return 'word'
	end
end

return p

it means[edit]

what is sub(1, -1)?

  • -1 = the last character of a string, -2 the one before last. e.g.
    xxx="abcdxyz"
    xxx:sub(-1) gives → z. -2 gives y etc.
  • 1 = the first character
    xxx="abcdxyz"
    xxx:sub(1) gives → a, 2 gives b
  • now both:
    xxx="abcdxyz"
    xxx:sub(1, -1) gives → abcdxyz the 1stposition and end at the lastposition.
  • sub(1, 1) the 1st position, and end with the 1st position again.

Note [by Erutuon]: string_variable:sub(1, 1) (method syntax) is synonymous with string.sub(string_variable, 1, 1). The method syntax (using a colon) provides the string variable as the first argument of the function. (The string.sub function is available as a method on a string because of a metatable, which is a more complicated concept for a beginner.)

test1[edit]

For el.wiktionary:

  • I copied the 'Preliminaries' from an existent el:Module:ετυμολογία for etymologies, and have redone the semantic loan section.
  • the greek data for el:Module:Languages is full of different genders and cases (feminine nominative, neuter plural, etc). There is no other way to create expressions suitable for Categories
  • I pseudo-translate my module trial of 2019.03.02.
  • I have tested it at template el:Πρότυπο:sarritest, and things APPEAR to be normal, except that horrible red warning when the codes do not exist in Module:Languages, but never mind that.
-- 2019.03.02. Fix 2nd param of sl (semantic loan) at Module:ετυμολογία for etymology
-- Structure: A. Preliminaries (copied). B. Function 'semantic loan', first test by Sarri.

export = {}

--Α. Preliminaries (copied)
local Ld = {}
Ld['languages'] = mw.loadData("Module:Languages")
--table of local functions
local Lf = {}

--find the name of the Template which called this Module
Lf['template'] =  function(frame)
    if type(frame.args) == 'table' and type(frame.getParent) == 'function' then
        local templateobj = mw.title.new(frame:getParent():getTitle())
        if templateobj.namespace == 10 then -- NS_TEMPLATE
            return templateobj.text:match( "^%s*(.-)%s*$" )
        else
            return nil
        end
    else
        return nil
    end
end

export['from template'] = function(frame)
    lc = {}
    lc['lemma parameters'] = frame:getParent().args
    --lc['param 1'] = lc['lemma parameters'][1] or ''
    --lc['param 2'] = lc['lemma parameters'][2] or ''
    lc['lemma title'] = mw.title.getCurrentTitle().text
    lc['template'] = Lf['template'](frame)
    if lc['template'] == 'sarritest' then return Lf['semantic loan'](lc) end

    if lc['lemma parameters'][1] == nil then
        error( 'No parameter was given!' .. "#" .. type(frame.args) .. "#" .. type(frame.getParent) .. "#" .. lc['template'] .. "#")
    end
end -- end export from template

--Β. FUNCTION semantic loan by Sarri (keep fingers crossed) 
                    --  [Template:xxxxxx]  {{#invoke:module name|semantic loan}} Creates Category:Semantic loans from...

Lf['semantic loan'] = function(lc)
    lc['iso donor-lang'] = lc['lemma parameters'][1] or ''
    lc['iso receiver-lang'] = lc['lemma parameters'][2] or ''
    lc['donor-word'] = lc['lemma parameters'][3] or ''
    lc['linkappearance'] = lc['lemma parameters'][4] or ''
    lc['default-text'] = '([[semantic loan]]) ' or ''
    -- notext
    lc['omit-deftext'] = lc ['lemma parameters']['notext'] or ''
    if lc['omit-deftext'] ~= '' then lc['default-text'] = '' else lc['default-text'] = '([[semantic loan]]) ' end
    -- special text
    lc['longtext'] = lc ['lemma parameters']['text'] or ''
    if lc['longtext'] ~= '' then lc['default-text'] = '[[semantic loan]] from the ' else lc['default-text'] = lc['default-text'] end    

    -- param#1 and #2 combinations
    if lc['iso donor-lang'] == '' and  lc['iso receiver-lang'] == '' then
    		lc['default-text'] =  lc['default-text']
            mw.addWarning('If you wish the lemma to enter a Category:Semantic loans, you must enter iso codes for the languages (1st and 2nd parameters)')
    		end
    if lc['iso donor-lang'] == '' and  lc['iso receiver-lang'] ~= '' then
    		lc['default-text'] =  lc['default-text']
            mw.addWarning('If you wish the lemma to enter a Category:Semantic loans, you must enter the iso code for the donor-language too (1st parameter)')
    		end
    if lc['iso donor-lang'] ~= '' and  lc['iso receiver-lang'] == '' then
    	lc['lang-donor'] = Ld['languages'][lc['iso donor-lang']]['name'] or ''
    	lc['lang-donor frm'] = Ld['languages'][lc['iso donor-lang']]['frm'] or ''
    	lc['default-text'] =  lc['default-text'] .. "''[[" .. lc['lang-donor'] .. '|' .. lc['lang-donor frm'] .. "]]''" .. ' '
        mw.addWarning('If you wish the lemma to enter a Category:Semantic loans, you must enter the iso code for the receiver-language too (2nd parameter)')
    		end    		
    if lc['iso donor-lang'] ~= '' and  lc['iso receiver-lang'] ~= '' then
    			lc['lang-donor'] = Ld['languages'][lc['iso donor-lang']]['name'] or ''
    			lc['lang-donor frm'] = Ld['languages'][lc['iso donor-lang']]['frm'] or ''
    			lc['lang-donor apota'] = Ld['languages'][lc['iso donor-lang']]['apota'] or ''
    			lc['lang-receiver'] = Ld['languages'][lc['iso receiver-lang']]['name'] or ''
    			lc['words of lang-receiver'] = Ld['languages'][lc['iso receiver-lang']]['words'] or ''
    			lc['of origin from lang-donor'] = Ld['languages'][lc['iso donor-lang']]['from'] or ''
    			-- nocat
    			lc['omitcategories'] = lc ['lemma parameters']['nocat'] or ''
            	if lc['omitcategories'] ~= '' then
            		lc['default-text'] =  lc['default-text'] .. "''[[" .. lc['lang-donor'] .. '|' .. lc['lang-donor frm'] .. "]]''" .. ' '
            	else
    		lc['default-text'] =  lc['default-text'] .. "''[[" .. lc['lang-donor'] .. '|' .. lc['lang-donor frm'] .. "]]''" .. ' ' ..
    		'[[Category:Semantic loans  ' .. lc['lang-donor apota'] .. ' (' ..lc['lang-receiver'] .. ')]]' ..
    		'[[Category:' .. lc['words of lang-receiver'] .. ' ' .. lc['of origin from lang-donor'] .. ']]'    	
    		end
    	end
		
           -- the link to the donor-word and its appearance
            if lc['donor-word'] ~= '' then
            	lc['its Language section'] = Ld['languages'][lc['iso donor-lang']]['link'] or ''
            	if lc['linkappearance'] ~= '' then
            		lc['default-text'] =  lc['default-text'] .. ' ' .. '[[' .. lc['donor-word'] .. "#" .. lc['its Language section'] .. '|' .. lc['linkappearance'] .. ']]'
            		else
                lc['default-text'] =  lc['default-text'] .. ' ' .. '[[' .. lc['donor-word'] .. "#" .. lc['its Language section'] .. '|' .. lc['donor-word'] .. ']]'
                end
            end

    return lc['default-text']
end

return export