Module:Footnotes/anchor id list/data

From All Skies Encyclopaedia
< Module:Footnotes‎ | anchor id list
Revision as of 19:05, 20 May 2020 by imported>Trappist the monk

Documentation for this module may be created at Module:Footnotes/anchor id list/data/doc

-- copied from Module:Ref info/data - maybe overkill here?
-- for this application just make lists from the redirect lists and force all template names lower case?
-- yes lowercase because Footnotes/anchor id list template_name_get() returns lowercase

--[[--------------------------< C S 1 _ T E M P L A T E _ P A T T E R N S >------------------------------------

These are patterns for cs1 templates and their redirects.  These patterns exclude redirects that are vcite-like
which redirects should be deleted because vcite is not cs1.

]]

local cs1_template_patterns = {													-- lua patterns of the cannonical names and redirects
	'[Cc]ite ar[Xx]iv',															-- arXiv is the canonical name
		'[Cc]ite ArXiv',

	'[Cc]ite AV media',															-- canonical
		'[Cc]ite audio', '[Cc]ite AV', '[Cc]ite AV ?Media', '[Cc]ite av media', 
		'[Cc]ite cd', '[Cc]ite DVD', '[Cc]ite dvd', '[Cc]ite film',
		'[Cc]ite image', '[Cc]ite media', '[Cc]ite movie',
		'[Cc]ite music video', '[Cc]ite radio', '[Cc]ite song',
		'[Cc]ite ?video', '[Cc]ite visual', '[Cc]ite You[Tt]ube',
		'[Cc]ita vídeo',														-- non-English redirect; TODO: tally separately?

	'[Cc]ite AV media notes',													-- canonical
		'[Cc]ite album[ %-]notes', '[Cc]ite av media notes',
		'[Cc]ite DVD[ %-]notes', '[Cc]ite dvd%-notes', '[Cc]ite liner notes',
		'[Cc]ite music release notes', '[Ll]iner notes',

	'[Cc]ite bio[Rr]xiv',														-- bioRxiv is the canonical form
	'[Cc]ite [Bb]ook',															-- book is the canonical form
		'[Bb]ook cite', '[Bb]ook reference', '[Bb]ook reference url',
		'[Cc] book', '[Cc]it book', '[Cc]ite books', '[Cc]ite chapter',
		'[Cc]ite ebook', '[Cc]ite manual', '[Cc]ite page',
		'[Cc]ite publication', '[Cc]ite score',
		'[Cc]ite work', '[Cc]ite%-?book', 
		'[Bb]okref', '[Cc]itace monografie', '[Cc]itar livro',					-- non-English redirects; TODO: tally separately?
		'[Cc]iteer boek', '[Oo]uvrage', '[Rr]ef%-llibre', '서적 인용',

	'[Cc]ite citeseerx',														-- canonical
	'[Cc]ite conference',														-- canonical
		'[Cc]ita conferenza', '[Cc]ite proceedings', '[Cc]onference reference',	-- cita conferenza is non-English; TODO: tally separately?
		
	'[Cc]ite ?encyclopedia',													-- cite encyclopedia is the canonical name
		'[Cc]ite contribution', '[Cc]ite dic', '[Cc]ite dictionary',
		'[Cc]ite encyclopaedia', '[Cc]ite encyclopædia', '[Ee]ncyclopedia',

	'[Cc]ite [Ee]pisode',														-- episode is the canonical form
		'[Cc]ite show',

	'[Cc]ite interview',														-- canonical
	'[Cc]ite ?journal',															-- cite journal is the canonical form
		'[Cc] journal', '[Cc]itation journal', '[Cc]ite abstract',
		'[Cc]ite document', '[Cc]ite Journal', '[Cc]ite journal zh',
		'[Cc]ite ?paper', '[Vv]cite2 journal',
		'[Cc]ita pubblicazione', '[Cc]itace periodika', '[Cc]itar jornal',		-- non-English redirects; TODO: tally separately?
		'[Cc]itar publicació', '[Cc]ytuj pismo', '[Tt]idskriftsref',
		'Навод из стручног часописа', '저널 인용',

	'[Cc]ite [Mm]agazine',														-- magazine is the canonical form
		'[Cc]ite mag', '[Cc]ite magazine article', '[Cc]ite newsletter',
		'[Cc]ite periodical',

	'[Cc]ite mailing ?list',													-- mailing list is the canonical form
		'[Cc]ite list',

	'[Cc]ite maps?',															-- map is the canonical form
	'[Cc]ite[ %-]?news',														-- cite news is the canonical form
		'[Cc] news', '[Cc]it news', '[Cc]itation news', '[Cc]ite article',
		'[Cc]ite n', '[Cc]ite new', '[Cc]ite newspaper', '[Cc]ite News',
		'[Cc]ite news%-q', '[Cc]ite news2', '[Cc]itenewsauthor', '[Cc]ute news',
		'[Cc]itar notícia', '[Hh]aber kaynağı', '[Tt]idningsref', 'استشهاد بخبر',	-- non-English redirects; TODO: tally separately?
		'뉴스 인용',

	'[Cc]ite newsgroup',														-- canonical
		'[Cc]ite usenet',
		
	'[Cc]ite podcast',															-- canonical
	'[Cc]ite [Pp]ress release',													-- press release is the canonical form
		'[Cc]ite media release', '[Cc]ite news release', '[Cc]ite pr',
		'[Cc]ite press', '[Cc]ite press release\.', '[Cc]ite press[%-]?release',

	'[Cc]ite report',															-- canonical
	'[Cc]ite serial',															-- canonical
	'[Cc]ite sign',																-- canonical
		'[Cc]ite plaque',

	'[Cc]ite speech',															-- canonical
	'[Cc]ite ssrn',																-- canonical
		'[Cc]ite SSRN',
		
	'[Cc]ite tech ?report',														-- techreport is the canonical form
		'[Cc]ite standard', '[Cc]ite technical report', '[Tt]echrep reference',

	'[Cc]ite thesis',															-- canonical
		'[Cc]ite dissertation',
		'[Cc]itar tese',														-- non-English redirect; TODO: tally separately?

	'[Cc]ite [Ww]eb',															-- web is the canonical form
		'[Cc] web', '[Cc]it web', '[Cc]ite blog', '[Cc]ite URL', '[Cc]ite url',
		'[Cc]ite w', '[Cc]ite wb', '[Cc]ite we', '[Cc]ite web\.',
		'[Cc]ite webpage', '[Cc]ite website', '[Cc]ite website article',
		'[Cc]ite%-?web', '[Cc]itweb', '[Cc]w', '[Rr]ef web', '[Ww]eb citation',
		'[Ww]eb cite', '[Ww]eb link', '[Ww]eb[ %-]reference', '[Ww]eblink',
		'[Cc]hú thích web', '[Cc]ita web', '[Cc]itace elektronické monografie',	-- non-English redirects; TODO: tally separately?
		'[Cc]itat web', 'مرجع ويب', 'یادکرد وب', '웹 인용',
	}


