Module:topos/functions: Διαφορά μεταξύ των αναθεωρήσεων

Περιεχόμενο που διαγράφηκε Περιεχόμενο που προστέθηκε
PROBLEMS
only functions needed for Module:auto cat, catword_to_first keyword at both data pages
 
Γραμμή 3:
-- 2) keywords from [[Module:topos/where]]
 
--[=[ 2020.11.09. Sarri.greek - Last update: 2020.11.0910.
Needed for [[Module:auto cat]] the id of the first columns: kind and where (repeated as firstkeyword)
PROBLEMS - check [[Module:autocat]] section TOPOS
* chek if expression at IF IT EXISTS is ok. It works only with 'and'
]=]--
 
Γραμμή 15 ⟶ 14 :
-- 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.
 
-- ???????????????? PROBLEM: It copies the cat_title of EVERY Category in wiktionary
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
Γραμμή 66 ⟶ 37 :
 
 
--------------------------------------------------------------------------
--- ========== write word_cat - get the sorting key ============= -- key ALWAYS EXISTS
-- keywords από το [[Module:topos/where]] --
-- 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.
-- write one keyword - get another
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 parentthe first keyword (where) ============= -- IFthey ITalways EXISTSexist
function p.catword_to_firstwhere(word_cat) -- word_cat expression exists in the name of the Category.
-- 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/kindwhere")) do
local word_cat, word, parentwhere = v.word_cat, v.word, v.parentwhere
word_to_char[word] = parentwhere
if word_cat then
word_to_char[word_cat:gsub("[%*%?]", "")] = parentwhere
end
end
Γραμμή 107 ⟶ 60 :
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