def get_patterns(words): patterns = Counter() words_combinations = itertools.combinations(words, 2) for word1, word2 in words_combinations: pattern, _ = patternize.find_pattern((word1, word2)) if pattern: pattern = Pattern(pattern) patterns[pattern] += 1 return patterns
def __add__(self, other): pattern = self.pattern other_pattern = other.pattern # if pattern[0] == '^' and other_pattern[0] != '^': # pattern = pattern[1:] # elif other_pattern[0] == '^' and pattern[0] != '^': # other_pattern = other_pattern[1:] # # # if pattern[-1] == '$' and other_pattern[-1] != '$': # pattern = pattern[:-1] # elif other_pattern[-1] == '$' and pattern[-1] != '$': # other_pattern = other_pattern[:-1] combined_pattern = patternize.find_pattern( (pattern, other_pattern))[0] if combined_pattern: return Pattern(combined_pattern) else: return None