

import re


# xth grade -> GRADE=XX|XX where X in [0,k,1-12]
#
#
import itertools
from bpfe.util import sentence_splitter


ROMAN_NUMERAL_REPLACEMENTS = [
    ('xii', '12'),
    ('xi', '11'),
    ('x', '10'),
    ('ix', '9'),
    ('viii', '8'),
    ('vii', '7'),
    ('vi', '6'),
    ('v', '5'),
    ('iv', '4'),
    ('iii', '3'),
    ('ii', '2'),
    ('i', '1')
]


REPLACEMENTS = [
    ('miscellenous', 'miscellaneous'),
    ('mainenance', 'maintenance'),
    ('porgram', 'program'),
    ('prgm', 'program'),
    ('progrm', 'program'),
    ('tailoring', 'tutoring'),
    ('matenance', 'maintenance'),
    ('buisness', 'business'),
    ('secur syst anly', 'security system analyst'),
    ('horticulture', 'lawn and garden'),
    ('ntnl', 'national'),
    ("nat'l", 'national'),
    ("natl", 'national'),
    ('worke', 'worker'),
    ('imporvment', 'improvement'),
    ('adj', 'adjunct'),
    ('nclusion coa', 'inclusion coach'),
    ('incl programs', 'inclusion programs'),
    ('pda facil coord', 'pda facility coordinator'),
    ('instrucational', 'instructional'),
    ('ncaa', 'football'),
    ('plmg', 'plumbing'),
    ('n/a', ''),
    ('teachers', 'teacher'),
    ('sub', 'substitute'),
    ('subs', 'substitute'),
    ('special needs', 'special education'),
    ('specials needs', 'special education'),
    ('special ed.', 'special education'),
    ('special ed', 'special education'),
    ('spec. ed.', 'special education'),
    ('spec. ed', 'special education'),
    ('spec.ed.', 'special education'),
    ('spec.ed', 'special education'),
    ('spec ed.', 'special education'),
    ('spec ed', 'special education'),
    ('spec. education', 'special education'),
    ('spec education', 'special education'),
    ('spec. (ed.)', 'special education'),
    ('spec.(ed.)', 'special education'),
    ('spec (ed.)', 'special education'),
    ('spec (ed)', 'special education'),
    ('sp. ed.', 'special education'),
    ('sp.ed.', 'special education'),
    ('sp ed.', 'special education'),
    ('sp ed', 'special education'),
    ('sp education', 'special education'),
    ('sped', 'special education'),
    ('pre-school', 'GRADE=0|0'),
    ('pre school', 'GRADE=0|0'),
    ('preschool', 'GRADE=0|0'),
    ('pre-kindergarten', 'GRADE=0|0'),
    ('pre kindergarten', 'GRADE=0|0'),
    ('prekindergarten', 'GRADE=0|0'),
    ('pre-k', 'GRADE=0|0'),
    ('pre k', 'GRADE=0|0'),
    ('prek', 'GRADE=0|0'),
    ('vpk', 'GRADE=0|0'),
    ('k-8', 'GRADE=k|8'),
    ('k 8', 'GRADE=k|8'),
    ('k8', 'GRADE=k|8'),
    ('pre-k-12', 'GRADE=0|12'),
    ('pre-k 12', 'GRADE=0|12'),
    ('pre k-12', 'GRADE=0|12'),
    ('pre k 12', 'GRADE=0|12'),
    ('k-12', 'GRADE=k|12'),
    ('k 12', 'GRADE=k|12'),
    ('k12', 'GRADE=k|12'),
    ('9-12', 'GRADE=9|12'),
    ('8-12', 'GRADE=8|12'),
    ('6-12', 'GRADE=6|12'),
    ('professi', 'professional'),
    ('elementary school', 'GRADE=1|6'),
    ('elementary schools', 'GRADE=1|6'),
    ('middle school', 'GRADE=7|8'),
    ('midd school', 'GRADE=7|8'),
    ('middle schools', 'GRADE=7|8'),
    ('high school', 'GRADE=9|12'),
    ('high schools', 'GRADE=9|12'),
    ('junior high school', 'GRADE=7|8'),
    ('junior high schools', 'GRADE=7|8'),
    ('middle\/junior high', 'GRADE=7|8'),
    ('elementary sch', 'GRADE=1|6'),
    ('middle sch', 'GRADE=7|8'),
    ('middle', 'GRADE=7|8'),
    ('jr. high', 'GRADE=7|8'),
    ('jr high', 'GRADE=7|8'),
    ('junior high', 'GRADE=7|8'),
    ('high sch', 'GRADE=9|12'),
    ('high', 'GRADE=9|12'),
    ('\(blank\)', ''),
    ('asst', 'assistant'),
    ('misc', 'miscellaneous'),
    ('paraprofessional', 'assistant professional'),
    ('para professional', 'assistant professional'),
    ('paraprof', 'assistant professional'),
    ('parapro', 'assistant professional'),
    ('contrib.', 'contribution'),
    ('maint', 'maintenance'),
    ('sch', 'school'),
    ('schl', 'school'),
    ('elem', 'GRADE=1|6'),
    ('p e', 'physical education'),
    ('p e.', 'physical education'),
    ('p. e', 'physical education'),
    ('p. e.', 'physical education'),
    ('p.e.', 'physical education'),
    ('pe.', 'physical education'),
    ('pe', 'physical education'),
    ('phys ed', 'physical education'),
    ('phys ed.', 'physical education'),
    ('phys. ed', 'physical education'),
    ('phys. ed.', 'physical education'),
    ('phys education', 'physical education'),
    ('phys therapist', 'physical therapist'),
    ('math', 'mathematics'),
    ('prog', 'program'),
    ('prg', 'program'),
    ('pgms', 'program'),
    ('bldg', 'building'),
    ('bldgs', 'building'),
    ('kindergarten', 'GRADE=k|k'),
    ('kidergarten', 'GRADE=k|k'),
    ('tchr', 'teacher'),
    ('tchrs', 'teacher'),
    ('tcher', 'teacher'),
    ('tchers', 'teacher'),
    ('afterschool', 'extracurricular'),
    ('gifted', 'accelerated'),
    ('t-el kin', 'teacher GRADE=k|k'),
    ('t-el pk', 'teacher GRADE=0|0'),
    ('pk', 'teacher GRADE=0|0'),
    ('t-el', 'GRADE=1|6'),
    ('t-ml', 'GRADE=5|8'),
    ('t-ms', 'GRADE=7|8'),
    ('t-hs', 'GRADE=9|12'),
    ('h. s.', 'GRADE=9|12'),
    ('h.s.', 'GRADE=9|12'),
    ('h s.', 'GRADE=9|12'),
    ('h. s', 'GRADE=9|12'),
    ('h s', 'GRADE=9|12'),
    ('hs', 'GRADE=9|12'),
    ('m. s.', 'GRADE=7|8'),
    ('m.s.', 'GRADE=7|8'),
    ('m. s', 'GRADE=7|8'),
    ('m s.', 'GRADE=7|8'),
    ('m s', 'GRADE=7|8'),
    ('ms', 'GRADE=7|8'),
    ('voc', 'vocational'),
    ('voc.', 'vocational'),
    ('qualit', 'quality'),
    ('kindergar', 'GRADE=k|k'),
    ('birth to kinder', 'GRADE=0|k'),
    ('kinder', 'GRADE=k|k'),
    ('kindergart', 'GRADE=k|k'),
    ('dept.', 'department'),
    ('dept', 'department'),
    ('yrs', 'years'),
    ('nat', 'national'),
    ("natl", 'national'),
    ('dir', 'director'),
    ('educ', 'education'),
    ('hrly', 'hourly'),
    ('ex-curr', 'extracurricular'),
    ('pathologst', 'pathologist'),
    ('bil', 'bilingual'),
    ('sci/hl', 'science\/health'),
    ('depty', 'deputy'),
    ('piano', 'piano music'),
    ('nutrit', 'nutrition'),
    ('gardener', 'lawn and garden'),
    ('staduim', 'stadium'),
    ('ipad', 'ipad electronic'),
    ('reasource', 'resource'),
    ('facilitato', 'facilitator'),
    ('instrum.', 'instrument'),
    ('architectur int', 'architecture intern'),
    ('building and grd', 'building and ground'),
    ('pshycologist', 'psychologist'),
    ('prinicpal', 'principal'),
    ('princ', 'principal'),
    ('cusotidan', 'custodian'),
    ('inovation', 'innovation'),
    ('stratey', 'strategy'),
    ('foremman', 'foreman'),
    ('sign lang interp', 'sign language interpreter'),
    ('partnershi', 'partnership'),
    ('lifeguar', 'lifeguard'),
    ('sysadm', 'system administrator'),
    ('help dsk', 'help desk'),
    ('public aff', 'public affairs'),
    ('educato', 'educator'),
    ('secetary', 'secretary'),
    ('bilinguial', 'bilingual'),
    ('involvment', 'involvement'),
    ('involvmt', 'involvement'),
    ('sup- commun', 'superintendent -- community school'),
    ('teachre', 'teacher'),
    ('\(hr\)', 'hourly'),
    ('teasher', 'teacher'),
    ('cfo', 'chief financial officer'),
    ('cio', 'chief information officer'),
    ('cto', 'chief technology officer'),
    ('reprod hlth edc', 'reproductive health educator'),
    ('sfty', 'safety'),
    ('systm', 'system'),
    ('frmn', 'foreman'),
    ('develope', 'development'),
    ('develptmt', 'development'),
    ('develpmnt', 'development'),
    ('plcmnt', 'placement'),
    ('wirelesscontvty', 'wireless connectivity'),
    ('chai', 'chair'),
    ('vegrtables', 'vegetables'),
    ('specialsit', 'specialist'),
    ('imporvoment', 'improvement'),
    ('mach', 'machinist'),
    ('volleybally', 'volleyball'),
    ('perfomance', 'performance'),
    ('forman', 'foreman'),
    ('netwk', 'network'),
    ('comptr', 'computer'),
    ('evaluati', 'evaluation'),
    ('scndy', 'secondary'),
    ('sci', 'science'),
    ('bio', 'biology'),
    ('chem', 'chemistry'),
    ('bilng', 'bilingual'),
    ('intrvtn', 'intervention'),
    ('anlayst', 'analyst'),
    ('frmn', 'foreman'),
    ('frm', 'foreman'),
    ('administ', 'administrative'),
    ('libr', 'library'),
    ('colleyball', 'volleyball'),
    ('mgr', 'manager'),
    ('mngr', 'manager'),
    ('ass.', 'assistant'),
    ('achiev', 'achievement'),
    ('tabacco', 'tobacco'),
    ('trainier', 'trainer'),
    ('mntl', 'mental'),
    ('hlth', 'health'),
    ('lic', 'licensed'),
    ('blngl', 'bilingual'),
    ('lng', 'language'),
    ('desgn', 'design'),
    ('saturda', 'saturday'),
    ('portble', 'portable'),
    ('hmn', 'human'),
    ('resourcs', 'resources'),
    ('fash', 'fashion'),
    ('dsgn', 'design'),
    ('adm', 'administrative'),
    ('custodain', 'custodian'),
    ('pirncipal', 'principal'),
    ('techer', 'teacher'),
    ('clos achiev gap', 'close achievement gap'),
    ('transprtn', 'transportation'),
    ('prj', 'project'),
    ('prjt', 'project'),
    ('proj', 'project'),
    ('teacjer', 'teacher'),
    ('suspensio', 'supsension'),
    ('educatoinal', 'educational'),
    ('thearpy', 'therapist'),
    ('photog', 'photograph'),
    ('transisition', 'transition'),
    ('instrucional', 'instructional'),
    ('assistane', 'assistant'),
    ('assessmen', 'assessment'),
    ('rescs', 'resources'),
    ('dep', 'department'),
    ('progs', 'program'),
    ('fundra', 'fundraising'),
    ('trnr', 'trainer'),
    ('communicatio', 'communication'),
    ('wrkr', 'worker'),
    ('directr', 'director'),
    ('retrd', 'retired'),
    ('shrt', 'short'),
    ('s. e.', 'secondary education'),
    ('s.e.', 'secondary education'),
    ('s.e', 'secondary education'),
    ('s. e', 'secondary education'),
    ('s e.', 'secondary education'),
    ('s e', 'secondary education'),
    ('se', 'secondary education'),
    # replace with HS (http://en.wikipedia
    # .org/wiki/Secondary_education_in_the_United_States)
    ('secondary education', 'GRADE=9|12'),
    ('lang', 'language'),
    ('instruct.', 'instructor'),
    ('instruct', 'instructor'),
    ('yr', 'year'),
    ('rtd', 'retired'),
    ('cert', 'certified'),
    ('bgt', 'budget'),
    ('equip.', 'equipment'),
    ('equip', 'equipment'),
    ('equipt', 'equipment'),
    ('exec', 'executive'),
    ('slry', 'salaried'),
    ('cha', 'chair'),
    ('supv', 'supervisor'),
    ('reso', 'resources'),
    ('assgnmt', 'assignment'),
    ('kg', 'GRADE=k|k'),
    ('bus dr.', 'bus driver'),
    ('bus dr', 'bus driver'),
    ('schls', 'school'),
    ('band', 'band music'),
    ('technol', 'technology'),
    ('kdg', 'GRADE=k|k'),
    ('chairperson', 'chair person'),
    ('set asid', 'set aside'),
    ('prt-time', 'part time'),
    ('prt', 'part time'),
    ('hrs.', 'hours'),
    ('hrs', 'hours'),
    ('mgmt', 'management'),
    ('admn.', 'administrative'),
    ('admn', 'administrative'),
    ('sheetmtl', 'sheet metal'),
    ('imprvmnt', 'improvement'),
    ('kinderagrten', 'GRADE=k|k'),
    ('kindergaten', 'GRADE=k|k'),
    ('kindergarden', 'GRADE=k|k'),
    ('orchestra', 'orchestra music'),
    ('wkr', 'worker'),
    ('forng', 'foreign'),
    ('&', 'and'),
    ('unalloc', 'unallocated'),
    ('unalloc', 'unallocated'),
    ('admin.', 'administrative'),
    ('admin', 'administrative'),
    ('administration', 'administrative'),
    ('contrib', 'contribution'),
    ('srvcs', 'service'),
    ('svcs', 'service'),
    ('srv', 'service'),
    ('svc', 'service'),
    ('srvc', 'service'),
    ('srvs', 'service'),
    ('serv', 'service'),
    ('servicess', 'service'),
    ('pupils', 'student'),
    ('pupil', 'student'),
    ('studnt', 'student'),
    ('emerg med', 'emergency medical'),
    ('eng language', 'english language'),
    ('eng scnd', 'english second'),
    ('eng design', 'engineering design'),
    ('hvy eqpt', 'heavy equipment'),
    ('hvy', 'heavy'),
    ('small eng rpr', 'small engine repair'),
    ('eng - 2nd', 'english second'),
    ('comm eng coord', 'community engagement coordinator'),
    ('addl', 'additional'),
    ('certifiedaddl', 'certified additional'),
    ('certifiedaddl', 'certified additional'),
    ('certificated', 'certified'),
    ('renov', 'renovation'),
    ('remod', 'remodeling'),
    ('involvem', 'involvement'),
    ('improvemen', 'improvement'),
    ('activi', 'activity'),
    ('activiti', 'activity'),
    ('spo', 'sport'),
    ('schoo', 'school'),
    ('interntl', 'international'),
    ('intn\'l', 'international'),
    ('foodsvc', 'food service'),
    ('multilingual', 'bilingual'),
    ('assistant prin', 'assistant principal'),
    ('busine', 'business'),
    ('pgm', 'program'),
    ('pc', 'computer'),
    ('hardw', 'hardware'),
    ('childhd', 'childhood'),
    ('improv', 'improvement'),
    ('bks and mags', 'books and magazines'),
    ('couns', 'counselor'),
    ('neighbrhd', 'neighborhood'),
    ('ctr', 'center'),
    ('choir', 'music choir'),
    ('2nd language', 'second language'),
    ('scrty', 'secretary'),
    ('xcurricluar', 'extra curricular'),
    ('reqd', 'required'),
    ('matls', 'materials'),
    ('bdgt', 'budget'),
    ('ldrshp', 'leadership'),
    ('mgt', 'management'),
    ('mangr', 'manager'),
    ('othr sourc', 'other source'),
    ('jr var', 'junior varsity'),
    ('var', 'varsity'),
    ('footbl', 'football'),
    ('hd coach', 'head coach'),
    ('volbl', 'volleyball'),
    ('volleyb', 'volleyball'),
    ('wrest', 'wrestling'),
    ('fam acad', 'family academy'),
    ('fam', 'family'),
    ('famly', 'family'),
    ('ncert', 'not certified'),
    ('assis', 'assistant'),
    ('partne', 'partner'),
    ('magement', 'management'),
    ('lpn', 'licensed practical nurse'),
    ('rn', 'registered nurse'),
    ('acctblty', 'accountability'),
    ('st.wide', 'statewide'),
    ('equp', 'equipment'),
    ('disabilit', 'disability'),
    ('jr', 'junior'),
    ('sk', 'skill'),
    ('add\'l', 'additional'),
    ('workers comp', 'workers compensation'),
    ('workers\' comp', 'workers compensation'),
    ('comp. lab', 'computer lab'),
    ('comp lab', 'computer lab'),
    ('benefits and comp', 'benefits and compensation'),
    ('unemployment comp', 'unemployment compensation'),
    ('comp cheerleading', 'competitive cheerleading'),
    ('comp science', 'computer science'),
    ('state comp', 'state compensation'),
    ('state comp.', 'state compensation'),
    ('sftwre dev', 'software development'),
    ('sheltered eng', 'sheltered english esl'),
    ('acq and const', 'acquisition and construction'),
    ('acq & constr', 'acquisition and construction'),
    ('prof. learning', 'professional learning'),
    ('ldrship', 'leadership'),
    ('mtrls', 'materials'),
    ('matrls', 'materials'),
    ('alloc', 'allocation'),
    ('tif', 'teacher incentive fund'),
    ('elementary', 'GRADE=1|6'),
    ('athl', 'athletic'),
    ('ldr', 'leader'),
    ('genl', 'general'),
    ('sec to supt', 'secretary to superintendent'),
    ('ac mechanic', 'air condi'),
    ('ac', 'assistant coach'),
    ('assistant coach mechanic', 'ac mechanic'),
    ('hc', 'head coach'),
    ('ahc', 'assistant head coach'),
    ('jrvar', 'junior varsity'),
    ('baseb', 'baseball'),
    ('softb', 'softball'),
    ('bb', 'baseball'),
    ('soc stud', 'social studies'),
    ('wrk', 'work'),
    ('stud support', 'student support'),
    ('jv', 'junior varsity'),
    ('coord', 'coordinator'),
    ('comm school', 'community school'),
    ('comm ed', 'community education'),
    ('comm. ed.', 'community education'),
    ('comm ed.', 'community education'),
    ('comm. ed', 'community education'),
    ('comm engage', 'community engagement'),
    ('psychological', 'psychologist'),
    ('equipt', 'equipment'),
    ('eqpt', 'equipment'),
    ('oper ofcr', 'operating officer'),
    ('ofcr', 'officer'),
    ('oper', 'operator'),
    ('footbll', 'football'),
    ('acq', 'acquisition'),
    ('ely chi', 'early childhood'),
    ('adult ed', 'adult education'),
    ('pt', 'part time'),
    ('fac', 'facility'),
    ('aux', 'auxiliary'),
    ('tchracct', 'teacher acct'),
    ('mech', 'mechanic'),
    ('ldr', 'leader'),
    ('gr', 'grade'),
    ('hr specialist', 'human resources specialist'),
    ('hr department', 'human resources department'),
    ('analy', 'analyst'),
    ('anlyt', 'analyst'),
    ('cntry', 'country'),
    ('relatated', 'related'),
    ('theatre', 'theater'),
    ('coun', 'counselor'),
    ('vfb', 'varsity football'),
    ('sys', 'system'),
    ('commty', 'community'),
    ('facil', 'facility'),
    ('bsktbl', 'basketball'),
    ('phys', 'physics'),
    ('theat', 'theater'),
    ('dram', 'drama'),
    ('lan art', 'language art'),
    ('lan ar', 'language art'),
    ('nwsppr', 'newspaper'),
    ('yrbk', 'yearbook'),
    ('directo', 'director'),
    ('instruc', 'instructor'),
    ('volly', 'volleyball'),
    ('trainr', 'trainer'),
    ('ther', 'therapist'),
    ('englsh', 'english'),
    ('assistant to supt', 'assistant to superintendent'),
    ('assistant supt', 'assistant superintendent'),
    ('sec to supt', 'secretary to superintendent'),
    ('specia', 'special'),
    ('rsrch', 'research'),
    ('occup', 'occupational'),
    ('teachersup', 'teacher assistant'),
    ('diagnosticia', 'diagnostician'),
    ('assistant to pri', 'assistant to principal'),
    ('supprt', 'support'),
    ('tch', 'teacher'),
    ('basebl', 'baseball'),
    ('langs', 'language'),
    ('comptrolle', 'comptroller'),
    ('desktp', 'desktop'),
    ('dispatc', 'dispatch'),
    ('elctrn', 'electrician'),
    ('journalis', 'journalist'),
    ('cler', 'clerical'),
    ('psych', 'psychologist'),
    ('containd', 'contained'),
    ('chld', 'child'),
    ('accnts', 'accounts'),
    ('donatio', 'donation'),
    ('paintng', 'painting'),
    ('ctrl', 'control'),
    ('cntl', 'control'),
    ('watrproofng', 'waterproofing'),
    ('transp', 'transportation'),
    ('msgr', 'messenger'),
    ('syst', 'system'),
    ('thera', 'therapist'),
    ('intrv', 'intervention'),
    ('algebra', 'algebra mathematics'),
    ('genl', 'general'),
    ('chf', 'chief'),
    ('bilingua', 'bilingual'),
    ('bilngl', 'bilingual'),
    ('facilit', 'facility'),
    ('brd', 'board'),
    ('regulr', 'regular'),
    ('reg', 'regular'),
    ('mus the', 'musical theater'),
    ('chrtr', 'charter'),
    ('engnr', 'engineer'),
    ('technlgies', 'technology'),
    ('chdrn', 'children'),
    ('kindergatn', 'kindergarten'),
    ('string instruments', 'music string instruments'),
    ('equipmnt', 'equipment'),
    ('plancement', 'placement'),
    ('prescl', 'GRADE=0|0'),
    ('s/l', 'speech language'),

    ('baseball', 'baseball sport'),
    ('basketball', 'basketball sport'),
    ('football', 'football sport'),
    ('volleyball', 'volleyball sport'),
    ('cheerleading', 'cheerleading sport'),
    ('soccer', 'soccer sport'),
    ('golf', 'golf sport'),

    # athletics
    # ('aide', 'assistant'),
    # ('aides', 'assistant'),
    # ('ela', 'english language arts'),

    ("fr'mn", 'foreman')
]


