Jump to content

Module:User:Xoristzatziki/test1

From Wiktionary, the free dictionary

This is a private module sandbox of Xoristzatziki, for their own experimentation. Items in this module may be added and removed at Xoristzatziki's discretion; do not rely on this module's stability.


-- create decl table for greek nouns
-- Option to select if only singular or only plural exists
_module ={}

bgcolor = 'd9ebff'
titlebgcolor = '#A1BDEA'
bordercolor = '#AAAACC'
kataliksicolor = 'DeepPink'

-- χρωματισμός κατάληξης
function _xk(kataliksi)
    return '<font style="color:' .. kataliksicolor ..';">' .. kataliksi .. '</font>'
end
 
atona = { ['Α'] = 'Ά', ['α'] = 'ά', ['ε'] = 'έ', ['Ε'] = 'Έ', 
        ['Η'] = 'Ή', ['η'] = 'ή', ['ι'] = 'Ί', ['ι'] = 'ί', ['ϊ'] = 'ΐ', 
        ['Ο'] = 'Ό', ['ο'] = 'ό', ['Υ'] = 'Ύ', ['υ'] = 'ύ', ['ϋ'] = 'ΰ', 
        ['Ω'] = 'Ώ', ['ω'] = 'ώ' }
tonismena = {
    ['Ά'] = 'Α',
    ['ά'] = 'α',
    ['Έ'] = 'Ε',
    ['έ'] = 'ε',
    ['Ή'] = 'Η',
    ['ή'] = 'η',
    ['Ί'] = 'Ι',
    ['ί'] = 'ι',
    ['ΐ'] = 'ϊ',
    ['Ό'] = 'Ο',
    ['ό'] = 'ο',
    ['Ύ'] = 'Υ',
    ['ύ'] = 'υ',
    ['ΰ'] = 'ϋ',
    ['Ώ'] = 'Ω',
    ['ώ'] = 'ω',
}
 
tonismena2 ={
    ['άι'] = 'αϊ',
    ['έι'] = 'εϊ',
    ['όι'] = 'οϊ',
    ['άυ'] = 'αϋ',
    ['έυ'] = 'εϋ',
    ['όυ'] = 'οϋ' 
}
    -- ['ύι'] = 'υϊ', δεν υπάρχει σε ουσιαστικά, μόνο στο επίθετο δρύινος. Αντίθετα, θα βάλει διαλυτικά
    -- στο βούισμα, βουίσματα
 
function _module.exeitono(anygreekstring)
    --για κάθε χαρακτήρα
    for codepoint in mw.ustring.gcodepoint( anygreekstring ) do
        --αντικατάστησέ τον με βάση τον πίνακα
        mychar = mw.ustring.char(codepoint)
        convertedchar = tonismena[mychar]            
        --αν βρήκε κάτι για αντικατάσταση
        --είναι δηλαδή τονισμένο γράμμα
        if convertedchar ~= nil then
            --βρήκα τονισμένο
            return true
        end
    end
    return false
end
 
function _module.removeaccent(stem)
    --για κάθε χαρακτήρα
    wordproduced = ''
    --για κάθε συνδυασμό γραμμάτων που μπορεί να χρειαστούν διαλυτικά
    for diplotonismeno, neatimh in pairs(tonismena2) do
        arxi, telos = mw.ustring.find(stem, diplotonismeno)
        if arxi ~= nil then
            wordproduced = mw.ustring.gsub(stem, diplotonismeno, neatimh, 1) --μια φορά αντικατάσταση
            --βρέθηκε ο τόνος και αφαιρέθηκε
            return wordproduced
        end        
    end
    for codepoint in mw.ustring.gcodepoint( stem ) do
        --αντικατάστησέ τον με βάση τον πίνακα
        mychar = mw.ustring.char(codepoint)
        convertedchar = tonismena[mychar]            
        --αν βρήκε κάτι για αντικατάσταση
        --είναι δηλαδή τονισμένο γράμμα
        if convertedchar ~= nil then
            --πρόσθεσέ το στη δημιουργούμενη κλείδα
            wordproduced = wordproduced .. convertedchar
        else
            --αλλιώς άσε το ίδιο
            wordproduced = wordproduced .. mychar        
        end
    end
    return wordproduced
