def distance(source_value, reference_value, task=None, **kw): threshold = float(task.get('threshold', 0.2)) source_value_norm = text.normalize_plain(source_value) reference_value_norm = text.normalize_plain(reference_value) length = max([len(source_value_norm), len(reference_value_norm)]) max_distance = int(length * threshold) + 1 #print [max_distance] return Levenshtein.distance(reference_value_norm, source_value_norm) \ < max_distance
def contains(source_value, reference_value, **kw): source_value_norm = text.normalize_plain(source_value) reference_value_norm = text.normalize_plain(reference_value) return reference_value_norm in source_value_norm