<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3AFishRef%2Futilities</id>
	<title>Module:FishRef/utilities - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3AFishRef%2Futilities"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:FishRef/utilities&amp;action=history"/>
	<updated>2026-05-24T21:46:23Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://stockhub.co/index.php?title=Module:FishRef/utilities&amp;diff=136225&amp;oldid=prev</id>
		<title>imported&gt;Jts1882: add algaebase preprocess</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:FishRef/utilities&amp;diff=136225&amp;oldid=prev"/>
		<updated>2021-11-24T14:23:42Z</updated>

		<summary type="html">&lt;p&gt;add algaebase preprocess&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local p = {}&lt;br /&gt;
&lt;br /&gt;
p.format_species_list = function(frame, taxa)&lt;br /&gt;
&lt;br /&gt;
  local list = frame.args[1] or frame:getParent().args[1] or taxa&lt;br /&gt;
  local expand = frame.args[&amp;#039;expand&amp;#039;] or frame:getParent().args[&amp;#039;expand&amp;#039;] -- want to subst template code&lt;br /&gt;
  local compare = frame.args[&amp;#039;compare&amp;#039;] or frame:getParent().args[&amp;#039;compare&amp;#039;] &lt;br /&gt;
  local option = frame.args[&amp;#039;option&amp;#039;] or frame:getParent().args[&amp;#039;option&amp;#039;] &lt;br /&gt;
  local mode = frame.args[&amp;#039;mode&amp;#039;] or frame:getParent().args[&amp;#039;mode&amp;#039;] &lt;br /&gt;
  local nolink =  frame.args[&amp;#039;nolink&amp;#039;] or frame:getParent().args[&amp;#039;nolink&amp;#039;] &lt;br /&gt;
  &lt;br /&gt;
  list = mw.text.trim( list )&lt;br /&gt;
  &lt;br /&gt;
	local names = mw.text.split( list, &amp;quot;\n&amp;quot; )   -- could use plain option&lt;br /&gt;
	--local genus, species, authority&lt;br /&gt;
	local output = { }            -- table of species names for output&lt;br /&gt;
&lt;br /&gt;
	local i = 1&lt;br /&gt;
	while names[i] do&lt;br /&gt;
		&lt;br /&gt;
		local name, match, skip&lt;br /&gt;
		local sep = &amp;quot; &amp;quot;                                               -- space between genus and species&lt;br /&gt;
		local infrasep = &amp;quot;&amp;quot;  &lt;br /&gt;
		local italics = &amp;quot;&amp;#039;&amp;#039;&amp;quot;&lt;br /&gt;
		local genus, species, subspecies, authority&lt;br /&gt;
        --local subspecies = &amp;quot;&amp;quot;&lt;br /&gt;
        &lt;br /&gt;
        names[i] = mw.text.trim(names[i])  &lt;br /&gt;
        &lt;br /&gt;
        -- custom preprocess options&lt;br /&gt;
        if names[i] == &amp;quot;&amp;quot; then skip = true end                -- ignore blank lines&lt;br /&gt;
        if compare and not names[i]:find(&amp;quot;^&amp;quot; .. compare) then -- only consider lines beginning with compare text (e.g. =genus)   &lt;br /&gt;
        	skip = true &lt;br /&gt;
        end                                                        &lt;br /&gt;
        if option and string.lower(option) == &amp;quot;worms&amp;quot; then               -- process WoRMS list&lt;br /&gt;
        	names[i] = names[i]:gsub(&amp;quot;^Species &amp;quot;, &amp;quot;&amp;quot;)         -- delete leading &amp;quot;Species&amp;quot;&lt;br /&gt;
        	if names[i]:find(&amp;quot;accepted as&amp;quot;) then              -- ignore invalid species, i.e. those &amp;quot;accepted as&amp;quot; something else&lt;br /&gt;
        		skip = true &lt;br /&gt;
            end&lt;br /&gt;
        end&lt;br /&gt;
        if option and string.lower(option) == &amp;quot;gbif&amp;quot; then               -- process GBIF list (copies with Species on alternate lines)&lt;br /&gt;
        	if names[i] == &amp;quot;Species&amp;quot; or names[i] == &amp;quot;Unranked&amp;quot; then&lt;br /&gt;
        		skip = true &lt;br /&gt;
            end        &lt;br /&gt;
        end&lt;br /&gt;
        if option and string.lower(option) == &amp;quot;tpl&amp;quot; then               -- process tpl list &lt;br /&gt;
        	if names[i]:find(&amp;quot;Accepted&amp;quot;) then &lt;br /&gt;
        		names[i] = names[i]:gsub(&amp;quot;^(.+)	Accepted.+&amp;quot;, &amp;quot;%1&amp;quot;)          -- only include up to Accepted&lt;br /&gt;
        		names[i] = mw.text.trim(names[i])                           -- needed as separate line as gsub returns str, i&lt;br /&gt;
        	else&lt;br /&gt;
        		skip = true                                                -- skip if not accepted&lt;br /&gt;
        	end   &lt;br /&gt;
        end&lt;br /&gt;
        &lt;br /&gt;
        if option and string.lower(option) == &amp;quot;algaebase&amp;quot; then               -- process algaebase&lt;br /&gt;
        	if names[i]:find(&amp;quot;C$&amp;quot;) then &lt;br /&gt;
        		names[i] = names[i]:gsub(&amp;quot;C$&amp;quot;, &amp;quot;&amp;quot;)                          -- only include C&lt;br /&gt;
        		names[i] = mw.text.trim(names[i])                           -- needed as separate line as gsub returns str, i&lt;br /&gt;
        	else&lt;br /&gt;
        		skip = true                                                -- skip if not accepted&lt;br /&gt;
        	end   &lt;br /&gt;
        end&lt;br /&gt;
        -- make list&lt;br /&gt;
                                                                              -- TODO try &amp;quot;(%S+)([%s×]+)(%S+) (.*)&amp;quot; &lt;br /&gt;
        if mode == &amp;quot;genus&amp;quot; or mode == &amp;quot;taxon&amp;quot; then               -- assume form taxon authority&lt;br /&gt;
 				for g, a in string.gmatch(names[i], &amp;quot;(%S+) (.*)&amp;quot; )  do -- match: genus × species authority&lt;br /&gt;
					genus = g&lt;br /&gt;
					species = &amp;quot;&amp;quot;&lt;br /&gt;
				    sep = &amp;quot;&amp;quot;&lt;br /&gt;
					if a ~= &amp;quot;&amp;quot; then authority = a end                          -- no authority after space&lt;br /&gt;
					match = true                                               -- we have a match &lt;br /&gt;
					if mode == &amp;quot;taxon&amp;quot; then italics = &amp;quot;&amp;quot; end&lt;br /&gt;
				end&lt;br /&gt;
      	&lt;br /&gt;
        else                                  -- match species list (various forms w/wo authority, hybrid)&lt;br /&gt;
&lt;br /&gt;
	        if not match then &lt;br /&gt;
				--for g, s, f, ss, a in string.gmatch(names[i], &amp;quot;(%S+) (%S+)( subsp%. )(%S+) (.*)&amp;quot; ) do -- match: genus species subsp. subspecies authority&lt;br /&gt;
				for g, s, f, ss, a in string.gmatch(names[i], &amp;quot;(%S+) (%S+)( [svfb][ubsparomiv]*%. )(%S+) (.*)&amp;quot; ) do -- match: genus species subsp. subspecies authority&lt;br /&gt;
					genus = g&lt;br /&gt;
					species = s &lt;br /&gt;
					subspecies = ss&lt;br /&gt;
					infrasep = f --&amp;quot; subsp. &amp;quot;&lt;br /&gt;
					sep = &amp;quot; &amp;quot;&lt;br /&gt;
					if a ~= &amp;quot;&amp;quot; then authority = a end                          -- no authority after space&lt;br /&gt;
					match = true                                               -- we have a match &lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
			if not match then &lt;br /&gt;
				--for g, s, f, ss in string.gmatch(names[i], &amp;quot;(%S+) (%S+)( subsp%. )(%S+)&amp;quot; ) do -- match: genus species subsp. subspecies&lt;br /&gt;
				for g, s, f, ss in string.gmatch(names[i], &amp;quot;(%S+) (%S+)( [svfb][ubsparomiv]*%. )(%S+)&amp;quot; ) do -- match: genus species subsp. subspecies&lt;br /&gt;
					genus = g&lt;br /&gt;
					species = s &lt;br /&gt;
					subspecies = ss&lt;br /&gt;
					infrasep = f -- &amp;quot; subsp. &amp;quot;&lt;br /&gt;
					sep = &amp;quot; &amp;quot;&lt;br /&gt;
					--if a ~= &amp;quot;&amp;quot; then authority = a end                          -- no authority after space&lt;br /&gt;
					match = true                                               -- we have a match &lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
	        if not match then &lt;br /&gt;
				for g, s, a in string.gmatch(names[i], &amp;quot;(%S+) × (%S+) (.*)&amp;quot; ) do -- match: genus × species authority&lt;br /&gt;
					genus = g&lt;br /&gt;
					species = s &lt;br /&gt;
					sep = &amp;quot; × &amp;quot;&lt;br /&gt;
					if a ~= &amp;quot;&amp;quot; then authority = a end                          -- no authority after space&lt;br /&gt;
					match = true                                               -- we have a match &lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
	&lt;br /&gt;
			if not match then &lt;br /&gt;
				for g, s in string.gmatch(names[i], &amp;quot;(%S+) × (%S+).*&amp;quot; ) do   --  match:  genus × species&lt;br /&gt;
					genus = g&lt;br /&gt;
					species = s&lt;br /&gt;
					sep = &amp;quot; × &amp;quot;&lt;br /&gt;
					if a ~= &amp;quot;&amp;quot; then authority = a end&lt;br /&gt;
					match = true&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
	        if not match then &lt;br /&gt;
				for g, s, a in string.gmatch(names[i], &amp;quot;(%S+) (%S+) (.*)&amp;quot; ) do -- match: genus species authority&lt;br /&gt;
					genus = g&lt;br /&gt;
					species = s &lt;br /&gt;
					if a ~= &amp;quot;&amp;quot; then authority = a end                          -- no authority after space&lt;br /&gt;
					match = true                                               -- we have a match for genus, species, authority&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
			if not match then &lt;br /&gt;
				for g, s in string.gmatch(names[i], &amp;quot;(%S+) (%S+).*&amp;quot; ) do       -- match: genus species&lt;br /&gt;
					genus = g&lt;br /&gt;
					species = s &lt;br /&gt;
					match = true&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
		if match and not skip then&lt;br /&gt;
			local species_name = genus .. sep .. species  &lt;br /&gt;
			if subspecies then&lt;br /&gt;
				name = &amp;quot;&amp;#039;&amp;#039;&amp;quot; .. species_name .. &amp;quot;&amp;#039;&amp;#039;&amp;quot; .. infrasep .. &amp;quot;&amp;#039;&amp;#039;&amp;quot;  .. subspecies ..&amp;quot;&amp;#039;&amp;#039;&amp;quot;          &lt;br /&gt;
				if not nolink then &lt;br /&gt;
					name =  &amp;quot;[[&amp;quot; .. species_name .. infrasep .. subspecies   .. &amp;quot;|&amp;quot; .. name .. &amp;quot;]]&amp;quot;    -- wikilinked name with redirect&lt;br /&gt;
			    end&lt;br /&gt;
			else&lt;br /&gt;
				name = species_name&lt;br /&gt;
				if not nolink then name = &amp;quot;[[&amp;quot; .. name .. &amp;quot;]]&amp;quot; end       -- add wikilink&lt;br /&gt;
				name = italics .. name .. italics                        -- add italics &lt;br /&gt;
			end&lt;br /&gt;
 &lt;br /&gt;
			if authority  and expand then&lt;br /&gt;
			   name = name.. &amp;quot; &amp;quot; .. frame:expandTemplate{ title = &amp;#039;small&amp;#039;, args = { authority } }  --expand template&lt;br /&gt;
			elseif authority then&lt;br /&gt;
			   name = name .. &amp;quot; {{small|&amp;quot; .. authority ..&amp;quot;}}&amp;quot;                                 -- don&amp;#039;t expand template&lt;br /&gt;
			end&lt;br /&gt;
&lt;br /&gt;
		end&lt;br /&gt;
	   	if name  then &lt;br /&gt;
	  		table.insert ( output , name )&lt;br /&gt;
	  	elseif not skip then &lt;br /&gt;
	  		table.insert ( output ,&amp;#039;&amp;lt;span class=&amp;quot;error&amp;quot;&amp;gt;unsupported format: expects &amp;quot;genus species authority&amp;quot;&amp;lt;/span&amp;gt;&amp;#039; )&lt;br /&gt;
	  	end&lt;br /&gt;
	   &lt;br /&gt;
  	 &lt;br /&gt;
		i=i+1&lt;br /&gt;
	end&lt;br /&gt;
  &lt;br /&gt;
	return &amp;quot;*&amp;quot; .. table.concat(output, &amp;quot;\n*&amp;quot;)&lt;br /&gt;
	&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
p.format_taxon_list = function(frame)&lt;br /&gt;
&lt;br /&gt;
  local list = frame.args[1] or frame:getParent().args[1] &lt;br /&gt;
  local expand = frame.args[&amp;#039;expand&amp;#039;] or frame:getParent().args[&amp;#039;expand&amp;#039;] -- want to subst template code&lt;br /&gt;
  &lt;br /&gt;
  list = mw.text.trim( list )&lt;br /&gt;
  &lt;br /&gt;
	local names = mw.text.split( list, &amp;quot;\n&amp;quot;, plain )&lt;br /&gt;
	--local genus, species, authority&lt;br /&gt;
	local output = { }            -- table of species names for output&lt;br /&gt;
    local patterns = { &amp;quot;(%S+)( × )(%S+) (.*)&amp;quot;,           --     genus × species authority&lt;br /&gt;
    	              &amp;quot;(%S+)( × )(%S+).*&amp;quot;,              --     genus × species&lt;br /&gt;
    	               &amp;quot;(%S+)( )(%S+) (.*)&amp;quot;,            --     genus species authority&lt;br /&gt;
    	               &amp;quot;(%S+)( )(%S+).*&amp;quot;,               --     genus species &lt;br /&gt;
    	                                                -- taxon or genus authority&lt;br /&gt;
    }&lt;br /&gt;
	local i = 1&lt;br /&gt;
	while names[i] do&lt;br /&gt;
		local name, match&lt;br /&gt;
		--local sep = &amp;quot; &amp;quot;                                               -- space between genus and species&lt;br /&gt;
		local genus, separator, species, authority&lt;br /&gt;
                                                                     -- TODO try &amp;quot;(%S+)([%s×]+)(%S+) (.*)&amp;quot; &lt;br /&gt;
       for k, v in pairs (patterns) do &lt;br /&gt;
			for g, sep, s, a in string.gmatch(names[i], v ) do -- match: genus × species authority&lt;br /&gt;
				genus = g&lt;br /&gt;
				species = s &lt;br /&gt;
				separator = sep&lt;br /&gt;
				if a and a ~= &amp;quot;&amp;quot; then authority = a end                          -- no authority after space&lt;br /&gt;
				match = true                                               -- we have a match &lt;br /&gt;
			end&lt;br /&gt;
			if match then break end&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
		if match then&lt;br /&gt;
			name = &amp;quot;&amp;#039;&amp;#039;[[&amp;quot; .. genus .. separator .. species .. &amp;quot;]]&amp;#039;&amp;#039;&amp;quot;  &lt;br /&gt;
			if authority  and expand then&lt;br /&gt;
			   name = name .. frame:expandTemplate{ title = &amp;#039;small&amp;#039;, args = { authority } }  --expand template&lt;br /&gt;
			elseif authority then&lt;br /&gt;
			   name = name .. &amp;quot;{{small|&amp;quot; .. authority ..&amp;quot;}}&amp;quot;                                 -- don&amp;#039;t expand template&lt;br /&gt;
			end&lt;br /&gt;
&lt;br /&gt;
		end&lt;br /&gt;
	   	if name  then &lt;br /&gt;
	  		table.insert ( output , name )&lt;br /&gt;
	  	else&lt;br /&gt;
	  		table.insert ( output ,&amp;#039;&amp;lt;span class=&amp;quot;error&amp;quot;&amp;gt;unsupported format: expects &amp;quot;genus species authority&amp;quot;&amp;lt;/span&amp;gt;&amp;#039; )&lt;br /&gt;
	  	end&lt;br /&gt;
	   &lt;br /&gt;
  	 &lt;br /&gt;
		i=i+1&lt;br /&gt;
	end&lt;br /&gt;
  &lt;br /&gt;
	return &amp;quot;*&amp;quot; .. table.concat(output, &amp;quot;\n*&amp;quot;)&lt;br /&gt;
	&lt;br /&gt;
end&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>imported&gt;Jts1882</name></author>
	</entry>
</feed>