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.
- data/History.txt +10 -5
- data/Manifest.txt +1 -2
- data/Manual.txt +88 -0
- data/README.txt +79 -48
- data/Rakefile +4 -3
- data/lib/ontomde-core/bootstrap_rdfs.rb +36 -37
- data/lib/ontomde-core/clone.rb +72 -73
- data/lib/ontomde-core/context.rb +114 -115
- data/lib/ontomde-core/customERB.rb +72 -72
- data/lib/ontomde-core/custom_method_missing.rb +52 -53
- data/lib/ontomde-core/delayed.rb +9 -9
- data/lib/ontomde-core/demoInstaller.rb +25 -25
- data/lib/ontomde-core/exceptions.rb +27 -28
- data/lib/ontomde-core/fileLoader.rb +191 -163
- data/lib/ontomde-core/fileTypes.rb +145 -133
- data/lib/ontomde-core/helper.rb +547 -538
- data/lib/ontomde-core/log.rb +32 -32
- data/lib/ontomde-core/meta.rb +410 -316
- data/lib/ontomde-core/profil.rb +60 -62
- data/lib/ontomde-core/resource.rb +277 -272
- data/lib/ontomde-core/resourceSet.rb +185 -173
- data/lib/ontomde-core/triplet.rb +159 -161
- data/lib/ontomde-core/version.rb +5 -5
- data/lib/ontomde-core.rb +26 -35
- data/test/protege/etatCivil.pprj +779 -526
- data/test/protege/etatCivil.rdf +3 -1
- data/test/protege/etatCivil.rdfs +6 -0
- data/test/protege/test_demo.rb +68 -46
- data/test/test_context.rb +88 -88
- data/test/test_ontomde-core.rb +9 -9
- data/test/test_protected.rb +291 -238
- data/test/test_uri.rb +37 -37
- data/test/unit_test_crash.rb +22 -22
- metadata +66 -59
- data/bin/ontomde-core +0 -0
- data/lib/ontomde-core/loader.rb +0 -70
@@ -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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
********** INVALID MODEL DETECTED **********
|
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
|
-
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
|
data/lib/ontomde-core/delayed.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
class Delayed2
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
-
|
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
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
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
|
-
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
|
-
|
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
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
#
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
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
|