def consume(self, message, role):
        """ Save message, find template and update model state """
        status = STATUS_NO_TRANSITION

        if not(self.mm.getState().endswith("END")):
            # Find matching template for the other side
            next_states = self.mm.get_next_states(role)
            if next_states:
                (template, fields) = self.tl.find_template(next_states, message)
            else:
                # TODO in some cases, next_states is null because only
                # a transition with a message from the other side is possible.
                # By using the role of the otherside and forcing a transition
                # by similarity search the exploration of the model is not blocked.
                if role == self.role:
                    other_role = self.otherside
                else:
                    other_role = self.role
                next_states = self.mm.get_next_states(other_role)
                template = None

            # if similarity search is active, the closest template to the
            # received message is selected.
            if self.similarity_search:
                if template is not None:
                    self.sim_matched_template = False
                    print ">>> EXACT MATCHED TEMPLATE: {}".format(template.ID)
                elif template is None:
                    try:
                        next_OFS_states = []
                        for state in self.mm.get_next_states(role):
                            if self.mm.get_subtree_weight_OFS(self,
                                                              state) > 0:
                                next_OFS_states += [state]
                            if not next_OFS_states:
                                next_OFS_states = self.mm.get_next_states(role)
                        (template, fields) = self.tl.find_similar_template(next_OFS_states,
                                                                           message)
                    except __HOLE__:
                        (template, fields) = (None, None)
                        status = STATUS_END
                    if template is not None:
                        self.sim_matched_template = True
                        print ">>> SIMILARITY MATCHED TEMPLATE: {}".format(template.ID)

            # wether an exact or a similar matching has been found,
            # the templates and fields are added to the ringBuffer
            # and the state in the model is updated
            if template is not None:
                self.templates.append(template)
                self.fields.append(fields)
                self.mm.update_state(template.state)
                print ">>> TRANSITION TO STATE: {}".format(self.mm.state)
                if template.state.endswith("END"):
                    status = STATUS_END
                else:
                    status = STATUS_OK
            else:
                # Only possible if similarity matching is deactivated or STATUS_END
                if status == STATUS_END:
                    print ">>> END STATE REACHED."
                else:
                    print ">>> CAN'T MATCH MESSAGE TO TEMPLATE!"
        else:
            status = STATUS_END
        return status
dataset/ETHPy150Open hgascon/pulsar/pulsar/core/lens.py/Lens.consume