Exemple #1
0
 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)
Exemple #2
0
 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)
Exemple #3
0
 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)
Exemple #4
0
    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
Exemple #5
0
 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)
Exemple #6
0
 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)
Exemple #7
0
 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)
Exemple #8
0
 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)
Exemple #9
0
 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)
Exemple #10
0
 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)
Exemple #11
0
 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)