Modul:Taksoboks/sandkasse
Hopp til navigering
Hopp til søk
Dokumentasjon for denne modulen kan opprettes på Modul:Taksoboks/sandkasse/dok
local p = {} --[[ Taksoboksens seksjon som viser biologisk klassifisering har en etikett i venstre kolonne og navnet på et nivå i hierarkiet i høyre kolonne. De forskjellige nivåenes etiketter baseres på de latinske navnene i tabellen translations. De oversatte etikettene på nivåene svarer til Petter Bøckmans Bruker:Petter_Bøckman/fornorske_rang. Funksjonen tester først om parameteret inneholder virus, unranked_ eller ikke_rankert_ og vil returnere «Gruppe» hvis den oppdager det. Hvis ikke vil den gå gjennom nøklene i translations og returnere oversettelsen straks den finner den. ]] p.translateRank = function (frame) local translations = { ['superdomain'] = 'Overdomene', ['domain'] = 'Domene', ['superregnum'] = 'Overrike', ['regnum'] = 'Rike', ['subregnum'] = 'Underrike', ['superdivisio'] = 'Overdivisjon', ['superphylum'] = 'Overrekke', ['divisio'] = 'Divisjon', ['phylum'] = 'Rekke', ['zoodivisio'] = 'Divisjon', ['subdivisio'] = 'Underdivisjon', ['subphylum'] = 'Underrekke', ['infraphylum'] = 'Infrarekke', ['microphylum'] = 'Mikrorekke', ['nanophylum'] = 'Nanorekke', ['superclassis'] = 'Overklasse', ['classis'] = 'Klasse', ['subclassis'] = 'Underklasse', ['infraclassis'] = 'Infraklasse', ['magnordo'] = 'Hyperorden', ['superordo'] = 'Overorden', ['ordo'] = 'Orden', ['subordo'] = 'Underorden', ['infraordo'] = 'Infraorden', ['parvordo'] = 'Parvorden', ['superfamilia'] = 'Overfamilie', ['familia'] = 'Familie', ['subfamilia'] = 'Underfamilie', ['supertribus'] = 'Overtribus', ['tribus'] = 'Tribus', ['subtribus'] = 'Undertribus', ['alliance'] = 'Allianse', ['genus'] = 'Slekt', ['subgenus'] = 'Underslekt', ['sectio'] = 'Seksjon', ['zoosectio'] = 'Seksjon', ['subsectio'] = 'Underseksjon', ['zoosubsectio'] = 'Underseksjon', ['series'] = 'Serien', ['subseries'] = 'Underserie', ['species_group'] = 'Artsgruppe', ['species_subgroup'] = 'Artsundergruppe', ['species_complex'] = 'Artskompleks', ['species'] = 'Art', ['subspecies'] = 'Underart', ['variety'] = 'Varietet', ['form'] = 'Form', ['infraspecies'] = 'Infraart', ['infratribus'] = 'Infratribus', ['subzoodivisio'] = 'Subdivisjon', ['micrordo'] = 'Mikro-orden', ['grandordo'] = 'Grandorden', ['cohort'] = 'Kohort', ['informal'] = 'Uformell gruppe', ['informal_group'] = 'Uformell gruppe', ['stem group'] = 'Kronegruppe', ['crown group'] = 'Kronegruppe', ['total group'] = 'Kronegruppe', ['legion'] = 'Legion', ['infralegion'] = 'Infralegion', ['superlegion'] = 'Overlegion', ['sublegion'] = 'Underlegion', ['cladus'] = 'Gruppe', ['clade'] = 'Gruppe', ['ichnostem-group'] = 'Iknokronegruppe', ['ichnosuperclassis'] = 'Iknooverklasse', ['ichnoclassis'] = 'Iknoklasse', ['ichnosubclassis'] = 'Iknounderklasse', ['ichnoinfraclassis'] = 'Iknoinfraklasse', ['ichnodivisio'] = 'Iknodivisjon', ['ichnosubdivisio'] = 'Iknounderdivisjon', ['ichnoinfradivisio'] = 'Iknoinfradivisjon', ['ichnomagnordo'] = 'Iknohyperorden', ['ichnosuperordo'] = 'Iknooverorden', ['ichnograndordo'] = 'Iknograndorden', ['ichnomicrordo'] = 'Iknomikrorden', ['ichnoordo'] = 'Iknoorden', ['ichnosubordo'] = 'Iknoudnerorden', ['ichnoinfraordo'] = 'Iknoinfraorden', ['ichnoparvordo'] = 'Iknoparvorden', ['ichnosuperfamilia'] = 'Iknooverfamilie', ['ichnofamilia'] = 'Iknofamilie', ['ichnosubfamilia'] = 'Iknounderfamilie', ['ichnogenus'] = 'Iknoslekt', ['ichnosubgenus'] = 'Iknounderslekt', ['ichnospecies'] = 'Iknoart', ['ichnosubspecies'] = 'Iknounderart', ['ichnoinfraspecies'] = 'Iknoinfraart', ['ooclassis'] = 'Ooklasse', ['oosubclassis'] = 'Oounderklasse', ['oosupercohort'] = 'Oooverkohort', ['oocohort'] = 'Ookohort', ['oomagnordo'] = 'Oohyperorden', ['oosuperordo'] = 'Ooverorden', ['oordo'] = 'Oorden', ['morphotype'] = 'Morfotype', ['oofamilia'] = 'Oofamilie', ['oogenus'] = 'Ooslekt', ['oosubgenus'] = 'Oounderslekt', ['oospecies'] = 'Ooart', ['oosubspecies'] = 'Oounderart', ['ooinfraspecies'] = 'Ooinfraart', } local label = "" local param_name = frame.args['param_name'] local unranked = { "ikke_rankert_", "unranked_", "virus", } for _,s in ipairs(unranked) do if mw.ustring.match( param_name , s ) ~= nil then return "Gruppe" end end for k,v in pairs(translations) do if param_name == k then label = v end if label ~= "" then return label end end return label end function p.getScientificName( frame ) -- check for wikibase connection, empty string if not exists if not mw.wikibase then mw.log('ingen wikibase-tilkobling') return "" end -- fetch the subject article wikidata entity, nil if not exists local subject = mw.wikibase.getEntity() -- fetches and stores the arguments passed to Mal:Taksoboks/sandkasse local pArgs = frame:getParent().args -- vitenskapsnavn is handled in Mal:Taksoboks/sandkasse/kjernekode -- selects and stores the parameter autor for simplicity, nil if not exists local autor = pArgs["autor"] if autor == nil then mw.log('autor ikke oppgitt i Mal:Taksoboks') end -- selects and stores the parameter autorår for simplicity, nil if not exists local autoraar = pArgs["autorår"] if autoraar == nil then mw.log('autoraar ikke oppgitt i Mal:taksoboks') end -- creates other empty variables to aid code readability local p225value = '' -- P225: vitenskapelig navn local p6507value = '' -- P6507: autorstreng local p105value = '' -- P105: taksonomisk rang local error = false local p225missing = true local p6507missing = true local italicName = 0 -- a table of taxonomic ranks to be italicized local italicNames = { [1] = {['qid'] = 'Q34740', ['label'] = 'slekt', ['abbr'] = nil}, [2] = {['qid'] = 'Q3238261', ['label'] = 'underslekt', ['abbr'] = ' subg. '}, [3] = {['qid'] = 'Q3181348', ['label'] = 'seksjon', ['abbr'] = ' sect. '}, [4] = {['qid'] = 'Q3025161', ['label'] = 'serie', ['abbr'] = ' ser. '}, [5] = {['qid'] = 'Q7432', ['label'] = 'art', ['abbr'] = nil}, [6] = {['qid'] = 'Q68947', ['label'] = 'underart', ['abbr'] = ' subsp. '}, [7] = {['qid'] = 'Q767728', ['label'] = 'varietet', ['abbr'] = ' var. '}, [8] = {['qid'] = 'Q279749', ['label'] = 'form', ['abbr'] = ' f. '}, } -- check for a qid passed to the template or to the module, empty string if not exists if not subject then mw.log('ingen wikidataelement funnet, prøver med qid') local qid = frame.args['qid'] if not qid then qid = pArgs['qid'] end if not qid then mw.log('ikke oppgitt qid i Mal:Taksoboks') return '' end subject = mw.wikibase.getEntity(qid) if not subject then mw.log('ingen tilkoblede wikidataelement') return "" end end -- select statements whose rank are not deprecated, preferred ranks are "best" local p225 = subject:getBestStatements( 'P225' ) local p6507 = subject:getBestStatements( 'P6507' ) local p105 = subject:getBestStatements( 'P105' ) -- what to do if statement exists or not if not p225 or #p225 < 1 then mw.log('Ingen aktuelle utsagn med egenskapen P225') else p225missing = false p225value = p225[1].mainsnak.datavalue.value mw.log('Takson hentet: ' .. p225value) end -- what to do if statement exists or not if not p6507 or #p6507 < 1 then mw.log('Ingen aktuelle utsagn med egenskapen P6507') mw.log('bruker autor og autorår i stedet') else p6507missing = false -- fetch value p6507value = p6507[1].mainsnak.datavalue.value end -- what to do if statement exists or not if not p105 or #p105 < 1 then mw.log('Feil: ingen aktuelle utsagn med egenskapen P105') -- unless this exists correct formatting needs human oversight error = true else -- fetch value p105value = p105[1].mainsnak.datavalue.value.id -- check if taxon rank should be italicized for k, v in ipairs(italicNames) do if v['qid'] == p105value then italicName = k mw.log(v['label'] .. ': navnet skal kursiveres') break end end end -- format strings of ranks lower than genus if not p225missing then if italicName > 0 then -- make sure abbriviations in names are not italicized if italicNames[italicName]['abbr'] then local oldStr = italicNames[italicName]['abbr'] local newStr = "''" .. oldStr .. "''" p225value = mw.ustring.gsub(p225value, oldStr, newStr, 1) mw.log('forkortelsen skal ikke kursiveres') end -- italicize names p225value = "''" .. p225value .. "''" mw.log('navnet ble kursivert') end end -- create autorstring from parameters passed to template if not on wikidata if p6507missing then p6507value = autor -- check for autorår and add if it exists if autoraar ~= nil then p6507value = autor .. ', ' .. autoraar end mw.log('bruker autor og autorår fra Mal:Taksoboks') end -- unless p105 is missing, return formatted string, else return empty string if not error then mw.log('RESULTAT: Vitenskapelig navn ble hentet fra Wikidata. Sjekk at verdiene stemmer, og at navnet stemmer overens med autornavn og autorår.') return p225value .. '<br/><small>' .. p6507value .. '</small>' else return '' end end return p