-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_graph.py
61 lines (60 loc) · 2.8 KB
/
make_graph.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
##########################################################################
# #
# cwb2dot #
# Copyright (C) 2019 Tobia Tesan #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
# #
##########################################################################
from process import *
from misc import *
from ccs import *
from graph import *
def make_graph(processname, processes, weak=False, normalization=True):
# normalization = True makes examples/boom.cwb collapse into agent
# BOOM = 'ping.BOOM --i.e. [pong/ping] is ignored since pong is
# not in the actions for boom.
debug_out("Graphing for " + processname)
p = KProcess(processname)
visited = dict()
traversal = list()
import queue
q = queue.Queue()
q.put(p)
visited[p] = Node(p, set())
g = visited[p]
edges = 0
while (not q.empty()):
p = q.get()
debug_out ("Visiting " + str(p))
if (normalization == True):
p = normalize(p, processes)
debug_out ("Normalizes to " + str(p))
if (weak):
acs = weak_transitions(p, processes)
else:
acs = transitions(p, processes)
debug_out ("Has transitions " + str(acs))
for transition in acs:
act, proc = (transition.a, transition.p)
if (normalization == True):
proc = normalize(proc, processes)
if(proc not in visited.keys()):
debug_out(str(proc) + " not in " + str(visited.keys()))
visited[proc] = Node(proc, set())
q.put(proc)
visited[p].e.add(Edge(act, visited[proc]))
edges += 1
debug_out ("Made ", edges, " edges")
return g