def filter_hits_by_distance(hits, source_text, min_similarity=DEFAULT_MIN_SIMILARITY):
 if ((min_similarity <= 0) or (min_similarity >= 1)):
  min_similarity = DEFAULT_MIN_SIMILARITY
 filtered_hits = []
 for hit in hits:
  hit_source_text = hit['_source']['source']
  distance = Levenshtein.distance(source_text, hit_source_text)
  similarity = (1 - (distance / float(max(len(source_text), len(hit_source_text)))))
  logger.debug('Similarity: %.2f (distance: %d)\nOriginal: DCTB %s\nComparing with: DCTB %s', similarity, distance, source_text, hit_source_text)
  if (similarity < min_similarity):
   break
  filtered_hits.append(hit)
 return filtered_hits

def filter_hits_by_distance ( hits , source_text , min_similarity = DEFAULT_MIN_SIMILARITY ) : if ( ( min_similarity <= 0 ) or ( min_similarity >= 1 ) ) : min_similarity = DEFAULT_MIN_SIMILARITY filtered_hits = [ ] for hit in hits : hit_source_text = hit [ '_source' ] [ 'source' ] distance = Levenshtein . distance ( source_text , hit_source_text ) similarity = ( 1 - ( distance / float ( max ( len ( source_text ) , len ( hit_source_text ) ) ) ) ) logger . debug ( 'Similarity: %.2f (distance: %d)\nOriginal: DCTB %s\nComparing with: DCTB %s' , similarity , distance , source_text , hit_source_text ) if ( similarity < min_similarity ) : break filtered_hits . append ( hit ) return filtered_hits
returns es hits filtered according to their levenshtein distance to the source_text .