Difference between revisions of "Module:Data/namespaces/videoGames/static/name"
(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( | + | :gsub( ' viii[!: ]', '8' ) |
− | :gsub( | + | :gsub( ' vii[!: ]', '7' ) |
− | :gsub( | + | :gsub( ' vi[!: ]', '6' ) |
− | :gsub( | + | :gsub( ' v[!: ]', '5' ) |
− | :gsub( | + | :gsub( ' iv[!: ]', '4' ) |
− | :gsub( | + | :gsub( ' iii[!: ]', '3' ) |
− | :gsub( | + | :gsub( ' ii[!: ]', '2' ) |
− | :gsub( | + | :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( | + | :gsub( 'yugioh', '' ) |
− | :gsub( | + | :gsub( '5ds', '' ) |
− | :gsub( | + | :gsub( 'zexal', '' ) |
− | :gsub( | + | :gsub( 'arcv', '' ) |
− | :gsub( | + | :gsub( 'vrains', '' ) |
-- Remove some redundant words: | -- Remove some redundant words: | ||
− | :gsub( | + | :gsub( 'the', '' ) |
− | :gsub( | + | :gsub( 'gameboy', '' ) |
-- Normalize some titles: | -- Normalize some titles: | ||
− | :gsub( | + | :gsub( 'expert', 'ex' ) |
:gsub( 'worldchampionshiptournament', 'worldchampionship' ) | :gsub( 'worldchampionshiptournament', 'worldchampionship' ) | ||
Line 48: | Line 48: | ||
end | end | ||
end | end | ||
− | + | ||
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>