Class: UriNamespace
- Includes:
- Singleton
- Defined in:
- lib/ontomde-core/triplet.rb
Instance Method Summary collapse
-
#addAlias(_alias, ns) ⇒ Object
adds an alias to the predefined list of aliases.
- #addAliasHelp(_alias, ns) ⇒ Object
-
#getNamespaceAlias(ns) ⇒ Object
Returns the alias associated to ns.
-
#initialize ⇒ UriNamespace
constructor
A new instance of UriNamespace.
-
#unalias(uri) ⇒ Object
Returns unaliases uri for uri Used by magic draw export plugin NOTE: raises an error if alias is unknown.
-
#urialias(uri) ⇒ Object
compute aliases name for given uri exemple alias(‘foo#bar’) –> ‘ns1:bar’ Note: method added for uml2_kb which stores unaliased uri in kb text field for back reference to uml model.
Constructor Details
#initialize ⇒ UriNamespace
Returns a new instance of UriNamespace.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ontomde-core/triplet.rb', line 5 def initialize # Les 1er sont prioritaire pour unalias ?? @urialiases=Hash.new(nil) @urialiases["http:\/\/uml\/2"]="uml" #@urialiases["http://schema.omg.org/spec/UML/2.1"]="uml" #@urialiases["http:\/\/uml\/1.4"]="uml" @urialiases["http:\/\/www.w3.org\/2000\/01\/rdf-schema"]="rdfs" @urialiases["http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns"]="rdf" @urialiases["http:\/\/protege.stanford.edu\/system"]="sys" @urialiases["http:\/\/protege.stanford.edu\/kb"]="kb" @urialiases["http:\/\/ft\/uml\/2"]="umlx" @urialiases["http:\/\/kb"]="ukb" @urialiases["http:\/\/orange-ftgroup.com\/2007\/rd\/xmda\/bpm"]="bpm" @urialiases["http:\/\/protege.stanford.edu\/soa"]="soa" #enterprise architect @urialiases["http:\/\/EA"]="ea" end |
Instance Method Details
#addAlias(_alias, ns) ⇒ Object
adds an alias to the predefined list of aliases.
92 93 94 95 96 |
# File 'lib/ontomde-core/triplet.rb', line 92 def addAlias(_alias,ns) log.debug { "Creation d'un alias de namespace xmlns:"+_alias+"=\""+ns+"#\"" } @urialiases[ns]=_alias return nil end |
#addAliasHelp(_alias, ns) ⇒ Object
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 |
# File 'lib/ontomde-core/triplet.rb', line 60 def addAliasHelp(_alias,ns) #return if context[:displayAddAliasHelp,true] log.debug <<ENDMSG ********************************************************** ** An unknown rdf namespace has been found and a random ** alias has been generated for it : '#{_alias}' ** ** Using a random alias is OK if you do not need to ** reference a namespace somewhere in your code. ** ** If, for example, you need to declare methods ** for elements of this namespace ** (for generating code for example), ** you will need a fix namespace alias. ** ** Run the following ruby code once in your ruby ** program to declare a new alias: ** ** YourCode.rb ** require 'ontomde-core' ** (...) ** UriNamespace.instance.addAlias('yourAlias', ** '#{ns.gsub(/\//,'\\\/')}' ** ) ** ** Note: beware of \\/ ruby string escaping) ********************************************************** ENDMSG end |
#getNamespaceAlias(ns) ⇒ Object
Returns the alias associated to ns. NOTE:
uri of the form http://orange-ft.com/[0-9]+/XyZ are aliases xyz
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ontomde-core/triplet.rb', line 43 def getNamespaceAlias(ns) _alias=@urialiases[ns] return _alias if _alias md=/^http:\/\/orange-ft.com\/[0-9]+\/([a-z0-9A-Z]+)$/.match(ns) if md.nil? _alias="ns_#{@urialiases.length.to_s}" else # La première lettre doit être minuscule _alias=md[1].downcase end addAliasHelp(_alias,ns) addAlias(_alias,ns) return _alias end |
#unalias(uri) ⇒ Object
Returns unaliases uri for uri Used by magic draw export plugin NOTE:
raises an error if alias is unknown.
Example:
unalias("rdf_XYZ") return @urialises("rdf")+"#"+"XYZ"
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ontomde-core/triplet.rb', line 29 def unalias(uri) n=uri.split('_',2) @urialiases.each {|k,v| next if v!=n[0] return k+"#"+n[1] } # no alias is ok return uri #raise "unalias failed for #{uri}" end |
#urialias(uri) ⇒ Object
compute aliases name for given uri exemple alias(‘foo#bar’) –> ‘ns1:bar’ Note: method added for uml2_kb which stores unaliased uri in kb text field for back reference to uml model.
102 103 104 105 106 107 108 |
# File 'lib/ontomde-core/triplet.rb', line 102 def urialias(uri) a=uri.split("#",2) return uri if a[1].nil? ns=getNamespaceAlias(a[0]) #puts "uri=#{ns}_#{a[1]}" return "#{ns}_#{a[1]}" end |