Difference between revisions of "Module:Data/namespaces/videoGames/static/name"

From Yugipedia
Jump to: navigation, search
(Video games' names' manager.)
 
m (That mw.log was for debugging. Align parenthesis.)
Line 10: Line 10:
 
:lower()
 
:lower()
 
-- Replace roman numerals:
 
-- Replace roman numerals:
:gsub( ' viii[!: ]', '8' )
+
:gsub(   ' viii[!: ]', '8' )
:gsub(   ' vii[!: ]', '7' )
+
:gsub(   ' vii[!: ]', '7' )
:gsub(   ' vi[!: ]', '6' )
+
:gsub(     ' vi[!: ]', '6' )
:gsub(     ' v[!: ]', '5' )
+
:gsub(     ' v[!: ]', '5' )
:gsub(   ' iv[!: ]', '4' )
+
:gsub(     ' iv[!: ]', '4' )
:gsub(   ' iii[!: ]', '3' )
+
:gsub(   ' iii[!: ]', '3' )
:gsub(   ' ii[!: ]', '2' )
+
:gsub(     ' ii[!: ]', '2' )
:gsub(     ' i[!: ]', '1' )
+
:gsub(     ' i[!: ]', '1' )
 
-- Remove a bunch of commonly used characters:
 
-- Remove a bunch of commonly used characters:
 
:gsub( "[%s%-_'/:! ]",  '' )
 
:gsub( "[%s%-_'/:! ]",  '' )
 
-- Remove series names:
 
-- Remove series names:
:gsub(     'yugioh',  '' )
+
:gsub(       'yugioh',  '' )
:gsub(         '5ds',  '' )
+
:gsub(         '5ds',  '' )
:gsub(       'zexal',  '' )
+
:gsub(       'zexal',  '' )
:gsub(       'arcv',  '' )
+
:gsub(         'arcv',  '' )
:gsub(     'vrains',  '' )
+
:gsub(       'vrains',  '' )
 
-- Remove some redundant words:
 
-- Remove some redundant words:
:gsub(         'the',  '' )
+
:gsub(         'the',  '' )
:gsub(     'gameboy',  '' )
+
:gsub(     'gameboy',  '' )
 
-- Normalize some titles:
 
-- Normalize some titles:
:gsub(     'expert', 'ex' )
+
:gsub(     'expert', 'ex' )
 
:gsub( 'worldchampionshiptournament', 'worldchampionship' )
 
:gsub( 'worldchampionshiptournament', 'worldchampionship' )
  
Line 48: Line 48:
 
end
 
end
 
end
 
end
mw.log( normalizedV )
+
 
 
return normalizedV
 
return normalizedV
 
end
 
end

Revision as of 15:17, 2 January 2020

-- <pre>
local thisData = mw.loadData( 'Module:Data/namespaces/videoGames/static/name/data' )

local function normalize( v )
	if type( v ) ~= 'string' then
		return nil
	end
	
	local normalizedV = table.concat( { v, ' ' } )
		:lower()
		-- Replace roman numerals:
		:gsub(   ' viii[!: ]', '8' )
		:gsub(    ' vii[!: ]', '7' )
		:gsub(     ' vi[!: ]', '6' )
		:gsub(      ' v[!: ]', '5' )
		:gsub(     ' iv[!: ]', '4' )
		:gsub(    ' iii[!: ]', '3' )
		:gsub(     ' ii[!: ]', '2' )
		:gsub(      ' i[!: ]', '1' )
		-- Remove a bunch of commonly used characters:
		:gsub( "[%s%-_'/:! ]",  '' )
		-- Remove series names:
		:gsub(       'yugioh',  '' )
		:gsub(          '5ds',  '' )
		:gsub(        'zexal',  '' )
		:gsub(         'arcv',  '' )
		:gsub(       'vrains',  '' )
		-- Remove some redundant words:
		:gsub(          'the',  '' )
		:gsub(      'gameboy',  '' )
		-- Normalize some titles:
		:gsub(      'expert', 'ex' )
		:gsub( 'worldchampionshiptournament', 'worldchampionship' )

	-- Remove "gx", if it's large enough (preserve "gx01", "gx3", "ygoo", "ygo" ):
	if normalizedV:len() > 4 then
		normalizedV = normalizedV
			:gsub(  'gx', '' )
			:gsub( 'ygo', '' )
		
		-- Remove "duelmonsters", if it's large enough (preserve cases like /duelmonsters\d/):
		if normalizedV:len() > 13 then
			normalizedV = normalizedV:gsub( 'duelmonsters', '' )
			-- Remove "worldchampionship", if it's large enough (preserve cases like /worldchampionship20\d\d/):
			if normalizedV:len() > 21 then
				normalizedV = normalizedV:gsub( 'worldchampionship', '' )
			end
		end
	end

	return normalizedV
end

return function( v )
	return thisData.main[
		thisData.normalize[
			normalize( v )
		]
	]
end
-- </pre>