มอดูล:Footnotes/anchor id list/data

-- copied from Module:Ref info/data - maybe overkill here?
-- for this application make lists from the redirect lists and force all template names first character uppercase
require('strict');
----------------------------------------------------------------
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
	'Ccite arXxiv',															-- arXiv is the canonical name
		'Ccite ArXiv',
	'Ccite AV media',															-- canonical
		'Ccite audio', 'Ccite AV', 'Ccite AV ?Media', 'Ccite av media', 
		'Ccite cd', 'Ccite DVD', 'Ccite dvd', 'Ccite film',
		'Ccite image', 'Ccite media', 'Ccite movie',
		'Ccite music video', 'Ccite radio', 'Ccite song',
		'Ccite ?video', 'Ccite visual', 'Ccite YouTtube',
		'Ccita vídeo',														-- non-English redirect; TODO: tally separately?
	'Ccite AV media notes',													-- canonical
		'Ccite album %-notes', 'Ccite av media notes',
		'Ccite DVD %-notes', 'Ccite dvd%-notes', 'Ccite liner notes',
		'Ccite music release notes', 'Lliner notes',
	'Ccite bioRrxiv',														-- bioRxiv is the canonical form
	'Ccite Bbook',															-- book is the canonical form
		'Bbook cite', 'Bbook reference', 'Bbook reference url',
		'Cc book', 'Ccit book', 'Ccite books', 'Ccite chapter',
		'Ccite ebook', 'Ccite manual', 'Ccite page',
		'Ccite publication', 'Ccite score',
		'Ccite work', 'Ccite%-?book', 
		'Bbokref', 'Ccitace monografie', 'Ccitar livro',					-- non-English redirects; TODO: tally separately?
		'Cciteer boek', 'Oouvrage', 'Rref%-llibre', '서적 인용',
	'Ccite citeseerx',														-- canonical
	'Ccite conference',														-- canonical
		'Ccita conferenza', 'Ccite proceedings', 'Cconference reference',	-- cita conferenza is non-English; TODO: tally separately?
		
	'Ccite ?encyclopedia',													-- cite encyclopedia is the canonical name
		'Ccite contribution', 'Ccite dic', 'Ccite dictionary',
		'Ccite encyclopaedia', 'Ccite encyclopædia', 'Eencyclopedia',
	'Ccite Eepisode',														-- episode is the canonical form
		'Ccite show',
	'Ccite interview',														-- canonical
	'Ccite ?journal',															-- cite journal is the canonical form
		'Cc journal', 'Ccitation journal', 'Ccite abstract',
		'Ccite document', 'Ccite Journal', 'Ccite journal zh',
		'Ccite ?paper', 'Vvcite2 journal',
		'Ccita pubblicazione', 'Ccitace periodika', 'Ccitar jornal',		-- non-English redirects; TODO: tally separately?
		'Ccitar publicació', 'Ccytuj pismo', 'Ttidskriftsref',
		'Навод из стручног часописа', '저널 인용',
	'Ccite Mmagazine',														-- magazine is the canonical form
		'Ccite mag', 'Ccite magazine article', 'Ccite newsletter',
		'Ccite periodical',
	'Ccite mailing ?list',													-- mailing list is the canonical form
		'Ccite list',
	'Ccite maps?',															-- map is the canonical form
	'Ccite %-?news',														-- cite news is the canonical form
		'Cc news', 'Ccit news', 'Ccitation news', 'Ccite article',
		'Ccite n', 'Ccite new', 'Ccite newspaper', 'Ccite News',
		'Ccite news%-q', 'Ccite news2', 'Ccitenewsauthor', 'Ccute news',
		'Ccitar notícia', 'Hhaber kaynağı', 'Ttidningsref', 'استشهاد بخبر',	-- non-English redirects; TODO: tally separately?
		'뉴스 인용',
	'Ccite newsgroup',														-- canonical
		'Ccite usenet',
		
	'Ccite podcast',															-- canonical
	'Ccite Ppress release',													-- press release is the canonical form
		'Ccite media release', 'Ccite news release', 'Ccite pr',
		'Ccite press', 'Ccite press release\.', 'Ccite press%-?release',
	'Ccite report',															-- canonical
	'Ccite serial',															-- canonical
	'Ccite sign',																-- canonical
		'Ccite plaque',
	'Ccite speech',															-- canonical
	'Ccite ssrn',																-- canonical
		'Ccite SSRN',
		
	'Ccite tech ?report',														-- techreport is the canonical form
		'Ccite standard', 'Ccite technical report', 'Ttechrep reference',
	'Ccite thesis',															-- canonical
		'Ccite dissertation',
		'Ccitar tese',														-- non-English redirect; TODO: tally separately?
	'Ccite Wweb',															-- web is the canonical form
		'Cc web', 'Ccit web', 'Ccite blog', 'Ccite URL', 'Ccite url',
		'Ccite w', 'Ccite wb', 'Ccite we', 'Ccite web\.',
		'Ccite webpage', 'Ccite website', 'Ccite website article',
		'Ccite%-?web', 'Ccitweb', 'Ccw', 'Rref web', 'Wweb citation',
		'Wweb cite', 'Wweb link', 'Wweb %-reference', 'Wweblink',
		'Cchú thích web', 'Ccita web', 'Ccitace elektronické monografie',	-- non-English redirects; TODO: tally separately?
		'Ccitat web', 'مرجع ويب', 'یادکرد وب', '웹 인용',
	}