--[[--------------------------< C S 2 _ T E M P L A T E _ P A T T E R N S >------------------------------------

These are patterns for cs2 templates redirects.

]]

local cs2_template_patterns = {													-- lua patterns of the cannonical names and redirects
	'[Cc]itation',
		'[Cc]ite', '[Cc]ite citation', '[Cc]ite study',
		'[Cc]ite [Tt]echnical standard',
	}


--[[--------------------------< V C I T E _ T E M P L A T E _ P A T T E R N S >--------------------------------

These are patterns for Vcite-family templates and their redirects.

]]

local vcite_template_patterns = {
	'[Vv]cite book',															-- canonical
		'[Vv]ancite book', '[Vv]ancite report', '[Vv]cite encyclopedia',
		'[Vv]cite report',

	'[Vv]cite journal',															-- canonical
		'[Cc]it journal', '[Cc]it paper', '[Vv]ancite journal', '[Vv]cite paper',

	'[Vv]cite news',															-- canonical
		'[Vv]ancite news',

	'[Vv]cite web',																-- canonical
		'[Vv]ancite web',
	}


--[[--------------------------< C S 1 2 _ S T R I P P E D _ L I S T >------------------------------------------

This table is created from cs1_template_patterns and cs2_template_patterns.  To make this table, entries in
the source tables are evaluated to replace lua patterns with the appropriate characters and create names for
this list.  This list is used to identify cs1|2 templates when counting and listing cs1-like templates.

For example:
	[Cc]ite ar[Xx]iv
becomes
	Cite arXiv
	Cite arxiv
	cite arXiv
	cite arxiv

]]

