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

Από Βικιλεξικό
Μετάβαση στην πλοήγηση Πήδηση στην αναζήτηση
Περιεχόμενο που διαγράφηκε Περιεχόμενο που προστέθηκε
test if nil
+IF IT EXISTS
Γραμμή 10: Γραμμή 10:
-- write one keyword - get another
-- write one keyword - get another


--- ============ write first keyword - get name of category ============== --
--- ============ 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 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.
-- I need word_cat, because it matches the name of Categories, the cat_title.
Γραμμή 35: Γραμμή 35:
end
end


--- ========== write word_cat - get the sorting key ============= --
--- ========== write word_cat - get the sorting key ============= -- key ALWAYS EXISTS
-- i need three keywordss, the third keyword i choose is: word
-- i need three keywordss, the third keyword i choose is: word
function p.catword_to_catkey(word_cat) -- word_cat is the name of the Category.
function p.catword_to_catkey(word_cat) -- word_cat is the name of the Category.
Γραμμή 57: Γραμμή 57:
end
end


--- ========== write word_cat - get parent ============= --
--- ========== write word_cat - get parent ============= -- IF IT EXISTS
-- i need three keywords, the third keyword i choose is: word
-- 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.
function p.catword_to_catparent(word_cat) -- word_cat is the name of the Category.
Γραμμή 81: Γραμμή 81:
end
end


--- ========== write word_cat - get parent2 ============= --
--- ========== write word_cat - get parent2 ============= -- IF IT EXISTS
-- i need three keywords, the third keyword i choose is: word
-- 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.
function p.catword_to_catparent2(word_cat) -- word_cat is the name of the Category.
Γραμμή 100: Γραμμή 100:
end
end
if parent2 == '' or parent2 == nil then return '' else
return table.concat(ret)
return table.concat(ret)
end
end
end


--- ========== write word_cat - get parent3 ============= --
--- ========== write word_cat - get parent3 ============= -- IF IT EXISTS
-- i need three keywords, the third keyword i choose is: word
-- 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.
function p.catword_to_catparent3(word_cat) -- word_cat is the name of the Category.
Γραμμή 122: Γραμμή 124:
end
end
if parent3 == '' or parent3 == nil then return '' else
return table.concat(ret)
return table.concat(ret)
end
end
end




--- ========== write word_cat - get parent4 ============= --
--- ========== write word_cat - get parent4 ============= -- IF IT EXISTS
-- i need three keywords, the third keyword i choose is: word
-- 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.
function p.catword_to_catparent4(word_cat) -- word_cat is the name of the Category.
Γραμμή 145: Γραμμή 149:
end
end
if parent4 == '' or parent4 == nil then return '' else
return table.concat(ret)
return table.concat(ret)
end
end
end




--- ========== write word_cat - get extra1 ============= --
--- ========== write word_cat - get extra1 ============= -- IF IT EXISTS
-- i need three keywords, the third keyword i choose is: word
-- 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.
function p.catword_to_catextra1(word_cat) -- word_cat is the name of the Category.
Γραμμή 168: Γραμμή 174:
end
end
if extra1 == '' or extra1 == nil then return '' else
return table.concat(ret)
return table.concat(ret)
end
end
end


--- ========== write word_cat - get extra2 ============= --
--- ========== write word_cat - get extra2 ============= -- IF IT EXISTS
-- i need three keywords, the third keyword i choose is: word
-- 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.
function p.catword_to_catextra2(word_cat) -- word_cat is the name of the Category.
Γραμμή 190: Γραμμή 198:
end
end
if extra2 == '' or extra2 == nil then return '' else
return table.concat(ret)
return table.concat(ret)
end
end
end




--- ========== write word_cat - get extra3 ============= --
--- ========== write word_cat - get extra3 ============= -- IF IT EXISTS
-- i need three keywords, the third keyword i choose is: word
-- 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.
function p.catword_to_catextra3(word_cat) -- word_cat is the name of the Category.
Γραμμή 213: Γραμμή 223:
end
end
if extra3 == '' or extra3 == nil then return '' else
return table.concat(ret)
return table.concat(ret)
end
end
end



Αναθεώρηση της 16:20, 9 Νοεμβρίου 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]]   

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

--- ========== write word_cat - get the sorting key ============= -- key ALWAYS EXISTS
-- i need three keywordss, 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
	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
	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