From: Mart Lubbers Date: Thu, 3 Jul 2014 21:19:31 +0000 (+0200) Subject: Added more sample data and better graph X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=70417b14ad3152e37b54d976c4fc34050566ebb2;p=bsc-thesis1415.git Added more sample data and better graph --- diff --git a/program/regexex/fsm.py b/program/regexex/fsm.py index 2f14fcc..1a24e88 100644 --- a/program/regexex/fsm.py +++ b/program/regexex/fsm.py @@ -23,7 +23,8 @@ class fsm(): # List of nodes number as key, info as value self.nodes = {-1: '#start', -2: '#end'} # List of connection tuples - self.connections = {} +# self.connections = {-2: set()} + self.connections = {-2: list()} # Dictionary of string that are added and have to be integrated self.strings = {} # Dictionary of marking locations in the graph @@ -60,8 +61,10 @@ class fsm(): keys = self.nodes.keys() if check or (node_from in keys and node_to in keys): if node_from not in self.connections: - self.connections[node_from] = set() - self.connections[node_from].add(node_to) +# self.connections[node_from] = set() + self.connections[node_from] = list() +# self.connections[node_from].add(node_to) + self.connections[node_from].append(node_to) else: raise Exception('One or more nodes not found') @@ -151,7 +154,8 @@ class fsm(): if fp != sys.stdout: fp.close() - def travers(self, current, subgraphs, state='none', visited=set()): + def travers(self, current, subgraphs, state='none', visited=set(), + nodestring='{} [label="{}"]', edgestring='{} -> {}'): """Traverse the graph and fill the dictionary for graphviz output Required arguments: @@ -162,13 +166,15 @@ class fsm(): Keyword arguments: state -- current state the traverser is in visited -- set of visited nodes + nodestring-- format string for the node-dot output + edgestring-- format string for the edge-dot output """ - if current != -2 and current not in visited: + if current not in visited: visited.add(current) - subgraphs[state][0].append('{} [label="{}"]'.format( + subgraphs[state][0].append(nodestring.format( current, self.nodes[current])) for c in self.connections[current]: - subgraphs[state][1].append('{} -> {}'.format(current, c)) + subgraphs[state][1].append(edgestring.format(current, c)) for name, markings in self.markings.iteritems(): if markings[0] == c: state = name @@ -187,8 +193,14 @@ if __name__ == '__main__': {'wanneer': (0, 29), 'wat': (33, 39)}) f.add_string('maandag 24 november 2014 20:30 - Fink', {'wanneer': (0, 29), 'wat': (33, 36)}) - f.add_string( - 'maandag 29 december 2014 20:30 - Alain Clark - Locatie: De Duif', - {'wanneer': (0, 29), 'wat': (33, 43), 'waar': (47, 62)}) + f.add_string('maandag 15 september 2014 20:30 - Ani DiFranco', + {'wanneer': (0, 30), 'wat': (34, 45)}) + f.add_string('maandag 13 oktober 2014 20:30 - Tarrus Riley', + {'wanneer': (0, 28), 'wat': (32, 43)}) + f.add_string("""maandag 29 december 2014 20:30 - Alain Clark - Locatie: De\ + Duif""", {'wanneer': (0, 29), 'wat': (33, 43), 'waar': (47, 62)}) + f.add_string("""zondag 26 oktober 2014 21:00 - The Majority Says - Locatie\ +: Bitterzoet""", {'wanneer': (0, 27), 'wat': (31, 47), 'waar': (51, 69)}) + f.optimize() f.graphviz()