Module:Classification

From Wikipedia

Documentation for this module may be created at Module:Classification/doc

-- module (test) to handle classifications (biology)

local p = {}

-- current used classification
local ccurrent = require "Module:Classification/ReptileDB"



--
function p.put(frame)
	local ns = frame.args["ns"]
	local auts = frame.args["auteurs"]
	
	if (ns == nil) then
		return "ERREUR DE PARAMETRE"
	end
	if (auts == nil) then
		auts = ""
	end
	
	-- nom scientifique double ?
	tmpx = mw.text.split(ns, " ", true);
	if (tmpx[2] ~= nil) then
		ns = tmpx[1]
		sp = tmpx[2]
	else
		sp = nil
	end
	
	
	-- on cherche le taxon
	local taxon = ccurrent.taxons[ns]
	if (taxon == nil) then
		return "TAXON NON TROUVE"
	end
	
	-- on récupère les éléments d'info
	local t_nom = taxon["nom"]
	local t_article = taxon["article"]
	local t_rang = taxon["rang"]
	
	-- table pour empiler les éléments en cours
	local resu = {}
	
	local tmp = ""
	if (sp == nil) then
		-- on insert le premier
		tmp = "{{Taxobox taxon | " .. ccurrent.domain .. " | " .. t_rang ..
		      " | " .. t_nom .. " | " .. auts .. "}}<br/>"
	else
		-- c'est une espèce, qu'on gère
		tmp = "{{Taxobox taxon | " .. ccurrent.domain .. " | espèce | " ..
		      ns .. " " .. sp .. " | " .. auts .. "}}<br/>"
	end
	

	-- on le met dans la table
	table.insert(resu, tmp)
	
	-- si c'est une espèce on insert le genre
	if (sp ~= nil) then
		-- on cherche le taxon
		local z = ccurrent.taxons[ns]
		if (z == nil) then
			table.insert(resu, 1, "Erreur")
			return "Erreur…"
		end
		
		-- on prépare cette ligne (façon simple)
		local txt = ""
		txt = txt .. "{{Taxon | " .. z["rang"] .. " | " ..
			      z["nom"] .. "}}<br/>"
 		-- ajout
 		table.insert(resu, 1, txt)
	end
	
	-- boucle pour chercher les niveaux du dessus
	local cur = t_nom
	while true do
		-- on cherche celui du dessus
		local sup = ccurrent.inclusions[t_nom]
		if (sup == nil) then
			break  -- terminé (ou erreur)
		end
		if (sup == "EOC") then
			table.insert(resu, 1, "<small>''Sommet de cette classification''</small><br/>")
			break
		end
		
		-- on cherche le taxon
		local z = ccurrent.taxons[sup]
		if (z == nil) then
			table.insert(resu, 1, "Erreur")
			break
		end
		
		-- on prépare cette ligne (façon simple)
		local txt = ""
		txt = txt .. "{{Taxon | " .. z["rang"] .. " | " ..
			      z["nom"] .. "}}<br/>"
 		-- ajout
 		table.insert(resu, 1, txt)
 		-- suivant
 		t_nom = z["nom"]
	end
	
	-- on construit le résultat final
	local retour = ""
	for i, v in ipairs(resu) do
		retour = retour .. v
	end
	
	return retour
end


--
return p