<s> """<STR_LIT>""" <EOL> class PorterStemmer : <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> self . b = "<STR_LIT>" <EOL> self . k = <NUM_LIT:0> <EOL> self . k0 = <NUM_LIT:0> <EOL> self . j = <NUM_LIT:0> <EOL> def cons ( self , i ) : <EOL> """<STR_LIT>""" <EOL> if self . b [ i ] == '<STR_LIT:a>' or self . b [ i ] == '<STR_LIT:e>' or self . b [ i ] == '<STR_LIT:i>' or self . b [ i ] == '<STR_LIT:o>' or self . b [ i ] == '<STR_LIT:u>' : <EOL> return <NUM_LIT:0> <EOL> if self . b [ i ] == '<STR_LIT:y>' : <EOL> if i == self . k0 : <EOL> return <NUM_LIT:1> <EOL> else : <EOL> return ( not self . cons ( i - <NUM_LIT:1> ) ) <EOL> return <NUM_LIT:1> <EOL> def m ( self ) : <EOL> """<STR_LIT>""" <EOL> n = <NUM_LIT:0> <EOL> i = self . k0 <EOL> while <NUM_LIT:1> : <EOL> if i > self . j : <EOL> return n <EOL> if not self . cons ( i ) : <EOL> break <EOL> i = i + <NUM_LIT:1> <EOL> i = i + <NUM_LIT:1> <EOL> while <NUM_LIT:1> : <EOL> while <NUM_LIT:1> : <EOL> if i > self . j : <EOL> return n <EOL> if self . cons ( i ) : <EOL> break <EOL> i = i + <NUM_LIT:1> <EOL> i = i + <NUM_LIT:1> <EOL> n = n + <NUM_LIT:1> <EOL> while <NUM_LIT:1> : <EOL> if i > self . j : <EOL> return n <EOL> if not self . cons ( i ) : <EOL> break <EOL> i = i + <NUM_LIT:1> <EOL> i = i + <NUM_LIT:1> <EOL> def vowelinstem ( self ) : <EOL> """<STR_LIT>""" <EOL> for i in range ( self . k0 , self . j + <NUM_LIT:1> ) : <EOL> if not self . cons ( i ) : <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> def doublec ( self , j ) : <EOL> """<STR_LIT>""" <EOL> if j < ( self . k0 + <NUM_LIT:1> ) : <EOL> return <NUM_LIT:0> <EOL> if ( self . b [ j ] != self . b [ j - <NUM_LIT:1> ] ) : <EOL> return <NUM_LIT:0> <EOL> return self . cons ( j ) <EOL> def cvc ( self , i ) : <EOL> """<STR_LIT>""" <EOL> if i < ( self . k0 + <NUM_LIT:2> ) or not self . cons ( i ) or self . cons ( i - <NUM_LIT:1> ) or not self . cons ( i - <NUM_LIT:2> ) : <EOL> return <NUM_LIT:0> <EOL> ch = self . b [ i ] <EOL> if ch == '<STR_LIT:w>' or ch == '<STR_LIT:x>' or ch == '<STR_LIT:y>' : <EOL> return <NUM_LIT:0> <EOL> return <NUM_LIT:1> <EOL> def ends ( self , s ) : <EOL> """<STR_LIT>""" <EOL> length = len ( s ) <EOL> if s [ length - <NUM_LIT:1> ] != self . b [ self . k ] : <EOL> return <NUM_LIT:0> <EOL> if length > ( self . k - self . k0 + <NUM_LIT:1> ) : <EOL> return <NUM_LIT:0> <EOL> if self . b [ self . k - length + <NUM_LIT:1> : self . k + <NUM_LIT:1> ] != s : <EOL> return <NUM_LIT:0> <EOL> self . j = self . k - length <EOL> return <NUM_LIT:1> <EOL> def setto ( self , s ) : <EOL> """<STR_LIT>""" <EOL> length = len ( s ) <EOL> self . b = self . b [ : self . j + <NUM_LIT:1> ] + s + self . b [ self . j + length + <NUM_LIT:1> : ] <EOL> self . k = self . j + length <EOL> def r ( self , s ) : <EOL> """<STR_LIT>""" <EOL> if self . m ( ) > <NUM_LIT:0> : <EOL> self . setto ( s ) <EOL> def step1ab ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . b [ self . k ] == '<STR_LIT:s>' : <EOL> if self . ends ( "<STR_LIT>" ) : <EOL> self . k = self . k - <NUM_LIT:2> <EOL> elif self . ends ( "<STR_LIT>" ) : <EOL> self . setto ( "<STR_LIT:i>" ) <EOL> elif self . b [ self . k - <NUM_LIT:1> ] != '<STR_LIT:s>' : <EOL> self . k = self . k - <NUM_LIT:1> <EOL> if self . ends ( "<STR_LIT>" ) : <EOL> if self . m ( ) > <NUM_LIT:0> : <EOL> self . k = self . k - <NUM_LIT:1> <EOL> elif ( self . ends ( "<STR_LIT>" ) or self . ends ( "<STR_LIT>" ) ) and self . vowelinstem ( ) : <EOL> self . k = self . j <EOL> if self . ends ( "<STR_LIT>" ) : self . setto ( "<STR_LIT>" ) <EOL> elif self . ends ( "<STR_LIT>" ) : self . setto ( "<STR_LIT>" ) <EOL> elif self . ends ( "<STR_LIT>" ) : self . setto ( "<STR_LIT>" ) <EOL> elif self . doublec ( self . k ) : <EOL> self . k = self . k - <NUM_LIT:1> <EOL> ch = self . b [ self . k ] <EOL> if ch == '<STR_LIT:l>' or ch == '<STR_LIT:s>' or ch == '<STR_LIT:z>' : <EOL> self . k = self . k + <NUM_LIT:1> <EOL> elif ( self . m ( ) == <NUM_LIT:1> and self . cvc ( self . k ) ) : <EOL> self . setto ( "<STR_LIT:e>" ) <EOL> def step1c ( self ) : <EOL> """<STR_LIT>""" <EOL> if ( self . ends ( "<STR_LIT:y>" ) and self . vowelinstem ( ) ) : <EOL> self . b = self . b [ : self . k ] + '<STR_LIT:i>' + self . b [ self . k + <NUM_LIT:1> : ] <EOL> def step2 ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . b [ self . k - <NUM_LIT:1> ] == '<STR_LIT:a>' : <EOL> if self . ends ( "<STR_LIT>" ) : self . r ( "<STR_LIT>" ) <EOL> elif self . ends ( "<STR_LIT>" ) : self . r ( "<STR_LIT>" ) <EOL> elif self . b [ self . k - <NUM_LIT:1> ] == '<STR_LIT:c>' : <EOL> if self . ends ( "<STR_LIT>" ) : self . r ( "<STR_LIT>" ) <EOL> elif self . ends ( "<STR_LIT>" ) : self . r ( "<STR_LIT>" ) <EOL> elif self . b [ self . k - <NUM_LIT:1> ] == '<STR_LIT:e>' : <EOL> if self . ends ( "<STR_LIT>" ) : self . r ( "<STR_LIT>" ) <EOL> elif self . b [ self . k - <NUM_LIT:1> ] == '<STR_LIT:l>' : <EOL> if self . ends ( "<STR_LIT>" ) : self . r ( "<STR_LIT>" ) <EOL> elif self . ends ( "<STR_LIT>" ) : self . r ( "<STR_LIT>" ) <EOL> elif self . ends ( "<STR_LIT>" ) : self . r ( "<STR_LIT>" ) <EOL> elif self . ends ( "<STR_LIT>" ) : self . r ( "<STR_LIT:e>" ) <EOL> elif self . ends ( "<STR_LIT>" ) : self . r ( "<STR_LIT>" ) <EOL> elif self . b [ self . k - <NUM_LIT:1> ] == '<STR_LIT:o>' : <EOL> if self . ends ( "<STR_LIT>" ) : self . r ( "<STR_LIT>" ) <EOL> elif self . ends ( "<STR_LIT>" ) : self . r ( "<STR_LIT>" ) <EOL> elif self . ends ( "<STR_LIT>" ) : self . r ( "<STR_LIT>" ) <EOL> elif self . b [ self . k - <NUM_LIT:1> ] == '<STR_LIT:s>' : <EOL> if self . ends ( "<STR_LIT>" ) : self . r ( "<STR_LIT>" ) <EOL> elif self . ends ( "<STR_LIT>" ) : self . r ( "<STR_LIT>" ) <EOL> elif self . ends ( "<STR_LIT>" ) : self . r ( "<STR_LIT>" ) <EOL> elif self . ends ( "<STR_LIT>" ) : self . r ( "<STR_LIT>" ) <EOL> elif self . b [ self . k - <NUM_LIT:1> ] == '<STR_LIT:t>' : <EOL> if self . ends ( "<STR_LIT>" ) : self . r ( "<STR_LIT>" ) <EOL> elif self . ends ( "<STR_LIT>" ) : self . r ( "<STR_LIT>" ) <EOL> elif self . ends ( "<STR_LIT>" ) : self . r ( "<STR_LIT>" ) <EOL> elif self . b [ self . k - <NUM_LIT:1> ] == '<STR_LIT:g>' : <EOL> if self . ends ( "<STR_LIT>" ) : self . r ( "<STR_LIT>" ) <EOL> def step3 ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . b [ self . k ] == '<STR_LIT:e>' : <EOL> if self . ends ( "<STR_LIT>" ) : self . r ( "<STR_LIT>" ) <EOL> elif self . ends ( "<STR_LIT>" ) : self . r ( "<STR_LIT>" ) <EOL> elif self . ends ( "<STR_LIT>" ) : self . r ( "<STR_LIT>" ) <EOL> elif self . b [ self . k ] == '<STR_LIT:i>' : <EOL> if self . ends ( "<STR_LIT>" ) : self . r ( "<STR_LIT>" ) <EOL> elif self . b [ self . k ] == '<STR_LIT:l>' : <EOL> if self . ends ( "<STR_LIT>" ) : self . r ( "<STR_LIT>" ) <EOL> elif self . ends ( "<STR_LIT>" ) : self . r ( "<STR_LIT>" ) <EOL> elif self . b [ self . k ] == '<STR_LIT:s>' : <EOL> if self . ends ( "<STR_LIT>" ) : self . r ( "<STR_LIT>" ) <EOL> def step4 ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . b [ self . k - <NUM_LIT:1> ] == '<STR_LIT:a>' : <EOL> if self . ends ( "<STR_LIT>" ) : pass <EOL> else : return <EOL> elif self . b [ self . k - <NUM_LIT:1> ] == '<STR_LIT:c>' : <EOL> if self . ends ( "<STR_LIT>" ) : pass <EOL> elif self . ends ( "<STR_LIT>" ) : pass <EOL> else : return <EOL> elif self . b [ self . k - <NUM_LIT:1> ] == '<STR_LIT:e>' : <EOL> if self . ends ( "<STR_LIT>" ) : pass <EOL> else : return <EOL> elif self . b [ self . k - <NUM_LIT:1> ] == '<STR_LIT:i>' : <EOL> if self . ends ( "<STR_LIT>" ) : pass <EOL> else : return <EOL> elif self . b [ self . k - <NUM_LIT:1> ] == '<STR_LIT:l>' : <EOL> if self . ends ( "<STR_LIT>" ) : pass <EOL> elif self . ends ( "<STR_LIT>" ) : pass <EOL> else : return <EOL> elif self . b [ self . k - <NUM_LIT:1> ] == '<STR_LIT:n>' : <EOL> if self . ends ( "<STR_LIT>" ) : pass <EOL> elif self . ends ( "<STR_LIT>" ) : pass <EOL> elif self . ends ( "<STR_LIT>" ) : pass <EOL> elif self . ends ( "<STR_LIT>" ) : pass <EOL> else : return <EOL> elif self . b [ self . k - <NUM_LIT:1> ] == '<STR_LIT:o>' : <EOL> if self . ends ( "<STR_LIT>" ) and ( self . b [ self . j ] == '<STR_LIT:s>' or self . b [ self . j ] == '<STR_LIT:t>' ) : pass <EOL> elif self . ends ( "<STR_LIT>" ) : pass <EOL> else : return <EOL> elif self . b [ self . k - <NUM_LIT:1> ] == '<STR_LIT:s>' : <EOL> if self . ends ( "<STR_LIT>" ) : pass <EOL> else : return <EOL> elif self . b [ self . k - <NUM_LIT:1> ] == '<STR_LIT:t>' : <EOL> if self . ends ( "<STR_LIT>" ) : pass <EOL> elif self . ends ( "<STR_LIT>" ) : pass <EOL> else : return <EOL> elif self . b [ self . k - <NUM_LIT:1> ] == '<STR_LIT:u>' : <EOL> if self . ends ( "<STR_LIT>" ) : pass <EOL> else : return <EOL> elif self . b [ self . k - <NUM_LIT:1> ] == '<STR_LIT:v>' : <EOL> if self . ends ( "<STR_LIT>" ) : pass <EOL> else : return <EOL> elif self . b [ self . k - <NUM_LIT:1> ] == '<STR_LIT:z>' : <EOL> if self . ends ( "<STR_LIT>" ) : pass <EOL> else : return <EOL> else : <EOL> return <EOL> if self . m ( ) > <NUM_LIT:1> : <EOL> self . k = self . j <EOL> def step5 ( self ) : <EOL> """<STR_LIT>""" <EOL> self . j = self . k <EOL> if self . b [ self . k ] == '<STR_LIT:e>' : <EOL> a = self . m ( ) <EOL> if a > <NUM_LIT:1> or ( a == <NUM_LIT:1> and not self . cvc ( self . k - <NUM_LIT:1> ) ) : <EOL> self . k = self . k - <NUM_LIT:1> <EOL> if self . b [ self . k ] == '<STR_LIT:l>' and self . doublec ( self . k ) and self . m ( ) > <NUM_LIT:1> : <EOL> self . k = self . k - <NUM_LIT:1> <EOL> def stem ( self , p , i , j ) : <EOL> """<STR_LIT>""" <EOL> self . b = p <EOL> self . k = j <EOL> self . k0 = i <EOL> if self . k <= self . k0 + <NUM_LIT:1> : <EOL> return self . b <EOL> self . step1ab ( ) <EOL> self . step1c ( ) <EOL> self . step2 ( ) <EOL> self . step3 ( ) <EOL> self . step4 ( ) <EOL> self . step5 ( ) <EOL> return self . b [ self . k0 : self . k + <NUM_LIT:1> ] <EOL> class Singleton : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . p = PorterStemmer ( ) <EOL> def __call__ ( self , s ) : <EOL> return self . p . stem ( s , <NUM_LIT:0> , len ( s ) - <NUM_LIT:1> ) <EOL> stem = Singleton ( ) </s>
