Module:Classification ReptileDB

 Documentation[voir] [modifier] [historique] [purger]

Ce module est destiné à des pages de maintenance du projet Herpétologie.

Utilisation modifier

  • acces(frame)

Détails et fonctions internes

  • p.levenshtein(mot1, mot2) – retourne la distance de Levenshtein entre deux mots. 0 signifie identique. La valeur la plus grande qui peut être retournée est la longueur de la plus grande des deux chaînes.

Exemples modifier

Pour des exemples, voir le bac à sable permettant de tester diverses modifications apportées.

-- ce module est un test : il est destiné à contenir sous forme exploitable
-- la classification supérieure (>= famille) des reptiles.

local p = {}

-- utile : contient les noms wikifiés des rangs et les formes wikifiées des classifications
local data = require "Module:Taxobox-data"


-- langue (global)
local lng = "fr"
-- distance (mots)
local dist = 1

-- table de lien/traduction pour les rangs
local rangs = {
    ["famille"] = { ["fr"] = "[[Famille (biologie)|famille]]", ["en"] = "[[:en:Family (biology)|family]]"},
    ["classe"] = { ["fr"] = "[[Classe (biologie)|classe]]", ["en"] = "[[:en:Class (biology)|class]]"},
    ["sous-classe"] = { ["fr"] = "[[Sous-classe (biologie)|sous-classe]]", ["en"] = "[[:en:Class (biology)|subclass]]"},
    ["ordre"] = { ["fr"] = "[[Ordre (biologie)|ordre]]", ["en"] = "[[:en:Ordre (biology)|order]]"},
    ["sous-ordre"] = { ["fr"] = "[[Sous-ordre (biologie)|sous-ordre]]", ["en"] = "[[:en:Ordre (biology)|suborder]]"},
    ["sous-famille"] = { ["fr"] = "[[Sous-famille (biologie)|sous-famille]]", ["en"] = "[[:en:Family (biology)|subfamily]]"},
    ["super-famille"] = { ["fr"] = "[[Super-famille (biologie)|super-famille]]", ["en"] = "[[:en:Family (biology)|superfamily]]"},
    ["infra-ordre"] = { ["fr"] = "[[Infra-ordre (biologie)|infra-ordre]]", ["en"] = "[[:en:Order (biology)|infraordre]]"},
}


