cpee-transformation 1.0.7 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 05ee4c81d220cd2715128abc5300b30d1b2d67f6fc77917b192f8df72a70b829
4
- data.tar.gz: 0dcab077fda611e0df946cf4161b1676e344126c0246067cc74961ace701938f
3
+ metadata.gz: 6511a19521470370c2ab83b0434cff42b5690cfee3fa081cd7db01567a11441f
4
+ data.tar.gz: '0811bb24cf24e6a6a8f594a4a21e2d05e36de3ee7e266c5175c2e9940225e434'
5
5
  SHA512:
6
- metadata.gz: 7ce23a76f587df201178a0c309ebb878b5129a6f2947aa68e53b8ea4d868483271c94d75b2051d04757b10136b247c0cc7788f512dd3cc597f5348516a4e7547
7
- data.tar.gz: ba6ba74143c9bb60e63c88985a4c8f8d53fe58595da55d2d7331c91d08b0c6688e483a8aad0304837157f3fc72e5f4a008b586395449b567f261ba65fc071e5d
6
+ metadata.gz: c0e038139f024a80c0b84f39047bbf63be391644873dd966abf0ab253377bae48a8ea3be8319bd72ac20dd241556774354e5c0b538d0fad10ad3376396004151
7
+ data.tar.gz: f1e1dd5f77be6a13064045bc2276b70c9e95af9b9850de09077da28404252c76e44d4781a2d75479e80692ada31a9509cbee0cca7374780734ce75c0e9cd933b
data/README.md CHANGED
@@ -35,6 +35,8 @@ name/value pairs, from BPMN2 sources only).
35
35
  | `/bpmn2/graphviz` | graphviz | BPMN2 |
36
36
  | `/mermaid/cpee` | CPEE | mermaid |
37
37
  | `/graphviz/cpee` | CPEE | graphviz |
38
+ | `/pnml/cpee` | CPEE | PNML |
39
+ | `/pnml-with-lifecycle/cpee` | CPEE | PNML, calling/receiving/done |
38
40
  | `/text-bf/cpee` | CPEE | text, text-bf |
39
41
  | `/text-df-PO-extended/cpee` | CPEE | text, text-df-PO-extended |
40
42
  | `/text-df-PO-reduced/cpee` | CPEE | text, text-df-PO-reduced |
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cpee-transformation"
3
- s.version = "1.0.7"
3
+ s.version = "1.1.0"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.license = "LGPL-3.0-or-later"
6
6
  s.summary = "CPEE Transformation between different formats"
@@ -53,7 +53,7 @@ module CPEE
53
53
  def map_nodes(shape,label)
54
54
  case [shape,label]
55
55
  in ['box' | 'rect' | 'rectangle', _]; :task
56
- in ['component', _]; :scriptTask
56
+ in ['record' | 'Mrecord', _]; :scriptTask
57
57
  in ['diamond', 'AND' | 'and' | '+']; :parallelGateway
58
58
  in ['diamond', 'X' | 'x']; :exclusiveGateway
59
59
  in ['diamond', '*']; :eventBasedGateway
@@ -73,11 +73,29 @@ module CPEE
73
73
  end #}}}
74
74
  private :unescape
75
75
 
76
+ def record_fields(raw) #{{{
77
+ raw = raw.strip
78
+ raw = raw[1..-2] if raw.start_with?('{') && raw =~ /(?<!\\)\}\z/
79
+ fields = ['']
80
+ raw.scan(/\\.|./m) do |c|
81
+ c == '|' ? fields << '' : fields.last << c
82
+ end
83
+ fields.map { |f| unescape(f.sub(/\A\s*<[^>]*>/,'')).strip }
84
+ end #}}}
85
+ private :record_fields
86
+
87
+ def record_label(raw) #{{{
88
+ fields = record_fields(raw)
89
+ fields.shift if fields.length > 1 && fields.first == 'S'
90
+ fields.join(' | ')
91
+ end #}}}
92
+ private :record_label
93
+
76
94
  ### key=value or key="value" pairs of an attribute list [...]
77
95
  def attributes(text) #{{{
78
96
  ret = {}
