Пример #1
0
 def __init__( self, key, pattern, decoder=unicode, maxErrors = 0 ):
     """ Build a line text analyzer.
    
         key: a label to recognized the type of the line trying to be identified.
         pattern: an approximate regular expression pattern to do the identification
         decoder: the constructor to the returned value.  It takes the matching text as argument
         maxErrors: the numbers of errors tolerated in the approximate regular expression
     """
     self.are = ARE( pattern, maxErrors )
     self.key = key
     self.decoder = decoder
Пример #2
0
class LineAnalyzer( object ):
    """ A LineAnalyzer is assumed to recognize substring in a line according to a certain pattern.
    """
    def __init__( self, key, pattern, decoder=unicode, maxErrors = 0 ):
        """ Build a line text analyzer.
       
            key: a label to recognized the type of the line trying to be identified.
            pattern: an approximate regular expression pattern to do the identification
            decoder: the constructor to the returned value.  It takes the matching text as argument
            maxErrors: the numbers of errors tolerated in the approximate regular expression
        """
        self.are = ARE( pattern, maxErrors )
        self.key = key
        self.decoder = decoder
    
    def analyze( self, line ):
        """ If line identify a part of the class detected by Line analyzer, return a tuple of a key descriptior, and the matched part of the line.
            Else return None.
        """
        match = self.are.search( line )
        if match == None:
            return None
        #print '!!!%s!!! %s' %( self.key, match.text )
        return self.key, self.decoder( match.text )