presidio-analyzer/analyzer/matcher.py
def __check_pattern(self, doc, results, field):
        """Check for specific pattern in text

        Args:
          doc: spacy document to analyze
          results: array containing the created results
          field: current field type (pattern)
        """

        max_matched_strength = -1.0
        for pattern in field.patterns:
            if pattern.strength <= max_matched_strength:
                break
            result_found = False

            match_start_time = datetime.datetime.now()
            matches = re.finditer(
                pattern.regex,
                doc.text,
                flags=re.IGNORECASE | re.DOTALL | re.MULTILINE)
            match_time = datetime.datetime.now() - match_start_time
            self.logger.debug('--- match_time[{}]: {}.{} seconds'.format(
                field.name, match_time.seconds, match_time.microseconds))

            for match in matches:
                start, end = match.span()
                field.text = doc.text[start:end]

                # Skip empty results
                if field.text == '':
                    continue

                # Don't add duplicate
                if len(field.patterns) > 1 and any(
                    ((x.location.start == start) or (x.location.end == end))
                        and ((x.field.name == field.name)) for x in results):
                    continue

                res = self.__create_result(doc, pattern.strength, field, start,
                                           end)

                if res is None or res.score == 0:
                    continue

                # Don't add overlap
                # if any(x.location.end >= start and x.score == 1.0
                #        for x in results):
                #     continue

                results.append(res)
                result_found = True

            if result_found:
                max_matched_strength = pattern.strength
Check for specific pattern in text

        Args:
          doc: spacy document to analyze
          results: array containing the created results
          field: current field type (pattern)
        
Check for specific pattern in text
Check for specific pattern in text
def __check_pattern(self, doc, results, field):
        max_matched_strength = -1.0
        for pattern in field.patterns:
            if pattern.strength <= max_matched_strength:
                break
            result_found = False
            match_start_time = datetime.datetime.now()
            matches = re.finditer(
                pattern.regex,
                doc.text,
                flags=re.IGNORECASE | re.DOTALL | re.MULTILINE)
            match_time = datetime.datetime.now() - match_start_time
            self.logger.debug('--- match_time[{}]: {}.{} seconds'.format(
                field.name, match_time.seconds, match_time.microseconds))
            for match in matches:
                start, end = match.span()
                field.text = doc.text[start:end]
                if field.text == '':
                    continue
                if len(field.patterns) > 1 and any(
                    ((x.location.start == start) or (x.location.end == end))
                        and ((x.field.name == field.name)) for x in results):
                    continue
                res = self.__create_result(doc, pattern.strength, field, start,
                                           end)
                if res is None or res.score == 0:
                    continue
                results.append(res)
                result_found = True
            if result_found:
                max_matched_strength = pattern.strength
def __check_pattern ( self , doc , results , field ) : max_matched_strength = - 1.0 for pattern in field . patterns : if pattern . strength <= max_matched_strength : break result_found = False match_start_time = datetime . datetime . now ( ) matches = re . finditer ( pattern . regex , doc . text , flags = re . IGNORECASE | re . DOTALL | re . MULTILINE ) match_time = datetime . datetime . now ( ) - match_start_time self . logger . debug ( '--- match_time[{}]: {}.{} seconds' . format ( field . name , match_time . seconds , match_time . microseconds ) ) for match in matches : start , end = match . span ( ) field . text = doc . text [ start : end ] if field . text == '' : continue if len ( field . patterns ) > 1 and any ( ( ( x . location . start == start ) or ( x . location . end == end ) ) and ( ( x . field . name == field . name ) ) for x in results ) : continue res = self . __create_result ( doc , pattern . strength , field , start , end ) if res is None or res . score == 0 : continue results . append ( res ) result_found = True if result_found : max_matched_strength = pattern . strength
Check for specific pattern in text
Check for specific pattern in text
"""Check for specific pattern in text

        Args:
          doc: spacy document to analyze
          results: array containing the created results
          field: current field type (pattern)
        """ # Skip empty results # Don't add duplicate # Don't add overlap # if any(x.location.end >= start and x.score == 1.0 #        for x in results): #     continue
self
doc
spacy document to analyze
spacy document to analyze
results
array containing the created results
array containing the created results
field
current field type (pattern)
current field type ( pattern )