end
 
-- Η συνάρτηση αρχίζει από το τελευταίο γράμμα του θέματος και πηγαίνει προς το πρώτο. 
-- Όταν συναντήσει το πρώτο (άτονο) φωνήεν, το τονίζει και τέλος
-- Εννοείται ότι η μεταβλητή stem δεν πρέπει να περιέχει τονισμένα φωνήεντα.
 
 
function _module.neostonos(stem)
    stempoint = mw.ustring.len(stem)
    wordproduced = ""
    while stempoint > 0 do
       mychar = mw.ustring.sub(stem, stempoint, stempoint)
       newchar = atona[mychar]
       if newchar ~= nil then
          if stempoint > 1 then
              return mw.ustring.sub(stem, 1, stempoint-1 ) .. newchar .. wordproduced
          else
              return newchar .. wordproduced
          end
       else
           wordproduced = mychar .. wordproduced
           stempoint = stempoint -1
       end
    end
    return wordproduced
end

--TODO παραμετροποίηση χρωμάτων για ευκολότερη μελλοντική τροποποίηση
fulltable = function (args,frame)
    --local output =''
    local stitlestr = ''
    local ptitlestr = ''
    local onomenstr = ''
    local onomplstr = ''
    local genenstr = ''
    local genplstr = ''
    local aitenstr = ''
    local aitplstr = ''
    local klenstr = ''
    local klplstr = ''
    local notes = ''
    local hassingular = true --(args['εν'] ~= nil)
    if args['α'] == "πλ" then hassingular = false end
    local hasplural = true -- (args['πλ'] ~= nil)
    if args['α'] == "εν" then hasplural = false end
      
    if not (args['notes'] == nil or mw.ustring.len(args['notes']) < 1) then        
        notes = '|-\n| colspan="' .. args.cols .. '" align="left" style="background:#d9ebff; font-size: 90%; font-style: italic;" | ' 
        notes = notes .. args.notes .. '\n'
    end
                
    if args.hassingular then
        stitlestr =  '! style="background:#cce4fc" | singular <small>(' .. frame:expandTemplate{ title = 'Grek', args = { '[[ενικός]]', lang = 'el' } } .. ')</small>' .. '\n'
        onomenstr =  '|' .. frame:expandTemplate{ title = 'Grek', args = { args[1], lang = 'el'  } }  .. '\n'
        genenstr =   '|' .. frame:expandTemplate{ title = 'Grek', args = { args[3], lang = 'el'  } }  .. '\n'
        aitenstr =   '|' .. frame:expandTemplate{ title = 'Grek', args = { args[5], lang = 'el'  } }  .. '\n'
        klenstr =   '|' .. frame:expandTemplate{ title = 'Grek', args = { args[7], lang = 'el'  } }  .. '\n'
    end
    if args.hasplural then
        ptitlestr = '! style="background:#cce4fc" | plural <small>(' .. frame:expandTemplate{title = 'Grek', args = { '[[πληθυντικός]]', lang = 'el'  } } .. ')</small>' .. '\n'
        onomplstr =   '|' .. frame:expandTemplate{ title = 'Grek', args = { args[2], lang = 'el'  } }  .. '\n'
        genplstr =    '|' .. frame:expandTemplate{ title = 'Grek', args = { args[4], lang = 'el'  } }  .. '\n'
        aitplstr =   '|' .. frame:expandTemplate{ title = 'Grek', args = { args[6], lang = 'el'  } }  .. '\n'
        klplstr =    '|' .. frame:expandTemplate{ title = 'Grek', args = { args[8], lang = 'el'  } }  .. '\n'
    end

    local output = '<div class="NavContent">\n'
    output = output .. '{| style="background:#fdfdfd; text-align:center; width:' .. args.width2 .. '; border-collapse:separate; border-spacing:1px" class="inflection-table"' .. '\n'
    output = output .. '|-' .. '\n'
    output = output .. '! style="width:' .. args.width3 .. ';background:#cce4fc" |' .. '\n' .. stitlestr .. ptitlestr .. '|-\n'
    output = output .. '! style="background:#e0f0ff" | nominative <small>(' .. frame:expandTemplate{ title = 'Grek', args = { '[[ονομαστική]]', lang = 'el'  } } .. ')</small>' .. '\n' .. onomenstr .. onomplstr .. '|-\n'
    output = output .. '! style="background:#e0f0ff" | genitive <small>(' .. frame:expandTemplate{ title = 'Grek', args = { '[[γενική]]', lang = 'el'  } } .. ')</small>' .. '\n' .. genenstr .. genplstr .. '|-\n'
    output = output .. '! style="background:#e0f0ff" | accusative <small>(' .. frame:expandTemplate{ title = 'Grek', args = { '[[αιτιατική]]', lang = 'el'  } } .. ')</small>' .. '\n' .. aitenstr .. aitplstr .. '|-\n'
    output = output .. '! style="background:#e0f0ff" | vocative <small>(' .. frame:expandTemplate{ title = 'Grek', args = { '[[κλητική]]', lang = 'el'  } } .. ')</small>' .. '\n' .. klenstr .. klplstr .. notes .. '\n' .. '|}</div>' 

    return output
end

function _module.declnoun1(frame)
    local args = frame.args 
    local lemmaargs = frame:getParent().args 
    --overrides parameters from Template and parent templates
    args['width1'] = '50em'
    args['width2'] = '100%'
    args['width3'] = '33%'
    args['cols'] = 4
    args['hassingular'] = true
    args['hasplural'] = true
    PAGENAME = mw.title.getCurrentTitle().text
    --if user wants only plural
    if lemmaargs['number'] ~= nil and lemmaargs['number'] == 'singonly' then
        args.hasplural = false 
    end
    if lemmaargs['number'] ~= nil and lemmaargs['number'] == 'plonly' then
        args.hassingular = false 
    end
    if args.hassingular ~= args.hasplural then
        args.width1 = '40em'
        args.width2 = '40em'
        args.width3 = '50%'
        args.cols = 3
    end 
    if lemmaargs['stem1'] ~= nil and mw.ustring.len(lemmaargs['stem1']) > 0 then
        args[1] = lemmaargs['stem1'] .. args[1]    
        args[2] = lemmaargs['stem1'] .. args[2]    
        args[3] = lemmaargs['stem1'] .. args[3]    
        args[4] = lemmaargs['stem1'] .. args[4]    
        args[5] = lemmaargs['stem1'] .. args[5]    
        args[6] = lemmaargs['stem1'] .. args[6]    
        args[7] = lemmaargs['stem1'] .. args[7]    
        args[8] = lemmaargs['stem1'] .. args[8]    
    end
     
    --inherit notes from notes in lemma's template invocation
    --override template notes
    --TODO concatenate notes from lemma and template
    if ((lemmaargs['notes'] ~= nil)  or  (lemmaargs['notes'] ~='')) then args['notes'] = lemmaargs['notes'] end
    -- else parameters are full words
    local output =''
    output = '<div class="NavFrame" style="width:' .. args.width1 .. [=[">
<div class="NavHead" style="background:#cce4fc; text-align:left" >declension of ]=] .. frame:expandTemplate{ title = 'Grek', args = { PAGENAME, lang = 'el' } } .. '</div>'
    output = output .. fulltable(args,frame) 
    output = output .. '</div>'
    return frame:preprocess(output )
end

