Module:User:Sarri.greek/utilities
Μετάβαση στην πλοήγηση
Πήδηση στην αναζήτηση
Module:User:Sarri.greek/utilities « τεκμηρίωση(documentation)
Module:User:Sarri.greek/utilities » data-sortkey
Module με utilities, χρήσιμες functions που καλούνται
- από άλλα modules με
require("utilities").nameoffunction
σε άλλα modules. - από Πρότυπα με
{{#invoke:utitlities|<όνομα function>|<παράμετρος αν υπάρχει>}}
Άλλα χρήσιμα:
- Module:lang για γλώσσες (iso, όνομα γλώσσας κ.λπ.)
- Module:page για τίτλο και άλλα μέρη των τίτλων
--[=[
A collection of little functions "how to..."
As more standalone as possible. Also, some help-instructions without functions.
Please add source, explanation and example (how to call it, where) for each function.
Please write copypaste expressions. Thank you. 2022.12.25. [[wikt:el:Sarri.greek]]
* call from modules with xx = require("utilities").nameoffunction ?how do we write parameters
* call from templates with {{#invoke:utitlities|<nameoffunction>|<parameter1>|<parameter2>}} or <namedparamter>|<namedparameter>|...
IF your parameters are written in a non-latin script, write them as ['yourLanguageParameter'].thisvalue
More:
* [[Module:lang]] write iso of language, get name, get... για γλώσσες (iso, όνομα γλώσσας κ.λπ.)
* [[Module:page]] get title or parenthesistext from PAGENAMES για τίτλο και άλλα μέρη των τίτλων
CONTENTS a...z functions:
* convertGreek characters --> no diacritics convertLatin characters --> no diacritics
* getSuffix (from Category pages)
* get_warning for [[Template:warning]]
* links_with_underscores
* reverse
* sortkey=convertAll characters
Reference
* [[wikt:en:Module:utilities]], [[wikt:en:Module:ugly hacks]]
* https://www.mediawiki.org/wiki/Global_templates
* https://www.mediawiki.org/wiki/Multilingual_Templates_and_Modules
*
To do: all questions are marked with: ?
]=]--
local export = {}
module_path = 'Module:User:Sarri.greek/utilities'
-- REQUIRED --------------------------
-- see function covert
-- DATA PAGES ------------------------
local m_data_sortkey = mw.loadData(module_path .. "/data-sortkey")
-- for function sortkey
--[=[ -------------------------- < convert Latin characters > --------------------------
Convert Latin characters --> to NO diacritics like ètre --> etre
-- see function sortkey for ALL characthers
* As in [[wikt:el:Module:Kleida-la]] function kleidaleksis
* call from modules with: require("Module:utilities").convertLatin("yourtexthere") -- O! this does not work at [[Module:auto cat]]
* call from templates with: {{#invoke:utilities|convertLatin|yourtexthere}}
e.g. at [[wikt:el:Template:lis2]] and [[Module:auto cat]] autosort affixes
]=]--
function export.convertLatin(frame)
-- local args = frame:getParent().args -- make a Template
local args = frame.args -- invoke
-- for BOTH
-- local zz = frame.args[1] or frame:getParent().args[1] or ''
local zz = args[1] or ''
if args[1] ~= '' and args[1] ~= nil then
zz = require("Module:Kleida-la").kleidaleksis(zz)
end
return zz
end
--[=[ -------------------------- < convert Greek characters > --------------------------
Convert Greek characters --> to NO diacritics like βᾶς --> βασ
-- see function sortkey for ALL characthers
* As in [[wikt:el:Module:Kleida-el]] function kleidaleksis
* call from modules with: require("Module:utilities").convertGreek("yourtexthere")
* call from templates with: {{#invoke:utilities|convertGreek|yourtexthere}}
e.g. at [[wikt:el:Template:λίστα2]] and [[Module:auto cat]] autosort affixes
]=]--
function export.convertGreek(frame)
-- local args = frame:getParent().args -- make a Template
local args = frame.args -- invoke
-- for BOTH
-- local zz = frame.args[1] or frame:getParent().args[1] or ''
local zz = args[1] or ''
if args[1] ~= '' and args[1] ~= nil then
zz = require("Module:Kleida-el").kleidaleksis(zz)
end
return zz
end
--[=[ -------------------------- < get suffix from Category title > --------------------------
Extract the suffix from a Category title
* e.g. get tion from [[:Κατηγορία:Λέξεις με επίθημα -tion (γαλλικά)]], υποκοριστικά, ονόματα, τοπωνύμια
We need a function to get the Category title without parenthesis brackets (if there are any)
[[wikt:el:Module:page]] the function require("Module:page").pagetitle(xx)
* call from modules with: require("Module:utilities").getSuffix
* call from templates or pages with: {{#invoke:utilities|getSuffix}}
USE at [[wikt:el:Template:λίστα2]], [[wikt:el:Template:list2]] to get suffixes
]=]--
-- ##?? TO DO with comma [[:Κατηγορία:Λέξεις με επίθημα -της, αρσενικό (αρχαία ελληνικά)]]
function export.getSuffix(suffix)
-- local cat_title = mw.title.getCurrentTitle() -- Title + (textparenthesis) if there is one
local cat_title = require("Module:page").pagetitle(xx) -- Category title WITHOUT a parentheis, if there is one
if mw.ustring.find(cat_title, "Λέξεις με επίθημα") then
suffix = mw.ustring.sub(mw.ustring.match(cat_title, "Λέξεις με επίθημα (.*)"), 1, -1) -- this is hyphen+affix
if mw.ustring.sub(mw.ustring.match(cat_title, "Λέξεις με επίθημα (.*)"), 1, -1):sub(1, 1) == '-'
then
suff = mw.ustring.sub(mw.ustring.match(cat_title, "Λέξεις με επίθημα (.*)"), 2, -1) -- no hyphen
else
suff = suffix
end
elseif mw.ustring.find(cat_title, "Λέξεις με υποκοριστικό επίθημα") then
suffix = mw.ustring.sub(mw.ustring.match(cat_title, "Λέξεις με υποκοριστικό επίθημα (.*)"), 1, -1) -- this is hyphen+affix
if mw.ustring.sub(mw.ustring.match(cat_title, "Λέξεις με υποκοριστικό επίθημα (.*)"), 1, -1):sub(1, 1) == '-'
then
suff = mw.ustring.sub(mw.ustring.match(cat_title, "Λέξεις με υποκοριστικό επίθημα (.*)"), 2, -1) -- no hyphen
else
suff = suffix
end
elseif mw.ustring.find(cat_title, "Λέξεις με μεγεθυντικό επίθημα") then
suffix = mw.ustring.sub(mw.ustring.match(cat_title, "Λέξεις με μεγεθυντικό επίθημα (.*)"), 1, -1) -- this is hyphen+affix
if mw.ustring.sub(mw.ustring.match(cat_title, "Λέξεις με μεγεθυντικό επίθημα (.*)"), 1, -1):sub(1, 1) == '-'
then
suff = mw.ustring.sub(mw.ustring.match(cat_title, "Λέξεις με μεγεθυντικό επίθημα (.*)"), 2, -1) -- no hyphen
else
suff = suffix
end
elseif mw.ustring.find(cat_title, "Ανδρικά επώνυμα με επίθημα") then
suffix = mw.ustring.sub(mw.ustring.match(cat_title, "Ανδρικά επώνυμα με επίθημα (.*)"), 1, -1) -- this is hyphen+affix
if mw.ustring.sub(mw.ustring.match(cat_title, "Ανδρικά επώνυμα με επίθημα (.*)"), 1, -1):sub(1, 1) == '-'
then
suff = mw.ustring.sub(mw.ustring.match(cat_title, "Ανδρικά επώνυμα με επίθημα (.*)"), 2, -1) -- no hyphen
else
suff = suffix
end
elseif mw.ustring.find(cat_title, "Γυναικεία επώνυμα με επίθημα") then
suffix = mw.ustring.sub(mw.ustring.match(cat_title, "Γυναικεία επώνυμα με επίθημα (.*)"), 1, -1) -- this is hyphen+affix
if mw.ustring.sub(mw.ustring.match(cat_title, "Γυναικεία επώνυμα με επίθημα (.*)"), 1, -1):sub(1, 1) == '-'
then
suff = mw.ustring.sub(mw.ustring.match(cat_title, "Γυναικεία επώνυμα με επίθημα (.*)"), 2, -1) -- no hyphen
else
suff = suffix
end
elseif mw.ustring.find(cat_title, "Ανδρικά ονόματα με επίθημα") then
suffix = mw.ustring.sub(mw.ustring.match(cat_title, "Ανδρικά ονόματα με επίθημα (.*)"), 1, -1) -- this is hyphen+affix
if mw.ustring.sub(mw.ustring.match(cat_title, "Ανδρικά ονόματα με επίθημα (.*)"), 1, -1):sub(1, 1) == '-'
then
suff = mw.ustring.sub(mw.ustring.match(cat_title, "Ανδρικά ονόματα με επίθημα (.*)"), 2, -1) -- no hyphen
else
suff = suffix
end
elseif mw.ustring.find(cat_title, "Γυναικεία ονόματα με επίθημα") then
suffix = mw.ustring.sub(mw.ustring.match(cat_title, "Γυναικεία ονόματα με επίθημα (.*)"), 1, -1) -- this is hyphen+affix
if mw.ustring.sub(mw.ustring.match(cat_title, "Γυναικεία ονόματα με επίθημα (.*)"), 1, -1):sub(1, 1) == '-'
then
suff = mw.ustring.sub(mw.ustring.match(cat_title, "Γυναικεία ονόματα με επίθημα (.*)"), 2, -1) -- no hyphen
else
suff = suffix
end
elseif mw.ustring.find(cat_title, "Επώνυμα κοινού γένους με επίθημα") then
suffix = mw.ustring.sub(mw.ustring.match(cat_title, "Επώνυμα κοινού γένους με επίθημα (.*)"), 1, -1) -- this is hyphen+affix
if mw.ustring.sub(mw.ustring.match(cat_title, "Επώνυμα κοινού γένους με επίθημα (.*)"), 1, -1):sub(1, 1) == '-'
then
suff = mw.ustring.sub(mw.ustring.match(cat_title, "Επώνυμα κοινού γένους με επίθημα (.*)"), 2, -1) -- no hyphen
else
suff = suffix
end
elseif mw.ustring.find(cat_title, "Τοπωνύμια με επίθημα") then
suffix = mw.ustring.sub(mw.ustring.match(cat_title, "Τοπωνύμια με επίθημα (.*)"), 1, -1) -- this is hyphen+affix
if mw.ustring.sub(mw.ustring.match(cat_title, "Τοπωνύμια με επίθημα (.*)"), 1, -1):sub(1, 1) == '-'
then
suff = mw.ustring.sub(mw.ustring.match(cat_title, "Τοπωνύμια με επίθημα (.*)"), 2, -1) -- no hyphen
else
suff = suffix
end
elseif mw.ustring.find(cat_title, "Λέξεις με συνθετικό") then
suffix = mw.ustring.sub(mw.ustring.match(cat_title, "Λέξεις με συνθετικό (.*)"), 2, -2) -- this is the combining form without apostrophs
if mw.ustring.sub(mw.ustring.match(cat_title, "Λέξεις με συνθετικό (.*)"), 1, -1):sub(1) == "'" -- apostroph at beginning
and mw.ustring.sub(mw.ustring.match(cat_title, "Λέξεις με συνθετικό (.*)"), 1, -1):sub(-1) == "'" -- apostroph at end
then
suff = mw.ustring.sub(mw.ustring.match(cat_title, "Λέξεις με συνθετικό (.*)"), 2, -2) -- no apostrophs
else
suff = suffix
end
end
return suff
end
--[=[ -------------------------- < get_warning > --------------------------
-- [[Template:warning]] -- [[Πρότυπο:προειδοποίηση]]
-- Χρησιμοποιείται μέσα σε πρότυπα ελέγχου όπως το [[Πρότυπο:έλεγχος νεολογισμού]]
-- User for 'request to check' templates e.g. [[Template:έλεγχος νεολογισμού]]
]=]--
function export.get_warning(frame)
local args = frame:getParent().args -- make a Template
-- local args = frame.args -- invoke
get_warning = args[1] or ''
if args[1] ~= '' and args[1] ~= nil then
output = mw.addWarning('<span style="color:#b22222; font-size:14px;"><b>'
.. get_warning .. '</b></span>')
else
output = '[[Κατηγορία:Σελίδες που χρειάζονται έλεγχο (νέα ελληνικά)]]'
mw.addWarning('<span style="color:#b22222; font-size:14px;"><b>'
.. 'Συμπληρώστε τις οδηγίες! Add some guidelines!' .. '</b></span>')
end
return output
end -- end function get_warning
--[=[ -------------------------- < links_with_underscores > --------------------------
from [[wikt:el:Template:λίστα1]]
]=]--
function export.links_with_underscores(frame)
-- local args = frame:getParent().args -- make a Template
local args = frame.args -- invoke
local link = args[1] or ''
if args[1] ~= '' and args[1] ~= nil then
output = args[1]:gsub( " ", "_" )
end
return output
end -- close links_with_underscores
--[=[ -------------------------- < reverse > --------------------------
reverse a string of text e.g. love = evol
* source: [[wikt:pl:Moduł:a tergo]]
** https://www.mediawiki.org/wiki/Lua/Tutorial
string.reverse(s) like = string.reverse("lua") gives aul
* also used at [[wikt:el:Module:Kleida-el]]
* call from modules with: require("Module:utilities").reverse("yourtexthere")
* call from templates with: {{#invoke:utilities|reverse|yourtexthere}}
e.g. at [[wikt:el:Template:list2]] to find all suffixes at Reverse Index.
]=]--
-- reverse the string
function export.reverse_it(text)
local s = ''
for codepoint in mw.ustring.gcodepoint(text) do
s = mw.ustring.char(codepoint) .. s
end
return s
end
-- apply reverse_it
function export.reverse(frame)
-- local args = frame:getParent().args -- make a Template
-- local args = frame.args -- invoke
-- for Templates ?? how do I invoke from modules?
local text = frame.args[1] or frame:getParent().args[1] or ''
return export.reverse_it(text)
end
--[=[ -------------------------- < sortkey convert all > --------------------------
Convert greek and latin characters --> to NO diacritics
from local m_data_sortkey = mw.loadData(module_path .. "/data-sortkey")
-- check [[:Κατηγορία:Λέξεις με επίθημα -gène (γαλλικά)]] check sorting at [[:Κατηγορία:Λέξεις κατά επίθημα (γαλλικά)]]
* As in [[wikt:el:Module:Kleida-el]] function _fmainkleida
* call from modules with: require("Module:utilities").sortkey(zz)
* call from templates with: {{#invoke:utilities|sortkey|yourtexthere}}
e.g. at [[Module:auto cat]], section SUFFIXES, the autosort
Also see functions convertGreek and convertLatin
]=]--
-- as in [[wikt:el:Module:Kleida-el]] by [[wikt:el:User:Xoristzatziki]]
-- Does not control: 1st letter = hyphen + 2nd = emptyspace
function export.convert_characters(any_string)
local mystring = any_string
local startingchar = mw.ustring.sub(mystring,1,1)
local wordproduced = ''
local mychar = ''
-- take away 1st character = hyphen (e.g. [[-tion]])
if startingchar == '-' then
mystring = mw.ustring.sub(mystring,2)
end
-- take away 1st character = asterisc (e.g. [[*λύκη]])
if startingchar == '*' then
mystring = mw.ustring.sub(mystring,2)
end
-- take away 1st character = simple apostroph U+0027 (e.g. [['γγίζω]])
if startingchar == "'" then
mystring = mw.ustring.sub(mystring,2)
end
-- if there was ONLY a hyphen or ONLY an asterisc, return the first parameter
if mystring == nil or mw.ustring.len(mystring) < 1 then
return any_string
end
startingchar = mw.ustring.sub(mystring,1,1)
-- convert 1st character
convertedchar = m_data_sortkey[startingchar]
-- if the 1st character is not in the data, do not convert it
if convertedchar == nil or mw.ustring.len(convertedchar) < 1 then
wordproduced = startingchar
else
-- else, put the converted character
wordproduced = convertedchar
end
-- if there are more...
if mw.ustring.len(mystring) > 1 then
-- use only the remaining ones
mystring = mw.ustring.sub(mystring,2)
-- for each character
for codepoint in mw.ustring.gcodepoint(mystring) do
-- convert, as in /data-sortkey
mychar = mw.ustring.char(codepoint)
convertedchar = m_data_sortkey[mychar]
-- if something is found to convert
if convertedchar ~= nil then
-- add it
wordproduced = wordproduced .. convertedchar
end
end
end
-- if endingminus then wordproduced = wordproduced .. '-' end
return wordproduced
end
-- check [[:Κατηγορία:Λέξεις με επίθημα -gène (γαλλικά)]] check sorting at [[:Κατηγορία:Λέξεις κατά επίθημα (γαλλικά)]]
-- from MODULES: as in SUFFIXES of [[Module:auto cat]] write require("Module:utilities").sortkey
function export.sortkey(word)
local arg = word
if mw.ustring.len(arg) > 32 then
-- make sortkey only for 32 characters
arg = mw.ustring.sub(arg,1,32)
end
return export.convert_characters(arg)
end
-- to #invoke from TEMPLATES like [[Template:list2]]
-- check [[:Κατηγορία:Λέξεις με επίθημα -mètre (γαλλικά)]]
-- check [[:Κατηγορία:Λέξεις με επίθημα -ῖτις (αρχαία ελληνικά)]] must get αρχαία_ελληνικά from [[Module:lang]].searchcat
function export.sortkey_temp(frame)
-- local args = frame:getParent().args -- make a Template
local args = frame.args -- invoke
local zz = args[1] or ''
if args[1] ~= '' and args[1] ~= nil then
if mw.ustring.len(zz) > 32 then
-- make sortkey only for 32 characters
zz = mw.ustring.sub(zz,1,32)
end
end
return export.convert_characters(zz)
-- return zz
end
return export