Module: OpenTox::Ontology::Model

Defined in:
lib/ontology.rb

Overview

Model Class for OpenTox::Ontology to register/deregister and check models in the ontology service

Examples:

Register a model URI to the ontology service, check if model URI exists and delete it

uri = "http://mymodelservice.net/model/1" # model uri will be checked by the ontology service itself
OpenTox::Ontology::Model.register(uri)
puts OpenTox::Ontology::Model.exists?(uri) # => should return true
OpenTox::Ontology::Model.delete(uri)
puts OpenTox::Ontology::Model.exists?(uri) # => should return false

Class Method Summary collapse

Class Method Details

.delete(uri, subjectid = nil) ⇒ Object

Deregister an OpenTox resource into ontology service

Parameters:

  • uri, (String)

    URI of recource to deregister/delete

  • subjectid (String) (defaults to: nil)


84
85
86
87
88
89
90
91
# File 'lib/ontology.rb', line 84

def self.delete(uri, subjectid=nil)
  begin
    RestClientWrapper.delete("#{ONTOLOGY_SERVER}?uri=#{CGI.escape(uri)}", {:subjectid => CGI.escape(subjectid)})
  rescue
    LOGGER.warn "OpenTox::Ontology::Model.exists ontology service is not reachable. Failed to delete URI: #{uri} with subjectid: #{subjectid}"
    false
  end
end

.exists?(uri, subjectid = nil) ⇒ Boolean

Find an OpenTox resource in the ontology service

Parameters:

  • uri, (String)

    URI of recource to find

  • subjectid (String) (defaults to: nil)

Returns:

  • (Boolean)


96
97
98
99
100
101
102
103
104
105
# File 'lib/ontology.rb', line 96

def self.exists?(uri, subjectid=nil)
  begin
    out = RestClientWrapper.get("#{ONTOLOGY_SERVER}?query=#{querystring(uri)}",:accept => "text/csv").collect{|l| l.gsub("\r\n", "") if l.match(/^http/)}.uniq.compact
    return true if out.size > 0
    false
  rescue
    LOGGER.warn "OpenTox::Ontology::Model.exists ontology service is not reachable. Failed to check for URI: #{uri} with subjectid: #{subjectid}"
    false
  end
end

.register(uri, subjectid = nil) ⇒ Object

Register an OpenTox resource into ontology service

Parameters:

  • uri, (String)

    URI of recource to register

  • subjectid (String) (defaults to: nil)


72
73
74
75
76
77
78
79
# File 'lib/ontology.rb', line 72

def self.register(uri, subjectid=nil)
  begin
    RestClientWrapper.post(ONTOLOGY_SERVER, {:uri => uri}, {:subjectid => CGI.escape(subjectid)})
  rescue
    LOGGER.warn "OpenTox::Ontology::Model.register ontology service is not reachable. Failed to register URI: #{uri} with subjectid: #{subjectid}"
    false
  end
end