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,161 +1,159 @@
1
- #:include: ../shared/license.rdoc
2
-
3
- require "singleton"
4
-
5
- class UriNamespace
6
- include Singleton
7
- def initialize
8
- # Les 1er sont prioritaire pour unalias ??
9
- @urialiases=Hash.new(nil)
10
- @urialiases["http:\/\/uml\/2"]="uml"
11
- #@urialiases["http:\/\/uml\/1.4"]="uml"
12
- @urialiases["http:\/\/www.w3.org\/2000\/01\/rdf-schema"]="rdfs"
13
- @urialiases["http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns"]="rdf"
14
- @urialiases["http:\/\/protege.stanford.edu\/system"]="sys"
15
- @urialiases["http:\/\/protege.stanford.edu\/kb"]="kb"
16
- @urialiases["http:\/\/ft\/uml\/2"]="umlx"
17
- @urialiases["http:\/\/kb"]="ukb"
18
- @urialiases["http:\/\/orange-ftgroup.com\/2007\/rd\/xmda\/bpm"]="bpm"
19
- end
20
-
21
- # Returns unaliases uri for uri
22
- # Used by magic draw export plugin
23
- # NOTE:
24
- # raises an error if alias is unknown.
25
- # Example:
26
- # unalias("rdf_XYZ") return @urialises("rdf")+"#"+"XYZ"
27
- def unalias(uri)
28
- n=uri.split('_',2)
29
- @urialiases.each {|k,v|
30
- next if v!=n[0]
31
- return k+"#"+n[1]
32
- }
33
- # no alias is ok
34
- return uri
35
- #raise "unalias failed for #{uri}"
36
- end
37
-
38
- # Returns the alias associated to ns.
39
- # NOTE:
40
- # uri of the form http://orange-ft.com/[0-9]+/XyZ are aliases xyz
41
- def getNamespaceAlias(ns)
42
- _alias=@urialiases[ns]
43
- return _alias if _alias
44
-
45
- md=/^http:\/\/orange-ft.com\/[0-9]+\/([a-z0-9A-Z]+)$/.match(ns)
46
- if md.nil?
47
- _alias="ns_#{@urialiases.length.to_s}"
48
- else
49
- # La premi�re lettre doit �tre minuscule
50
- _alias=md[1].downcase
51
- end
52
- addAliasHelp(_alias,ns)
53
- addAlias(_alias,ns)
54
- return _alias
55
-
56
- end
57
-
58
- def addAliasHelp(_alias,ns)
59
- #return if context[:displayAddAliasHelp,true]
60
- log.debug <<-ENDMSG
61
-
62
- **********************************************************
63
- ** An unknown rdf namespace has been found and a random
64
- ** alias has been generated for it : '#{_alias}'
65
- **
66
- ** Using a random alias is OK if you do not need to
67
- ** reference a namespace somewhere in your code.
68
- **
69
- ** If, for example, you need to declare methods
70
- ** for elements of this namespace
71
- ** (for generating code for example),
72
- ** you will need a fix namespace alias.
73
- **
74
- ** Run the following ruby code once in your ruby
75
- ** program to declare a new alias:
76
- **
77
- ** YourCode.rb
78
- ** require 'ontomde-core'
79
- ** (...)
80
- ** UriNamespace.instance.addAlias('yourAlias',
81
- ** '#{ns.gsub(/\//,'\\\/')}'
82
- ** )
83
- **
84
- ** Note: beware of \\/ ruby string escaping)
85
- **********************************************************
86
- ENDMSG
87
- end
88
-
89
- #adds an alias to the predefined list of aliases.
90
- def addAlias(_alias,ns)
91
- log.debug { "Creation d'un alias de namespace xmlns:"+_alias+"=\""+ns+"#\"" }
92
- @urialiases[ns]=_alias
93
- return nil
94
- end
95
-
96
- #compute aliases name for given uri
97
- #exemple alias('http://foo#bar') --> 'ns1:bar'
98
- #Note:
99
- # method added for uml2_kb which stores unaliased uri in kb text field for back reference to uml model.
100
- def urialias(uri)
101
- a=uri.split("#",2)
102
- return uri if a[1].nil?
103
- ns=getNamespaceAlias(a[0])
104
- #puts "uri=#{ns}_#{a[1]}"
105
- return "#{ns}_#{a[1]}"
106
- end
107
- end
108
-
109
- #RDF triplet handling.
110
- class NTriple
111
- attr_reader :about_uri, :predicat_uri, :value_uri, :value_litteral
112
- def valueIsReference?
113
- end
114
-
115
- # Initialization of internal cache (performance enchancement)
116
- def initialize
117
- # Le cache est remis z�ro chaque fichier.
118
- # Les essais avec SID.nt montrent un gain de performance
119
- # de 10% sur la m�thode urialias, les fichiers �tant largement disjoints.
120
- #@@cacheUse=1
121
- #@@cacheMiss=100
122
- #log.debug "initialize triplet"
123
- @uriMappingCache=Hash.new(nil)
124
- end
125
-
126
- # Returns an aliases uri
127
- # uri is in ntriple format: '<http://foo#bar>'
128
- # Optimize for ntriple file handling
129
- def urialias(uri)
130
- #log.debug "#{uri} ??"
131
- #return nil if uri == nil
132
- ret=@uriMappingCache[uri]
133
- #log.debug "cache miss %=#{1.0*@@cacheMiss/@@cacheUse*100} cacheUse=#{@@cacheUse}"
134
- #@@cacheUse=@@cacheUse+1
135
- return ret unless ret.nil?
136
- #log.debug "cache miss"
137
- #@@cacheMiss=@@cacheMiss+1
138
- @uriMappingCache[uri]=ret=compute_urialias(uri)
139
- #log.debug "#{uri} -> #{ret}"
140
- return ret
141
- end
142
-
143
- # Internal use
144
- def compute_urialias(uri)
145
- #renvoi une uri apres avoir remplacer le chemin par son alias
146
- raise Warning.new,"Bad NT URI (#{uri})" if uri.nil? || (uri[0] != 60)
147
- #uri=uri[1,uri.length-2]
148
- #log.debug "uri[0,1] -> '#{uri[0,1]}'"
149
- uri=uri[1,uri.length].split(">",2)[0]
150
- #log.debug "uri-->#{uri}"
151
- return ::UriNamespace.instance.urialias(uri)
152
-
153
- #a=uri.split("#",2)
154
- #return uri if a[1].nil?
155
- #r=::UriNamespace.instance.getNamespaceAlias(a[0])
156
- #log.debug "urialias="+r+"_"+a[1]
157
- #return r+"_"+a[1]
158
- #return "#{r}_#{a[1]}"
159
- end
160
-
161
- end
1
+ require "singleton"
2
+
3
+ class UriNamespace
4
+ include Singleton
5
+ def initialize
6
+ # Les 1er sont prioritaire pour unalias ??
7
+ @urialiases=Hash.new(nil)
8
+ @urialiases["http:\/\/uml\/2"]="uml"
9
+ #@urialiases["http:\/\/uml\/1.4"]="uml"
10
+ @urialiases["http:\/\/www.w3.org\/2000\/01\/rdf-schema"]="rdfs"
11
+ @urialiases["http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns"]="rdf"
12
+ @urialiases["http:\/\/protege.stanford.edu\/system"]="sys"
13
+ @urialiases["http:\/\/protege.stanford.edu\/kb"]="kb"
14
+ @urialiases["http:\/\/ft\/uml\/2"]="umlx"
15
+ @urialiases["http:\/\/kb"]="ukb"
16
+ @urialiases["http:\/\/orange-ftgroup.com\/2007\/rd\/xmda\/bpm"]="bpm"
17
+ end
18
+
19
+ # Returns unaliases uri for uri
20
+ # Used by magic draw export plugin
21
+ # NOTE:
22
+ # raises an error if alias is unknown.
23
+ # Example:
24
+ # unalias("rdf_XYZ") return @urialises("rdf")+"#"+"XYZ"
25
+ def unalias(uri)
26
+ n=uri.split('_',2)
27
+ @urialiases.each {|k,v|
28
+ next if v!=n[0]
29
+ return k+"#"+n[1]
30
+ }
31
+ # no alias is ok
32
+ return uri
33
+ #raise "unalias failed for #{uri}"
34
+ end
35
+
36
+ # Returns the alias associated to ns.
37
+ # NOTE:
38
+ # uri of the form http://orange-ft.com/[0-9]+/XyZ are aliases xyz
39
+ def getNamespaceAlias(ns)
40
+ _alias=@urialiases[ns]
41
+ return _alias if _alias
42
+
43
+ md=/^http:\/\/orange-ft.com\/[0-9]+\/([a-z0-9A-Z]+)$/.match(ns)
44
+ if md.nil?
45
+ _alias="ns_#{@urialiases.length.to_s}"
46
+ else
47
+ # La première lettre doit être minuscule
48
+ _alias=md[1].downcase
49
+ end
50
+ addAliasHelp(_alias,ns)
51
+ addAlias(_alias,ns)
52
+ return _alias
53
+
54
+ end
55
+
56
+ def addAliasHelp(_alias,ns)
57
+ #return if context[:displayAddAliasHelp,true]
58
+ log.debug <<ENDMSG
59
+
60
+ **********************************************************
61
+ ** An unknown rdf namespace has been found and a random
62
+ ** alias has been generated for it : '#{_alias}'
63
+ **
64
+ ** Using a random alias is OK if you do not need to
65
+ ** reference a namespace somewhere in your code.
66
+ **
67
+ ** If, for example, you need to declare methods
68
+ ** for elements of this namespace
69
+ ** (for generating code for example),
70
+ ** you will need a fix namespace alias.
71
+ **
72
+ ** Run the following ruby code once in your ruby
73
+ ** program to declare a new alias:
74
+ **
75
+ ** YourCode.rb
76
+ ** require 'ontomde-core'
77
+ ** (...)
78
+ ** UriNamespace.instance.addAlias('yourAlias',
79
+ ** '#{ns.gsub(/\//,'\\\/')}'
80
+ ** )
81
+ **
82
+ ** Note: beware of \\/ ruby string escaping)
83
+ **********************************************************
84
+ ENDMSG
85
+ end
86
+
87
+ #adds an alias to the predefined list of aliases.
88
+ def addAlias(_alias,ns)
89
+ log.debug { "Creation d'un alias de namespace xmlns:"+_alias+"=\""+ns+"#\"" }
90
+ @urialiases[ns]=_alias
91
+ return nil
92
+ end
93
+
94
+ #compute aliases name for given uri
95
+ #exemple alias('http://foo#bar') --> 'ns1:bar'
96
+ #Note:
97
+ # method added for uml2_kb which stores unaliased uri in kb text field for back reference to uml model.
98
+ def urialias(uri)
99
+ a=uri.split("#",2)
100
+ return uri if a[1].nil?
101
+ ns=getNamespaceAlias(a[0])
102
+ #puts "uri=#{ns}_#{a[1]}"
103
+ return "#{ns}_#{a[1]}"
104
+ end
105
+ end
106
+
107
+ #RDF triplet handling.
108
+ class NTriple
109
+ attr_reader :about_uri, :predicat_uri, :value_uri, :value_litteral
110
+ def valueIsReference?
111
+ end
112
+
113
+ # Initialization of internal cache (performance enchancement)
114
+ def initialize
115
+ # Le cache est remis à zéro à chaque fichier.
116
+ # Les essais avec SID.nt montrent un gain de performance
117
+ # de 10% sur la méthode urialias, les fichiers étant largement disjoints.
118
+ #@@cacheUse=1
119
+ #@@cacheMiss=100
120
+ #log.debug "initialize triplet"
121
+ @uriMappingCache=Hash.new(nil)
122
+ end
123
+
124
+ # Returns an aliases uri
125
+ # uri is in ntriple format: '<http://foo#bar>'
126
+ # Optimize for ntriple file handling
127
+ def urialias(uri)
128
+ #log.debug "#{uri} ??"
129
+ #return nil if uri == nil
130
+ ret=@uriMappingCache[uri]
131
+ #log.debug "cache miss %=#{1.0*@@cacheMiss/@@cacheUse*100} cacheUse=#{@@cacheUse}"
132
+ #@@cacheUse=@@cacheUse+1
133
+ return ret unless ret.nil?
134
+ #log.debug "cache miss"
135
+ #@@cacheMiss=@@cacheMiss+1
136
+ @uriMappingCache[uri]=ret=compute_urialias(uri)
137
+ #log.debug "#{uri} -> #{ret}"
138
+ return ret
139
+ end
140
+
141
+ # Internal use
142
+ def compute_urialias(uri)
143
+ #renvoi une uri apres avoir remplacer le chemin par son alias
144
+ raise Warning.new,"Bad NT URI (#{uri})" if uri.nil? || (uri[0] != 60)
145
+ #uri=uri[1,uri.length-2]
146
+ #log.debug "uri[0,1] -> '#{uri[0,1]}'"
147
+ uri=uri[1,uri.length].split(">",2)[0]
148
+ #log.debug "uri-->#{uri}"
149
+ return ::UriNamespace.instance.urialias(uri)
150
+
151
+ #a=uri.split("#",2)
152
+ #return uri if a[1].nil?
153
+ #r=::UriNamespace.instance.getNamespaceAlias(a[0])
154
+ #log.debug "urialias="+r+"_"+a[1]
155
+ #return r+"_"+a[1]
156
+ #return "#{r}_#{a[1]}"
157
+ end
158
+
159
+ end
@@ -1,5 +1,5 @@
1
- module Ontomde
2
- module Core
3
- VERSION='1.0.2'
4
- end
5
- end
1
+ module Ontomde
2
+ module Core
3
+ VERSION='1.0.4'
4
+ end
5
+ end
data/lib/ontomde-core.rb CHANGED
@@ -1,35 +1,26 @@
1
- # In order to use ontomde-core just include this file
2
- #
3
- # include 'ontomde-core'
4
- #
5
- # NOTE: cf demo/etatCivil for sample raw use of ontomde-core.
6
- #
7
- #:include: shared/license.rdoc
8
-
9
- require "#{__FILE__[0..-4]}/version.rb"
10
-
11
- require 'set'
12
- require 'ontomde-redland-win'
13
-
14
- here="#{File.dirname(__FILE__)}/ontomde-core"
15
-
16
- require "#{here}/log.rb"
17
- require "#{here}/fileLoader.rb"
18
- require "#{here}/custom_method_missing"
19
- require "#{here}/triplet.rb"
20
- require "#{here}/exceptions.rb"
21
- require "#{here}/meta.rb"
22
- require "#{here}/resource.rb"
23
- require "#{here}/resourceSet.rb"
24
- require "#{here}/bootstrap_rdfs.rb"
25
- require "#{here}/clone.rb"
26
- require "#{here}/fileTypes.rb"
27
- require "#{here}/helper.rb"
28
- require "#{here}/context.rb"
29
- require "#{here}/delayed.rb"
30
-
31
- #MTKRunner.rb
32
- require "#{here}/loader.rb"
33
- #require "#{here}/profil.rb"
34
- require "#{here}/customERB.rb"
35
-
1
+
2
+ require "#{__FILE__[0..-4]}/version.rb"
3
+ require 'set'
4
+ require 'ontomde-redland-win'
5
+
6
+ here="#{File.dirname(__FILE__)}/ontomde-core"
7
+
8
+ require "#{here}/log.rb"
9
+ require "#{here}/fileLoader.rb"
10
+ require "#{here}/custom_method_missing"
11
+ require "#{here}/triplet.rb"
12
+ require "#{here}/exceptions.rb"
13
+ require "#{here}/meta.rb"
14
+ require "#{here}/resource.rb"
15
+ require "#{here}/resourceSet.rb"
16
+ require "#{here}/bootstrap_rdfs.rb"
17
+ require "#{here}/clone.rb"
18
+ require "#{here}/fileTypes.rb"
19
+ require "#{here}/helper.rb"
20
+ require "#{here}/context.rb"
21
+ require "#{here}/delayed.rb"
22
+
23
+ #MTKRunner.rb
24
+ #require "#{here}/profil.rb"
25
+ require "#{here}/customERB.rb"
26
+