-- données UICN (famille → liste des genres reconnus
local uicn = {}
uicn["Agamidae"] = { "Bronchocela", "Calotes", "Ceratophora", "Cophotis", "Ctenophorus", "Draco", "Gonocephalus", "Hydrosaurus", "Phrynocephalus", "Trapelus", "Tympanocryptis", "Uromastyx",  }
uicn["Alligatoridae"] = { "Alligator", "Caiman", "Melanosuchus", "Paleosuchus",  }
uicn["Amphisbaenidae"] = { "Blanus",  }
uicn["Anguidae"] = { "Abronia", "Anguis", "Barisia", "Celestus", "Diploglossus", "Elgaria", "Gerrhonotus", "Hyalosaurus", "Mesaspis", "Ophisaurus",  }
uicn["Anniellidae"] = { "Anniella",  }
uicn["Anomochilidae"] = { "Anomochilus",  }
uicn["Atractaspididae"] = { "Micrelaps",  }
uicn["Bipedidae"] = { "Bipes",  }
uicn["Boidae"] = { "Acrantophis", "Aspidites", "Charina", "Epicrates", "Lichanura", "Morelia", "Python", "Sanzinia",  }
uicn["Bolyeridae"] = { "Bolyeria", "Casarea",  }
uicn["Carettochelyidae"] = { "Carettochelys",  }
uicn["Chamaeleonidae"] = { "Bradypodion", "Brookesia", "Calumma", "Furcifer",  }
uicn["Chelidae"] = { "Acanthochelys", "Chelodina", "Elseya", "Elusor", "Emydura", "Hydromedusa", "Mesoclemmys", "Pseudemydura", "Rheodytes", "Rhinemys",  }
uicn["Cheloniidae"] = { "Caretta", "Chelonia", "Eretmochelys", "Lepidochelys", "Natator",  }
uicn["Chelydridae"] = { "Chelydra", "Macrochelys",  }
uicn["Colubridae"] = { "Achalinus", "Adelophis", "Adelphicos", "Alsophis", "Arizona", "Bogertophis", "Boiga", "Calamaria", "Calamodontophis", "Carphophis", "Cemophora", "Chersodromus", "Chilomeniscus", "Chionactis", "Chironius", "Clonophis", "Coluber", "Coniophanes", "Conophis", "Conopsis", "Contia", "Coronella", "Cryophis", "Cyclocorus", "Dendrophidion", "Diadophis", "Dipsas", "Dolichophis", "Drymarchon", "Drymobius", "Dryocalamus", "Dryophiops", "Eirenis", "Elachistodon", "Elaphe", "Enulius", "Eridiphas", "Farancia", "Ficimia", "Geagras", "Geophis", "Gyalopion", "Hemorrhois", "Heterodon", "Hierophis", "Hologerrhum", "Homoroselaps", "Hypsiglena", "Iguanognathus", "Imantodes", "Lampropeltis", "Lamprophis", "Leptodeira", "Leptophis", "Liochlorophis", "Liopeltis", "Liophis", "Lycodon", "Lycognathophis", "Macroprotodon", "Malpolon", "Manolepis", "Masticophis", "Mastigodryas", "Myersophis", "Natrix", "Nerodia", "Ninia", "Oligodon", "Opheodrys", "Opisthotropis", "Oxyrhabdium", "Pantherophis", "Parahelicops", "Pareas", "Philodryas", "Phyllorhynchus", "Pituophis", "Platyceps", "Pliocercus", "Pseudoficimia", "Pseudoleptodeira", "Pseudorabdion", "Pseudoxyrhopus", "Pseustes", "Ptyas", "Regina", "Rhabdophis", "Rhadinaea", "Rhadinophanes", "Rhinechis", "Rhinocheilus", "Rhynchocalamus", "Salvadora", "Seminatrix", "Sibon", "Sibynophis", "Sonora", "Spalerosophis", "Stegonotus", "Stenorrhina", "Stilosoma", "Storeria", "Symphimus", "Tantalophis", "Tantilla", "Tantillita", "Telescopus", "Thamnophis", "Thermophis", "Trimorphodon", "Tropidoclonion", "Tropidodipsas", "Tropidonophis", "Virginia", "Xenocalamus", "Zamenis",  }
uicn["Cordylidae"] = { "Cordylus", "Gerrhosaurus", "Platysaurus", "Pseudocordylus", "Tetradactylus",  }
uicn["Corytophanidae"] = { "Laemanctus",  }
uicn["Crocodylidae"] = { "Crocodylus", "Osteolaemus", "Tomistoma",  }
uicn["Crotaphytidae"] = { "Crotaphytus", "Gambelia",  }
uicn["Dermatemydidae"] = { "Dermatemys",  }
uicn["Dermochelyidae"] = { "Dermochelys",  }
uicn["Dibamidae"] = { "Anelytropsis",  }
uicn["Elapidae"] = { "Austrelaps", "Denisonia", "Echiopsis", "Elapognathus", "Furina", "Hemibungarus", "Hoplocephalus", "Laticauda", "Micruroides", "Micrurus", "Naja", "Ogmodon", "Simoselaps",  }
uicn["Emydidae"] = { "Actinemys", "Clemmys", "Emydoidea", "Emys", "Glyptemys", "Graptemys", "Malaclemys", "Pseudemys", "Terrapene", "Trachemys",  }
uicn["Eublepharidae"] = { "Coleonyx",  }
uicn["Gavialidae"] = { "Gavialis",  }
uicn["Gekkonidae"] = { "Afroedura", "Agamura", "Ailuronyx", "Asaccus", "Bunopus", "Carinatogecko", "Christinus", "Cryptactites", "Cyrtodactylus", "Cyrtopodion", "Dixonius", "Eublepharis", "Euleptes", "Gekko", "Goggia", "Goniurosaurus", "Hemidactylus", "Hemiphyllodactylus", "Homopholis", "Hoplodactylus", "Lepidoblepharis", "Lepidodactylus", "Luperosaurus", "Lygodactylus", "Nactus", "Naultinus", "Nephrurus", "Phelsuma", "Phyllodactylus", "Pseudogekko", "Ptychozoon", "Ptyodactylus", "Quedenfeldtia", "Saurodactylus", "Sphaerodactylus", "Stenodactylus", "Tarentola", "Tropiocolotes", "Underwoodisaurus", "Urocotyledon",  }
uicn["Geoemydidae"] = { "Batagur", "Callagur", "Chinemys", "Cuora", "Cyclemys", "Geoclemys", "Geoemyda", "Hardella", "Heosemys", "Leucocephalon", "Malayemys", "Mauremys", "Melanochelys", "Morenia", "Notochelys", "Ocadia", "Orlitia", "Pangshura", "Rhinoclemmys", "Sacalia", "Siebenrockiella", "Vijayachelys",  }
uicn["Gerrhosauridae"] = { "Zonosaurus",  }
uicn["Helodermatidae"] = { "Heloderma",  }
uicn["Iguanidae"] = { "Amblyrhynchus", "Brachylophus", "Conolophus", "Ctenosaura", "Cyclura", "Dipsosaurus", "Iguana", "Sauromalus",  }
uicn["Kinosternidae"] = { "Claudius", "Kinosternon", "Staurotypus", "Sternotherus",  }
uicn["Lacertidae"] = { "Acanthodactylus", "Algyroides", "Anatololacerta", "Apathya", "Archaeolacerta", "Atlantolacerta", "Australolacerta", "Dalmatolacerta", "Darevskia", "Dinarolacerta", "Eremias", "Gallotia", "Hellenolacerta", "Iberolacerta", "Iranolacerta", "Lacerta", "Mesalina", "Ophisops", "Parvilacerta", "Philochortus", "Phoenicolacerta", "Podarcis", "Psammodromus", "Scelarcis", "Teira", "Timon", "Zootoca",  }
uicn["Leptotyphlopidae"] = { "Leptotyphlops",  }
uicn["Pelomedusidae"] = { "Pelusios",  }
uicn["Phrynosomatidae"] = { "Callisaurus", "Cophosaurus", "Holbrookia", "Petrosaurus", "Phrynosoma", "Sceloporus", "Uma", "Urosaurus", "Uta",  }
uicn["Platysternidae"] = { "Platysternon",  }
uicn["Podocnemididae"] = { "Erymnochelys", "Peltocephalus", "Podocnemis",  }
uicn["Polychrotidae"] = { "Anisolepis", "Anolis", "Pristidactylus",  }
uicn["Pygopodidae"] = { "Aprasia", "Delma", "Ophidiocephalus", "Paradelma",  }
uicn["Rhineuridae"] = { "Rhineura",  }
uicn["Scincidae"] = { "Ablepharus", "Acontophiops", "Anomalopus", "Barkudia", "Brachymeles", "Chalcides", "Coeranoscincus", "Ctenotus", "Cyclodina", "Dasia", "Egernia", "Emoia", "Eulamprus", "Eumeces", "Eutropis", "Isopachys", "Janetaescincus", "Leiolopisma", "Lerista", "Lipinia", "Lygosoma", "Macroscincus", "Mesoscincus", "Neoseps", "Niveoscincus", "Oligosoma", "Ophiomorus", "Pamelaescincus", "Parvoscincus", "Phoboscincus", "Scelotes", "Scincella", "Sphenomorphus", "Sphenops", "Tachygyia", "Tiliqua", "Trachylepis", "Tribolonotus", "Tropidophorus", "Typhlosaurus",  }
uicn["Sphenodontidae"] = { "Sphenodon",  }
uicn["Teiidae"] = { "Ameiva", "Aspidoscelis", "Callopistes", "Cnemidophorus",  }
uicn["Testudinidae"] = { "Astrochelys", "Cylindraspis", "Geochelone", "Gopherus", "Homopus", "Indotestudo", "Kinixys", "Malacochersus", "Manouria", "Psammobates", "Pyxis", "Testudo",  }
uicn["Trionychidae"] = { "Amyda", "Apalone", "Aspideretes", "Chitra", "Cyclanorbis", "Cycloderma", "Dogania", "Lissemys", "Nilssonia", "Palea", "Pelochelys", "Pelodiscus", "Rafetus", "Trionyx",  }
uicn["Trogonophidae"] = { "Trogonophis",  }
uicn["Tropidophiidae"] = { "Exiliboa",  }
uicn["Tropiduridae"] = { "Leiocephalus", "Liolaemus", "Microlophus", "Stenocercus",  }
uicn["Typhlopidae"] = { "Acutotyphlops", "Ramphotyphlops", "Rhinotyphlops", "Typhlops",  }
uicn["Varanidae"] = { "Varanus",  }
uicn["Viperidae"] = { "Agkistrodon", "Atropoides", "Bitis", "Bothriechis", "Bothrops", "Cerrophidion", "Crotalus", "Daboia", "Lachesis", "Macrovipera", "Montivipera", "Ophryacus", "Porthidium", "Protobothrops", "Pseudocerastes", "Sistrurus", "Trimeresurus", "Vipera", "Zhaoermia",  }
uicn["Xantusiidae"] = { "Lepidophyma", "Xantusia",  }
uicn["Xenosauridae"] = { "Xenosaurus",  }


-- structure des informations :
-- une liste de taxons (définit par son nom), chaque taxon étant un élément de la table (clé=nom)
-- chaque taxon contient :
--  [1] : le rang du taxon
--  [2] : une liste de noms synonymes ou nil
--  [3] : le nom du taxon supérieur
--  [4] : un champs commentaire
local taxons = {}
taxons["Anapsida"] = { "sous-classe", nil, "Sauropsida", "", "Anapsida" }
taxons["Testudines"] = { "ordre", nil, "Anapsida", "", "Testudines" }
taxons["Cryptodira"] = { "sous-ordre", nil, "Testudines", "", "Cryptodira" }
taxons["Chelydridae"] = { "famille", nil, "Cryptodira", "", "Chelydridae" }
taxons["Testudinoidea"] = { "super-famille", nil, "Cryptodira", "", "Testudinoidea" }
taxons["Emydidae"] = { "famille", nil, "Testudinoidea", "", "Emydidae" }
taxons["Testudinidae"] = { "famille", nil, "Testudinoidea", "", "Testudinidae" }
taxons["Geoemydidae"] = { "famille", nil, "Testudinoidea", "", "Geoemydidae" }
taxons["Platysternidae"] = { "famille", nil, "Testudinoidea", "", "Platysternidae" }
taxons["Trionychoidea"] = { "super-famille", nil, "Cryptodira", "", "Trionychoidea" }
taxons["Carettochelyidae"] = { "famille", nil, "Trionychoidea", "", "Carettochelyidae" }
taxons["Trionychidae"] = { "famille", nil, "Trionychoidea", "", "Trionychidae" }
taxons["Kinosternoidea"] = { "super-famille", nil, "Cryptodira", "", "Kinosternoidea" }
taxons["Dermatemydidae"] = { "famille", nil, "Kinosternoidea", "", "Dermatemydidae" }
taxons["Kinosternidae"] = { "famille", nil, "Kinosternoidea", "", "Kinosternidae" }
taxons["Chelonioidea"] = { "super-famille", nil, "Cryptodira", "", "Chelonioidea" }
taxons["Cheloniidae"] = { "famille", nil, "Chelonioidea", "", "Cheloniidae" }
taxons["Dermochelyidae"] = { "famille", nil, "Chelonioidea", "", "Dermochelyidae" }
taxons["Pleurodira"] = { "sous-ordre", nil, "Testudines", "", "Pleurodira" }
taxons["Chelidae"] = { "famille", nil, "Pleurodira", "", "Chelidae" }
taxons["Pelomedusoidea"] = { "super-famille", nil, "Pleurodira", "", "Pelomedusoidea" }
taxons["Pelomedusidae"] = { "famille", nil, "Pelomedusoidea", "", "Pelomedusidae" }
taxons["Podocnemididae"] = { "famille", nil, "Pelomedusoidea", "", "Podocnemididae" }
taxons["Lepidosauria"] = { "sous-classe", nil, "Sauropsida", "", "Lepidosauria" }
taxons["Rhynchocephalia"] = { "ordre", nil, "Lepidosauria", "", "Rhynchocephalia" }
taxons["Sphenodontida"] = { "sous-ordre", nil, "Rhynchocephalia", "", "Sphenodontida" }
taxons["Sphenodontidae"] = { "famille", nil, "Sphenodontida", "", "Sphenodontidae" }
taxons["Squamata"] = { "ordre", nil, "Lepidosauria", "", "Squamata" }
taxons["Sauria"] = { "sous-ordre", { "Lacertilia" }, "Squamata", "", "Sauria" }
taxons["Iguania"] = { "infra-ordre", nil, "Sauria", "", "Iguania" }
taxons["Agamidae"] = { "famille", nil, "Iguania", "", "Agamidae" }
taxons["Chamaeleonidae"] = { "famille", nil, "Iguania", "", "Chamaeleonidae" }
taxons["Iguanidae"] = { "super-famille", nil, "Iguania", "", "Iguanidae" }
taxons["Corytophanidae"] = { "famille", nil, "Iguanidae", "", "Corytophanidae" }
taxons["Crotaphytidae"] = { "famille", nil, "Iguanidae", "", "Crotaphytidae" }
taxons["Dactyloidae"] = { "famille", nil, "Iguanidae", "", "Dactyloidae" }
taxons["Hoplocercidae"] = { "famille", nil, "Iguanidae", "", "Hoplocercidae" }
taxons["Iguanidae"] = { "famille", nil, "Iguania", "", "Iguanidae" }
taxons["Leiocephalidae"] = { "famille", nil, "Iguanidae", "", "Leiocephalidae" }
taxons["Leiosauridae"] = { "famille", nil, "Iguanidae", "", "Leiosauridae" }
taxons["Liolaemidae"] = { "famille", nil, "Iguanidae", "", "Liolaemidae" }
taxons["Opluridae"] = { "famille", nil, "Iguanidae", "", "Opluridae" }
taxons["Phrynosomatidae"] = { "famille", nil, "Iguanidae", "", "Phrynosomatidae" }
taxons["Polychrotidae"] = { "famille", nil, "Iguanidae", "", "Polychrotidae" }
taxons["Tropiduridae"] = { "famille", nil, "Iguanidae", "", "Tropiduridae" }
taxons["Gekkota"] = { "infra-ordre", nil, "Sauria", "", "Gekkota" }
taxons["Gekkonidae"] = { "famille", nil, "Gekkota", "", "Gekkonidae" }
taxons["Carphodactylidae"] = { "famille", nil, "Gekkota", "", "Carphodactylidae" }
taxons["Diplodactylidae"] = { "famille", nil, "Gekkota", "", "Diplodactylidae" }
taxons["Eublepharidae"] = { "famille", nil, "Gekkota", "", "Eublepharidae" }
taxons["Phyllodactylidae"] = { "famille", nil, "Gekkota", "", "Phyllodactylidae" }
taxons["Sphaerodactylidae"] = { "famille", nil, "Gekkota", "", "Sphaerodactylidae" }
taxons["Pygopodidae"] = { "famille", nil, "Gekkota", "", "Pygopodidae" }
taxons["Scincomorpha"] = { "infra-ordre", nil, "Sauria", "", "Scincomorpha" }
taxons["Cordylidae"] = { "famille", nil, "Scincomorpha", "", "Cordylidae" }
taxons["Gerrhosauridae"] = { "famille", nil, "Scincomorpha", "", "Gerrhosauridae" }
taxons["Gymnophthalmidae"] = { "famille", nil, "Scincomorpha", "", "Gymnophthalmidae" }
taxons["Teiidae"] = { "famille", nil, "Scincomorpha", "", "Teiidae" }
taxons["Lacertidae"] = { "famille", nil, "Scincomorpha", "", "Lacertidae" }
taxons["Scincidae"] = { "famille", nil, "Scincomorpha", "", "Scincidae" }
taxons["Xantusiidae"] = { "famille", nil, "Scincomorpha", "", "Xantusiidae" }
taxons["Diploglossa"] = { "infra-ordre", nil, "Sauria", "", "Diploglossa" }
taxons["Anguidae"] = { "famille", nil, "Diploglossa", "", "Anguidae" }
taxons["Anniellidae"] = { "famille", nil, "Diploglossa", "", "Anniellidae" }
taxons["Xenosauridae"] = { "famille", nil, "Diploglossa", "", "Xenosauridae" }
taxons["Dibamia"] = { "infra-ordre", nil, "Sauria", "", "Dibamia" }
taxons["Dibamidae"] = { "famille", nil, "Dibamia", "", "Dibamidae" }
taxons["Platynota"] = { "infra-ordre", { "Varanoidea" }, "Sauria", "", "Platynota" }
taxons["Helodermatidae"] = { "famille", nil, "Platynota", "", "Helodermatidae" }
taxons["Lanthanotidae"] = { "famille", nil, "Platynota", "", "Lanthanotidae" }
taxons["Varanidae"] = { "famille", nil, "Platynota", "", "Varanidae" }
taxons["Shinisauroidea"] = { "super-famille", nil, "Platynota", "", "Shinisauroidea" }
taxons["Shinisauridae"] = { "famille", nil, "Shinisauroidea", "", "Shinisauridae" }
taxons["Amphisbaenia"] = { "sous-ordre", nil, "Squamata", "", "Amphisbaenia" }
taxons["Amphisbaenidae"] = { "famille", nil, "Amphisbaenia", "", "Amphisbaenidae" }
taxons["Bipedidae"] = { "famille", nil, "Amphisbaenia", "", "Bipedidae" }
taxons["Blanidae"] = { "famille", nil, "Amphisbaenia", "", "Blanidae" }
taxons["Cadeidae"] = { "famille", nil, "Amphisbaenia", "", "Cadeidae" }
taxons["Rhineuridae"] = { "famille", nil, "Amphisbaenia", "", "Rhineuridae" }
taxons["Trogonophiidae"] = { "famille", nil, "Amphisbaenia", "", "Trogonophiidae" }
taxons["Ophidia"] = { "sous-ordre", { "Serpentes" }, "Squamata", "", "Ophidia" }
taxons["Aniliidae"] = { "famille", nil, "Ophidia", "", "Aniliidae" }
taxons["Bolyeriidae"] = { "famille", nil, "Ophidia", "", "Bolyeriidae" }
taxons["Tropidophiidae"] = { "famille", nil, "Ophidia", "", "Tropidophiidae" }
taxons["Acrochordoidea"] = { "sous-famille", nil, "Tropidophiidae", "", "Acrochordoidea" }
taxons["Acrochordidae"] = { "famille", nil, "Ophidia", "", "Acrochordidae" }
taxons["Uropeltoidea"] = { "sous-famille", nil, "Acrochordidae", "", "Uropeltoidea" }
taxons["Anomochilidae"] = { "famille", nil, "Ophidia", "", "Anomochilidae" }
taxons["Cylindrophiidae"] = { "famille", nil, "Ophidia", "", "Cylindrophiidae" }
taxons["Uropeltidae"] = { "famille", nil, "Ophidia", "", "Uropeltidae" }
taxons["Pythonoidea"] = { "sous-famille", nil, "Uropeltidae", "", "Pythonoidea" }
taxons["Loxocemidae"] = { "famille", nil, "Ophidia", "", "Loxocemidae" }
taxons["Pythonidae"] = { "famille", nil, "Ophidia", "", "Pythonidae" }
taxons["Xenopeltidae"] = { "famille", nil, "Ophidia", "", "Xenopeltidae" }
taxons["Booidea"] = { "sous-famille", nil, "Xenopeltidae", "", "Booidea" }
taxons["Boidae"] = { "famille", nil, "Ophidia", "", "Boidae" }
taxons["Boinae"] = { "sous-famille", nil, "Boidae", "", "Boinae" }
taxons["Ungaliophiinae"] = { "sous-famille", nil, "Boidae", "", "Ungaliophiinae" }
taxons["Erycinae"] = { "sous-famille", nil, "Boidae", "", "Erycinae" }
taxons["Colubroidea"] = { "sous-famille", nil, "Boidae", "", "Colubroidea" }
taxons["Colubridae"] = { "famille", nil, "Ophidia", "", "Colubridae" }
taxons["Colubrinae"] = { "sous-famille", nil, "Colubridae", "", "Colubrinae" }
taxons["Grayiinae"] = { "sous-famille", nil, "Colubridae", "", "Grayiinae" }
taxons["Calamariinae"] = { "sous-famille", nil, "Colubridae", "", "Calamariinae" }
taxons["Dipsadinae"] = { "sous-famille", nil, "Colubridae", "", "Dipsadinae" }
taxons["Pseudoxenodontinae"] = { "sous-famille", nil, "Colubridae", "", "Pseudoxenodontinae" }
taxons["Natricinae"] = { "sous-famille", nil, "Colubridae", "", "Natricinae" }
taxons["Scaphiodontophiinae"] = { "sous-famille", nil, "Colubridae", "", "Scaphiodontophiinae" }
taxons["Lamprophiidae"] = { "famille", nil, "Ophidia", "", "Lamprophiidae" }
taxons["Aparallactinae"] = { "sous-famille", nil, "Lamprophiidae", "", "Aparallactinae" }
taxons["Atractaspidinae"] = { "sous-famille", nil, "Lamprophiidae", "", "Atractaspidinae" }
taxons["Lamprophiinae"] = { "sous-famille", nil, "Lamprophiidae", "", "Lamprophiinae" }
taxons["Psammophiinae"] = { "sous-famille", nil, "Lamprophiidae", "", "Psammophiinae" }
taxons["Prosymninae"] = { "sous-famille", nil, "Lamprophiidae", "", "Prosymninae" }
taxons["Pseudaspidinae"] = { "sous-famille", nil, "Lamprophiidae", "", "Pseudaspidinae" }
taxons["Pseudoxyrhophiinae"] = { "sous-famille", nil, "Lamprophiidae", "", "Pseudoxyrhophiinae" }
taxons["Elapidae"] = { "famille", nil, "Ophidia", "", "Elapidae" }
taxons["Elapoidea"] = { "sous-famille", nil, "Elapidae", "", "Elapoidea" }
taxons["Elapinae"] = { "sous-famille", nil, "Elapidae", "", "Elapinae" }
taxons["Hydrophiinae"] = { "sous-famille", nil, "Elapidae", "", "Hydrophiinae" }
taxons["Homalopsidae"] = { "famille", nil, "Ophidia", "", "Homalopsidae" }
taxons["Pareatidae"] = { "famille", nil, "Ophidia", "", "Pareatidae" }
taxons["Viperidae"] = { "famille", nil, "Ophidia", "", "Viperidae" }
taxons["Azemiopinae"] = { "sous-famille", nil, "Viperidae", "", "Azemiopinae" }
taxons["Crotalinae"] = { "sous-famille", nil, "Viperidae", "", "Crotalinae" }
taxons["Viperinae"] = { "sous-famille", nil, "Viperidae", "", "Viperinae" }
taxons["Xenodermatidae"] = { "famille", nil, "Ophidia", "", "Xenodermatidae" }
taxons["Typhlopoidea"] = { "sous-famille", { "Scolecophidia" }, "Xenodermatidae", "", "Typhlopoidea" }
taxons["Anomalepididae"] = { "famille", nil, "Ophidia", "", "Anomalepididae" }
taxons["Gerrhopilidae"] = { "famille", nil, "Ophidia", "", "Gerrhopilidae" }
taxons["Typhlopidae"] = { "famille", nil, "Ophidia", "", "Typhlopidae" }
taxons["Leptotyphlopidae"] = { "famille", nil, "Ophidia", "", "Leptotyphlopidae" }
taxons["Leptotyphlopinae"] = { "sous-famille", nil, "Leptotyphlopidae", "", "Leptotyphlopinae" }
taxons["Epictinae"] = { "sous-famille", nil, "Leptotyphlopidae", "", "Epictinae" }
taxons["Xenotyphlopidae"] = { "famille", nil, "Ophidia", "", "Xenotyphlopidae" }
taxons["Archosauria"] = { "sous-classe", nil, "Sauropsida", "", "Archosauria" }
taxons["Crocodylia"] = { "ordre", nil, "Archosauria", "", "Crocodylia" }
taxons["Eusuchia"] = { "sous-ordre", nil, "Crocodylia", "", "Eusuchia" }
taxons["Crocodylidae"] = { "famille", nil, "Eusuchia", "", "Crocodylidae" }
taxons["Alligatoridae"] = { "famille", nil, "Eusuchia", "", "Alligatoridae" }
taxons["Gavialidae"] = { "famille", nil, "Eusuchia", "", "Gavialidae" }


-- calcule la distance de Levenshtein entre deux mots (ASCII)
function p.levenshtein(mot1, mot2)
    if (type(mot1) ~= "string" or type(mot2) ~= "string") then
        return nil
    end
    -- cas simple
    if (mot1 == mot2) then
        return 0
    end
    local d = {}
    -- on simule un tableau à deux dimensions
    for i = 1, string.len(mot1)+1 do
        d[i] = {}
        d[i][1] = i
    end
    for j = 1, string.len(mot2)+1 do
        d[1][j] = j
    end
    -- init a 0 des autres. Pas sûr que ce soit nécessaire
    for i = 1, string.len(mot1)+1 do
        for j = 1, string.len(mot2)+1 do
            if (d[i][j] == nil) then
                d[i][j] = 0
            end
        end
    end
    
    local cout = 0
    for i = 2, string.len(mot1) do
        for j = 2, string.len(mot2) do
            -- on récupère les deux caractères
            local c1 = string.byte(mot1, i-1)
            local c2 = string.byte(mot2, j-1)
            if (c1 == c2) then
                cout = 0
            else
                cout = 1
            end
            d[i][j] = math.min(d[i-1][j]+1,
                d[i][j-1]+1, d[i-1][j-1]+cout)
        end
    end
    return d[string.len(mot1)][string.len(mot2)] - 1
end


-- retourne vrai si le taxon est référencé, faux sinon.
-- retourne en plus vrai si le taxon est "natif" ou "obsolète"
function p.existe(nom)
    if (nom == nil or nom == "") then
        return false
    end
    local t = taxons[nom]
    if (t ~= nil) then
        return { true, true }
    end
    -- pas direct, on cherche si présent en synonyme
    for k, v in pairs(taxons) do
        if (v ~= nil) then
           if (v[2] ~= nil) then
               local i = 1
               while (v[2][i] ~= nil) do
                    if (v[2][i] == nom) then
                        return { true, false }
                    end
                    i = i + 1
                end
           end
        end
    end
    
    return false
end

-- retourne l'entrée du taxon si il existe (y compris synonyme)
function p.data(nom)
    if (nom == nil or nom == "") then
        return nil
    end
    local t = taxons[nom]
    if (t ~= nil) then
        return t
    end
    -- pas direct, on cherche si présent en synonyme
    for k, v in pairs(taxons) do
        if (v ~= nil) then
           if (v[2] ~= nil) then
               local i = 1
               while (v[2][i] ~= nil) do
                    if (v[2][i] == nom) then
                        return v
                    end
                    i = i + 1
                end
           end
        end
    end
    
    return nil
end

-- affiche la liste des taxons supérieurs au taxon indiqué
function p.liste_sup(nom)
    local ret = ""
    if (nom == nil or nom == "") then
        return "<vide>\n"
    end

    local cur = p.data(nom)
    local dernier
    while (cur ~= nil) do
        local r = data.est_rang(cur[1])
        local rr
        if (r[1] == 1) then
            rr = r[2][1]
        else
            rr = "<erreur>"
        end
        ret = ret .. rr .. " [[" .. cur[5] .. "]] "
        local z = cur[2]
        if (z ~= nil) then
            local i = 1
            ret = ret .. "("
            while (z[i] ~= nil) do
                if (i > 1) then ret = ret .. " " end
                ret = ret .. "[[" .. z[i] .. "]]"
                i = i + 1
            end
            ret = ret .. ")"
        end
        ret = ret .. " → "
        -- suivant
        dernier = cur[3]
        cur = p.data(cur[3])
    end
    -- la fin
    if (dernier ~= nil) then
        ret = ret .. "(" .. dernier .. ")<br/>\n"
    end
    return ret
end

-- retourne une table hiérarchique à partir des éléments à plat
function p.liste_all_table()
    local t = {} -- table contenant la classification structurée
    local premier = nil -- le père (la racine)
    
    -- pour chaque taxon
    for k, v in pairs(taxons) do -- k=nom taxon, v[3]=taxon sup
        local sp = v[3]
        -- si pas d'entrée pour le taxon on le crée
        if (t[k] == nil) then
            t[k] = {} -- créé vide
        end
        -- idem pour le taxon père
        if (t[sp] == nil) then
            t[sp] = {} -- créé vide
        end
        -- on insert k dans sp
        table.insert(t[sp], t[k])
        -- si sp n'existe pas c'est le "père" de tous
        if (taxons[sp] == nil) then
            premier = sp
        end
    end
    
    -- on retourne la table et le premier
    return t, premier
end

-- cherche l'élément qui correspond à la table
function p.cherche_el(tbl, el)
    for k, v in pairs(tbl) do
        if (el == v) then
            return k
        end
    end
    return nil
end

-- cherche dans la liste UICN s'il existe une entrée "proche" de "pr".
-- si non retourne nil. Si oui retourne le nom UICN correspondant
-- retourne le terme avec la distance la plus petit (inf. ou égal à dist)
function p.cherche_uicn_proche(pr)
    local mn = dist + 1
    local trouve = nil
    
    for k, v in pairs(uicn) do
        -- on ne prend pas les entrées qui on déjà une entrée exacte
        local d = p.levenshtein(pr, k)
        if (d < mn) then
            mn = d
            trouve = k
        end
    end
    return trouve
end


-- version récursive de la précédente
local function liste_r (tbl, pr, dec)
    local res = ""

    if (pr == nil or tbl == nil) then
        return "<erreur>"
    end
    
    local desc = taxons[pr]
    if (desc == nil) then
        res = res .. string.rep("*", dec) .. " [[" .. pr .. "]] :\n"
    else
        local trans = rangs[desc[1]]
        local prt
        if (trans == nil) then
            prt = desc[1]
        else
            if (trans[lng] ~= nil) then
                prt = trans[lng]
            else
                -- fr par défaut au cas où
                if (trans["fr"] ~= nil) then
                    prt = trans["fr"]
                else
                    prt = desc[1]
                end
            end
        end
        res = res .. string.rep("*", dec) .. " " .. prt .. " [[" .. pr .. "]]"
        -- on teste si présent dans UICN
        if (uicn[pr] ~= nil) then
            res = res .. " <abbr title=\"" .. table.concat(uicn[pr], " ") .. "\">(UICN)</abbr>"
        else
            if (desc[1] == "famille") then -- uniquement les familles
                -- on cherche dans les entrées un élément "pas trop distant"
                local proche = p.cherche_uicn_proche(pr)
                if (proche ~= nil) then
                    res = res .. " <abbr title=\"" .. proche .. " : " .. table.concat(uicn[proche], " ") .. "\">(''UICN'')</abbr>"
                end
            end
        end
        res = res .. " :\n" -- MeF
    end
    local i = 1
    while (tbl[pr][i] ~= nil) do
        local el = p.cherche_el(tbl, tbl[pr][i])
        res = res .. liste_r(tbl, el, dec+1)
        i = i + 1
    end
    return res
end

-- version récursive de la précédente (format ReptileDB)
local function liste_rdb_r (tbl, pr, dec)
    local res
    if (dec > 1) then
        res = ""
    else
        res = '\n<span style="color: #FF0000;">{{grossir|facteur=2.2|Higher Taxa in Extant Reptiles}}</span><br/><br/>\n'
    end

    if (pr == nil or tbl == nil) then
        return "<erreur>"
    end
    
    local fact = 2.0 - dec/10
    local desc = taxons[pr]
    if (desc == nil) then
        res = res .. string.rep("*", dec) .. " {{grossir|facteur=" .. fact .. "|" .. pr .. "}}\n"
    else
        local trans = rangs[desc[1]]
        local prt
        if (trans == nil) then
            prt = desc[1]
        else
            if (trans[lng] ~= nil) then
                prt = trans[lng]
            else
                -- fr par défaut au cas où
                if (trans["fr"] ~= nil) then
                    prt = trans["fr"]
                else
                    prt = desc[1]
                end
            end
        end
        if (desc[1] == "famille") then
            res = res .. string.rep("*", dec) .. " {{grossir|facteur=" .. fact .. "|" .. prt .. "}}"
            res = res .. " [http://reptile-database.reptarium.cz/advanced_search?taxon=" .. pr .. "&submit=Search " .. "{{grossir|facteur=" .. fact .. "|" .. pr .. "}}]"
        else
            res = res .. string.rep("*", dec) .. " {{grossir|facteur=" .. fact .. "|" .. prt .. " " .. pr .. "}}"
        end
        -- on teste si présent dans UICN
        if (uicn[pr] ~= nil) then
            res = res .. " <abbr title=\"" .. table.concat(uicn[pr], " ") .. "\">" .. "{{grossir|facteur=" .. fact .. "|" .. "(UICN)}}</abbr>"
        else
            if (desc[1] == "famille") then -- uniquement les familles
                -- on cherche dans les entrées un élément "pas trop distant"
                local proche = p.cherche_uicn_proche(pr)
                if (proche ~= nil) then
                    res = res .. " <abbr title=\"" .. proche .. " : " .. table.concat(uicn[proche], " ") .. "\">" .. "{{grossir|facteur=" .. fact .. "|" .. "(''UICN'')}}</abbr>"
                end
            end
        end
        res = res .. " − [[:en:" .. pr .. "|W]] [[fr:" .. pr .. "|fr.W]]\n" -- MeF
    end
    local i = 1
    while (tbl[pr][i] ~= nil) do
        local el = p.cherche_el(tbl, tbl[pr][i])
        res = res .. liste_rdb_r(tbl, el, dec+1)
        i = i + 1
    end
    return res
end


function p.liste_all()
    local t, premier = p.liste_all_table()
    
    if (t == nil or type(t) ~= "table" or premier == nil) then
        return "<erreur interne>"
    end
    
    -- on génère une forme affichable de cette table
    return liste_r(t, premier, 1)
end

function p.liste_rdb()
    local t, premier = p.liste_all_table()
    
    if (t == nil or type(t) ~= "table" or premier == nil) then
        return "<erreur interne>"
    end
    
    -- on génère une forme affichable de cette table
    return liste_rdb_r(t, premier, 1)
end




-- affiche la liste des taxons supérieurs au taxon indiqué
function p.liste_sup_simple(nom)
    local ret = ""
    if (nom == nil or nom == "") then
        return " <vide>\n"
    end

    local cur = p.data(nom)
    local dernier
    while (cur ~= nil) do
        ret = ret .. " " .. cur[1] .. " " .. cur[5]
        -- suivant
        dernier = cur[3]
        cur = p.data(cur[3])
    end
    ret = ret .. "\n"
    return ret
end

-- affiche les niveaux sup de chaque famille / sous-famille
function p.liste_lst()
    local t, premier = p.liste_all_table()
    local ret = ""
    
    -- parcours entrées
    for k, v in pairs(taxons) do
        -- seulement famille/sous-famille
        if (v[1] == "famille" or v[1] == "sous-famille") then
            ret = ret .. p.liste_sup_simple(v[5])
        end
    end
    return ret
end


-- wrapper
function p.acces(frame)
    -- présence de la langue ?
    if (frame.args["langue"] or frame:getParent().args["langue"]) then
        lng = frame.args["langue"] or frame:getParent().args["langue"]
    end
    -- on fixe la distance ?
    if (frame.args["distance"] or frame:getParent().args["distance"]) then
        lng = frame.args["distance"] or frame:getParent().args["distance"]
    end
    
    local cible = frame.args[1] or frame:getParent().args[1] or ""
    if (cible == "sup") then
        local res = p.liste_sup(frame.args[2] or frame:getParent().args[2] or "")
        return res
    elseif (cible == "all") then
        return p.liste_all()
    elseif (cible == "lst") then
        return p.liste_lst()
    elseif (cible == "rdb") then
        -- reptileDB print format
        return frame:preprocess(p.liste_rdb())
        -- return p.liste_rdb()
    end
    
end

return p