------------------
klisi1 = function(args,frame)
    local lemma = ""
    args['width1'] = '50em'
    args['width2'] = '100%'
    args['width3'] = '33%'
    args['cols'] = 4
    args.hassingular = true --(args['εν'] ~= nil)
    if args['α'] == "πλ" then args.hassingular = false end
    args.hasplural = true -- (args['πλ'] ~= nil)
    if args['α'] == "εν" then args.hasplural = false end
    
    if args['lemma'] ~= nil and args['lemma'] ~= "" then
        lemma = args['lemma']
    else
        PAGENAME = mw.title.getCurrentTitle().text
        --αφαίρεση κενών στην αρχή και στο τέλος
        lemma = PAGENAME:match( "^%s*(.-)%s*$" )
    end
    local stemnumber = 0
    if args['α'] ~= "πλ" then
        stemnumber = tonumber(mw.ustring.len(args['οε']))
    else
        stemnumber = tonumber(mw.ustring.len(args['οπ']))
    end
    local stem = {}
    stem["1"] = mw.ustring.sub(lemma,1,-stemnumber-1)
    stem["2"] = _module.removeaccent(stem["1"])
    stem["3"] = _module.neostonos(stem["2"])
 
    for  i, ptwsi in ipairs({'οε', 'γε', 'γε2', 'αε', 'κε', 'κε2', 'κε0', 'οπ', 'οπ2', 'γπ', 'γπ0', 'γπ2', 'απ', 'απ2'}) do
       if args[ptwsi .. 'θ'] == nil then args[ptwsi .. 'θ'] = "1" end
    end
    for  i, ptwsi in ipairs({'γε', 'γε2', 'γπ', 'γπ0', 'γπ2'}) do
       if args[ptwsi] ~= nil then
          if _module.exeitono(args[ptwsi]) then args[ptwsi .. 'θ'] = "2" end
       end
    end
    if args['οπ'] == "άδες" then 
    args['οπθ'] = "2"
	args['απθ'] = "2"
    end
    if args['οπ2'] == "άδες" or args['οπ2'] == "αίοι" then 
	args['οπ2θ'] = "2"
	args['απ2θ'] = "2"
    end
    if args['απ'] == nil then 
       args['απ'] = args['οπ']
       args['απθ'] = args['οπθ']
    end
    if args['απ2'] == nil then
       args['απ2'] = args['οπ2']
       args['απθ2'] = args['οπθ2']
    end
    if args['κε'] == nil then args['κε'] = args['αε'] end
 
    args['οε'] = stem[args['οεθ']] .. _xk( args['οε'])
    -- Γενική ενικού
    if (args['γε'] == "-" or args['γε'] == "" or args['γε'] == nil) then
        args['γε'] = ""
    else
        args['γε'] = stem[args['γεθ']] .. _xk( args['γε'])
    end
    if args['γε2'] ~=nil and args['γε2'] ~= "" and args['γε2'] ~= "-" then
        args['γε2'] = "<br />& " .. stem[args['γε2θ']] .. _xk( args['γε2'])
    else 
        args['γε2'] = ''
    end
    args['γε'] = args['γε'] .. args['γε2']
 
    args['αε'] = stem[args['αεθ']] .. _xk( args['αε'])
 
    ----ΚΛΗΤΙΚΗ ΕΝΙΚΟΥ
    if args['κε0'] ~= nil then
        args['κε'] = '(' .. stem[args['κε0θ']] .. _xk( args['κε0']) .. ')'
    else
	args['κε'] = stem[args['κεθ']] .. _xk( args['κε'])
    end
    if args['κε2'] ~=nil and args['κε2'] ~= "" and args['κε2'] ~= "-" then
        args['κε2'] = "<br />" .. stem[args['κε2θ']] .. _xk( args['κε2']) .. '*'
    else
        args['κε2'] = ""
    end
    args['κε'] = args['κε'] .. args['κε2']
 
    --Ονομ. πληθ
    args['οπ'] = stem[args['οπθ']] .. _xk( args['οπ'])
    if args['οπ2'] ~=nil and args['οπ2'] ~= "" and args['οπ2'] ~= "-" then
        args['οπ2'] = "<br />& " .. stem[args['οπ2θ']] .. _xk( args['οπ2'])
    else
        args['οπ2'] = ''
    end
    args['οπ'] = args['οπ'] .. args['οπ2']
    args['κπ'] = args['οπ']
 
    --γενική πληθυντικού
    if (args['γπ'] == "-" or args['γπ'] == "" or args['γπ'] == nil) then
        args['γπ'] = ""
    else
        args['γπ'] = stem[args['γπθ']] .. _xk( args['γπ'])
    end
    if args['γπ0'] ~= nil then
        args['γπ'] = '(' .. stem[args['γπ0θ']] .. _xk( args['γπ0']) .. ')'
    end
    if args['γπ2'] ~=nil and args['γπ2'] ~= "" and args['γπ2'] ~= "-" then
        args['γπ2'] = stem[args['γπ2θ']] .. _xk( args['γπ2'])
        if args['γπ'] ~= "" then 
	        args['γπ2'] = "<br />& " .. args['γπ2']
	    end
    else
        args['γπ2'] = ""
    end
    args['γπ'] = args['γπ'] .. args['γπ2']
 
    --Αιτιατική πληθ.
    args['απ'] = stem[args['απθ']] .. _xk( args['απ'])
    if args['απ2'] ~=nil and args['απ2'] ~= "" and args['απ2'] ~= "-" then
        args['απ2'] = "<br />& " .. stem[args['απ2θ']] .. _xk( args['απ2'])
    else
        args['απ2'] = ''
    end
    args['απ'] = args['απ'] .. args['απ2']
 	args[1] = args['οε']
 	args[2] = args['οπ']
 	args[3] = args['γε']
 	args[4] = args['γπ']
 	args[5] = args['αε']
 	args[6] = args['απ']
 	args[7] = args['κε']
 	args[8] = args['κπ']
    --inherit notes from notes in lemma's template invocation
    --override template notes
    --TODO concatenate notes from lemma and template
    --if ((args['notes'] ~= nil)  or  (args['notes'] ~='')) then args['notes'] = lemmaargs['notes'] end
    -- else parameters are full words
    
    if args.hassingular ~= args.hasplural then
        args.width1 = '40em'
        args.width2 = '40em'
        args.width3 = '50%'
        args.cols = 3
    end 
    
    local output =''
    output = '<div class="NavFrame" style="width:' .. args.width1 .. [=[">
<div class="NavHead" style="background:#cce4fc; text-align:left" >declension of ]=] .. frame:expandTemplate{ title = 'Grek', args = { PAGENAME, lang = 'el' } } .. '</div>'
    output = output .. fulltable(args,frame) 
    output = output .. '</div>'
    return frame:preprocess(output )
end

_module.templates = function (frame)
    local templateargs = frame.args
    local args = frame:getParent().args
    local localargs = {}
    localargs['α'] = templateargs[number]
    if templateargs[1] == 'el-nF-α-αδες-1' then
    	localargs['α'] = nil
        return _module.giagia(frame,localargs)
    --test
    elseif templateargs[1] == 'el-nF-α-αδες-2' then
        localargs['α'] = 'εν'
        return _module.giagia(frame,localargs)
    --test
    elseif templateargs[1] == 'el-nF-α-αδες-3' then
        localargs['α'] = 'πλ'
        return _module.giagia(frame,localargs)
    else
    	--TODO return error
    end 
end

_module.giagia = function(frame,localargs)
    local args = frame:getParent().args
    args['α'] = localargs['α']
    args['οε'] = "ά"
    args['γε'] = "άς"
    args['αε'] = "ά"
    args['οπ'] = "άδες"
    args['γπ'] = "άδων"
    return frame:preprocess(klisi1(args,frame))
end

return _module