Module:topos/functions: Διαφορά μεταξύ των αναθεωρήσεων
Μετάβαση στην πλοήγηση
Πήδηση στην αναζήτηση
Περιεχόμενο που διαγράφηκε Περιεχόμενο που προστέθηκε
p.catword_to_firstkeyword(word_cat) |
problem p.catword_to_firstkeyword(word_cat) |
||
Γραμμή 40: | Γραμμή 40: | ||
end |
end |
||
-- ???????????????????????????????? FAIL. I do not know how to call the first keyword |
|||
-- perhaps I could create an extra keyword to REPEAT the first one, as a key |
|||
--- ========== write word_cat - get the first keyword (kind) ============= -- they always exist |
--- ========== write word_cat - get the first keyword (kind) ============= -- they always exist |
||
-- i need three keywords, the third keyword i choose is: word |
-- i need three keywords, the third keyword i choose is: word |
Αναθεώρηση της 07:54, 10 Νοεμβρίου 2020
Module:topos >> Module:topos/kind << Module:topos/τεκμηρίωση (documentation) <<
Module:topos >> Module:topos/where
Module:topos >> Module:topos/functions
Το Module καλείται από το Πρότυπο:τόπος όπου υπάρχουν οδηγίες. Δείτε και την Κατηγορία:Τοπωνύμια.
Επιμέρους functions, χρήσιμες σε άλλα Modules υπάρχουν στο Module:topos/functions
CheckCheck
-- Useful functions. Used by other modules, like [[Module:auto cat]]
-- 1) keywords from [[Module:topos/kind]]
-- 2) keywords from [[Module:topos/where]]
--[=[ 2020.11.09. Sarri.greek - Last update: 2020.11.09.
PROBLEMS - check [[Module:autocat]] section TOPOS
* chek if expression at IF IT EXISTS is ok. It works only with 'and'
]=]--
local p = {}
--------------------------------------------------------------------------
-- keywords από το [[Module:topos/kind]] --
--------------------------------------------------------------------------
-- write one keyword - get another
--- ============ write first keyword - get name of category ============== -- word_cat ALWAYS EXISTS
-- I wish to get the keyword 'word_cat' if I write the first keyword, which is called 'kind'
-- I need word_cat, because it matches the name of Categories, the cat_title.
-- We need 3 keys for this function: kind, word_cat, and one more. I choose: word.
function p.firstkeyword_to_catword(kind) -- kind is the name of the first keyword. You MUST use it
local ret = {}
local i = 1
local word_to_char = {}
for _, v in pairs(require("Module:topos/kind")) do
local kind, word, word_cat = v.kind, v.word, v.word_cat
word_to_char[word] = word_cat
if kind then
word_to_char[kind:gsub("[%*%?]", "")] = word_cat
end
end
for c in mw.text.gsplit(kind, "%.") do
ret[i] = word_to_char[c] or c
i = i + 1
end
return table.concat(ret)
end
-- ???????????????????????????????? FAIL. I do not know how to call the first keyword
-- perhaps I could create an extra keyword to REPEAT the first one, as a key
--- ========== write word_cat - get the first keyword (kind) ============= -- they always exist
-- i need three keywords, the third keyword i choose is: word
function p.catword_to_firstkeyword(word_cat) -- word_cat is the name of the Category.
local ret = {}
local i = 1
local word_to_char = {}
for _, v in pairs(require("Module:topos/kind")) do
local word_cat, word, kind = v.word_cat, v.word, v.kind
word_to_char[word] = kind
if word_cat then
word_to_char[word_cat:gsub("[%*%?]", "")] = kind
end
end
for c in mw.text.gsplit(word_cat, "%.") do
ret[i] = word_to_char[c] or c
i = i + 1
end
return table.concat(ret)
end
--- ========== write word_cat - get the sorting key ============= -- key ALWAYS EXISTS
-- i need three keywords, the third keyword i choose is: word
function p.catword_to_catkey(word_cat) -- word_cat is the name of the Category.
local ret = {}
local i = 1
local word_to_char = {}
for _, v in pairs(require("Module:topos/kind")) do
local word_cat, word, key = v.word_cat, v.word, v.key
word_to_char[word] = key
if word_cat then
word_to_char[word_cat:gsub("[%*%?]", "")] = key
end
end
for c in mw.text.gsplit(word_cat, "%.") do
ret[i] = word_to_char[c] or c
i = i + 1
end
return table.concat(ret)
end
--- ========== write word_cat - get parent ============= -- IF IT EXISTS
-- i need three keywords, the third keyword i choose is: word
function p.catword_to_catparent(word_cat) -- word_cat is the name of the Category.
local ret = {}
local i = 1
local word_to_char = {}
for _, v in pairs(require("Module:topos/kind")) do
local word_cat, word, parent = v.word_cat, v.word, v.parent
word_to_char[word] = parent
if word_cat then
word_to_char[word_cat:gsub("[%*%?]", "")] = parent
end
end
for c in mw.text.gsplit(word_cat, "%.") do
ret[i] = word_to_char[c] or c
i = i + 1
end
if parent == '' or parent == nil then return '' else -- check [[:Κατηγορία:Ωκεανοί]]
return table.concat(ret)
end
end
--- ========== write word_cat - get parent2 ============= -- IF IT EXISTS
-- i need three keywords, the third keyword i choose is: word
function p.catword_to_catparent2(word_cat) -- word_cat is the name of the Category.
local ret = {}
local i = 1
local word_to_char = {}
for _, v in pairs(require("Module:topos/kind")) do
local word_cat, word, parent2 = v.word_cat, v.word, v.parent2
word_to_char[word] = parent2
if word_cat then
word_to_char[word_cat:gsub("[%*%?]", "")] = parent2
end
end
for c in mw.text.gsplit(word_cat, "%.") do
ret[i] = word_to_char[c] or c
i = i + 1
end
if parent2 == '' or parent2 == nil then return '' else
return table.concat(ret)
end
end
--- ========== write word_cat - get parent3 ============= -- IF IT EXISTS
-- i need three keywords, the third keyword i choose is: word
function p.catword_to_catparent3(word_cat) -- word_cat is the name of the Category.
local ret = {}
local i = 1
local word_to_char = {}
for _, v in pairs(require("Module:topos/kind")) do
local word_cat, word, parent3 = v.word_cat, v.word, v.parent3
word_to_char[word] = parent3
if word_cat then
word_to_char[word_cat:gsub("[%*%?]", "")] = parent3
end
end
for c in mw.text.gsplit(word_cat, "%.") do
ret[i] = word_to_char[c] or c
i = i + 1
end
if parent3 == '' or parent3 == nil then return '' else
return table.concat(ret)
end
end
--- ========== write word_cat - get parent4 ============= -- IF IT EXISTS
-- i need three keywords, the third keyword i choose is: word
function p.catword_to_catparent4(word_cat) -- word_cat is the name of the Category.
local ret = {}
local i = 1
local word_to_char = {}
for _, v in pairs(require("Module:topos/kind")) do
local word_cat, word, parent4 = v.word_cat, v.word, v.parent4
word_to_char[word] = parent4
if word_cat then
word_to_char[word_cat:gsub("[%*%?]", "")] = parent4
end
end
for c in mw.text.gsplit(word_cat, "%.") do
ret[i] = word_to_char[c] or c
i = i + 1
end
if parent4 == '' or parent4 == nil then return '' else -- or works for [[:Κατηγορία:Αεροδρόμια]]
return table.concat(ret)
end
end
--- ========== write word_cat - get extra1 ============= -- IF IT EXISTS
-- i need three keywords, the third keyword i choose is: word
function p.catword_to_catextra1(word_cat) -- word_cat is the name of the Category.
local ret = {}
local i = 1
local word_to_char = {}
for _, v in pairs(require("Module:topos/kind")) do
local word_cat, word, extra1 = v.word_cat, v.word, v.extra1
word_to_char[word] = extra1
if word_cat then
word_to_char[word_cat:gsub("[%*%?]", "")] = extra1
end
end
for c in mw.text.gsplit(word_cat, "%.") do
ret[i] = word_to_char[c] or c
i = i + 1
end
if extra1 == '' or extra1 == nil then return '' else
return table.concat(ret)
end
end
--- ========== write word_cat - get extra2 ============= -- IF IT EXISTS
-- i need three keywords, the third keyword i choose is: word
function p.catword_to_catextra2(word_cat) -- word_cat is the name of the Category.
local ret = {}
local i = 1
local word_to_char = {}
for _, v in pairs(require("Module:topos/kind")) do
local word_cat, word, extra2 = v.word_cat, v.word, v.extra2
word_to_char[word] = extra2
if word_cat then
word_to_char[word_cat:gsub("[%*%?]", "")] = extra2
end
end
for c in mw.text.gsplit(word_cat, "%.") do
ret[i] = word_to_char[c] or c
i = i + 1
end
if extra2 == '' or extra2 == nil then return '' else
return table.concat(ret)
end
end
--- ========== write word_cat - get extra3 ============= -- IF IT EXISTS
-- i need three keywords, the third keyword i choose is: word
function p.catword_to_catextra3(word_cat) -- word_cat is the name of the Category.
local ret = {}
local i = 1
local word_to_char = {}
for _, v in pairs(require("Module:topos/kind")) do
local word_cat, word, extra3 = v.word_cat, v.word, v.extra3
word_to_char[word] = extra3
if word_cat then
word_to_char[word_cat:gsub("[%*%?]", "")] = extra3
end
end
for c in mw.text.gsplit(word_cat, "%.") do
ret[i] = word_to_char[c] or c
i = i + 1
end
if extra3 == '' or extra3 == nil then return '' else
return table.concat(ret)
end
end
return p