# 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
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')
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:
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
{'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()