79
97
  text.to_s.scan(/(\w+)\s*=\s*(?:#{GRAPHVIZ_STRING}|([^\s,;\]]+))/) do |k,q,v|
80
- ret[k] = q.nil? ? v : unescape(q)
98
+ ret[k] = q.nil? ? v : q
81
99
  end
82
100
  ret
83
101
  end #}}}
@@ -88,13 +106,19 @@ module CPEE
88
106
  links = []
89
107
  text.each_line do |line|
90
108
  if line =~ /^\s*#{GRAPHVIZ_STRING}\s*->\s*#{GRAPHVIZ_STRING}\s*(\[(.*)\])?\s*;?\s*$/
91
- links << [unescape($1), unescape($2), attributes($4)['label']]
109
+ links << [unescape($1), unescape($2), unescape(attributes($4)['label'])]
92
110
  elsif line =~ /^\s*#{GRAPHVIZ_STRING}\s*\[(.*)\]\s*;?\s*$/
93
111
  id = unescape($1)
94
112
  attrs = attributes($2)
95
- type = map_nodes(attrs['shape'],attrs['label'])
96
113
  ### without a label graphviz shows the id
97
- label = attrs['label'] || id
114
+ label = if attrs['label'].nil?
115
+ id
116
+ elsif attrs['shape'] =~ /^M?record$/
117
+ record_label(attrs['label'])
118
+ else
119
+ unescape(attrs['label'])
120
+ end
121
+ type = map_nodes(attrs['shape'],label)
98
122
 
99
123
  n = Node.new(self.object_id,id,type,label,0,0)
100
124
  @graph.add_node n
@@ -130,7 +154,7 @@ module CPEE
130
154
  "digraph G {\n" +
131
155
  " rankdir=LR;\n" +
132
156
  @labels.values.map{ |e| " #{e};\n" }.join +
133
- @fromto.map{ |e| " #{quote e[0]} -> #{quote e[1]}#{e.length == 3 ? "[label=#{quote e[2]}]" : ''};\n" }.join +
157
+ @fromto.map{ |e| " #{quote e[0]} -> #{quote e[1]}#{edge_attrs e[2]};\n" }.join +
134
158
  "}\n"
135
159
  end
136
160
 
@@ -150,10 +174,23 @@ module CPEE
150
174
  '"' + s.to_s.gsub(/\\/,'\\\\\\\\').gsub(/"/,'\\"').gsub(/\n/,'\\n') + '"'
151
175
  end
152
176
 
177
+ def edge_attrs(label)
178
+ case label
179
+ when nil then ''
180
+ when :default then '[taillabel="/" labelangle=0 labeldistance=1]'
181
+ else "[label=#{quote label}]"
182
+ end
183
+ end
184
+
153
185
  def node_def(nid,shape,label,style=nil)
154
186
  "#{quote nid}[shape=#{shape}#{style ? " style=#{style}" : ''} label=#{quote label}]"
155
187
  end
156
188
 
189
+ def script_def(nid,label)
190
+ fields = label.to_s.gsub(/[\\"{}|<>]/) { |c| "\\#{c}" }.gsub(/\n/,'\\n')
191
+ "#{quote nid}[shape=record style=rounded label=\"{S|#{fields}}\"]"
192
+ end
193
+
157
194
  def set_fromto(pn,nid)
158
195
  if pn.is_a?(Array) && pn.length > 1
159
196
  @fromto << [pn[0],nid,pn[1]]
@@ -166,7 +203,7 @@ module CPEE
166
203
  nid = node.id
167
204
  label = node.label.to_s.strip
168
205
  if node.endpoints.empty? && ((!node.script.nil? && node.script.strip != '') || node.type == :scriptTask)
169
- @labels[nid] = node_def(nid,'component',label)
206
+ @labels[nid] = script_def(nid,label)
170
207
  else
171
208
  @labels[nid] = node_def(nid,'box',label,'rounded')
172
209
  end
@@ -192,8 +229,8 @@ module CPEE
192
229
  def print_Parallel(node,pn)
193
230
  nid = id_find(node.id)
194
231
  set_fromto pn, "#{nid}s"
195
- @labels["#{nid}s"] = node_def("#{nid}s",'diamond','AND')
196
- @labels["#{nid}e"] = node_def("#{nid}e",'diamond','AND')
232
+ @labels["#{nid}s"] = node_def("#{nid}s",'diamond','+')
233
+ @labels["#{nid}e"] = node_def("#{nid}e",'diamond','+')
197
234
  node.sub.each do |branch|
198
235
  pn = generate_in_list(branch,"#{nid}s")
199
236
  set_fromto pn, "#{nid}e"
@@ -206,11 +243,14 @@ module CPEE
206
243
  set_fromto pn, "#{nid}s"
207
244
  @labels["#{nid}s"] = node_def("#{nid}s",'diamond','x')
208
245
  @labels["#{nid}e"] = node_def("#{nid}e",'diamond','x')
246
+ conditional = node.sub.any? { |branch| branch.condition.any? }
209
247
  node.sub.each do |branch|
210
248
  ### branches without condition (incl. otherwise) are plain edges, the reader
211
249
  ### treats the last of them as otherwise
212
250
  pn = if branch.condition.any?
213
251
  generate_in_list(branch,["#{nid}s",branch.condition.join(' or ')])
252
+ elsif conditional
253
+ generate_in_list(branch,["#{nid}s",:default])
214
254
  else
215
255
  generate_in_list(branch,"#{nid}s")
216
256
  end
@@ -22,6 +22,7 @@ require 'timeout'
22
22
  require_relative 'bpmn2'
23
23
  require_relative 'mermaid'
24
24
  require_relative 'graphviz'
25
+ require_relative 'pnml'
25
26
  require_relative 'transformer'
26
27
  require_relative 'cpee'
27
28
 
@@ -56,6 +57,10 @@ module CPEE
56
57
  ['text/plain', CPEE::Transformation::Target::Mermaid]
57
58
  when 'graphviz'
58
59
  ['text/plain', CPEE::Transformation::Target::Graphviz]
60
+ when 'pnml'
61
+ ['text/xml', CPEE::Transformation::Target::PNML]
62
+ when 'pnml-with-lifecycle'
63
+ ['text/xml', CPEE::Transformation::Target::PNML_with_lifecycle]
59
64
  when 'text-bf'
60
65
  ['text/plain', CPEE::Transformation::Target::Text_bf]
61
66
  when 'text-df-PO-extended'
@@ -32,6 +32,8 @@
32
32
  <layer name="xml_cpee">
33
33
  <apply-to>/cpee/bpmn2</apply-to>
34
34
  <apply-to>/bpmn2/cpee</apply-to>
35
+ <apply-to>/pnml/cpee</apply-to>
36
+ <apply-to>/pnml-with-lifecycle/cpee</apply-to>
35
37
  </layer>
36
38
  <layer name="text_cpee">
37
39
  <apply-to>/cpee/mermaid</apply-to>
@@ -223,8 +223,8 @@ module CPEE
223
223
  def print_Parallel(node,pn)
224
224
  nid = id_find(node.id)
225
225
  set_fromto pn, "#{nid}s"
226
- @labels["#{nid}s"] = "#{nid}s:parallelgateway:{AND}"
227
- @labels["#{nid}e"] = "#{nid}e:parallelgateway:{AND}"
226
+ @labels["#{nid}s"] = "#{nid}s:parallelgateway:{+}"
227
+ @labels["#{nid}e"] = "#{nid}e:parallelgateway:{+}"
228
228
  node.sub.each do |branch|
229
229
  pn = generate_in_list(branch,"#{nid}s")
230
230
  set_fromto pn, "#{nid}e"
@@ -0,0 +1,243 @@
1
+ # encoding: UTF-8
2
+ #
3
+ # This file is part of CPEE-TRANSFORMATION.
4
+ #
5
+ # CPEE-TRANSFORMATION is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or (at your
8
+ # option) any later version.
9
+ #
10
+ # CPEE-TRANSFORMATION is distributed in the hope that it will be useful, but
11
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13
+ # for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with CPEE-TRANSFORMATION (file LICENSE in the main directory). If not,
17
+ # see <http://www.gnu.org/licenses/>.
18
+
19
+ require_relative 'target'
20
+ require 'xml/smart'
21
+
22
+ module CPEE
23
+
24
+ module Transformation
25
+
26
+ module Target #{{{
27
+
28
+ ### workflow net in the pnml dialect pm4py reads ($invisible$, finalmarkings).
29
+ ### every print_* gets the place it starts from and returns the place it
30
+ ### ends in, nil after break and terminate
31
+ class PNML < Default
32
+
33
+ def generate
34
+ @places = []
35
+ @transitions = []
36
+ @arcs = []
37
+ @exits = []
38
+ @start = place(1,'start')
39
+ @end = place(0,'end')
40
+ last = generate_in_list(@tree,silent(@start))
41
+ silent(last,@end) if last
42
+ reduce
43
+ to_xml
44
+ end
45
+
46
+ private
47
+
48
+ def place(tokens=0,id=nil)
49
+ @places << { :id => id || "p#{@places.length + 1}", :tokens => tokens }
50
+ @places.last
51
+ end
52
+
53
+ def transition(name,silent=false)
54
+ @transitions << { :id => "t#{@transitions.length + 1}", :name => name, :silent => silent }
55
+ @transitions.last
56
+ end
57
+
58
+ def arc(source,target)
59
+ @arcs << [source,target]
60
+ end
61
+
62
+ def step(from,to,name,silent)
63
+ to ||= place
64
+ t = transition(name,silent)
65
+ arc(from,t)
66
+ arc(t,to)
67
+ to
68
+ end
69
+
70
+ def silent(from,to=nil,name=nil) = step(from,to,name,true)
71
+ def visible(from,name) = step(from,nil,name,false)
72
+
73
+ def script?(node)
74
+ node.endpoints.empty? && ((!node.script.nil? && node.script.strip != '') || node.type == :scriptTask)
75
+ end
76
+
77
+ def activity(node,from)
78
+ label = node.label.to_s.strip
79
+ visible(from,label.empty? ? node.id.to_s : label)
80
+ end
81
+
82
+ ### after break or terminate nothing is reachable
83
+ def alive(pn) = pn || place
84
+
85
+ def print_Node(node,pn) = activity(node,alive(pn))
86
+
87
+ def print_Break(node,pn)
88
+ silent(alive(pn),@exits.last || @end,'break')
89
+ nil
90
+ end
91
+
92
+ def print_Terminate(node,pn)
93
+ silent(alive(pn),@end,'terminate')
94
+ nil
95
+ end
96
+
97
+ def print_Parallel(node,pn)
98
+ ### a place is a deferred choice
99
+ return choice(node.sub,alive(pn)) if node.type == :eventBasedGateway
100
+ split = transition(nil,true)
101
+ join = transition(nil,true)
102
+ arc(alive(pn),split)
103
+ node.sub.each do |branch|
104
+ bp = place
105
+ arc(split,bp)
106
+ last = generate_in_list(branch,bp)
107
+ arc(last,join) if last
108
+ end
109
+ to = place
110
+ arc(join,to)
111
+ to
112
+ end
113
+
114
+ ### inclusive: parallel, every branch can be skipped (also all of them)
115
+ def print_Conditional(node,pn)
116
+ return choice(node.sub,alive(pn)) unless node.type == :inclusiveGateway
117
+ split = transition(nil,true)
118
+ join = transition(nil,true)
119
+ arc(alive(pn),split)
120
+ node.sub.each do |branch|
121
+ bp = place
122
+ arc(split,bp)
123
+ last = choice([branch,[]],bp)
124
+ arc(last,join) if last
125
+ end
126
+ to = place
127
+ arc(join,to)
128
+ to
129
+ end
130
+
131
+ ### exclusive: all branches start in the same place, conditions are lost
132
+ def choice(branches,pn)
133
+ merge = place
134
+ reached = false
135
+ branches.each do |branch|
136
+ last = generate_in_list(branch,pn)
137
+ next unless last
138
+ silent(last,merge)
139
+ reached = true
140
+ end
141
+ reached ? merge : nil
142
+ end
143
+
144
+ ### single: body plus the (implicit) way out, like in the other targets.
145
+ ### otherwise the alternatives decide, and only breaks leave the loop
146
+ def print_Loop(node,pn)
147
+ head = silent(alive(pn))
148
+ exit = place
149
+ @exits.push exit
150
+ single = node.sub.length == 1 || (node.sub.length == 2 && node.sub[1].condition.empty? && ((node.sub[1].length == 1 && node.sub[1][0].class.name.gsub(/\w+:+/,'') == 'Break') || node.sub[1].length == 0))
151
+ finite = single && (node.sub.length == 2 || node.sub[0].condition.any?)
152
+ silent(head,exit) if finite && node.mode == :pre_test
153
+ last = single ? generate_in_list(node.sub[0],head) : choice(node.sub,head)
154
+ if last
155
+ silent(last,head) unless last.equal?(head)
156
+ silent(last,exit) if finite && node.mode != :pre_test
157
+ end
158
+ @exits.pop
159
+ exit
160
+ end
161
+
162
+ def inputs(n) = @arcs.select { |s,t| t.equal?(n) }
163
+ def outputs(n) = @arcs.select { |s,t| s.equal?(n) }
164
+
165
+ ### fuse places connected by a silent transition, if the first place
166
+ ### leads nowhere else. Does not change what the net can do
167
+ def reduce
168
+ loop do
169
+ fused = @transitions.any? do |t|
170
+ next false unless t[:silent]
171
+ ins, outs = inputs(t), outputs(t)
172
+ next false unless ins.length == 1 && outs.length == 1
173
+ p, q = ins[0][0], outs[0][1]
174
+ next false if p.equal?(q) || outputs(p).length != 1
175
+ if inputs(q).length == 1
176
+ keep, gone = p, q
177
+ moved = outputs(q).map { |s,x| [keep,x] }
178
+ elsif p[:tokens] == 0
179
+ keep, gone = q, p
180
+ moved = inputs(p).map { |x,s| [x,keep] }
181
+ else
182
+ next false
183
+ end
184
+ next false if moved.any? { |a| @arcs.any? { |b| b[0].equal?(a[0]) && b[1].equal?(a[1]) } }
185
+ @arcs.reject! { |s,x| s.equal?(gone) || x.equal?(gone) || s.equal?(t) || x.equal?(t) }
186
+ @arcs.concat moved
187
+ @transitions.delete_if { |x| x.equal?(t) }
188
+ @places.delete_if { |x| x.equal?(gone) }
189
+ @start = keep if gone.equal?(@start)
190
+ @end = keep if gone.equal?(@end)
191
+ keep[:id] = gone[:id] if %w(start end).include?(gone[:id])
192
+ true
193
+ end
194
+ break unless fused
195
+ end
196
+ @places.select! { |x| x.equal?(@start) || x.equal?(@end) || @arcs.any? { |s,t| s.equal?(x) || t.equal?(x) } }
197
+ end
198
+
199
+ def to_xml
200
+ res = XML::Smart.string('<pnml xmlns="http://www.pnml.org/version-2009/grammar/pnml"><net id="net1" type="http://www.pnml.org/version-2009/grammar/pnmlcoremodel"><page id="page1"/></net></pnml>')
201
+ res.register_namespace 'p', 'http://www.pnml.org/version-2009/grammar/pnml'
202
+ net = res.find('/p:pnml/p:net').first
203
+ page = res.find('/p:pnml/p:net/p:page').first
204
+ @places.each do |x|
205
+ n = page.add('place', 'id' => x[:id])
206
+ n.add('name').add('text',x[:id])
207
+ n.add('initialMarking').add('text',x[:tokens].to_s) if x[:tokens] > 0
208
+ end
209
+ @transitions.each do |x|
210
+ n = page.add('transition', 'id' => x[:id])
211
+ n.add('name').add('text',x[:name] || x[:id])
212
+ n.add('toolspecific', 'tool' => 'ProM', 'version' => '6.4', 'activity' => '$invisible$') if x[:silent]
213
+ end
214
+ @arcs.each_with_index do |(s,t),i|
215
+ page.add('arc', 'id' => "a#{i + 1}", 'source' => s[:id], 'target' => t[:id])
216
+ end
217
+ net.add('finalmarkings').add('marking').add('place', 'idref' => @end[:id]).add('text','1')
218
+ res.to_s
219
+ end
220
+
221
+ end
222
+
223
+ ### calls as in cpee logs: calling, receiving (once or more), done.
224
+ ### scripts only log done. names are <id>_<lifecycle>
225
+ class PNML_with_lifecycle < PNML
226
+
227
+ private
228
+
229
+ def activity(node,from)
230
+ return visible(from,"#{node.id}_done") if script?(node)
231
+ called = visible(from,"#{node.id}_calling")
232
+ received = visible(called,"#{node.id}_receiving")
233
+ silent(received,called,'redo_receiving')
234
+ visible(received,"#{node.id}_done")
235
+ end
236
+
237
+ end
238
+
239
+ end #}}}
240
+
241
+ end
242
+
243
+ end
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/ruby
2
+ # encoding: UTF-8
3
+ #
4
+ # This file is part of CPEE-TRANSFORMATION.
5
+ #
6
+ # CPEE-TRANSFORMATION is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Lesser General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or (at your
9
+ # option) any later version.
10
+ #
11
+ # CPEE-TRANSFORMATION is distributed in the hope that it will be useful, but
12
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14
+ # for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public License
17
+ # along with CPEE-TRANSFORMATION (file LICENSE in the main directory). If not,
18
+ # see <http://www.gnu.org/licenses/>.
19
+
20
+ def wrap(s1, s2, width=78, indent=ARGV.options.summary_width + 3)
21
+ lines = []
22
+ s = ARGV.options.summary_indent + s1 + ' ' * (indent - s1.length - ARGV.options.summary_indent.length) + s2
23
+ line, s = s[0..indent-2], s[indent..-1]
24
+ s.split(/\n/).each do |ss|
25
+ ss.split(/[ \t]+/).each do |word|
26
+ if line.size + word.size >= width
27
+ lines << line
28
+ line = (" " * (indent)) + word
29
+ else
30
+ line << " " << word
31
+ end
32
+ end
33
+ lines << line if line
34
+ line = (" " * (indent-1))
35
+ end
36
+ return lines.join("\n")
37
+ end
38
+
39
+ require 'optparse'
40
+
41
+ require_relative '../lib/cpee/transformation/transformer' rescue nil
42
+ require_relative '../lib/cpee/transformation/cpee' rescue nil
43
+ require_relative '../lib/cpee/transformation/pnml' rescue nil
44
+
45
+ interactive = false
46
+ printtree = false
47
+
48
+ ARGV.options { |opt|
49
+ opt.summary_indent = ' ' * 2
50
+ opt.summary_width = 18
51
+ opt.banner = "Usage:\n#{opt.summary_indent}#{File.basename($0)} FNAME\n"
52
+ opt.on("Options:")
53
+ opt.on("--help", "-h", "This text") { puts opt; exit }
54
+ opt.on("--interactive", "-i", "Interactive mode") { interactive = true }
55
+ opt.on("--tree", "-t", "Print tree") { printtree = true }
56
+ opt.on("")
57
+ opt.on(wrap("[FNAME]","convert cpee tree in file FNAME to pnml and output to console."))
58
+ opt.parse!
59
+ }
60
+
61
+ if ARGV.length != 1
62
+ puts ARGV.options
63
+ exit
64
+ else
65
+ f = ARGV[0]
66
+ end
67
+
68
+ model = CPEE::Transformation::Source::CPEE.new(File.read(f))
69
+
70
+ trans = CPEE::Transformation::Transformer.new(model)
71
+ traces = trans.build_traces
72
+
73
+ if interactive
74
+ puts traces.legend
75
+ puts
76
+ tree = trans.build_tree(true)
77
+ else
78
+ tree = trans.build_tree(false)
79
+ end
80
+
81
+ if printtree
82
+ puts tree.to_s
83
+ else
84
+ puts trans.generate_model(CPEE::Transformation::Target::PNML)
85
+ end
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/ruby
2
+ # encoding: UTF-8
3
+ #
4
+ # This file is part of CPEE-TRANSFORMATION.
5
+ #
6
+ # CPEE-TRANSFORMATION is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Lesser General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or (at your
9
+ # option) any later version.
10
+ #
11
+ # CPEE-TRANSFORMATION is distributed in the hope that it will be useful, but
12
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14
+ # for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public License
17
+ # along with CPEE-TRANSFORMATION (file LICENSE in the main directory). If not,
18
+ # see <http://www.gnu.org/licenses/>.
19
+
20
+ def wrap(s1, s2, width=78, indent=ARGV.options.summary_width + 3)
21
+ lines = []
22
+ s = ARGV.options.summary_indent + s1 + ' ' * (indent - s1.length - ARGV.options.summary_indent.length) + s2
23
+ line, s = s[0..indent-2], s[indent..-1]
24
+ s.split(/\n/).each do |ss|
25
+ ss.split(/[ \t]+/).each do |word|
26
+ if line.size + word.size >= width
27
+ lines << line
28
+ line = (" " * (indent)) + word
29
+ else
30
+ line << " " << word
31
+ end
32
+ end
33
+ lines << line if line
34
+ line = (" " * (indent-1))
35
+ end
36
+ return lines.join("\n")
37
+ end
38
+
39
+ require 'optparse'
40
+
41
+ require_relative '../lib/cpee/transformation/transformer' rescue nil
42
+ require_relative '../lib/cpee/transformation/cpee' rescue nil
43
+ require_relative '../lib/cpee/transformation/pnml' rescue nil
44
+
45
+ interactive = false
46
+ printtree = false
47
+
48
+ ARGV.options { |opt|
49
+ opt.summary_indent = ' ' * 2
50
+ opt.summary_width = 18
51
+ opt.banner = "Usage:\n#{opt.summary_indent}#{File.basename($0)} FNAME\n"
52
+ opt.on("Options:")
53
+ opt.on("--help", "-h", "This text") { puts opt; exit }
54
+ opt.on("--interactive", "-i", "Interactive mode") { interactive = true }
55
+ opt.on("--tree", "-t", "Print tree") { printtree = true }
56
+ opt.on("")
57
+ opt.on(wrap("[FNAME]","convert cpee tree in file FNAME to pnml with calling/receiving/done transitions and output to console."))
58
+ opt.parse!
59
+ }
60
+
61
+ if ARGV.length != 1
62
+ puts ARGV.options
63
+ exit
64
+ else
65
+ f = ARGV[0]
66
+ end
67
+
68
+ model = CPEE::Transformation::Source::CPEE.new(File.read(f))
69
+
70
+ trans = CPEE::Transformation::Transformer.new(model)
71
+ traces = trans.build_traces
72
+
73
+ if interactive
74
+ puts traces.legend
75
+ puts
76
+ tree = trans.build_tree(true)
77
+ else
78
+ tree = trans.build_tree(false)
79
+ end
80
+
81
+ if printtree
82
+ puts tree.to_s
83
+ else
84
+ puts trans.generate_model(CPEE::Transformation::Target::PNML_with_lifecycle)
85
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cpee-transformation
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juergen eTM Mangler
@@ -113,6 +113,7 @@ files:
113
113
  - lib/cpee/transformation/implementation.rb
114
114
  - lib/cpee/transformation/implementation.xml
115
115
  - lib/cpee/transformation/mermaid.rb
116
+ - lib/cpee/transformation/pnml.rb
116
117
  - lib/cpee/transformation/ptml.rb
117
118
  - lib/cpee/transformation/structures.rb
118
119
  - lib/cpee/transformation/target.rb
@@ -135,6 +136,8 @@ files:
135
136
  - tools/trans_cpee-to-dataflow
136
137
  - tools/trans_cpee-to-graphviz
137
138
  - tools/trans_cpee-to-mermaid
139
+ - tools/trans_cpee-to-pnml
140
+ - tools/trans_cpee-to-pnml-with-lifecycle
138
141
  - tools/trans_cpee-to-ptml
139
142
  - tools/trans_cpee-to-text-bf
140
143
  - tools/trans_cpee-to-text-df-poe