Foruma hoş geldin 👋, Ziyaretçi

Forum içeriğine ve tüm hizmetlerimize erişim sağlamak için foruma kayıt olmalı ya da giriş yapmalısınız. Foruma üye olmak tamamen ücretsizdir.

Modül:Clade

bullvar_katip

Administrator
Katılım
21 Mayıs 2024
Mesajlar
532,105
--NOTE: this module contains functions for generating the table structure of the clade tree: The main function is called by the template using the instruction; the three main functions are: p.main(frame) - opens and closes table, loops through the children of node, main is invoked once and controls the rest, calling ... p.addTaxon(childNumber, nodeLeaf) - the nuts and bolts; code dealing with each child node p.addLabel(childNumber) - adds the label text now uses templatestyles require('Module:No globals') local p = {} local pargs = {} -- parent arguments local lastNode=0 local nodeCount=0 local cladeCount=0 local leafCount=0 local templateStylesCount=0 local infoOutput local reverseClade = false -- main function === -- main function, which will generate the table structure of the tree Test version: Usage: Template:CladeN Release version: Usage: Template:Clade function p.main(frame) local cladeString = "" local maxChildren = 20 -- was 17 in the clade/cladex templates local childNumber = 0 local childCount = 0 -- number of leaves in the clade (can use to set bottom of bracket in addTaxon local totalCount = 0 pargs = frame:getParent.args -- parent arguments infoOutput = p.getCladeTreeInfo -- get info about clade structure, e.g. lastNode (last |N= child number) --add the templatestyles tag conditionally to reduce expansion size (currently diabled) when added to every clade table, it increases post‐expand include size significantly e.g. the Neosuchia page (or test version) is increase by about 8% (672 bytes each) if template styles added to all pages there are 133 stripmarkers with cladeCount 1 condition, this is reduced to 34 however cladeCount 1 condition interfers with fix for additional line due to parser bug T18700 killing the strip markers also removes backlinks to references using citation templates -- --cladeString =mw.text.killMarkers( cladeString ) -- also kills off strip markers using citation templates --cladeString = mw.text.unstrip(cladeString) --if cladeCount==1 then local src = "Modül:Clade/styles.css" cladeString = cladeString .. p.templateStyle( frame, src ) .. '\n' --end local tableStyle = frame.args.style or "" if tableStyle ~= "" then tableStyle = ' style="' .. tableStyle .. '"' -- include style= in string to suppress empty style elements end reverseClade =frame.args.reverse or pargs.reverse or false -- a global --ENFORCE GLOBAL FOR DEVELOPMENT --reverseClade = true local captionName = pargs['caption'] or "" local captionStyle = pargs['captionstyle'] or "" -- add an element to mimick nowiki WORKS BUT DISABLE FOR DEMO PURPOSES --cladeString = '\n' -- open table -- (border-collapse causes problems (see talk) -- cladeString = cladeString .. '{| style="border-collapse:collapse;border-spacing:0;margin:0;' .. tableStyle .. '"' -- (before CSS styling) -- cladeString = cladeString .. return cladeString end -- emulate a standard split string function -- why not use mw.text.split(s, sep)? function p.strsplit(inputstr, sep) if sep == nil then sep = "%s" end local t={} local i=1 for str in string.gmatch(inputstr, "([^"..sep.."]+)") do t = str i = i + 1 end return t end -- experimental Newick to clade parser function = --Function of convert Newick strings to clade format Usage: function p.newickConverter(frame) local newickString = frame.args['newickstring'] or pargs['newick'] --if newickString '{}' then return newickString end newickString p.processNewickString(newickString,"") -- "childNumber") -- show the Newick string local cladeString local levelNumber 1 -- for depth of iteration local childNumber 1 -- number of sister elements on node (always one for root) -- converted the newick string to the clade structure cladeString cladeString .. local resultString local option pargs['option'] or if option 'tree' then --show the transcluded clade diagram resultString = cladeString else -- show the Newick string resultString = -- show the converted clade structure resultString = resultString .. end --resultString = frame:expandTemplate{ title = 'clade', frame:preprocess(cladeString) } return resultString end --labelN=labelname 2. the left hand term in parenthesis has common delimited child nodes, each of which can be i. a taxon name which just needs: |N=leafname ii. a Newick string which needs further processing through reiteration function p.newickParseLevel(newickString,levelNumber,childNumber) local cladeString = "" local indent = p.getIndent(levelNumber) --levelNumber=levelNumber+1 local j=0 local k=0 j,k = string.find(newickString, '%(.*%)') -- find location of outer parenthesised term local innerTerm = string.sub(newickString, j+1, k-1) -- select content in parenthesis local outerTerm = string.gsub(newickString, "%b", "") -- delete parenthetic term cladeString = cladeString .. indent .. '|label'..childNumber..'=' .. outerTerm cladeString = cladeString .. indent .. '|' .. childNumber..'=' .. return cladeString end function p.getIndent(levelNumber) local indent = "\r" local extraIndent = pargs['indent'] or mw.getCurrentFrame.args['indent'] or 0 while tonumber(extraIndent) > 0 do indent = indent .. " " -- an extra indent to make aligining compound trees easier extraIndent = extraIndent - 1 end while levelNumber > 1 do indent = indent .. " " levelNumber = levelNumber-1 end return indent end function p.newickstuff(newickString) end function p.processNewickString(newickString,childNumber) local maxPatterns = 5 local i = 0 local pargs = pargs local pattern = pargs['newick'..tostring(childNumber)..'-pattern'] -- unnumbered option for i=1 local replace = pargs['newick'..tostring(childNumber)..'-replace'] while i < maxPatterns do i=i+1 pattern = pattern or pargs['newick'..tostring(childNumber)..'-pattern'..tostring(i)] replace = replace or pargs['newick'..tostring(childNumber)..'-replace'..tostring(i)] or "" if pattern then newickString = string.gsub (newickString, pattern, replace) end pattern = nil; replace = nil end newickString = string.gsub (newickString, "_", " ") -- replace underscore with space return newickString end ------------------------------------------------------------------------------------------ function p.test2(target) local target ="User:Jts1882/sandbox/templates/Template:Passeroidea" local result = mw.getCurrentFrame:expandTemplate{ title = target, args = {['style'] = } } return result end ------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------- --function getCladeTreeInfo this preprocessing loop gets information about the whole structure (number of nodes, leaves etc) it makes a redundant calls to the templates through transclusion, but doen't affect the template depths; it provides the global lastNode that is used to limit the main while loop -- function p.getCladeTreeInfo -- enable proprocessing loop local childNumber = 0 local childCount =0 local maxChildren =20 --info veriables (these are global for now) nodeCount=0 cladeCount=0 leafCount=0 while childNumber < maxChildren do -- preprocessing loop childNumber = childNumber + 1 -- so we start with 1 local nodeLeaf,data = pargs[tostring(childNumber)] or "" -- get data from |N= local newickString = pargs['newick'..tostring(childNumber)] or "" -- get data from |labelN= local listString = pargs['list'..tostring(childNumber)] or "" -- get data from |labelN= if newickString ~= "" or nodeLeaf ~= "" or listString ~= "" then --if nodeLeaf ~= "" then childCount = childCount + 1 -- this counts child elements in this clade --|rowspan") do -- count number of rows started (transclusion) nodeCount = nodeCount + 1 end for i in string.gmatch(nodeLeaf, '{|class="clade"') do -- count number of tables started (transclusion) cladeCount = cladeCount + 1 end -- count occurences of clade structure using number of classes used and add to counters local _, nClades = string.gsub(nodeLeaf, 'class="clade"', "") local _, nNodes = string.gsub(nodeLeaf, 'class="clade%-leaf"', "") cladeCount = cladeCount + nClades nodeCount = nodeCount + nNodes lastNode = childNumber -- this gets the last node with a valid entry, even when missing numbers end end --]] -- nodes can be either terminal leaves or a clade structure (table) -- note: should change class clade-leaf to clade-node to reflect this nodeCount = nodeCount -- number of nodes (class clade-leaf) passed down by transduction + childCount + 1 -- plus one for current clade and one for each of its child element cladeCount = cladeCount + 1 -- number of clade structure tables passed down by transduction (plus one for current clade) leafCount = nodeCount-cladeCount -- number of terminal leaves (equals height of cladogram) -- output for testing: number of clades / total nodes / terminal nodes (=leaves) -- (internal nodes) (cladogram height) infoOutput = return infoOutput end --code for placing TemplateStyles from the module source: Anomie (CC-0) https://phabricator.wikimedia.org/T200442 function p.templateStyle( frame, src ) return frame:extensionTag( 'templatestyles', , { src = src } ); end function p.showClade(frame) --local code = frame.args.code or "" local code = frame:getParent.args['code2'] or "" --return code --return mw.text.unstrip(code) --local test = "" --return string.sub(test,6,-7) local o1 =frame:getParent:getArgument('code2') return o1:expand --return string.sub(code,2,-1) -- strip marker \127'"`UNIQ--tagname-8 hex digits-QINU`"'\127 --return frame:preprocess(string.sub(code,3)) end function p.firstToUpper(str) return (str:gsub("^%l", string.upper)) end --function to generate cladogram from a wikitext-like list - uses @ instead of * because we don't want wikitext processed and nowiki elements are passed as stripmarkers (?) function p.list(count,listString) local cladeString = "" --count = count+1 local list = mw.text.split(listString, "\n") local i=1 local child=1 local lastNode=0--table.getn(list) -- number of child branches (potential) cladeString = cladeString .. mw.addWarning("WARNING. This is a test feature only.") return cladeString end -- experimental Newick to clade parser function = --Function of convert Newick strings to clade format Usage: function p.cladeConverter(frame) end function p.listConverter(frame) local listString = frame.args['list'] or pargs['list'] -- show the list string local cladeString = local levelNumber = 1 -- for depth of iteration local childNumber = 1 -- number of sister elements on node (always one for root) local indent = p.getIndent(levelNumber) -- converted the newick string to the clade structure cladeString = cladeString .. indent .. local resultString = local option = pargs['option'] or if option == 'tree' then --show the transcluded clade diagram resultString = cladeString else -- show the Newick string resultString = -- show the converted clade structure resultString = resultString .. end --resultString = frame:expandTemplate{ title = 'clade', frame:preprocess(cladeString) } return resultString end function p.listParseLevel(listString,levelNumber,childNumber) local cladeString = "" local indent = p.getIndent(levelNumber) levelNumber=levelNumber+1 local list = mw.text.split(listString, "\n") local i=1 local child=1 local lastNode=0 while list do list=list:gsub("^@", "") -- strip the first @ if not string.match( list, "^@", 1 ) then -- count children at this level (not beginning wiht @) lastNode = lastNode+1 end i=i+1 end i=1 while list do --pseudocode: if next value begins with @ we have a subtree, which must be recombined and past iteratively else we have a simple leaf -- if the next value begins with @, we have a subtree which should be recombined if list[i+1] and string.match( list[i+1], "^@", 1 ) then local label=list i=i+1 local recombined = list while list[i+1] and string.match( list[i+1], "^@", 1 ) do recombined = recombined .. "\n" .. list[i+1] i=i+1 end cladeString = cladeString .. indent .. '|label' .. child ..'=' .. label cladeString = cladeString .. indent .. '|' .. child ..'=' .. '' return cladeString end -- this must be at end return p
 

Tema özelleştirme sistemi

Bu menüden forum temasının bazı alanlarını kendinize özel olarak düzenleye bilirsiniz.

Zevkine göre renk kombinasyonunu belirle

Tam ekran yada dar ekran

Temanızın gövde büyüklüğünü sevkiniz, ihtiyacınıza göre dar yada geniş olarak kulana bilirsiniz.

Izgara yada normal mod

Temanızda forum listeleme yapısını ızgara yapısında yada normal yapıda listemek için kullanabilirsiniz.

Forum arkaplan resimleri

Forum arkaplanlarına eklenmiş olan resimlerinin kontrolü senin elinde, resimleri aç/kapat

Sidebar blogunu kapat/aç

Forumun kalabalığında kurtulmak için sidebar (kenar çubuğunu) açıp/kapatarak gereksiz kalabalıklardan kurtula bilirsiniz.

Yapışkan sidebar kapat/aç

Yapışkan sidebar ile sidebar alanını daha hızlı ve verimli kullanabilirsiniz.

Radius aç/kapat

Blok köşelerinde bulunan kıvrımları kapat/aç bu şekilde tarzını yansıt.

Foruma hoş geldin 👋, Ziyaretçi

Forum içeriğine ve tüm hizmetlerimize erişim sağlamak için foruma kayıt olmalı ya da giriş yapmalısınız. Foruma üye olmak tamamen ücretsizdir.

Geri