Module:Wt/grc/Kleida-grc
Appearance
Καλείται απόν τὸ Template:Wt/grc/κλείδα-αρχ
-- @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
-- η τιμή που επιστρέφει μπορεί να χρησιμοποιηθεί
-- και για να ταξινομηθούν αλφαβητικά και απλές γραμμές
-- (π.χ. σε πίνακες ή ενότητες)
p._mappedletters = {
["Α"] = "α",
["ά"] = "α",
["α"] = "α",
["ἀ"] = "α",
["ἁ"] = "α",
["ἂ"] = "α",
["ἃ"] = "α",
["ἄ"] = "α",
["ἅ"] = "α",
["ἆ"] = "α",
["ἇ"] = "α",
["Ἀ"] = "α",
["Ἁ"] = "α",
["Ἂ"] = "α",
["Ἃ"] = "α",
["Ἄ"] = "α",
["Ἅ"] = "α",
["Ἆ"] = "α",
["Ἇ"] = "α",
["ὰ"] = "α",
["ά"] = "α",
["ᾀ"] = "α",
["ᾁ"] = "α",
["ᾂ"] = "α",
["ᾃ"] = "α",
["ᾄ"] = "α",
["ᾅ"] = "α",
["ᾆ"] = "α",
["ᾇ"] = "α",
["ᾈ"] = "α",
["ᾉ"] = "α",
["ᾊ"] = "α",
["ᾋ"] = "α",
["ᾌ"] = "α",
["ᾍ"] = "α",
["ᾎ"] = "α",
["ᾏ"] = "α",
["ᾰ"] = "α",
["ᾱ"] = "α",
["ᾲ"] = "α",
["ᾳ"] = "α",
["ᾴ"] = "α",
["ᾶ"] = "α",
["ᾷ"] = "α",
["Ᾰ"] = "α",
["Ᾱ"] = "α",
["Ὰ"] = "α",
["Ά"] = "α",
["ᾼ"] = "α",
["Β"] = "β",
["β"] = "β",
["Γ"] = "γ",
["γ"] = "γ",
["Δ"] = "δ",
["δ"] = "δ",
["Έ"] = "ε",
["Ε"] = "ε",
["έ"] = "ε",
["ε"] = "ε",
["ἐ"] = "ε",
["ἑ"] = "ε",
["ἒ"] = "ε",
["ἓ"] = "ε",
["ἔ"] = "ε",
["ἕ"] = "ε",
["Ἐ"] = "ε",
["Ἑ"] = "ε",
["Ἒ"] = "ε",
["Ἓ"] = "ε",
["Ἔ"] = "ε",
["Ἕ"] = "ε",
["ὲ"] = "ε",
["Ὲ"] = "ε",
["Έ"] = "ε",
["Ζ"] = "ζ",
["ζ"] = "ζ",
["Ή"] = "η",
["Η"] = "η",
["ή"] = "η",
["η"] = "η",
["ἠ"] = "η",
["ἡ"] = "η",
["ἢ"] = "η",
["ἣ"] = "η",
["ἤ"] = "η",
["ἥ"] = "η",
["ἦ"] = "η",
["ἧ"] = "η",
["Ἠ"] = "η",
["Ἡ"] = "η",
["Ἢ"] = "η",
["Ἣ"] = "η",
["Ἤ"] = "η",
["Ἥ"] = "η",
["Ἦ"] = "η",
["Ἧ"] = "η",
["ὴ"] = "η",
["ή"] = "η",
["ᾐ"] = "η",
["ᾑ"] = "η",
["ᾒ"] = "η",
["ᾓ"] = "η",
["ᾔ"] = "η",
["ᾕ"] = "η",
["ᾖ"] = "η",
["ᾗ"] = "η",
["ᾘ"] = "η",
["ᾙ"] = "η",
["ᾚ"] = "η",
["ᾛ"] = "η",
["ᾜ"] = "η",
["ᾝ"] = "η",
["ᾞ"] = "η",
["ᾟ"] = "η",
["ῂ"] = "η",
["ῃ"] = "η",
["ῄ"] = "η",
["ῆ"] = "η",
["ῇ"] = "η",
["Ὴ"] = "η",
["Ή"] = "η",
["ῌ"] = "η",
["Θ"] = "θ",
["θ"] = "θ",
["Ί"] = "ι",
["ΐ"] = "ι",
["Ι"] = "ι",
["Ϊ"] = "ι",
["ί"] = "ι",
["ι"] = "ι",
["ϊ"] = "ι",
["ἰ"] = "ι",
["ἱ"] = "ι",
["ἲ"] = "ι",
["ἳ"] = "ι",
["ἴ"] = "ι",
["ἵ"] = "ι",
["ἶ"] = "ι",
["ἷ"] = "ι",
["Ἰ"] = "ι",
["Ἱ"] = "ι",
["Ἲ"] = "ι",
["Ἳ"] = "ι",
["Ἴ"] = "ι",
["Ἵ"] = "ι",
["Ἶ"] = "ι",
["Ἷ"] = "ι",
["ὶ"] = "ι",
["ί"] = "ι",
["ῖ"] = "ι",
["ῗ"] = "ι",
["Ῐ"] = "ι",
["Ῑ"] = "ι",
["Ὶ"] = "ι",
["Ί"] = "ι",
["Κ"] = "κ",
["κ"] = "κ",
["Λ"] = "λ",
["λ"] = "λ",
["Μ"] = "μ",
["μ"] = "μ",
["Ν"] = "ν",
["ν"] = "ν",
["Ξ"] = "ξ",
["ξ"] = "ξ",
["Ό"] = "ο",
["Ο"] = "ο",
["ο"] = "ο",
["ό"] = "ο",
["ὀ"] = "ο",
["ὁ"] = "ο",
["ὂ"] = "ο",
["ὃ"] = "ο",
["ὄ"] = "ο",
["ὅ"] = "ο",
["Ὀ"] = "ο",
["Ὁ"] = "ο",
["Ὂ"] = "ο",
["Ὃ"] = "ο",
["Ὄ"] = "ο",
["Ὅ"] = "ο",
["ὸ"] = "ο",
["ό"] = "ο",
["Ὸ"] = "ο",
["Ό"] = "ο",
["Π"] = "π",
["π"] = "π",
["Ρ"] = "ρ",
["ρ"] = "ρ",
["ῤ"] = "ρ",
["ῥ"] = "ρ",
["Ῥ"] = "ρ",
["Σ"] = "σ",
["ς"] = "σ",
["σ"] = "σ",
["Τ"] = "τ",
["τ"] = "τ",
["Ύ"] = "υ",
["Υ"] = "υ",
["Ϋ"] = "υ",
["ΰ"] = "υ",
["υ"] = "υ",
["ϋ"] = "υ",
["ύ"] = "υ",
["ὐ"] = "υ",
["ὑ"] = "υ",
["ὒ"] = "υ",
["ὓ"] = "υ",
["ὔ"] = "υ",
["ὕ"] = "υ",
["ὖ"] = "υ",
["ὗ"] = "υ",
["Ὑ"] = "υ",
["Ὓ"] = "υ",
["Ὕ"] = "υ",
["Ὗ"] = "υ",
["ὺ"] = "υ",
["ύ"] = "υ",
["ῠ"] = "υ",
["ῡ"] = "υ",
["ῢ"] = "υ",
["ΰ"] = "υ",
["ῦ"] = "υ",
["ῧ"] = "υ",
["Ῠ"] = "υ",
["Ῡ"] = "υ",
["Ὺ"] = "υ",
["Ύ"] = "υ",
["Φ"] = "φ",
["φ"] = "φ",
["Χ"] = "χ",
["χ"] = "χ",
["Ψ"] = "ψ",
["ψ"] = "ψ",
["Ώ"] = "ω",
["Ω"] = "ω",
["ω"] = "ω",
["ώ"] = "ω",
["ὠ"] = "ω",
["ὡ"] = "ω",
["ὢ"] = "ω",
["ὣ"] = "ω",
["ὤ"] = "ω",
["ὥ"] = "ω",
["ὦ"] = "ω",
["ὧ"] = "ω",
["Ὠ"] = "ω",
["Ὡ"] = "ω",
["Ὢ"] = "ω",
["Ὣ"] = "ω",
["Ὤ"] = "ω",
["Ὥ"] = "ω",
["Ὦ"] = "ω",
["Ὧ"] = "ω",
["ὼ"] = "ω",
["ώ"] = "ω",
["ᾠ"] = "ω",
["ᾡ"] = "ω",
["ᾢ"] = "ω",
["ᾣ"] = "ω",
["ᾤ"] = "ω",
["ᾥ"] = "ω",
["ᾦ"] = "ω",
["ᾧ"] = "ω",
["ᾨ"] = "ω",
["ᾩ"] = "ω",
["ᾪ"] = "ω",
["ᾫ"] = "ω",
["ᾬ"] = "ω",
["ᾭ"] = "ω",
["ᾮ"] = "ω",
["ᾯ"] = "ω",
["ῲ"] = "ω",
["ῳ"] = "ω",
["ῴ"] = "ω",
["ῶ"] = "ω",
["ῷ"] = "ω",
["Ὼ"] = "ω",
["Ώ"] = "ω",
["ῼ"] = "ω",
["Ω"] = "ω",
}
-- Δεν ελέγχει την περίπτωση το πρώτο γράμμα να είναι παύλα και το δεύτερο κενό
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
-- αν ο πρώτος χαρακτήρας είναι απλή απόστροφος (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
--[[αφαίρεση των κενών πριν και μετά το λήμμα γιατί μάλλον τα στέλνει το πρότυπο
και δεν χρειάζονται έτσι κι αλλιώς
(συνάρτηση αντιγραμμένη "τυφλά", είναι σωστή;)]]
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
--[[αφαίρεση των κενών πριν και μετά το λήμμα γιατί μάλλον τα στέλνει το πρότυπο
και δεν χρειάζονται έτσι κι αλλιώς
(συνάρτηση αντιγραμμένη "τυφλά", είναι σωστή;)]]
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:Wt/grc/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:Wt/grc/Languages")
langforsort = languages[lang].name or ''
if langforsort then
return _fmainkleida(langforsort)
else
return lang
end
else
return ''
end
end
return p