Module: OpenTox

Included in:
Algorithm, Crossvalidation, CrossvalidationReport, Dataset, Feature, Model, QMRFReport, Task, Validation, ValidationReport
Defined in:
lib/task.rb,
lib/error.rb,
lib/model.rb,
lib/parser.rb,
lib/policy.rb,
lib/dataset.rb,
lib/feature.rb,
lib/opentox.rb,
lib/to-html.rb,
lib/compound.rb,
lib/algorithm.rb,
lib/serializer.rb,
lib/validation.rb,
lib/authorization.rb,
lib/ontology_service.rb,
lib/rest_client_wrapper.rb

Defined Under Namespace

Modules: Algorithm, Authorization, Model, OntologyService, Parser, Serializer Classes: BadRequestError, Compound, Crossvalidation, CrossvalidationReport, Dataset, ErrorReport, FakeSubTask, Feature, LazarPrediction, NotAuthorizedError, NotFoundError, Policies, Policy, QMRFReport, RestCallError, RestClientWrapper, ServiceUnavailableError, SubTask, Task, Validation, ValidationReport, WrapperResult

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#metadataObject

Returns the value of attribute metadata.



4
5
6
# File 'lib/opentox.rb', line 4

def 
  @metadata
end

#uriObject

Returns the value of attribute uri.



3
4
5
# File 'lib/opentox.rb', line 3

def uri
  @uri
end

Class Method Details

.all(uri, subjectid = nil) ⇒ Array

Get all objects from a service

Returns:

  • List of available URIs



22
23
24
# File 'lib/opentox.rb', line 22

def self.all(uri, subjectid=nil)
  RestClientWrapper.get(uri,:accept => "text/uri-list", :subjectid => subjectid).to_s.split(/\n/)
end

.login(msg = nil) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/to-html.rb', line 70

def self.( msg=nil )
  html = "<html><title>Login</title><img src="+OT_LOGO+"><body>"
  html += "<form method='POST' action='"+$url_provider.url_for("/login",:full)+"'>"
  html += "<pre><p style=\"padding:15px; border:10px solid \#5D308A\">"
  html += msg+"\n\n" if msg
  html += "Please login to "+$url_provider.url_for("",:full)+"\n\n"
  html += "<table border=0>"
  html += "<tr><td>user:</td><td><input type='text' name='user' size='15' /></td></tr>"+
        "<tr><td>password:</td><td><input type='password' name='password' size='15' /></td></tr>"+
        #"<input type=hidden name=back_to value="+back_to.to_s+">"+
        "<tr><td><input type='submit' value='Login' /></td></tr>"
  html += "</table></p></pre></form></body><html>"
  html
end

.text_to_html(text, subjectid = nil, related_links = nil, description = nil, post_params = nil) ⇒ String

produces a html page for making web services browser friendly format of text (=string params) is preserved (e.g. line breaks) urls are marked as links [ [ [:mandatory_param_1], [:mandatory_param_2], [:optional_param,"default_value"] ], [ [:alteranative_mandatory_param_1], [:alteranative_mandatory_param_2] ] ]

Examples:

post params:

Parameters:

  • this is the actual content,

  • (defaults to: nil)

    info on related resources

  • (defaults to: nil)

    general info

  • array of arrays containing info on POST operation, see example

Returns:

  • html page



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
# File 'lib/to-html.rb', line 27

def self.text_to_html( text, subjectid=nil, related_links=nil, description=nil, post_params=nil  )
  
  # TODO add title as parameter
  title = nil #$sinatra.url_for($sinatra.request.env['PATH_INFO'], :full) if $sinatra
  html = "<html>"
  html += "<title>"+title+"</title>" if title
  html += "<img src="+OT_LOGO+"><body>"
    
  if AA_SERVER
    user = OpenTox::Authorization.get_user(subjectid) if subjectid
    html +=  "<pre><p align=\"right\">"
    unless user
      html += "You are currently not logged in to "+$url_provider.url_for("",:full)+
        ", <a href="+$url_provider.url_for("/login",:full)+">login</a>"
    else
      html += "You are logged in as '#{user}' to "+$url_provider.url_for("",:full)+
        ", <a href="+$url_provider.url_for("/logout",:full)+">logout</a>"
    end
    html += "  </p></pre>"
  end 
 
  html += "<h3>Description</h3><pre><p>"+description.link_urls+"</p></pre>" if description
  html += "<h3>Related links</h3><pre><p>"+related_links.link_urls+"</p></pre>" if related_links
  if post_params
    html += "<h3>POST parameters</h3>"
    count = 0
    post_params.each do |p|
      html += "<pre><p>alternatively:</p></pre>" if count > 0
      html += "<pre><p><table><thead><tr><th>param</th><th>default_value</th></tr></thead>"
      p.each do |k,v|
        html += "<tr><th>"+k.to_s+"</th><th>"+(v!=nil ? v.to_s : "<i>mandatory</i>")+"</th></tr>"
      end
      html += "</table></p></pre>"
      count += 1
    end
  end
  html += "<h3>Content</h3>" if description || related_links
  html += "<pre><p style=\"padding:15px; border:10px solid \#5D308A\">"
  html += text.link_urls
  html += "</p></pre></body><html>"
  html
end

Instance Method Details

#add_metadata(metadata) ⇒ Object



33
34
35
# File 'lib/opentox.rb', line 33

def ()
  .each { |k,v| @metadata[k] = v }
end

#delete(subjectid = nil) ⇒ Object

deletes the resource, deletion should have worked when no RestCallError raised



47
48
49
# File 'lib/opentox.rb', line 47

def delete(subjectid=nil)
  RestClientWrapper.delete(uri,:subjectid => subjectid)
end

#initialize(uri = nil) ⇒ Object

Initialize OpenTox object with optional uri

Parameters:



8
9
10
11
# File 'lib/opentox.rb', line 8

def initialize(uri=nil)
  @metadata = {}
  self.uri = uri if uri
end

#load_metadata(subjectid = nil) ⇒ Hash

Load (and return) metadata from object URI

Returns:

  • Metadata



28
29
30
31
# File 'lib/opentox.rb', line 28

def (subjectid=nil)
  @metadata = Parser::Owl::Generic.new(@uri).(subjectid)
  @metadata
end

#to_rdfxmlapplication/rdf+xml

Get OWL-DL representation in RDF/XML format

Returns:

  • RDF/XML representation



39
40
41
42
43
44
# File 'lib/opentox.rb', line 39

def to_rdfxml
  s = Serializer::Owl.new
  s.(@uri,@metadata)
  #s.add_parameters(@uri,@parameters) if @parameters
  s.to_rdfxml
end