presidio-analyzer/analyzer/matcher.py
def __calculate_score(self, doc, match_strength, field, start, end):
        """Calculate score of match by context

        Args:
          doc: spacy document to analyze
          match_strength: Base score according to the pattern strength
          field: current field type (pattern)
          start: match start offset
          end: match end offset
        """

        if field.should_check_checksum:
            if field.check_checksum() is not True:
                self.logger.debug('Checksum failed for %s', field.text)
                return 0
            else:
                return 1.0

        score = match_strength

        # Add context similarity
        context = self.__extract_context(doc, start, end)
        context_similarity = self.__calculate_context_similarity(
            context, field)
        if context_similarity >= CONTEXT_SIMILARITY_THRESHOLD:
            score += context_similarity * CONTEXT_SIMILARITY_FACTOR
            score = max(score, MIN_SCORE_WITH_CONTEXT_SIMILARITY)

        return min(score, 1)
Calculate score of match by context

        Args:
          doc: spacy document to analyze
          match_strength: Base score according to the pattern strength
          field: current field type (pattern)
          start: match start offset
          end: match end offset
        
Calculate score of match by context
Calculate score of match by context
def __calculate_score(self, doc, match_strength, field, start, end):
        if field.should_check_checksum:
            if field.check_checksum() is not True:
                self.logger.debug('Checksum failed for %s', field.text)
                return 0
            else:
                return 1.0
        score = match_strength
        context = self.__extract_context(doc, start, end)
        context_similarity = self.__calculate_context_similarity(
            context, field)
        if context_similarity >= CONTEXT_SIMILARITY_THRESHOLD:
            score += context_similarity * CONTEXT_SIMILARITY_FACTOR
            score = max(score, MIN_SCORE_WITH_CONTEXT_SIMILARITY)
        return min(score, 1)
def __calculate_score ( self , doc , match_strength , field , start , end ) : if field . should_check_checksum : if field . check_checksum ( ) is not True : self . logger . debug ( 'Checksum failed for %s' , field . text ) return 0 else : return 1.0 score = match_strength context = self . __extract_context ( doc , start , end ) context_similarity = self . __calculate_context_similarity ( context , field ) if context_similarity >= CONTEXT_SIMILARITY_THRESHOLD : score += context_similarity * CONTEXT_SIMILARITY_FACTOR score = max ( score , MIN_SCORE_WITH_CONTEXT_SIMILARITY ) return min ( score , 1 )
Calculate score of match by context
Calculate score of match by context
"""Calculate score of match by context

        Args:
          doc: spacy document to analyze
          match_strength: Base score according to the pattern strength
          field: current field type (pattern)
          start: match start offset
          end: match end offset
        """ # Add context similarity
self
doc
spacy document to analyze
spacy document to analyze
match_strength
Base score according to the pattern strength
Base score according to the pattern strength
field
current field type (pattern)
current field type ( pattern )
start
match start offset
match start offset
end
match end offset
match end offset