----------------------------------------------------------------
These are patterns for cs2 templates redirects.
local cs2_template_patterns = {													-- lua patterns of the cannonical names and redirects
	'Ccitation',
		'Ccite', 'Ccite citation', 'Ccite study',
		'Ccite Ttechnical standard',
	}
------------------------------------------------------------
These are patterns for Vcite-family templates and their redirects.
local vcite_template_patterns = {
	'Vvcite book',															-- canonical
		'Vvancite book', 'Vvancite report', 'Vvcite encyclopedia',
		'Vvcite report',
	'Vvcite journal',															-- canonical
		'Ccit journal', 'Ccit paper', 'Vvancite journal', 'Vvcite paper',
	'Vvcite news',															-- canonical
		'Vvancite news',
	'Vvcite web',																-- canonical
		'Vvancite web',
	}
------------------------------------------------------------
These are patterns for the harvc template and its redirects.
local harvc_template_patterns = {
	'Hharvc',																	-- canonical
		'Ccitec',
	}
------------------------------------------------------
These are patterns for miscellaneous templates and their redirects that 'look like' cs1 templates (begin with cite ...)
Because they 'look like' cs1 templates they are handled as if they were cs1 templates.  These templates are NOT
wrapper templates; names and dates are always to be extracted from the article instantiation of the template.
local cs1_like_template_patterns = {
	'Ccite LSA',																-- canonical
	}
------------------------------------------------------
These are patterns for the wikicite template and its redirects.
local wikicite_template_patterns = {
	'Wwikicite',																-- canonical
	}
----------------------------------------------------------
These are patterns for the anchor template and its redirects.
local anchor_template_patterns = {
	'Aanchors?',																-- anchor is canonical form
	'Aanchor for redirect',
	'Aanchro',
	'Aancor',
	}
--------------------------------------------------------------
These are patterns for the anchor template and its redirects.
local sfn_whitelist_patterns = {
	'Ssfn whitelist',															-- canonical
		'Hharv whitelist',
	}
----------------------------------------------------------------------------
These tables are created from the *_template_patterns tables.  To make these tables, entries in the source tables
are evaluated to replace lua patterns with the appropriate characters to create names for the output tables.
First charqacter is always uppercase
For example:
	Ccite arXxiv
becomes
	Cite arXiv
	Cite arxiv
local known_templates_cs12 = {};												-- the exported tables
local known_templates_vcite = {};
local known_templates_harvc = {};
local known_templates_wikicite = {};
local known_templates_anchor = {};
local known_templates_sfn_whitelist = {};
	local function add_stripped (list, name)
		if not listname then
			listname = true;
		end
	end
	local function pattern_convert (pattern, list)
		local lead, tail, c, l, name;
		local first_char_patterns = {
			'^%(%a)%a%',														-- leading character (usually uppercase)
			'^%%a(%a)%',														-- leading character (usually lowercase)
			}
			
		c = tostring (pattern:match ('%u'));									-- tostring() required because I don't know why; lua chokes complaining that c is not a string
		name = pattern:gsub ('^%%a%a%', c);									-- replace bracketed first character Xx with selected character from the match
		
		if name:match ('(.-)%(%a)(%a)%(.*)') then								-- mixed case optional letters
			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 _, t in ipairs ({
		{cs1_template_patterns, known_templates_cs12},
		{cs2_template_patterns, known_templates_cs12},
		{cs1_like_template_patterns, known_templates_cs12},
		{vcite_template_patterns, known_templates_vcite},
		{harvc_template_patterns, known_templates_harvc},
		{wikicite_template_patterns, known_templates_wikicite},
		{anchor_template_patterns, known_templates_anchor},
		{sfn_whitelist_patterns, known_templates_sfn_whitelist},
		}) do
			for _, pattern in ipairs (t1) do									-- for each patern in *_template_patterns
				pattern_convert (pattern, t2)									-- convert and store in known_templates_			end
	end
--------------------------------------------------------------------------------------------
return
	{
	known_templates_anchor = known_templates_anchor,
	known_templates_cs12 = known_templates_cs12,
	known_templates_harvc = known_templates_harvc,
	known_templates_vcite = known_templates_vcite,
	known_templates_wikicite = known_templates_wikicite,
	known_templates_sfn_whitelist = known_templates_sfn_whitelist,
	}