<s> """<STR_LIT>""" <EOL> import re <EOL> _step2list = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:e>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> _step3list = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> _cons = "<STR_LIT>" <EOL> _vowel = "<STR_LIT>" <EOL> _cons_seq = "<STR_LIT>" <EOL> _vowel_seq = "<STR_LIT>" <EOL> _mgr0 = re . compile ( "<STR_LIT>" + _cons_seq + "<STR_LIT>" + _vowel_seq + _cons_seq ) <EOL> _meq1 = re . compile ( "<STR_LIT>" + _cons_seq + "<STR_LIT>" + _vowel_seq + _cons_seq + "<STR_LIT:(>" + _vowel_seq + "<STR_LIT>" ) <EOL> _mgr1 = re . compile ( "<STR_LIT>" + _cons_seq + "<STR_LIT>" + _vowel_seq + _cons_seq + _vowel_seq + _cons_seq ) <EOL> _s_v = re . compile ( "<STR_LIT>" + _cons_seq + "<STR_LIT>" + _vowel ) <EOL> _c_v = re . compile ( "<STR_LIT>" + _cons_seq + _vowel + "<STR_LIT>" ) <EOL> _ed_ing = re . compile ( "<STR_LIT>" ) <EOL> _at_bl_iz = re . compile ( "<STR_LIT>" ) <EOL> _step1b = re . compile ( "<STR_LIT>" ) <EOL> _step2 = re . compile ( "<STR_LIT>" ) <EOL> _step3 = re . compile ( "<STR_LIT>" ) <EOL> _step4_1 = re . compile ( "<STR_LIT>" ) <EOL> _step4_2 = re . compile ( "<STR_LIT>" ) <EOL> _step5 = re . compile ( "<STR_LIT>" ) <EOL> def stem ( w ) : <EOL> """<STR_LIT>""" <EOL> if len ( w ) < <NUM_LIT:3> : <EOL> return w <EOL> first_is_y = w [ <NUM_LIT:0> ] == "<STR_LIT:y>" <EOL> if first_is_y : <EOL> w = "<STR_LIT:Y>" + w [ <NUM_LIT:1> : ] <EOL> if w . endswith ( "<STR_LIT:s>" ) : <EOL> if w . endswith ( "<STR_LIT>" ) : <EOL> w = w [ : - <NUM_LIT:2> ] <EOL> elif w . endswith ( "<STR_LIT>" ) : <EOL> w = w [ : - <NUM_LIT:2> ] <EOL> elif w [ - <NUM_LIT:2> ] != "<STR_LIT:s>" : <EOL> w = w [ : - <NUM_LIT:1> ] <EOL> if w . endswith ( "<STR_LIT>" ) : <EOL> s = w [ : - <NUM_LIT:3> ] <EOL> if _mgr0 . match ( s ) : <EOL> w = w [ : - <NUM_LIT:1> ] <EOL> else : <EOL> m = _ed_ing . match ( w ) <EOL> if m : <EOL> stem = m . group ( <NUM_LIT:1> ) <EOL> if _s_v . match ( stem ) : <EOL> w = stem <EOL> if _at_bl_iz . match ( w ) : <EOL> w += "<STR_LIT:e>" <EOL> elif _step1b . match ( w ) : <EOL> w = w [ : - <NUM_LIT:1> ] <EOL> elif _c_v . match ( w ) : <EOL> w += "<STR_LIT:e>" <EOL> if w . endswith ( "<STR_LIT:y>" ) : <EOL> stem = w [ : - <NUM_LIT:1> ] <EOL> if _s_v . match ( stem ) : <EOL> w = stem + "<STR_LIT:i>" <EOL> m = _step2 . match ( w ) <EOL> if m : <EOL> stem = m . group ( <NUM_LIT:1> ) <EOL> suffix = m . group ( <NUM_LIT:2> ) <EOL> if _mgr0 . match ( stem ) : <EOL> w = stem + _step2list [ suffix ] <EOL> m = _step3 . match ( w ) <EOL> if m : <EOL> stem = m . group ( <NUM_LIT:1> ) <EOL> suffix = m . group ( <NUM_LIT:2> ) <EOL> if _mgr0 . match ( stem ) : <EOL> w = stem + _step3list [ suffix ] <EOL> m = _step4_1 . match ( w ) <EOL> if m : <EOL> stem = m . group ( <NUM_LIT:1> ) <EOL> if _mgr1 . match ( stem ) : <EOL> w = stem <EOL> else : <EOL> m = _step4_2 . match ( w ) <EOL> if m : <EOL> stem = m . group ( <NUM_LIT:1> ) + m . group ( <NUM_LIT:2> ) <EOL> if _mgr1 . match ( stem ) : <EOL> w = stem <EOL> m = _step5 . match ( w ) <EOL> if m : <EOL> stem = m . group ( <NUM_LIT:1> ) <EOL> if _mgr1 . match ( stem ) or ( _meq1 . match ( stem ) and not _c_v . match ( stem ) ) : <EOL> w = stem <EOL> if w . endswith ( "<STR_LIT>" ) and _mgr1 . match ( w ) : <EOL> w = w [ : - <NUM_LIT:1> ] <EOL> if first_is_y : <EOL> w = "<STR_LIT:y>" + w [ <NUM_LIT:1> : ] <EOL> return w <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> print ( stem ( "<STR_LIT>" ) ) </s>
