<s> import re <EOL> from . keywords import * <EOL> def _replace_roman_numerals ( name ) : <EOL> if name is None or name == '<STR_LIT>' : <EOL> raise Exception <EOL> words = name . split ( '<STR_LIT:U+0020>' ) <EOL> for i , word in enumerate ( words ) : <EOL> if i == <NUM_LIT:0> : <EOL> continue <EOL> if i == len ( words ) - <NUM_LIT:1> and word == '<STR_LIT:i>' : <EOL> words [ i ] = str ( <NUM_LIT:1> ) <EOL> return '<STR_LIT:U+0020>' . join ( words ) <EOL> if word in roman_numerals : <EOL> words [ i ] = str ( roman_numerals . index ( word ) + <NUM_LIT:2> ) <EOL> return '<STR_LIT:U+0020>' . join ( words ) <EOL> return name <EOL> def _get_year ( name ) : <EOL> if name is None or name == '<STR_LIT>' : <EOL> raise Exception <EOL> if len ( name . split ( '<STR_LIT:U+0020>' ) ) == <NUM_LIT:1> : <EOL> return ( name , None ) <EOL> for pattern in year_extract_patterns : <EOL> match = re . match ( pattern , name ) <EOL> if match is not None : <EOL> year = match . group ( '<STR_LIT>' ) <EOL> if int ( year ) >= <NUM_LIT> : <EOL> return ( str ( match . group ( '<STR_LIT:name>' ) ) , int ( year ) ) <EOL> return ( name , None ) <EOL> def sanitize ( name ) : <EOL> if name is None or name == '<STR_LIT>' : <EOL> raise Exception <EOL> for keyword in case_sensitive_keywords : <EOL> if keyword in name : <EOL> name = name . replace ( keyword , '<STR_LIT>' ) <EOL> name = name . lower ( ) <EOL> for keyword in regex_keywords : <EOL> name = re . sub ( keyword , '<STR_LIT>' , name ) <EOL> for keyword in print_keywords : <EOL> if keyword in name : <EOL> name = name . replace ( keyword , '<STR_LIT>' ) <EOL> for keyword in case_insensitive_keywords : <EOL> if keyword in name : <EOL> name = name . replace ( keyword , '<STR_LIT>' ) <EOL> name = _replace_roman_numerals ( name . strip ( ) ) <EOL> name = re . sub ( '<STR_LIT>' , '<STR_LIT:U+0020>' , name ) <EOL> name = re . sub ( '<STR_LIT>' , '<STR_LIT:U+0020>' , name ) <EOL> name = name . strip ( ) <EOL> return _get_year ( name ) </s>