REPLACEMENTS_SET = frozenset([j for j in itertools.chain(
    *[sentence_splitter(i[0]) for i in REPLACEMENTS]
)])


def replacements(value):
    if any(word in REPLACEMENTS_SET for word in sentence_splitter(value)):
        for v, replacement in REPLACEMENTS:
            value = replace(v, replacement, value)
    return value


def replace(value, replacement, sentence):
    if value not in sentence:
        return sentence
    v = sentence
    v = re.sub('^(' + value + ')([^\w\d]+)', replacement + '\\2', v)
    v = re.sub(
        '([^\w\d]+)(' + value + ')([^\w\d]+)', '\\1' + replacement + '\\3', v)
    v = re.sub('([^\w\d]+)(' + value + ')$', '\\1' + replacement, v)
    v = re.sub('^(' + value + ')$', replacement, v)
    return v


def grade_replacement(value):
    if 'grade' in value or '-' in value:
        value = re.sub('(\d+)(th|st|nd|rd) grade', r' GRADE=\1|\1 ', value)
        value = re.sub(
            't-el (\d+)(th|st|nd|rd)', r'teacher GRADE=\1|\1 ', value)
        value = re.sub('t-ms (\d+)th', r'teacher GRADE=\1|\1 ', value)
        value = re.sub('t-hs (\d+)th', r'teacher GRADE=\1|\1 ', value)
        value = re.sub('(k|\d+)-(\d+)', r' GRADE=\1|\2 ', value)
    return value


def itemx_replacement(value):
    # maybe make like TITLE or GRADE?
    if 'item' in value:
        value = re.sub('item[a-z\.]+\s+', '', value)
    return value


def title_replacement(value):
    if 'title' in value:
        for numeral, repl in ROMAN_NUMERAL_REPLACEMENTS:
            value = value.replace('title ' + numeral, 'TITLE=' + repl)
    return value


def transform(original):
    value = original

    # one some occasions, these are right against actual words,
    # breaking mappings for some entries
    value = value.replace('&', ' & ')
    value = value.replace('iii', ' ')

    value = grade_replacement(value)
    value = replacements(value)
    value = itemx_replacement(value)
    value = title_replacement(value)
    return original, value
