Dokumentaci tohoto modulu lze vytvořit na stránce Nápověda:Modul:Kleida-el
-- @brief
-- creates DEFAULTSORT for greek (and almost all ancient greek) lemmas
---- since greek lemmas in dictionaries are listed depending on one of 24 letters of alfabet
---- independently from their accents
-- @param
-- none, uses PAGENAME from "frame"
-- ]
objkleida = {}
-- mapping dictionary
-- maps every greek letter (except the very archaic like digamma)
-- to one of the 24 anaccented letters of greek alphabet
objkleida._mappedletters = {
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "α",
= "β",
= "β",
= "γ",
= "γ",
= "δ",
= "δ",
= "ε",
= "ε",
= "ε",
= "ε",
= "ε",
= "ε",
= "ε",
= "ε",
= "ε",
= "ε",
= "ε",
= "ε",
= "ε",
= "ε",
= "ε",
= "ε",
= "ε",
= "ε",
= "ε",
= "ζ",
= "ζ",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "η",
= "θ",
= "θ",
= "ι",
= "ι",
= "ι",
= "ι",
= "ι",
= "ι",
= "ι",
= "ι",
= "ι",
= "ι",
= "ι",
= "ι",
= "ι",
= "ι",
= "ι",
= "ι",
= "ι",
= "ι",
= "ι",
= "ι",
= "ι",
= "ι",
= "ι",
= "ι",
= "ι",
= "ι",
= "ι",
= "ι",
= "ι",
= "ι",
= "ι",
= "κ",
= "κ",
= "λ",
= "λ",
= "μ",
= "μ",
= "ν",
= "ν",
= "ξ",
= "ξ",
= "ο",
= "ο",
= "ο",
= "ο",
= "ο",
= "ο",
= "ο",
= "ο",
= "ο",
= "ο",
= "ο",
= "ο",
= "ο",
= "ο",
= "ο",
= "ο",
= "ο",
= "ο",
= "ο",
= "ο",
= "π",
= "π",
= "ρ",
= "ρ",
= "ρ",
= "ρ",
= "ρ",
= "σ",
= "σ",
= "σ",
= "τ",
= "τ",
= "υ",
= "υ",
= "υ",
= "υ",
= "υ",
= "υ",
= "υ",
= "υ",
= "υ",
= "υ",
= "υ",
= "υ",
= "υ",
= "υ",
= "υ",
= "υ",
= "υ",
= "υ",
= "υ",
= "υ",
= "υ",
= "υ",
= "υ",
= "υ",
= "υ",
= "υ",
= "υ",
= "υ",
= "υ",
= "υ",
= "υ",
= "φ",
= "φ",
= "χ",
= "χ",
= "ψ",
= "ψ",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
= "ω",
}
-- function _fmainkleida
-- (can also be used independently to sort lines in tables, etc)
-- Δεν ελέγχει την περίπτωση το πρώτο γράμμα να είναι παύλα και το δεύτερο κενό
-- Does not check if first letter is hyphent followed by space
-- LUA problem, if parameter (any_string) contains more than 32 characters
-- Except from the first character,
-- keeps only "mapped characters"
-- (aka the 24 anaccented letters of greek alphabet)
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 first character is hyphen is removed
-- this way "endings" (like -λογία) will be sorted under their first character
if startingchar == '-' then
mystring = mw.ustring.sub(mystring,2)
end
-- αν υπήρχε μόνο η παύλα τότε επιστρέφει την αρχική παράμετρο
--if only a hyphen existed then returns that hyphen
if mystring == nil or mw.ustring.len(mystring) < 1 then
return any_string
end
startingchar = mw.ustring.sub(mystring,1,1)
--δοκίμασε να μετατρέψεις το πρώτο γράμμα
--"map" first letter
convertedchar = objkleida._mappedletters
-- αν το πρώτο γράμμα δεν είναι ελληνικό κράτα το όπως ήταν
-- if first letter was not a "greek" one
-- keep it as is
-- (why? maybe it is a punctuation mark or other mark)
if convertedchar == nil or mw.ustring.len(convertedchar) < 1 then
wordproduced = startingchar
--αλλιώς βάλε στην αρχή αυτό που έφερε από τη μετατροπή
--else replace it with the return value
else
wordproduced = convertedchar
end
-- αν έχει και άλλα
-- if more characters exist...
if mw.ustring.len(mystring) > 1 then
--χρησιμοποίησε μόνο τα υπόλοιπα
--use only the rest.
mystring = mw.ustring.sub(mystring,2)
--για κάθε χαρακτήρα
--For every character
for codepoint in mw.ustring.gcodepoint( mystring ) do
--αντικατάστησέ τον με βάση τον πίνακα
--replace it according to mapping table
mychar = mw.ustring.char(codepoint)
convertedchar = objkleida._mappedletters
--αν βρήκε κάτι για αντικατάσταση
--είναι δηλαδή ελληνικό γράμμα
--if something returned
--(aka was a greek letter, accented or not)
if convertedchar ~= nil then
--πρόσθεσέ το στη δημιουργούμενη κλείδα
--add it to "defaultsort"
wordproduced = wordproduced .. convertedchar
end
-- else is a non greek character a space, another hyphen etc
-- do nothing with it
end
end
-- if endingminus then wordproduced = wordproduced .. '-' end
return wordproduced
end
--function that will be used for DEFAULTSORT
--will use "frame" and current tile to invoke parameter
objkleida.kleida = function( frame )
PAGENAME = mw.title.getCurrentTitle().text
--[[αφαίρεση των κενών πριν και μετά το λήμμα γιατί μάλλον τα στέλνει το πρότυπο
και δεν χρειάζονται έτσι κι αλλιώς
(συνάρτηση αντιγραμμένη "τυφλά", είναι σωστή;)]]
local myarg1 = PAGENAME:match( "^%s*(.-)%s*$" )
if mw.ustring.len(myarg1) > 32 then
--δημιουργία κλείδας μόνο για τους πρώτους 32 χαρακτήρες
--LUE problems exist if more than 32 characters are used
--But can be extended to support "chunks" of 32 characters
--(which maybe is not so usefull in such big words)
myarg1 = mw.ustring.sub(myarg1,1,32)
end
--creates DEFAULTSORT entry for the first 32 characters
return frame:preprocess(_fmainkleida(myarg1))
end
return objkleida