def test_search2(self): tab = self.a + self.b + self.a regex = tab + self.b * 3 + tab strregex = re.compile("ababbbaba") m = refo.search(regex, self.seq) strm = strregex.search(self.string) self._eq_span_n_stuff(m, strm)
def test_search3(self): tab = self.a + self.b regex = tab + tab + refo.Plus(self.b) strregex = re.compile("ababb+") m = refo.search(regex, self.seq) strm = strregex.search(self.string) self._eq_span_n_stuff(m, strm)
def test_search5(self): tab = self.a + self.b regex = tab * (2, 5) strregex = re.compile("(?:ab){2,5}") m = refo.search(regex, self.seq) strm = strregex.search(self.string) self._eq_span_n_stuff(m, strm)
def match(sentence, template): regex = template['regex'] slot_list = template['slot_list'] m = refo.search(regex, sentence) if m is None: return False, arguments = {} for slot in slot_list: m_span = m.span(slot) arguments[slot] = sentence[m_span[0]:m_span[1]] # 打分 score = 0 slots_score = template['slot_score'] any_slots = list(slots_score.keys()) for any_slot in any_slots: scores_for_slot = slots_score[any_slot] m_span = m.span(any_slot) matched_words = sentence[m_span[0]:m_span[1]] for keyword in scores_for_slot.keys(): if keyword in matched_words: score += scores_for_slot[keyword] return True, arguments, score
def test_search4(self): tab = self.a + self.b regex = tab * 2 + refo.Plus(self.b, greedy=False) strregex = re.compile("ababb+?") m = refo.search(regex, self.seq) strm = strregex.search(self.string) self._eq_span_n_stuff(m, strm)
def test_search1(self): regex = self.a + self.b + self.b + self.b + self.a strregex = re.compile("abbba") m = refo.search(regex, self.seq) strm = strregex.search(self.string) self._eq_span_n_stuff(m, strm)