Module:Kleida-el >> Module:Kleida-el/τεκμηρίωση
Καλείται από το πρότυπο {{κλείδα-ελλ}} που τοποθετείται στο τέλος της σελίδας για όλα τα ελληνικά λήμματα (νέα, μεσαιωνικά και αρχαία).

Κατατάσσει όλα τα ελληνικά λήμματα αλφαβητικά στις διάφορες Κατηγορίες.


Called by {{κλείδα-ελλ}}, placed at the very end of the page for any greek lemma (modern, mediaeval or ancient).
It alphabetizes the lemmata in the various Categories.


-- @brief
--  φτιάχνει την απλή κλείδα που χρησιμεύει για τη σωστή ταξινόμηση των ελληνικών λέξεων
--  μπορεί να φτιαχτεί για όλες τις γλώσσες
-- @param
--  η κλήση του module δεν χρειάζεται παράμετρο, δουλεύει με το PAGENAME της σελίδας
-- @return
--  επιστρέφει την κλείδα ταξινόμησης
--  π.χ. για το Ὦ ξεῖν', ἀγγέλλειν Λακεδαιμονίοι επιστρέφει ωξειναγγελλεινλακεδαιμονιοισ
-- για το -κόπος επιστρέφει κοποσ
-- δεν επιστρέφει την παύλα στο τέλος αλλά μπορεί να φτιαχτεί αν χρειάζεται
-- επιστρέφει κλείδα μόνο για τους πρώτους 32 χαρακτήρες
-- αγνοεί ως πρώτο χαρακτήρα: παύλα, απόστροφο U+0027, αστερίσκο
-- @authors
--  [[wikt:el:Χρήστης:Xoristzatziki]]
--  [[wikt:el:Χρήστης:Flyax]]
--  [[wikt:el:Χρήστης:Svlioras]]

p = {}
--All lua modules on Wikipedia must begin by defining a variable 
                    --that will hold their externally accessible functions.
                    --Such variables can have whatever name you want and may 
                    --also contain various data as well as functions.

