ontomde-core 2.0.4 → 2.0.5

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.
@@ -93,8 +93,10 @@ lib/ontomde-core/meta.rb
93
93
  lib/ontomde-core/profil.rb
94
94
  lib/ontomde-core/resource.rb
95
95
  lib/ontomde-core/resourceSet.rb
96
+ lib/ontomde-core/threads.rb
96
97
  lib/ontomde-core/triplet.rb
97
98
  lib/ontomde-core/version.rb
99
+ lib/ontomde-core/xslt.rb
98
100
  test/protege/demo.sh
99
101
  test/protege/etatCivil.pprj
100
102
  test/protege/etatCivil.rdf
@@ -19,6 +19,8 @@ require "#{here}/fileTypes.rb"
19
19
  require "#{here}/helper.rb"
20
20
  require "#{here}/context.rb"
21
21
  require "#{here}/delayed.rb"
22
+ require "#{here}/threads.rb"
23
+ require "#{here}/xslt.rb"
22
24
 
23
25
  #MTKRunner.rb
24
26
  #require "#{here}/profil.rb"
@@ -39,7 +39,7 @@ FINCODE
39
39
  end
40
40
 
41
41
  module Mrdf_Repository
42
- @@context=WarningHash.new()
42
+ Thread.current["@@context"]=WarningHash.new()
43
43
 
44
44
  #returns context hastable.
45
45
  #
@@ -52,7 +52,7 @@ module Mrdf_Repository
52
52
  # Please refer to #mtk_context method for information on
53
53
  # how to populate context.
54
54
  def context
55
- return @@context
55
+ return Thread.current["@@context"]
56
56
  end
57
57
 
58
58
  # Similar to mtk_context but preserves already defined context.
@@ -60,7 +60,7 @@ module Mrdf_Repository
60
60
  def mtk_default_context(*additional_context,&block)
61
61
  filtered_context=Array.new
62
62
  additional_context.each { |item| item.each { |k,v|
63
- next if @@context.include?(k)
63
+ next if Thread.current["@@context"].include?(k)
64
64
  filtered_context << item
65
65
  }}
66
66
  mtk_context(*filtered_context,&block)
@@ -93,13 +93,13 @@ module Mrdf_Repository
93
93
  # puts context[:build] # BUILD_ONE
94
94
  # }
95
95
  def mtk_context(*additional_context,&block)
96
- context_save=@@context
97
- @@context=context_save.clone
96
+ context_save=Thread.current["@@context"]
97
+ Thread.current["@@context"]=context_save.clone
98
98
  additional_context.each { |item| item.each { |k,v|
99
- @@context[k]=v
99
+ Thread.current["@@context"][k]=v
100
100
  }}
101
101
  yield
102
- @@context=context_save
102
+ Thread.current["@@context"]=context_save
103
103
  return nil
104
104
  end
105
105
 
@@ -1,5 +1,6 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <xsl:stylesheet version="2.0" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:uml="http://schema.omg.org/spec/UML/2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ns0="http://uml/2#">
2
+ <xsl:stylesheet version="2.0" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:uml="http://schema.omg.org/spec/UML/2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ns0="http://uml/2#"
3
+ xmlns:thecustomprofile="http://www.sparxsystems.com/profiles/thecustomprofile/1.0">
3
4
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
4
5
 
5
6
  <!-- Create Defined and used Stereotypes for later creation of missing stereotype definitions -->
@@ -10,6 +11,7 @@
10
11
  <xsl:key name="ExtensionConnectorIdRef" match="//xmi:Extension//connector" use="@xmi:idref"/>
11
12
  <xsl:key name="ExtensionOperationIdRef" match="//xmi:Extension//operation" use="@xmi:idref"/>
12
13
  <xsl:key name="ExtensionParameterIdRef" match="//xmi:Extension//parameter" use="@xmi:idref"/>
14
+ <xsl:key name="CustomProfile" match="//thecustomprofile:*" use="@*"/>
13
15
 
14
16
  <!-- Profile -->
15
17
  <xsl:template name="Profile" xmlns:uml="http://schema.omg.org/spec/UML/2.1/uml.xml">
@@ -56,9 +58,9 @@
56
58
  </xsl:if>
57
59
  <!-- Stereotype -->
58
60
  <rdf:Description rdf:about="{@xmi:id}" ns0:name="{@name}">
59
- <xsl:if test="key('ExtensionElementIdRef',current()/@xmi:id)/properties/@stereotype">
60
- <ns0:appliedStereotype rdf:resource="{key('ExtensionElementIdRef',current()/@xmi:id)/properties/@stereotype}"/>
61
- </xsl:if>
61
+ <xsl:for-each select="key('ExtensionElementIdRef',current()/@xmi:id)/properties/@stereotype">
62
+ <ns0:appliedStereotype><xsl:attribute name="rdf:resource"><xsl:value-of select="."/></xsl:attribute></ns0:appliedStereotype>
63
+ </xsl:for-each>
62
64
  <ns0:visibility rdf:resource="http://uml/2#visibilityKind_{@visibility}"/>
63
65
  <xsl:if test="@isAbstract='true'">
64
66
  <ns0:isAbstract>true</ns0:isAbstract>
@@ -80,6 +82,7 @@
80
82
  <ns0:supplier rdf:resource="{@supplier}"/>
81
83
  <ns0:realizingClassifier rdf:resource="{@realizingClassifier}"/>
82
84
  <ns0:implementingClassifier rdf:resource="{@client}"/>
85
+ <xsl:call-template name="MyAppliedStereotypes"/>
83
86
  </rdf:Description>
84
87
  </xsl:for-each>
85
88
  <!-- ownedAttribute -->
@@ -87,6 +90,17 @@
87
90
  <!-- ownedOperation -->
88
91
  <xsl:apply-templates select="ownedOperation"/>
89
92
  </xsl:template>
93
+
94
+ <!-- looks for stereotype using two different methods -->
95
+ <xsl:template name="MyAppliedStereotypes">
96
+ <xsl:for-each select="key('ExtensionElementIdRef',current()/@xmi:id)/properties/@stereotype">
97
+ <ns0:appliedStereotype><xsl:attribute name="rdf:resource"><xsl:value-of select="."/></xsl:attribute></ns0:appliedStereotype>
98
+ </xsl:for-each>
99
+ <xsl:for-each select="key('CustomProfile',@xmi:id)">
100
+ <ns0:appliedStereotype><xsl:attribute name="rdf:resource"><xsl:value-of select="substring-after(name(),':')"/></xsl:attribute></ns0:appliedStereotype>
101
+ </xsl:for-each>
102
+ </xsl:template>
103
+
90
104
  <!-- Comment -->
91
105
  <xsl:template name="Comment">
92
106
  <xsl:param name="body"/>
@@ -192,29 +192,27 @@ END
192
192
 
193
193
  def translateEAXMI_to_NT(eaxmifile,ea_version)
194
194
  translatedfile="#{eaxmifile}_tmp.nt"
195
- param1="#{eaxmifile} -o #{translatedfile}_prestep2 #{File.dirname(__FILE__)}\\converter-ea\\#{ea_version}\\XMI2RDFS.xslt"
196
- #step2 is for getting rid of file://xxx
197
- param2="#{translatedfile}_prestep2 -o #{translatedfile} #{File.dirname(__FILE__)}\\converter-ea\\#{ea_version}\\XMI2RDFS_step2.xslt"
195
+ f1="#{translatedfile}_deleteMe_prestep2"
196
+ mtk_addTempFileToDelete(translatedfile)
197
+ mtk_addTempFileToDelete(f1)
198
+
199
+ # load xslt engine
200
+ xslt=Mtk_xslt::XsltProcessor.new
201
+
202
+ puts " :starting Enterprise Architect XMI conversion using xslt:#{xslt.name}"
203
+
204
+ #step1 transforms xmi into xml-rdf
205
+ xslt1="#{File.dirname(__FILE__)}\\converter-ea\\#{ea_version}\\XMI2RDFS.xslt"
206
+ in1=eaxmifile
207
+ out1=f1
208
+ xslt.transform(xslt1,in1,out1)
209
+
210
+ #step2 is for getting rid of uri such as: file://xxx
211
+ xslt2="#{File.dirname(__FILE__)}\\converter-ea\\#{ea_version}\\XMI2RDFS_step2.xslt"
212
+ in2=out1
213
+ out2=translatedfile
214
+ xslt.transform(xslt2,in2,out2)
198
215
 
199
- if ! OS_IS_WINDOWS
200
- #we are not under windows
201
- #built in rapper cannot be used (it is for windows)
202
- #we use rapper available in path.
203
- raise Exception.new('TODO: use xslt under linux')
204
- elsif PLATFORM_IS_JAVA
205
- #We are under windows but under jruby
206
- cmd1="#{File.dirname(__FILE__)}\\converter-ea\\msxsl.exe "+param1.tr('/','\\\\')
207
- cmd2="#{File.dirname(__FILE__)}\\converter-ea\\msxsl.exe "+param2.tr('/','\\\\')
208
- else
209
- #We are under windows but under Matz Ruby Implementation (MRI)
210
- cmd1="#{File.dirname(__FILE__)}\\converter-ea\\msxsl.exe "+param1.tr('/','\\\\')
211
- cmd2="#{File.dirname(__FILE__)}\\converter-ea\\msxsl.exe "+param2.tr('/','\\\\')
212
- end
213
- puts " :starting Enterprise Architect XMI conversion using msxml"
214
- [cmd1,cmd2].each { |cmd|
215
- ret=system(cmd)
216
- raise Exception.new("\n***\n***Error running command\n***\n***#{cmd}\n***Please check that no msxml process is running in background\n***\n") unless ret
217
- }
218
216
  puts " :done with Enterprise Architect file conversion"
219
217
  return translateXMLRDF_to_NT(translatedfile)
220
218
  end
@@ -233,7 +231,7 @@ END
233
231
  def translateXMLRDF_to_NT(srcFileName)
234
232
  # added version number to avoid cache reuse when upgrading
235
233
  fileName="#{srcFileName}.#{Ontomde::Core::VERSION}.cache.deleteMe.nt"
236
- useCache=context[:useTranslateToNtCache,true]
234
+ useCache=context[:useTranslateToNtCache,false]
237
235
  mtk_addTempFileToDelete(fileName) unless useCache
238
236
  if( useCache && File.exists?(fileName) && File.mtime(fileName) > File.mtime(srcFileName) )
239
237
  puts "INFO:Using cache in #{fileName}"
@@ -80,11 +80,11 @@ module Mmtk_helper
80
80
 
81
81
  ret=nil
82
82
  mtk_context(:mtk_out=>file,:mtk_fileName=>fileName) {
83
- @@mtk_out=context[:mtk_out] # perf
83
+ #@@mtk_out=context[:mtk_out] # perf
84
84
  yield
85
- ret=@@mtk_out.to_s
85
+ ret=context[:mtk_out].to_s
86
86
  }
87
- @@mtk_out=context.get(:mtk_out) # perf
87
+ #@@mtk_out=context.get(:mtk_out) # perf
88
88
  return ret
89
89
  end
90
90
 
@@ -141,20 +141,20 @@ module Mmtk_helper
141
141
  file=NullFileWriter.instance
142
142
  #log.debug { "Simulating Write to #{fileName} (because context[:dryRun]==true)" }
143
143
  mtk_context(:mtk_out=>file,:mtk_fileName=>fileName,:protectedReverse=>protectedReverse) {
144
- @@mtk_out=context[:mtk_out] # perf
144
+ #@@mtk_out=context[:mtk_out] # perf
145
145
  yield
146
146
  }
147
- @@mtk_out=context.get(:mtk_out) # perf
147
+ #@@mtk_out=context.get(:mtk_out) # perf
148
148
  return
149
149
  end
150
150
  File.open(fileName+TEMP_FILE_SUFFIX,File::CREAT|File::TRUNC|File::RDWR, 0644) {
151
151
  |file|
152
152
  mtk_context(:mtk_out=>file,:mtk_fileName=>fileName,:protectedReverse=>protectedReverse) {
153
153
  #log.debug { "Writing #{fileName}" }
154
- @@mtk_out=context[:mtk_out] # perf
154
+ #@@mtk_out=context[:mtk_out] # perf
155
155
  yield
156
156
  }
157
- @@mtk_out=context.get(:mtk_out) # perf
157
+ #@@mtk_out=context.get(:mtk_out) # perf
158
158
  }
159
159
  #Temporary file has been corectly generated.
160
160
  unusedData=protectedReverse.unusedData
@@ -304,8 +304,9 @@ You must take the appropriate actions before re-running generator.
304
304
 
305
305
  # Write string to the current file opened by mtk_writeSession.
306
306
  def write(str)
307
- if !@@mtk_out.nil?
308
- @@mtk_out.write(str)
307
+ o=context[:mtk_out]
308
+ if !o.nil?
309
+ o.write(str)
309
310
  return
310
311
  end
311
312
  raise Warning.new(), <<END
@@ -178,8 +178,18 @@ class Crdf_Resource
178
178
 
179
179
  #Transforms a uri to a valid ruby identifier.
180
180
  #cf. getRubyNameInverse
181
+ @@CacheGetRubyName=Hash.new
182
+
183
+ def freeCacheGetRubyName
184
+ @@CacheGetRubyName=Hash.new
185
+ end
181
186
  def getRubyName
182
- return @uri.tr('^a-zA-Z0-9','_')
187
+ x=@@CacheGetRubyName[@uri]
188
+ if x.nil?
189
+ x=@uri.tr('^a-zA-Z0-9','_')
190
+ @@CacheGetRubyName[@uri]=x
191
+ end
192
+ return x
183
193
  #return @rdf_label if @rdf_label
184
194
  #return self.class.to_s # bootstrap
185
195
  end
@@ -0,0 +1,55 @@
1
+ # Multi-threading is necessary for taking advantage of multi cpu/core
2
+ # * MRI does not take advantage of multi core so you will not see any gain
3
+ # * JRUBY does use native thread and thus will benefit of threading.
4
+ #
5
+ # I have personnaly gainned 15% of global ontomde execution time on a
6
+ # dual CPU with anti-virus using between 25% and 90% of one core.
7
+ # Benefit should be more noticeable with a quad core.
8
+ #
9
+ # (may 2009)
10
+ #
11
+
12
+ module Enumerable
13
+ PLATFORM_IS_JAVA=!(RUBY_PLATFORM.index('java').nil?)
14
+ THREAD_NUMBER= ENV['ONTOMDE_THREADS'].nil? ? (PLATFORM_IS_JAVA ? 4 : 1) : ENV['ONTOMDE_THREADS'].to_int
15
+ def eachInThread(res,nbThread=THREAD_NUMBER,&proc)
16
+ if(res.context[:mtkThread,false])
17
+ puts "!! WARNING: recursive multi-thread request ignored"
18
+ nbThread=1
19
+ end
20
+ if(nbThread<=1 || (size < (nbThread*2)) )
21
+ each &proc
22
+ return
23
+ end
24
+
25
+ t=Array.new
26
+ (0..(nbThread-1)).each { |i|
27
+ t[i]=Array.new
28
+ }
29
+ # split collection in nbThread collections
30
+ i=0
31
+ each { |elt|
32
+ t[i].push(elt)
33
+ i=(i+1)%nbThread
34
+ }
35
+
36
+ # run one thread for each sub-collection
37
+ rt=Array.new
38
+ (0..(nbThread-1)).each { |i|
39
+ puts "!Starting thread #{i} for #{t[i].size} elements"
40
+ rt.push(Thread.new(i,t[i],res.context) { |ii,tas,ctx|
41
+ Thread.current["@@context"]=ctx
42
+ res.mtk_context(:mtkThread => true) {
43
+ tas.each &proc
44
+ #puts "!thread #{ii} done."
45
+ }})
46
+
47
+ }
48
+
49
+ puts "!waiting for unfinished parallel tasks"
50
+ rt.each { |th|
51
+ th.join
52
+ }
53
+ end
54
+
55
+ end
@@ -1,5 +1,5 @@
1
1
  module Ontomde
2
2
  module Core
3
- VERSION='2.0.4'
3
+ VERSION='2.0.5'
4
4
  end
5
5
  end
