def template_match(template1: Template, template2: Template): """ Compare two lists of strings :param template1: first template :param template2: second template :return: True if template1 is a "sub-set" of template2 False if two lists are different """ if template1.get_length() != template2.get_length(): return False for index in range(0, template1.get_length()): if template2.token[index] == "*": continue if template1.token[index] != template2.token[index]: return False return True
def add_template(self, template: Template): """ Adds a template to the chromosome :param template: an object of type Template :return: the template will be added to the corresponding cluster with key = len(template) """ key = template.get_length() if key in self.templates.keys(): self.templates[key].append(template) else: self.templates[key] = [] self.templates[key].append(template)
def match(message: Message, template: Template): """ Compare two lists of strings :param message: a message from the log file :param template: a template from the chromosome :return: True if two list are equal False if two lists are different """ for index in range(0, template.get_length()): if template.token[index] == "*" or template.token[index] == "#spec#": continue if template.token[index] != message.words[index]: return False return True
def compute_matched_lines(messages: dict, template: Template): # if the templates has not be changed # we don't need to recompute the list of matched lines if not template.is_changed(): return # Otherwise, we recompute the list of matched lines template.matched_lines = [] cluster_id = template.get_length() for index in range(0, len(messages[cluster_id])): message = messages[cluster_id][index] if match(message, template): template.matched_lines.append(index) # Now the template has to be set as NOT CHANGED template.set_changed(False)
def delete_template(self, template: Template): """ Deletes the template from the given cluster id :param index: cluster id :return the cluster without the template :raises IndexError: An error occurs if a negative cluster id is provided or if the cluster id doesn't exist """ key = template.get_length() if key not in self.templates: raise IndexError("No cluster with the giving id!") self.templates[key].remove(template)