-- κύρια συνάρτηση kleida
--  η τιμή που επιστρέφει μπορεί να χρησιμοποιηθεί 
--   και για να ταξινομηθούν αλφαβητικά και απλές γραμμές
--   (π.χ. σε πίνακες ή ενότητες)
-- latin letters added because sort clashes with other languages e.g. [[a priori]]
p._mappedletters = {
	['à'] = 'a', ['â'] = 'a', ['å'] = 'a', ['é'] = 'e', ['è'] = 'e', ['ê'] = 'e',
	['ë'] = 'e', ['î'] = 'i', ['ï'] = 'i', ['ô'] = 'o', ['ö'] = 'o', ['œ'] = 'oe',
	['ù'] = 'u', ['û'] = 'u', ['ü'] = 'u', ['ç'] = 'c', ['æ'] = 'ae',
	["A"] = "a", ["a"] = "a", ["B"] = "b", ["b"] = "b", ["C"] = "c", ["c"] = "c", 
	["D"] = "d", ["d"] = "d", ["E"] = "e", ["e"] = "e", ["F"] = "f", ["f"] = "f", 
	["G"] = "g", ["g"] = "g", ["H"] = "h", ["h"] = "h", ["I"] = "i", ["i"] = "i", 
	["J"] = "j", ["j"] = "j", ["K"] = "k", ["k"] = "k", ["L"] = "l", ["l"] = "l", 
	["M"] = "m", ["m"] = "m", ["N"] = "n", ["n"] = "n", ["O"] = "o", ["o"] = "o", 
	["P"] = "p", ["p"] = "p", ["Q"] = "q", ["q"] = "q", ["R"] = "r", ["r"] = "r",
	["S"] = "s", ["s"] = "s", ["T"] = "t", ["t"] = "t", ["U"] = "u", ["u"] = "u", 
	["V"] = "v", ["v"] = "v", ["W"] = "w", ["w"] = "w", ["X"] = "x", ["x"] = "x", 
	["Y"] = "y", ["y"] = "a", ["Z"] = "z", ["z"] = "z", 
        ["Α"]  = "α",
        ["ά"]  = "α",
        ["α"]  = "α",
        ["ἀ"]  = "α",
        ["ἁ"]  = "α",
        ["ἂ"]  = "α",
        ["ἃ"]  = "α",
        ["ἄ"]  = "α",
        ["ἅ"]  = "α",
        ["ἆ"]  = "α",
        ["ἇ"]  = "α",
        ["Ἀ"]  = "α",
        ["Ἁ"]  = "α",
        ["Ἂ"]  = "α",
        ["Ἃ"]  = "α",
        ["Ἄ"]  = "α",
        ["Ἅ"]  = "α",
        ["Ἆ"]  = "α",
        ["Ἇ"]  = "α",
        ["ὰ"]  = "α",
        ["ά"]  = "α",
        ["ᾀ"]  = "α",
        ["ᾁ"]  = "α",
        ["ᾂ"]  = "α",
        ["ᾃ"]  = "α",
        ["ᾄ"]  = "α",
        ["ᾅ"]  = "α",
        ["ᾆ"]  = "α",
        ["ᾇ"]  = "α",
        ["ᾈ"]  = "α",
        ["ᾉ"]  = "α",
        ["ᾊ"]  = "α",
        ["ᾋ"]  = "α",
        ["ᾌ"]  = "α",
        ["ᾍ"]  = "α",
        ["ᾎ"]  = "α",
        ["ᾏ"]  = "α",
        ["ᾰ"]  = "α",
        ["ᾱ"]  = "α",
        ["ᾲ"]  = "α",
        ["ᾳ"]  = "α",
        ["ᾴ"]  = "α",
        ["ᾶ"]  = "α",
        ["ᾷ"]  = "α",
        ["Ᾰ"]  = "α",
        ["Ᾱ"]  = "α",
        ["Ὰ"]  = "α",
        ["Ά"]  = "α",
        ["ᾼ"]  = "α",
        ["Β"]  = "β",
        ["β"]  = "β",
        ["Γ"]  = "γ",
        ["γ"]  = "γ",
        ["Δ"]  = "δ",
        ["δ"]  = "δ",
        ["Έ"]  = "ε",
        ["Ε"]  = "ε",
        ["έ"]  = "ε",
        ["ε"]  = "ε",
        ["ἐ"]  = "ε",
        ["ἑ"]  = "ε",
        ["ἒ"]  = "ε",
        ["ἓ"]  = "ε",
        ["ἔ"]  = "ε",
        ["ἕ"]  = "ε",
        ["Ἐ"]  = "ε",
        ["Ἑ"]  = "ε",
        ["Ἒ"]  = "ε",
        ["Ἓ"]  = "ε",
        ["Ἔ"]  = "ε",
        ["Ἕ"]  = "ε",
        ["ὲ"]  = "ε",
        ["Ὲ"]  = "ε",
        ["Έ"]  = "ε",
        ["Ζ"]  = "ζ",
        ["ζ"]  = "ζ",
        ["Ή"]  = "η",
        ["Η"]  = "η",
        ["ή"]  = "η",
        ["η"]  = "η",
        ["ἠ"]  = "η",
        ["ἡ"]  = "η",
        ["ἢ"]  = "η",
        ["ἣ"]  = "η",
        ["ἤ"]  = "η",
        ["ἥ"]  = "η",
        ["ἦ"]  = "η",
        ["ἧ"]  = "η",
        ["Ἠ"]  = "η",
        ["Ἡ"]  = "η",
        ["Ἢ"]  = "η",
        ["Ἣ"]  = "η",
        ["Ἤ"]  = "η",
        ["Ἥ"]  = "η",
        ["Ἦ"]  = "η",
        ["Ἧ"]  = "η",
        ["ὴ"]  = "η",
        ["ή"]  = "η",
        ["ᾐ"]  = "η",
        ["ᾑ"]  = "η",
        ["ᾒ"]  = "η",
        ["ᾓ"]  = "η",
        ["ᾔ"]  = "η",
        ["ᾕ"]  = "η",
        ["ᾖ"]  = "η",
        ["ᾗ"]  = "η",
        ["ᾘ"]  = "η",
        ["ᾙ"]  = "η",
        ["ᾚ"]  = "η",
        ["ᾛ"]  = "η",
        ["ᾜ"]  = "η",
        ["ᾝ"]  = "η",
        ["ᾞ"]  = "η",
        ["ᾟ"]  = "η",
        ["ῂ"]  = "η",
        ["ῃ"]  = "η",
        ["ῄ"]  = "η",
        ["ῆ"]  = "η",
        ["ῇ"]  = "η",
        ["Ὴ"]  = "η",
        ["Ή"]  = "η",
        ["ῌ"]  = "η",
        ["Θ"]  = "θ",
        ["θ"]  = "θ",
        ["Ί"]  = "ι",
        ["ΐ"]  = "ι",
        ["Ι"]  = "ι",
        ["Ϊ"]  = "ι",
        ["ί"]  = "ι",
        ["ι"]  = "ι",
        ["ϊ"]  = "ι",
        ["ἰ"]  = "ι",
        ["ἱ"]  = "ι",
        ["ἲ"]  = "ι",
        ["ἳ"]  = "ι",
        ["ἴ"]  = "ι",
        ["ἵ"]  = "ι",
        ["ἶ"]  = "ι",
        ["ἷ"]  = "ι",
        ["Ἰ"]  = "ι",
        ["Ἱ"]  = "ι",
        ["Ἲ"]  = "ι",
        ["Ἳ"]  = "ι",
        ["Ἴ"]  = "ι",
        ["Ἵ"]  = "ι",
        ["Ἶ"]  = "ι",
        ["Ἷ"]  = "ι",
        ["ὶ"]  = "ι",
        ["ί"]  = "ι",
        ["ῖ"]  = "ι",
        ["ῗ"]  = "ι",
        ["Ῐ"]  = "ι",
        ["Ῑ"]  = "ι",
        ["Ὶ"]  = "ι",
        ["Ί"]  = "ι",
        ["Κ"]  = "κ",
        ["κ"]  = "κ",
        ["Λ"]  = "λ",
        ["λ"]  = "λ",
        ["Μ"]  = "μ",
        ["μ"]  = "μ",
        ["Ν"]  = "ν",
        ["ν"]  = "ν",
        ["Ξ"]  = "ξ",
        ["ξ"]  = "ξ",
        ["Ό"]  = "ο",
        ["Ο"]  = "ο",
        ["ο"]  = "ο",
        ["ό"]  = "ο",
        ["ὀ"]  = "ο",
        ["ὁ"]  = "ο",
        ["ὂ"]  = "ο",
        ["ὃ"]  = "ο",
        ["ὄ"]  = "ο",
        ["ὅ"]  = "ο",
        ["Ὀ"]  = "ο",
        ["Ὁ"]  = "ο",
        ["Ὂ"]  = "ο",
        ["Ὃ"]  = "ο",
        ["Ὄ"]  = "ο",
        ["Ὅ"]  = "ο",
        ["ὸ"]  = "ο",
        ["ό"]  = "ο",
        ["Ὸ"]  = "ο",
        ["Ό"]  = "ο",
        ["Π"]  = "π",
        ["π"]  = "π",
        ["Ρ"]  = "ρ",
        ["ρ"]  = "ρ",
        ["ῤ"]  = "ρ",
        ["ῥ"]  = "ρ",
        ["Ῥ"]  = "ρ",
        ["Σ"]  = "σ",
        ["ς"]  = "σ",
        ["σ"]  = "σ",
        ["Τ"]  = "τ",
        ["τ"]  = "τ",
        ["Ύ"]  = "υ",
        ["Υ"]  = "υ",
        ["Ϋ"]  = "υ",
        ["ΰ"]  = "υ",
        ["υ"]  = "υ",
        ["ϋ"]  = "υ",
        ["ύ"]  = "υ",
        ["ὐ"]  = "υ",
        ["ὑ"]  = "υ",
        ["ὒ"]  = "υ",
        ["ὓ"]  = "υ",
        ["ὔ"]  = "υ",
        ["ὕ"]  = "υ",
        ["ὖ"]  = "υ",
        ["ὗ"]  = "υ",
        ["Ὑ"]  = "υ",
        ["Ὓ"]  = "υ",
        ["Ὕ"]  = "υ",
        ["Ὗ"]  = "υ",
        ["ὺ"]  = "υ",
        ["ύ"]  = "υ",
        ["ῠ"]  = "υ",
        ["ῡ"]  = "υ",
        ["ῢ"]  = "υ",
        ["ΰ"]  = "υ",
        ["ῦ"]  = "υ",
        ["ῧ"]  = "υ",
        ["Ῠ"]  = "υ",
        ["Ῡ"]  = "υ",
        ["Ὺ"]  = "υ",
        ["Ύ"]  = "υ",
        ["Φ"]  = "φ",
        ["φ"]  = "φ",
        ["Χ"]  = "χ",
        ["χ"]  = "χ",
        ["Ψ"]  = "ψ",
        ["ψ"]  = "ψ",
        ["Ώ"]  = "ω",
        ["Ω"]  = "ω",
        ["ω"]  = "ω",
        ["ώ"]  = "ω",
        ["ὠ"]  = "ω",
        ["ὡ"]  = "ω",
        ["ὢ"]  = "ω",
        ["ὣ"]  = "ω",
        ["ὤ"]  = "ω",
        ["ὥ"]  = "ω",
        ["ὦ"]  = "ω",
        ["ὧ"]  = "ω",
        ["Ὠ"]  = "ω",
        ["Ὡ"]  = "ω",
        ["Ὢ"]  = "ω",
        ["Ὣ"]  = "ω",
        ["Ὤ"]  = "ω",
        ["Ὥ"]  = "ω",
        ["Ὦ"]  = "ω",
        ["Ὧ"]  = "ω",
        ["ὼ"]  = "ω",
        ["ώ"]  = "ω",
        ["ᾠ"]  = "ω",
        ["ᾡ"]  = "ω",
        ["ᾢ"]  = "ω",
        ["ᾣ"]  = "ω",
        ["ᾤ"]  = "ω",
        ["ᾥ"]  = "ω",
        ["ᾦ"]  = "ω",
        ["ᾧ"]  = "ω",
        ["ᾨ"]  = "ω",
        ["ᾩ"]  = "ω",
        ["ᾪ"]  = "ω",
        ["ᾫ"]  = "ω",
        ["ᾬ"]  = "ω",
        ["ᾭ"]  = "ω",
        ["ᾮ"]  = "ω",
        ["ᾯ"]  = "ω",
        ["ῲ"]  = "ω",
        ["ῳ"]  = "ω",
        ["ῴ"]  = "ω",
        ["ῶ"]  = "ω",
        ["ῷ"]  = "ω",
        ["Ὼ"]  = "ω",
        ["Ώ"]  = "ω",
        ["ῼ"]  = "ω",
        ["Ω"]  = "ω",
}

