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
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
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)
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)
def test_single(self): m = TaggedFragments(UNICODE) m.append(Character([('b', 'c')], UNICODE), 'bc') l = list(m) assert l == [(('b', 'c'), ['bc'])], l
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
def test_single(self): m = TaggedFragments(UNICODE) m.append(Character([("b", "c")], UNICODE), "bc") l = list(m) assert l == [(("b", "c"), ["bc"])], l