示例#1
0
 def test_overlap(self):
     m = TaggedFragments(UNICODE)
     m.append(Character([('b', 'd')], UNICODE), 'bd')
     m.append(Character([('c', 'e')], UNICODE), 'ce')
     l = list(m)
     assert l == [(('b', 'b'), ['bd']), (('c', 'd'), ['bd', 'ce']),
                  (('e', 'e'), ['ce'])], l
示例#2
0
文件: interval.py 项目: sunaaron/lepl
 def test_overlap(self):
     m = TaggedFragments(UNICODE)
     m.append(Character([('b', 'd')], UNICODE), 'bd')
     m.append(Character([('c', 'e')], UNICODE), 'ce')
     l = list(m)
     assert l == [(('b', 'b'), ['bd']), (('c', 'd'), ['bd', 'ce']),
                  (('e', 'e'), ['ce'])], l
示例#3
0
文件: core.py 项目: cajus/python-lepl
 def __fragment_transitions(self, nfa_nodes):
     '''
     From the given nodes we can accumulate the destination nodes and
     terminals associated with each transition (edge/character).
     At the same time we separate the character matches into non-overlapping 
     fragments.
     '''
     fragments = TaggedFragments(self.__alphabet)
     for nfa_node in nfa_nodes:
         for (dest, edge) in self.__nfa.transitions(nfa_node):
             (nodes, terminals) = self.__nfa.connected([dest])
             fragments.append(edge, (nodes, list(terminals)))
     return fragments
示例#4
0
 def __fragment_transitions(self, nfa_nodes):
     '''
     From the given nodes we can accumulate the destination nodes and
     terminals associated with each transition (edge/character).
     At the same time we separate the character matches into non-overlapping 
     fragments.
     '''
     fragments = TaggedFragments(self.__alphabet)
     for nfa_node in nfa_nodes:
         for (dest, edge) in self.__nfa.transitions(nfa_node):
             (nodes, terminals) = self.__nfa.connected([dest])
             fragments.append(edge, (nodes, list(terminals)))
     return fragments
示例#5
0
文件: core.py 项目: cajus/python-lepl
 def __build_table(self):
     '''
     Rewrite the graph as a transition table, with appropriate ordering.
     '''
     for src in self.__graph:
         # construct an interval map of possible destinations and terminals
         # given a character
         fragments = TaggedFragments(self.__alphabet)
         for (dest, char) in self.__graph.transitions(src):
             fragments.append(char, (dest, self.__graph.terminal(dest)))
         map_ = IntervalMap()
         for (interval, dts) in fragments:
             map_[interval] = dts
         # collect empty transitions
         empties = [(dest, self.__graph.terminal(dest))
                    # ordering here is reverse of what is required, which
                    # is ok because we use empties[-1] below
                    for dest in sorted(self.__graph.empty_transitions(src))]
         self.__table[src] = (map_, empties)
示例#6
0
 def __build_table(self):
     '''
     Rewrite the graph as a transition table, with appropriate ordering.
     '''
     for src in self.__graph:
         # construct an interval map of possible destinations and terminals
         # given a character
         fragments = TaggedFragments(self.__alphabet)
         for (dest, char) in self.__graph.transitions(src):
             fragments.append(char, (dest, self.__graph.terminal(dest)))
         map_ = IntervalMap()
         for (interval, dts) in fragments:
             map_[interval] = dts
         # collect empty transitions
         empties = [
             (dest, self.__graph.terminal(dest))
             # ordering here is reverse of what is required, which
             # is ok because we use empties[-1] below
             for dest in sorted(self.__graph.empty_transitions(src))
         ]
         self.__table[src] = (map_, empties)
示例#7
0
 def test_single(self):
     m = TaggedFragments(UNICODE)
     m.append(Character([('b', 'c')], UNICODE), 'bc')
     l = list(m)
     assert l == [(('b', 'c'), ['bc'])], l
示例#8
0
 def test_single(self):
     m = TaggedFragments(UNICODE)
     m.append(Character([('b', 'c')], UNICODE), 'bc')
     l = list(m)
     assert l == [(('b', 'c'), ['bc'])], l
示例#9
0
文件: interval.py 项目: sunaaron/lepl
 def test_overlap(self):
     m = TaggedFragments(UNICODE)
     m.append(Character([("b", "d")], UNICODE), "bd")
     m.append(Character([("c", "e")], UNICODE), "ce")
     l = list(m)
     assert l == [(("b", "b"), ["bd"]), (("c", "d"), ["bd", "ce"]), (("e", "e"), ["ce"])], l
示例#10
0
文件: interval.py 项目: sunaaron/lepl
 def test_single(self):
     m = TaggedFragments(UNICODE)
     m.append(Character([("b", "c")], UNICODE), "bc")
     l = list(m)
     assert l == [(("b", "c"), ["bc"])], l