Commit 24050044 authored by Mathias Haage's avatar Mathias Haage
Browse files

Update conversion to jgrafchart

parent 0f4d8a53
#!/usr/bin/python
import sys
def uuri2dot(uuri):
return "n_%s"%(uuri.replace("http://node/", "").replace("-", "_"),)
def dot2uuri(dot):
return ("http://node/"%(dot[2:],)).replace("_", "-")
def dot2only_uuri(dot):
return dot[2:].replace("_", "-")
if __name__ == "__main__":
f_sfc_from_kif = sys.argv[1]
f_dot_plain = sys.argv[2]
f = open(f_sfc_from_kif)
rdf = []
for line in f:
split = line.strip().split(',')
subject = split[0]
predicate = split[1]
object = ','.join(split[2:])
rdf = rdf + [(subject,predicate,object)]
f.close()
f = open(f_dot_plain)
plain = []
for line in f:
plain = plain + [line.strip().split(' ')]
f.close()
print('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>')
print('<GCDocument color="-1" dimTicks="25" dpwsInterface="" dpwsPort="-1" height="1609" horizontalScrollBar="1" modifiable="1" name="appname" saveVersion="8" scale="1.0" simulationMode="1" socketHost="localhost" socketIsServer="0" socketPort="4242" socketSendMode="Changed" threadSpeed="40" tokenLuminance="0" verticalScrollBar="1" viewPositionX="0" viewPositionY="0" width="1223" x="0" y="0">')
uuid2width = {}
for x in rdf:
obj = x[2]
if obj == 'http://sfc/output':
node = uuri2dot(x[0])
for y in plain:
if y[0] == 'node':
if y[1] == node:
plain_node = y
for y in rdf:
subj = y[0]
if subj == x[0]:
if y[1] == 'http://type':
type = y[2]
if y[1] == 'http://name':
name = y[2]
id = dot2only_uuri(node)
n = name
x = str(int(float(plain_node[2])*100))
y = str(int(float(plain_node[3])*100))
w = str(int(float(plain_node[4])*100))
h = str(int(float(plain_node[5])*100))
print('<SocketStringOut height="%s" identifier="%s" name="%s" procelmode="0" sendMode="Assigned" value="" width="%s" x="%s" y="%s"/>'%(h,n,n,w,x,y))
for x in rdf:
obj = x[2]
if obj == 'http://sfc/input':
node = uuri2dot(x[0])
for y in plain:
if y[0] == 'node':
if y[1] == node:
plain_node = y
for y in rdf:
subj = y[0]
if subj == x[0]:
if y[1] == 'http://type':
type = y[2]
if y[1] == 'http://name':
name = y[2]
id = dot2only_uuri(node)
n = name
x = str(int(float(plain_node[2])*100))
y = str(int(float(plain_node[3])*100))
w = str(int(float(plain_node[4])*100))
h = str(int(float(plain_node[5])*100))
print('<SocketStringIn height="%s" identifier="%s" name="%s" value="" width="%s" x="%s" y="%s"/>'%(h,n,n,w,x,y))
for x in rdf:
obj = x[2]
if obj == 'http://sfc/startstate':
node = uuri2dot(x[0])
for y in plain:
if y[0] == 'node':
if y[1] == node:
plain_node = y
n = dot2only_uuri(node)
x = str(int(float(plain_node[2])*100))
y = str(int(float(plain_node[3])*100))
w = str(int(float(plain_node[4])*100))
h = str(int(float(plain_node[5])*100))
uuid2width[n] = w
#<GCInitialStep actionBlockVisible="0" actionText=";" fileName="" height="70" id="4fdaafac-9028-4a0e-92aa-86fe0af72229" name="a" useIcon="0" width="60" x="210" y="65"/>
print('<GCInitialStep actionBlockVisible="0" actionText=";" fileName="" height="%s" id="%s" name="start" useIcon="0" width="%s" x="%s" y="%s"/>'%(h,n,w,x,y))
for x in rdf:
obj = x[2]
if obj == 'http://sfc/state':
node = uuri2dot(x[0])
for y in plain:
if y[0] == 'node':
if y[1] == node:
plain_node = y
for y in rdf:
subj = y[0]
if subj == x[0]:
if y[1] == 'http://action':
action = y[2]
if y[1] == 'http://description':
name = y[2]
id = dot2only_uuri(node)
n = name
a = 's Output=&quot;%s&quot;;'%(action,)
x = str(int(float(plain_node[2])*100))
y = str(int(float(plain_node[3])*100))
w = str(int(float(plain_node[4])*100))
h = str(int(float(plain_node[5])*100))
uuid2width[id] = w
print('<GCStep actionBlockVisible="0" actionText="%s" fileName="" height="%s" id="%s" name="%s" useIcon="0" width="%s" x="%s" y="%s"/>'%(a,h,id,n,w,x,y))
for x in rdf:
obj = x[2]
if obj == 'http://sfc/transition':
node = uuri2dot(x[0])
for y in plain:
if y[0] == 'node':
if y[1] == node:
plain_node = y
for y in plain:
if y[0] == 'edge':
if y[1] == plain_node[1]:
from_plain = y
if y[2] == plain_node[1]:
to_plain = y
for y in rdf:
subj = y[0]
if subj == x[0]:
if y[1] == 'http://name':
name = y[2]
if y[1] == 'http://condition':
cond = y[2]
if y[1] == 'http://from':
from_node = y[2]
if y[1] == 'http://to':
to_node = y[2]
id = dot2only_uuri(node)
n = name
c = cond
x = str(int(float(plain_node[2])*100))
y = str(int(float(plain_node[3])*100))
w = str(int(float(plain_node[4])*100))
h = str(int(float(plain_node[5])*100))
f = dot2only_uuri(uuri2dot(from_node))
t = dot2only_uuri(uuri2dot(to_node))
print('<GCTransition actionText="%s" conditionVisible="1" height="%s" id="%s" width="%s" x="%s" y="%s"/>'%(c,h,id,w,x,y))
print('<GCLink fromObject="%s" manAdj="0" toObject="%s">'%(f,id))
n = int(from_plain[3])
for i in range(n):
j = 4 + 2*i
x = str(int(float(from_plain[j])*100 + float(uuid2width[f])/2))
y = str(int(float(from_plain[j+1])*100))
print('<Stroke x="%s" y="%s"/>'%(x,y))
print('</GCLink>')
print('<GCLink fromObject="%s" manAdj="0" toObject="%s">'%(id,t))
n = int(to_plain[3])
for i in range(n):
j = 4 + 2*i
x = str(int(float(to_plain[j])*100 + float(uuid2width[t])/2))
y = str(int(float(to_plain[j+1])*100))
print('<Stroke x="%s" y="%s"/>'%(x,y))
print('</GCLink>')
print('</GCDocument>')
#!/usr/bin/python
import sys
def uuri2dot(uuri):
return "n_%s"%(uuri.replace("http://node/", "").replace("-", "_"),)
if __name__ == "__main__":
f_sfc_from_kif = sys.argv[1]
f = open(f_sfc_from_kif)
rdf = []
for line in f:
rdf = rdf + [line.strip().split(',')]
f.close()
print("digraph statemachine {")
#print("splines=ortho;")
for triplett in rdf:
subject = triplett[0]
object = triplett[2]
if object == 'http://sfc/startstate':
print(uuri2dot("%s [shape=box];"%(subject,)))
if object == 'http://sfc/state':
print(uuri2dot("%s [shape=box];"%(subject,)))
if object == 'http://sfc/input':
print(uuri2dot("%s [shape=box];"%(subject,)))
if object == 'http://sfc/output':
print(uuri2dot("%s [shape=box];"%(subject,)))
if object == 'http://sfc/transition':
print(uuri2dot("%s [shape=box];"%(subject,)))
for triplett in rdf:
subject = triplett[0]
object = triplett[2]
if object == 'http://sfc/transition':
for t in rdf:
s = t[0]
p = t[1]
o = t[2]
if s == subject:
if p == 'http://from':
from_node = uuri2dot(o)
if p == 'http://to':
to_node = uuri2dot(o)
node = uuri2dot(subject)
print("%s->%s;"%(from_node,node))
print("%s->%s;"%(node,to_node))
print("}")
#!/bin/bash
USAGE="Usage: %s rdf\n"
if [ "$#" -ne 1 ]; then
printf "$USAGE" $0
exit 1
fi
RDF=$1
GV=$RDF.gv
PLAIN=$GV.plain
PNG=$GV.png
sfc2dot $RDF >$GV
dot -Tplain $GV >$PLAIN
dot -Tpng $GV >$PNG
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment