ontomde-core 1.0.2 → 1.0.4

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.
@@ -1,53 +1,52 @@
1
- # Overrides standard ruby method_missing interceptor.
2
- # NOTE:
3
- # This is a workaround for standard method_missing
4
- # generates very high CPU usage
5
- # when a significant model is loaded in memory.
6
- #:include: ../shared/license.rdoc
7
-
8
-
9
- def method_missing(methId,args=nil)
10
- msg=respond_to?(:rdf_uri) ? "#{rdf_uri}" : "nil"
11
- log.error { "method #{methId} not available for object of class #{self.class.name}, (uri=#{msg})(to_s=#{self})" }
12
-
13
- if msg=="ukb_null"
14
- log.error { <<-END
15
- ********** INVALID MODEL DETECTED **********
16
- ********** INVALID MODEL DETECTED **********
17
- **** An invalid source model was used (an ukb_null was found).
18
- **** Probable cause is that you are using a RSM modeler, and
19
- **** one of your model contains an invalid reference somewhere.
20
- ****
21
- **** Because RSM does not tell you where this error is located,
22
- **** you have to use your .nt export file :
23
- ****
24
- **** 1) open .nt export file with a text editor.
25
- **** 2) locate <http://kb#null> string.
26
- **** 3) locate left member refering to this null element.
27
- **** 4) This element is the key of RSM invalid element.
28
- **** 5) Locate this element in RSM and fix it (or delete it).
29
- **** 6) Re-export your model and check for null uris.
30
- ****
31
- ********** INVALID MODEL DETECTED **********
32
- END
33
- }
34
- end
35
-
36
- log.debug {
37
- msg=""
38
- self.methods.sort{|a,b| a<=>b}.each {|m|
39
- msg="#{msg}, #{m}"
40
- }
41
- "Available methods are: #{msg}"
42
- }
43
-
44
- #self.included_modules.each { |m|
45
- # #puts "include #{m}"
46
- # }
47
- puts "end of custom method_missing"
48
- #TODO: l'appel au stock method_missing genere des temps de traitements infinis. (cpu a 100%, conso memoire enorme)
49
- #super
50
- puts "exiting"
51
- throw NoMethodError.new("method missing '#{methId}' for object '#{self.class.name}'",methId,args)
52
- #exit
53
- end
1
+ # Overrides standard ruby method_missing interceptor.
2
+ # NOTE:
3
+ # This is a workaround for standard method_missing
4
+ # generates very high CPU usage
5
+ # when a significant model is loaded in memory.
6
+
7
+
8
+ def method_missing(methId,args=nil)
9
+ msg=respond_to?(:rdf_uri) ? "#{rdf_uri}" : "nil"
10
+ log.error { "method #{methId} not available for object of class #{self.class.name}, (uri=#{msg})(to_s=#{self})" }
11
+
12
+ if msg=="ukb_null"
13
+ log.error { <<END
14
+ ********** INVALID MODEL DETECTED **********
15
+ ********** INVALID MODEL DETECTED **********
16
+ **** An invalid source model was used (an ukb_null was found).
17
+ **** Probable cause is that you are using a RSM modeler, and
18
+ **** one of your model contains an invalid reference somewhere.
19
+ ****
20
+ **** Because RSM does not tell you where this error is located,
21
+ **** you have to use your .nt export file :
22
+ ****
23
+ **** 1) open .nt export file with a text editor.
24
+ **** 2) locate <http://kb#null> string.
25
+ **** 3) locate left member refering to this null element.
26
+ **** 4) This element is the key of RSM invalid element.
27
+ **** 5) Locate this element in RSM and fix it (or delete it).
28
+ **** 6) Re-export your model and check for null uris.
29
+ ****
30
+ ********** INVALID MODEL DETECTED **********
31
+ END
32
+ }
33
+ end
34
+
35
+ log.debug {
36
+ msg=""
37
+ self.methods.sort{|a,b| a<=>b}.each {|m|
38
+ msg="#{msg}, #{m}"
39
+ }
40
+ "Available methods are: #{msg}"
41
+ }
42
+
43
+ #self.included_modules.each { |m|
44
+ # #puts "include #{m}"
45
+ # }
46
+ puts "end of custom method_missing"
47
+ #TODO: l'appel au stock method_missing genere des temps de traitements infinis. (cpu a 100%, conso memoire enorme)
48
+ #super
49
+ puts "exiting"
50
+ throw NoMethodError.new("method missing '#{methId}' for object '#{self.class.name}'",methId,args)
51
+ #exit
52
+ end
@@ -1,10 +1,10 @@
1
- class Delayed2
2
- def initialize(&b)
3
- @b=b
4
- end
5
- def to_s
6
- return @b.call
7
- end
1
+ class Delayed2
2
+ def initialize(&b)
3
+ @b=b
4
+ end
5
+ def to_s
6
+ return @b.call
7
+ end
8
8
  end
9
9
 
10
10
  #Example usage:
@@ -12,8 +12,8 @@ end
12
12
  #c=mtk_delay { i + 5 }
13
13
  #i=35
14
14
  #puts c.to_s
15
- def mtk_delay (&block)
16
- return Delayed2.new(&block)
15
+ def mtk_delay (&block)
16
+ return Delayed2.new(&block)
17
17
  end
18
18
 
19
19
 
@@ -1,32 +1,32 @@
1
1
  module DemoInstaller
2
- def proceed(target,source,banner)
3
- options = { }
4
- options[:target]="#{target}"
5
- OptionParser.new do |opts|
6
- opts.banner =banner +<<END
2
+ def proceed(target,source,banner)
3
+ options = { }
4
+ options[:target]="#{target}"
5
+ OptionParser.new do |opts|
6
+ opts.banner =banner +<<END
7
7
 
8
8
  Command syntax:
9
9
  ----------
10
10
  END
11
- opts.on("-t","--target DIRECTORY","","target directory where demo project will be installed","default: --target #{options[:target]}" ) do |v|
12
- options[:target] = v
13
- end
14
-
15
-
16
- # No argument, shows at tail. This will print an options summary.
17
- # Try it and see!
18
- opts.on_tail("-h", "--help", "Show this message") do
19
- puts opts
20
- exit
21
- end
22
- end.parse!
11
+ opts.on("-t","--target DIRECTORY","","target directory where demo project will be installed","default: --target #{options[:target]}" ) do |v|
12
+ options[:target] = v
13
+ end
23
14
 
24
- if File.exist?(options[:target])
25
- puts "WARNING: File already exists (#{options[:target]})"
26
- puts "WARNING: Copy aborted"
27
- else
28
- cp_r("#{source}", options[:target] )
29
- puts "INFO: Project created in #{options[:target]}"
30
- end
31
- end
15
+
16
+ # No argument, shows at tail. This will print an options summary.
17
+ # Try it and see!
18
+ opts.on_tail("-h", "--help", "Show this message") do
19
+ puts opts
20
+ exit
21
+ end
22
+ end.parse!
23
+
24
+ if File.exist?(options[:target])
25
+ puts "WARNING: File already exists (#{options[:target]})"
26
+ puts "WARNING: Copy aborted"
27
+ else
28
+ cp_r("#{source}", options[:target] )
29
+ puts "INFO: Project created in #{options[:target]}"
30
+ end
31
+ end
32
32
  end
@@ -1,28 +1,27 @@
1
- # Core exceptions class
2
- #:include: ../shared/license.rdoc
3
-
4
- # Generic use exception.
5
- class Warning < RuntimeError
6
- def initialize()
7
- end
8
- end
9
-
10
- # Exception raised when an URI is not found in current model.
11
- class WarningURIundefined < RuntimeError
12
- attr_reader :uri
13
- def initialize(uri)
14
- @uri=uri
15
- end
16
- end
17
-
18
- # Exception raised when a ressources claims to be of a type not defined in currently loaded metamodels.
19
- class WarningRubyTypeUndefined < RuntimeError
20
- attr_reader :uri,:res
21
- def initialize(uri,res)
22
- @res=res
23
- @uri=uri
24
- end
25
- end
26
-
27
- class WarningUnknownFileType < RuntimeError
28
- end
1
+ # Core exceptions class
2
+
3
+ # Generic use exception.
4
+ class Warning < RuntimeError
5
+ def initialize()
6
+ end
7
+ end
8
+
9
+ # Exception raised when an URI is not found in current model.
10
+ class WarningURIundefined < RuntimeError
11
+ attr_reader :uri
12
+ def initialize(uri)
13
+ @uri=uri
14
+ end
15
+ end
16
+
17
+ # Exception raised when a ressources claims to be of a type not defined in currently loaded metamodels.
18
+ class WarningRubyTypeUndefined < RuntimeError
19
+ attr_reader :uri,:res
20
+ def initialize(uri,res)
21
+ @res=res
22
+ @uri=uri
23
+ end
24
+ end
25
+
26
+ class WarningUnknownFileType < RuntimeError
27
+ end
@@ -1,163 +1,191 @@
1
- #:include: ../shared/license.rdoc
2
-
3
- class NTriple ; end
4
-
5
- class NTripleFile < NTriple
6
- attr_reader :line
7
- def line=(_line)
8
- @line=_line
9
- @about_uri=@predicat_uri=@value_uri=@value_litteral=nil
10
- @split=@line.split(" ",3)
11
- end
12
-
13
- def about_uri
14
- @about_uri=urialias(@split[0]) if !@about_uri
15
- return @about_uri
16
- end
17
- def predicat_uri
18
- @predicat_uri=urialias(@split[1]) if !@predicat_uri
19
- return @predicat_uri
20
- end
21
- def value_uri
22
- @value_uri=urialias(@split[2]) if ! @value_uri
23
- return @value_uri
24
- end
25
- def value_litteral
26
- @value_litteral=@split[2][1,@split[2].length-5] if !@value_literral
27
- return @value_litteral
28
- end
29
-
30
- def valueIsReference?
31
- case @split[2][0]
32
- when 60 then return true
33
- when 34 then return false
34
- else raise Warning.new,"Bad ntriple detected"
35
- end
36
- end
37
-
38
- COMMENT_SIGNATURE="#"[0]
39
- def isComment?
40
- return @line[0]==COMMENT_SIGNATURE
41
- end
42
-
43
-
44
- def isOntoMDXHeader?
45
- return @line.to_s=="#!ontomdx\n"
46
- end
47
- end
48
-
49
- module Mrdf_Model
50
- def loadMetaModelFromFile(fileName,ignoreHeader=false)
51
- @updateCount=@updateCount+1
52
- raise Exception.new("nil fileName passed to loadMetaModelFromFile") if fileName.nil?
53
- m=fileName+".rb"
54
- #log.debug "m=#{m}"
55
- if( File.exists?(m) && File.mtime(m) > File.mtime(fileName) )
56
- log.debug "Using cache in #{m}"
57
- require(m)
58
- loadModelFromFile(fileName,ignoreHeader)
59
- else
60
- log.debug "Generating cache in #{m}"
61
- loadModelFromFile(fileName,ignoreHeader)
62
- self.generateClassesFromMetamodel(m)
63
- end
64
- end
65
-
66
- def loadModelFromFile (srcFileName,ignoreHeader=false)
67
- fileName=translateToNt(srcFileName)
68
- @updateCount=@updateCount+1
69
- #Crdf_Resource.new(self,"xx").initUpdate
70
- [false,true].each { |modeData|
71
- begin
72
- File.open(fileName,"r") { |aFile|
73
- parseModelStream(aFile,modeData,ignoreHeader)
74
- }
75
- rescue Exception => e
76
- raise Exception.new(e.message+"ERROR *** current file is: \"#{fileName}\"\nERROR ***\n")
77
- end
78
- }
79
- end
80
-
81
- def parseModelStream(stream,modeData,ignoreHeader=false)
82
- aFile=stream
83
- i=0
84
- nt=NTripleFile.new()
85
- aFile.each_line {
86
- |nt.line|
87
- begin
88
- i=i+1
89
-
90
- if(!ignoreHeader)
91
- ignoreHeader=true
92
- next if nt.isOntoMDXHeader?
93
- p="\nERROR *** "
94
- raise Exception.new("#{p}#{p}ontomdx was given a model file without#{p}a valid ontomdx plugin file header.#{p}If you have used a model file created by a modeler plugin,#{p}upgrade your plugin.#{p}Il you have used a plain RDF or RDFS file,#{p}specify ignoreHeader=true when loading model with loadModel.#{p}\n")
95
- end
96
-
97
- next if nt.isComment?
98
- parse(nt,modeData)
99
- rescue WarningRubyTypeUndefined => z
100
- log.error "WARNING ["+(modeData ? "data":"res")+" :nt.line "+i.to_s+", "+z.to_s+", Will create a default type. Possible discrepancies if defined later on. In case of problem, Consider bootstraping]:"+nt.line
101
- #log.debug "z.res=#{z.res}"
102
- z.res.createRubyClassMinimal(self)
103
- i=i-1
104
- retry
105
-
106
- rescue WarningURIundefined => z
107
- log.error "WARNING ["+(modeData ? "data":"res")+" :line "+i.to_s+", "+z.to_s+",Will create a default entry]:"+nt.line
108
- #log.debug "z.uri=#{z.uri}"
109
- Crdf_Resource.new(self,z.uri)
110
- #parse(nt.line,modeData)
111
- i=i-1
112
- retry
113
- rescue Warning => w
114
- log.error "WARNING ["+(modeData ? "data":"res")+" :line "+i.to_s+", "+w.to_s+"]:"+nt.line
115
-
116
- end
117
- }
118
- end
119
-
120
- # moved to ontomde-redland-win
121
- # WIN_PATH_RAPPER=File.expand_path("#{File.dirname(__FILE__)}/../../dist/redland-1.0.3-Win32/rapper.exe").tr('/','\\\\')
122
-
123
- PLATFORM_IS_UNIX=!(RUBY_PLATFORM.index("inux").nil?)
124
- def rapperRun(param)
125
- if PLATFORM_IS_UNIX
126
- cmd="rapper "+param
127
- else
128
- cmd='"'+WIN_PATH_RAPPER+'"'+param
129
- end
130
- return if system(cmd)
131
- raise Exception.new("\n***\n***Error running command\n***\n***#{cmd}\n***\n")
132
-
133
- end
134
- def translateToNt(srcFileName)
135
- return srcFileName if ! (srcFileName=~/.rdfs*$/ )
136
-
137
- fileName="#{srcFileName}.cache.deleteMe.nt"
138
- if( File.exists?(fileName) && File.mtime(fileName) > File.mtime(srcFileName) )
139
- log.debug "INFO:Using cache in #{fileName}"
140
- else
141
- raise "Blanc dans nom de fichier non supportes sous windows" if fileName.include?(" ")
142
- if PLATFORM_IS_UNIX
143
- param=' -q -o ntriples -i rdfxml '+srcFileName+' > '+fileName
144
- else
145
- param=' -q -o ntriples -i rdfxml '+srcFileName.tr('/','\\\\')+' > '+fileName.tr('/','\\\\')+''
146
- end
147
- rapperRun(param)
148
- end
149
- return fileName
150
- end
151
-
152
- def translateToXML(srcFileName,fileName)
153
- raise "Blanc dans nom de fichier non supportes sous windows" if fileName.include?(" ") || srcFileName.include?(" ")
154
- if PLATFORM_IS_UNIX
155
- param=' -q -i ntriples -o rdfxml '+srcFileName+' > '+fileName+''
156
- else
157
- param=' -q -i ntriples -o rdfxml '+srcFileName.tr('/','\\\\')+' > '+fileName.tr('/','\\\\')+''
158
- end
159
- rapperRun(param)
160
- return fileName
161
- end
162
-
163
- end
1
+
2
+ class NTriple ; end
3
+
4
+ class NTripleFile < NTriple
5
+ attr_reader :line
6
+ attr :litOffset
7
+
8
+ def initialize
9
+ super
10
+ @litOffset=nil
11
+ end
12
+
13
+ def line=(_line)
14
+ @line=_line
15
+ @about_uri=@predicat_uri=@value_uri=@value_litteral=nil
16
+ @split=@line.split(" ",3)
17
+ end
18
+
19
+ def about_uri
20
+ @about_uri=urialias(@split[0]) if !@about_uri
21
+ return @about_uri
22
+ end
23
+ def predicat_uri
24
+ @predicat_uri=urialias(@split[1]) if !@predicat_uri
25
+ return @predicat_uri
26
+ end
27
+ def value_uri
28
+ @value_uri=urialias(@split[2]) if ! @value_uri
29
+ return @value_uri
30
+ end
31
+ def value_litteral
32
+ @value_litteral=@split[2][1,@split[2].length-lineOffset] if !@value_litteral
33
+ return @value_litteral
34
+ end
35
+ #return number of chars to be deleted at then end of line.
36
+ #number depend on file type CR/LF and on platform (ruby, jruby, ...)
37
+ #This value should be computed once per file.
38
+ #(A File should not mix CR/LF lines with CR lines)
39
+ def lineOffset
40
+ return @litOffset unless @litOffset.nil?
41
+ i=@split[2].rindex(".")
42
+ l=@split[2].length
43
+ @litOffset=l-i+3
44
+ return @litOffset
45
+ end
46
+
47
+ def valueIsReference?
48
+ case @split[2][0]
49
+ when 60 then return true
50
+ when 34 then return false
51
+ else raise Warning.new,"Bad ntriple detected"
52
+ end
53
+ end
54
+
55
+ COMMENT_SIGNATURE="#"[0]
56
+ def isComment?
57
+ return @line[0]==COMMENT_SIGNATURE
58
+ end
59
+
60
+
61
+ def isOntoMDXHeader?
62
+ return @line.to_s=="#!ontomdx\n"
63
+ end
64
+ end
65
+
66
+ module Mrdf_Model
67
+ def loadMetaModelFromFile(fileName,ignoreHeader=false)
68
+ @updateCount=@updateCount+1
69
+ raise Exception.new("nil fileName passed to loadMetaModelFromFile") if fileName.nil?
70
+ m=fileName+".rb"
71
+ #log.debug "m=#{m}"
72
+ #TODO: cacheMetaModelFile forced to false
73
+ # because range handling broke it
74
+ if( context[:cacheMetaModelFile,false] && File.exists?(m) && File.mtime(m) > File.mtime(fileName) )
75
+ log.debug "Using cache in #{m}"
76
+ require(m)
77
+ loadModelFromFile(fileName,ignoreHeader)
78
+ else
79
+ log.debug "Generating cache in #{m}"
80
+ loadModelFromFile(fileName,ignoreHeader)
81
+ self.generateClassesFromMetamodel(m)
82
+ end
83
+ end
84
+
85
+ def loadModelFromFile (srcFileName,ignoreHeader=false)
86
+ fileName=translateToNt(srcFileName)
87
+ @updateCount=@updateCount+1
88
+ #Crdf_Resource.new(self,"xx").initUpdate
89
+ [false,true].each { |modeData|
90
+ begin
91
+ File.open(fileName,"r") { |aFile|
92
+ parseModelStream(aFile,modeData,ignoreHeader)
93
+ }
94
+ rescue Exception => e
95
+ raise Exception.new(e.message+"ERROR *** current file is: \"#{fileName}\"\nERROR ***\n")
96
+ end
97
+ }
98
+ end
99
+
100
+ def parseModelStream(stream,modeData,ignoreHeader=false)
101
+ aFile=stream
102
+ i=0
103
+ nt=NTripleFile.new()
104
+ aFile.each_line {
105
+ |nt.line|
106
+ begin
107
+ i=i+1
108
+
109
+ if(!ignoreHeader)
110
+ ignoreHeader=true
111
+ next if nt.isOntoMDXHeader?
112
+ p="\nERROR *** "
113
+ raise Exception.new("#{p}#{p}ontomdx was given a model file without#{p}a valid ontomdx plugin file header.#{p}If you have used a model file created by a modeler plugin,#{p}upgrade your plugin.#{p}Il you have used a plain RDF or RDFS file,#{p}specify ignoreHeader=true when loading model with loadModel.#{p}\n")
114
+ end
115
+
116
+ next if nt.isComment?
117
+ parse(nt,modeData)
118
+ rescue WarningRubyTypeUndefined => z
119
+ log.error "WARNING ["+(modeData ? "data":"res")+" :nt.line "+i.to_s+", "+z.to_s+", Will create a default type. Possible discrepancies if defined later on. In case of problem, Consider bootstraping]:"+nt.line
120
+ #log.debug "z.res=#{z.res}"
121
+ z.res.createRubyClassMinimal(self)
122
+ i=i-1
123
+ retry
124
+
125
+ rescue WarningURIundefined => z
126
+ log.error "WARNING ["+(modeData ? "data":"res")+" :line "+i.to_s+", "+z.to_s+",Will create a default entry]:"+nt.line
127
+ #log.debug "z.uri=#{z.uri}"
128
+ Crdf_Resource.new(self,z.uri)
129
+ #parse(nt.line,modeData)
130
+ i=i-1
131
+ retry
132
+ rescue Warning => w
133
+ log.error "WARNING ["+(modeData ? "data":"res")+" :line "+i.to_s+", "+w.to_s+"]:"+nt.line
134
+
135
+ end
136
+ }
137
+ end
138
+
139
+ PLATFORM_IS_JAVA=!(RUBY_PLATFORM.index("java").nil?)
140
+ OS_IS_WINDOWS=!(ENV['OS'].index("Windows").nil?)
141
+
142
+ puts(%{O/S detected: #{OS_IS_WINDOWS ? "WINDOWS" : "*nix"}})
143
+ puts(%{Ruby platform detected: #{PLATFORM_IS_JAVA ? "Java" : "C"}})
144
+
145
+ def rapperRun(param)
146
+ if ! OS_IS_WINDOWS
147
+ #we are not under windows
148
+ #built in rapper cannot be used (it is for windows)
149
+ #we use rapper available in path.
150
+ cmd="rapper "+param
151
+ elsif PLATFORM_IS_JAVA
152
+ #We are under windows but under jruby
153
+ cmd=WIN_PATH_RAPPER+" "+param
154
+ else
155
+ #We are under windows but under Matz Ruby Implementation (MRI)
156
+ cmd='"'+WIN_PATH_RAPPER+'"'+param
157
+ end
158
+ return if system(cmd)
159
+ raise Exception.new("\n***\n***Error running command\n***\n***#{cmd}\n***\n")
160
+
161
+ end
162
+ def translateToNt(srcFileName)
163
+ return srcFileName if ! (srcFileName=~/.rdfs*$/ )
164
+
165
+ fileName="#{srcFileName}.cache.deleteMe.nt"
166
+ if( context[:useTranslateToNtCache,false] && File.exists?(fileName) && File.mtime(fileName) > File.mtime(srcFileName) )
167
+ #log.debug "INFO:Using cache in #{fileName}"
168
+ else
169
+ raise "Blanc dans nom de fichier non supportes sous windows" if fileName.include?(" ")
170
+ if !OS_IS_WINDOWS
171
+ param=' -q -o ntriples -i rdfxml '+srcFileName+' > '+fileName
172
+ else
173
+ param=' -q -o ntriples -i rdfxml '+srcFileName.tr('/','\\\\')+' > '+fileName.tr('/','\\\\')+''
174
+ end
175
+ rapperRun(param)
176
+ end
177
+ return fileName
178
+ end
179
+
180
+ def translateToXML(srcFileName,fileName)
181
+ raise "Blanc dans nom de fichier non supportes sous windows" if fileName.include?(" ") || srcFileName.include?(" ")
182
+ if !OS_IS_WINDOWS
183
+ param=' -q -i ntriples -o rdfxml '+srcFileName+' > '+fileName+''
184
+ else
185
+ param=' -q -i ntriples -o rdfxml '+srcFileName.tr('/','\\\\')+' > '+fileName.tr('/','\\\\')+''
186
+ end
187
+ rapperRun(param)
188
+ return fileName
189
+ end
190
+
191
+ end