@@ -0,0 +1,87 @@
1
+
2
+
3
+ PLATFORM_IS_JAVA=!(RUBY_PLATFORM.index('java').nil?)
4
+ OS_IS_WINDOWS=!(ENV['OS'].nil? ? true : ENV['OS'].index('Windows').nil?)
5
+
6
+
7
+ if OS_IS_WINDOWS
8
+ module Mtk_xslt
9
+ class XsltProcessor
10
+ def name
11
+ return "msxml"
12
+ end
13
+ def transform(xslt,infile,outfile)
14
+ param="#{infile} -o #{outfile} #{xslt}"
15
+ cmd="#{File.dirname(__FILE__)}\\converter-ea\\msxsl.exe "+param.tr('/','\\\\')
16
+ ret=system(cmd)
17
+ raise Exception.new("\n***\n***Error running command\n***\n***#{cmd}\n***Please check that no msxml process is running in background\n***\n") unless ret
18
+ end
19
+ end # XsltProcessor
20
+ end
21
+ elsif PLATFORM_IS_JAVA
22
+ # Jruby version
23
+
24
+ #from:
25
+ # http://kfahlgren.com/blog/2007/03/02/borrowing-javas-xslt-support-for-ruby/
26
+
27
+ require 'java'
28
+ module Mtk_xslt
29
+ include_class "javax.xml.transform.TransformerFactory"
30
+ include_class "javax.xml.transform.Transformer"
31
+ include_class "javax.xml.transform.stream.StreamSource"
32
+ include_class "javax.xml.transform.stream.StreamResult"
33
+ include_class "java.lang.System"
34
+
35
+
36
+ class Saxon
37
+ def transform(xslt,infile,outfile)
38
+ transformer = @tf.newTransformer(StreamSource.new(xslt))
39
+ transformer.transform(StreamSource.new(infile), StreamResult.new(outfile))
40
+ end
41
+ def name
42
+ return "jruby/saxon"
43
+ end
44
+ TRANSFORMER_FACTORY_IMPL = "net.sf.saxon.TransformerFactoryImpl"
45
+ def initialize
46
+ System.setProperty("javax.xml.transform.TransformerFactory", TRANSFORMER_FACTORY_IMPL)
47
+ @tf = TransformerFactory.newInstance
48
+ raise Exception.new("\n*** *******\n*** ERROR loading saxon into jruby.\n*** This error may be caused by missing Saxon jars in jruby lib directory\n*** *******") if @tf.nil?
49
+ end
50
+ end
51
+ class Xalan
52
+ def transform(xslt,infile,outfile)
53
+ transformer = @tf.newTransformer(StreamSource.new(xslt))
54
+ transformer.transform(StreamSource.new(infile), StreamResult.new(outfile))
55
+ end
56
+ def name
57
+ return "jruby/xalanl"
58
+ end
59
+ TRANSFORMER_FACTORY_IMPL = "org.apache.xalan.processor.TransformerFactoryImpl"
60
+ def initialize
61
+ System.setProperty("javax.xml.transform.TransformerFactory", TRANSFORMER_FACTORY_IMPL)
62
+ @tf = TransformerFactory.newInstance
63
+ raise Exception.new("\n*** *******\n*** ERROR loading saxon into jruby.\n*** This error may be caused by missing xalan jars in jruby lib directory\n*** *******") if @tf.nil?
64
+ end
65
+ end
66
+ #class XsltProcessor < Saxon ; end
67
+ class XsltProcessor < Xalan ; end
68
+ end
69
+
70
+ # if you wanted to run this from the command line, do something like
71
+ # $ jruby lib/jxslt.rb a.xsl in.xml out.xml
72
+ #xalan = Mtk_xslt::XsltProcessor.new
73
+ #xalan.transform(*ARGV)
74
+ #saxon = JXslt::Saxon.new
75
+ #saxon.transform(*ARGV)
76
+
77
+ else
78
+ # XSLT is not available
79
+ module Mtk_xslt
80
+ class XsltProcessor
81
+ def initialize
82
+ raise Exception.new("\n***\n***XSLT is not available on your platform. Currently supported platform are JRUBY and Windows\n***\n***")
83
+ end
84
+ end
85
+ end
86
+ end
87
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ontomde-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 2.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Orange-labs BIZZ/CIL/SAM
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-08 00:00:00 +02:00
12
+ date: 2009-04-23 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -130,8 +130,10 @@ files:
130
130
  - lib/ontomde-core/profil.rb
131
131
  - lib/ontomde-core/resource.rb
132
132
  - lib/ontomde-core/resourceSet.rb
133
+ - lib/ontomde-core/threads.rb
133
134
  - lib/ontomde-core/triplet.rb
134
135
  - lib/ontomde-core/version.rb
136
+ - lib/ontomde-core/xslt.rb
135
137
  - test/protege/demo.sh
136
138
  - test/protege/etatCivil.pprj
137
139
  - test/protege/etatCivil.rdf