-- Δεν ελέγχει την περίπτωση το πρώτο γράμμα να είναι παύλα και το δεύτερο κενό
function _fmainkleida ( any_string ) 
    local mystring = any_string
    local startingchar = mw.ustring.sub(mystring,1,1)
    local wordproduced = ''
    local mychar = ''
--[[    
-- if ending minus must be returned
--    local endingminus = false
--    if mw.ustring.sub(any_string, -1) == '-' then endingminus = true end
--]]
-- αν ο πρώτος χαρακτήρας είναι παύλα τον αφαιρούμε (π.χ. [[-άκι]])
    if startingchar == '-' then
        mystring = mw.ustring.sub(mystring,2)
    end
-- αν ο πρώτος χαρακτήρας είναι αστερίσκος τον αφαιρούμε (π.χ. [[*θανατάς]])
    if startingchar == '*' then
        mystring = mw.ustring.sub(mystring,2)
    end
-- αν ο πρώτος χαρακτήρας είναι απλή απόστροφος (U+0027) την αφαιρούμε (παράδειγμα: λήμμα [['γγίζω]])
    if startingchar == "'" then
        mystring = mw.ustring.sub(mystring,2)
    end
    -- αν υπήρχε μόνο η παύλα (ή απόστροφος ή αστερίσκος) τότε επιστρέφει την αρχική παράμετρο
    if mystring == nil or mw.ustring.len(mystring) < 1 then
        return any_string 
    end
    startingchar = mw.ustring.sub(mystring,1,1)
-- να μετατρέψεις το πρώτο γράμμα
    convertedchar = p._mappedletters[startingchar]    
-- αν το πρώτο γράμμα δεν είναι ελληνικό κράτα το όπως ήταν
    if convertedchar == nil or mw.ustring.len(convertedchar) < 1 then
         wordproduced = startingchar
    else
         -- αλλιώς βάλε στην αρχή αυτό που έφερε από τη μετατροπή
         wordproduced = convertedchar
    end
-- αν έχει και άλλα
    if mw.ustring.len(mystring) > 1 then
        -- χρησιμοποίησε μόνο τα υπόλοιπα
        mystring = mw.ustring.sub(mystring,2)        
        -- για κάθε χαρακτήρα
        for codepoint in mw.ustring.gcodepoint( mystring ) do
            -- αντικατάστησέ τον με βάση τον πίνακα
            mychar = mw.ustring.char(codepoint)
            convertedchar = p._mappedletters[mychar]            
            -- αν βρήκε κάτι για αντικατάσταση
            -- είναι δηλαδή ελληνικό γράμμα
            if convertedchar ~= nil then
                -- πρόσθεσέ το στη δημιουργούμενη κλείδα
                wordproduced = wordproduced .. convertedchar
            end
        end
    end
--    if endingminus then wordproduced = wordproduced .. '-' end
    return wordproduced
end

p.kleida = function( frame ) 
    PAGENAME = mw.title.getCurrentTitle().text  
    --[[ αφαίρεση των κενών πριν και μετά το λήμμα γιατί μάλλον τα στέλνει το πρότυπο
    και δεν χρειάζονται έτσι κι αλλιώς
    (συνάρτηση αντιγραμμένη "τυφλά") βλ. και PAGENAME = mw.title.getCurrentTitle().text ]]
    local myarg1 = PAGENAME:match( "^%s*(.-)%s*$" )
    if mw.ustring.len(myarg1) > 32 then
        -- δημιουργία κλείδας μόνο για τους πρώτους 32 χαρακτήρες
        myarg1 =  mw.ustring.sub(myarg1,1,32)
    end
    return frame:preprocess(_fmainkleida(myarg1))
end
-- για χρήση σε άλλα modules
-- εύρεση κλείδας σε οποιαδήποτε ελληνική λέξη
p.kleidaleksis = function( leksi ) 
	local arg = leksi
    if mw.ustring.len(arg) > 32 then
        -- δημιουργία κλείδας μόνο για τους πρώτους 32 χαρακτήρες
        arg =  mw.ustring.sub(arg,1,32)
    end
    return _fmainkleida(arg)
end

p['κλείδα'] = function(leksi) 
	return p.kleidaleksis(leksi) 
end 

--[[:pl:Moduł:a tergo]]
function reverseatext( text )
        local s = ''
        for codepoint in mw.ustring.gcodepoint( text ) do
            s = mw.ustring.char(codepoint) .. s
        end
        return s
end

p.reverseit = function( frame ) 
    PAGENAME = mw.title.getCurrentTitle().text  
    --[[αφαίρεση των κενών πριν και μετά το λήμμα γιατί μάλλον τα στέλνει το πρότυπο
    και δεν χρειάζονται έτσι κι αλλιώς
    (συνάρτηση αντιγραμμένη "τυφλά") βλ. και PAGENAME = mw.title.getCurrentTitle().text]]
    local myarg1 = PAGENAME:match( "^%s*(.-)%s*$" )
    -- θα αντιστρέψει και τη θέση της παύλας
    local antistrofo = reverseatext(myarg1)
    if mw.ustring.len(antistrofo) > 32 then
        -- δημιουργία κλείδας μόνο για τους πρώτους 32 χαρακτήρες
        antistrofo =  mw.ustring.sub(antistrofo,1,32)
    end
    
    return _fmainkleida(antistrofo)    
end

-- επιστρέφει την κλείδα του ονόματος της γλώσσας
-- εφόσον η γλώσσα έχει δοθεί με τη μορφή δίψηφου ή τρίψηφου ή άλλου κωδικού
-- που υπάρχει στο [[Module:Languages]]
-- Χρήση μέσω προτύπου (αφού παίρνει την παράμετρο με getParent) 
-- Επιστρέφει κενό αν δεν βρει κάτι
p['κλ-γλ'] = function(frame)
	local pargs = frame:getParent().args
	local output =''
	local lang = pargs[1] or ''
	if lang then
		local languages = mw.loadData("Module:Languages")
		langforsort = languages[lang].name or ''
		if langforsort then
			return _fmainkleida(langforsort)
		else
			return lang
		end
	else
		return ''
	end
	
end

return p