local known_templates_cs12 = {};
local known_templates_vcite = {};

	local function add_stripped (list, name)
		name = name:lower();													-- because Footnotes/anchor id list template_name_get() returns lowercase
		if not list[name] then
			list[name] = true;
		end
	end


	local function pattern_convert (list, name)
		if name:match ('(.-)%[(%a)(%a)%](.*)') then								-- mixed case optional letters
			local l;
			lead, c, l, tail = name:match ('(.-)%[(%a)(%a)%](.*)');
			add_stripped (list, lead .. c .. tail);									-- uppercase
			add_stripped (list, lead .. l .. tail);									-- lowercase
	
		elseif name:match ('^([^%[]+)(%[ %%%-%]%?)(.+)$') then					-- [ %-]?
			lead, c, tail = name:match ('^([^%[]+)(%[ %%%-%]%?)(.+)$');
			add_stripped (list, lead .. tail);										-- neither char
			add_stripped (list, lead .. ' ' .. tail);									-- space
			add_stripped (list, lead .. '-' .. tail);									-- hyphen
	
		elseif name:match ('^([^%[]+)(%[%%%-%]%?)(.+)$') then					-- [%-]?
			lead, c, tail = name:match ('^([^%[]+)(%[%%%-%]%?)(.+)$');
			add_stripped (list, lead .. tail);										-- no hyphen
			add_stripped (list, lead .. '-' .. tail);									-- hyphen
	
		elseif name:match ('^([^%[]+)(%[ %%%-%])(.+)$') then					-- [ %-]
			lead, c, tail = name:match ('^([^%[]+)(%[ %%%-%])(.+)$');
			add_stripped (list, lead .. ' ' .. tail);									-- space
			add_stripped (list, lead .. '-' .. tail);									-- hyphen
	
		elseif name:match ('^([^%?]+)(%%%-%?)(.+)$') then						-- %-?
			lead, c, tail = name:match ('^([^%?]+)(%%%-%?)(.+)$');
			add_stripped (list, lead .. tail);										-- no hyphen
			add_stripped (list, lead .. '-' .. tail);									-- hyphen
	
		elseif name:match ('^(.-)(%%%-)(.+)$') then								-- %-
			lead, c, tail = name:match ('^(.-)(%%%-)(.+)$');
			add_stripped (list, lead .. '-' .. tail);									-- hyphen

		elseif name:match ('^(.-)(.)%?(.*)$') then								-- .?
			lead, c, tail = name:match ('^(.-)(.)%?(.*)$');
			add_stripped (list, lead .. tail);										-- no character
			add_stripped (list, lead .. c .. tail);									-- character
	
		else
			add_stripped (list, name);												-- no patterns so save as is
		end
	end


	for _, list in ipairs ({cs1_template_patterns, cs2_template_patterns}) do
		for _, pattern in ipairs (list) do
			local name = pattern:gsub ('^%[(%a)%a%]', '%1');					-- leading character (usually uppercase)
			pattern_convert ('known_templates_cs12', name);
			name = pattern:gsub ('^%[%a(%a)%]', '%1');							-- leading character (usually lowercase)
			pattern_convert ('known_templates_cs12', name);
		end
	end

	for _, pattern in ipairs (vcite_template_patterns) do
		local name = pattern:gsub ('^%[(%a)%a%]', '%1');						-- leading character (usually uppercase)
		pattern_convert ('known_templates_vcite', name);
		name = pattern:gsub ('^%[%a(%a)%]', '%1');								-- leading character (usually lowercase)
		pattern_convert ('known_templates_vcite', name);
	end


--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]

return
	{
	known_templates_cs12 = known_templates_cs12,
	known_templates_vcite = known_templates_vcite,
	}