summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormguetlein <martin.guetlein@gmail.com>2010-05-06 11:32:05 +0200
committermguetlein <martin.guetlein@gmail.com>2010-05-06 11:32:05 +0200
commit9e356d0d94ea4fe210ea7cefce5d4c1179cb63cd (patch)
tree486bd97d9e968c56c755dfa69331a8cabc70895f
parent8439bb9b337bded4a54018c03500a15082bce6b0 (diff)
major change: using literal datatypes in owl
-rw-r--r--lib/algorithm.rb2
-rw-r--r--lib/compound.rb8
-rw-r--r--lib/dataset.rb21
-rw-r--r--lib/environment.rb1
-rw-r--r--lib/model.rb40
-rw-r--r--lib/owl.rb306
-rw-r--r--lib/rest_client_wrapper.rb9
-rw-r--r--lib/task.rb4
-rw-r--r--lib/utils.rb15
9 files changed, 251 insertions, 155 deletions
diff --git a/lib/algorithm.rb b/lib/algorithm.rb
index 8083db2..7a25408 100644
--- a/lib/algorithm.rb
+++ b/lib/algorithm.rb
@@ -21,7 +21,7 @@ module OpenTox
def self.create_model(params)
LOGGER.debug params
LOGGER.debug File.basename(__FILE__) + ": creating model"
- resource = RestClient::Resource.new(File.join(@@config[:services]["opentox-algorithm"], "lazar"), :user => @@users[:users].keys[0], :password => @@users[:users].values[0], :content_type => "application/x-yaml")
+ resource = RestClient::Resource.new(File.join(@@config[:services]["opentox-algorithm"], "lazar"), :user => @@users[:users].keys[0], :password => @@users[:users].values[0], :content_type => "text/x-yaml")
@uri = resource.post(:dataset_uri => params[:dataset_uri], :feature_uri => params[:feature_uri], :feature_generation_uri => File.join(@@config[:services]["opentox-algorithm"], "fminer")).chomp
end
diff --git a/lib/compound.rb b/lib/compound.rb
index 0ee853d..cc29fc5 100644
--- a/lib/compound.rb
+++ b/lib/compound.rb
@@ -18,18 +18,18 @@ module OpenTox
@uri = File.join(@@config[:services]["opentox-compound"],URI.escape(@inchi))
elsif params[:name]
# paranoid URI encoding to keep SMILES charges and brackets
- @inchi = RestClient.get("#{@@cactus_uri}#{URI.encode(params[:name], Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))}/stdinchi").chomp
+ @inchi = RestClientWrapper.get("#{@@cactus_uri}#{URI.encode(params[:name], Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))}/stdinchi").chomp
@uri = File.join(@@config[:services]["opentox-compound"],URI.escape(@inchi))
elsif params[:uri]
@uri = params[:uri]
case params[:uri]
when /ambit/ # Ambit does not deliver InChIs reliably
- smiles = RestClient.get @uri, :accept => 'chemical/x-daylight-smiles'
+ smiles = RestClientWrapper.get @uri, :accept => 'chemical/x-daylight-smiles'
@inchi = obconversion(smiles,'smi','inchi')
when /InChI/ # shortcut for IST services
@inchi = params[:uri].sub(/^.*InChI/, 'InChI')
else
- @inchi = RestClient.get @uri, :accept => 'chemical/x-inchi'
+ @inchi = RestClientWrapper.get @uri, :accept => 'chemical/x-inchi'
end
end
end
@@ -44,7 +44,7 @@ module OpenTox
end
def image
- RestClient.get("#{@@cactus_uri}#{@inchi}/image")
+ RestClientWrapper.get("#{@@cactus_uri}#{@inchi}/image")
end
def image_uri
diff --git a/lib/dataset.rb b/lib/dataset.rb
index c513463..ff07a6f 100644
--- a/lib/dataset.rb
+++ b/lib/dataset.rb
@@ -12,12 +12,21 @@ module OpenTox
@compounds = []
end
- def self.find(uri)
+ def self.find(uri, accept_header=nil)
- if uri.match(/webservices.in-silico.ch|localhost|ot.dataset.de|opentox.informatik.uni-freiburg.de/) # try to get YAML first
- d = YAML.load RestClientWrapper.get(uri.to_s.strip, :accept => 'application/x-yaml').to_s
+ unless accept_header
+ if uri.match(@@config[:services]["opentox-dataset"])
+ accept_header = 'text/x-yaml'
+ else
+ accept_header = "application/rdf+xml"
+ end
+ end
+
+ case accept_header
+ when "text/x-yaml"
+ d = YAML.load RestClientWrapper.get(uri.to_s.strip, :accept => 'text/x-yaml').to_s
d.uri = uri unless d.uri
- else # get default rdf+xml
+ when "application/rdf+xml"
owl = OpenTox::Owl.from_uri(uri.to_s.strip, "Dataset")
d = Dataset.new
@@ -32,6 +41,8 @@ module OpenTox
d.compounds.uniq!
d.features.uniq!
+ else
+ raise "cannot get datset with accept header: "+accept_header.to_s
end
return d
end
@@ -159,7 +170,7 @@ module OpenTox
@features.uniq!
@compounds.uniq!
- RestClient::Resource.new(@@config[:services]["opentox-dataset"], :user => @@users[:users].keys[0], :password => @@users[:users].values[0]).post(self.to_yaml, :content_type => "application/x-yaml").chomp.to_s
+ OpenTox::RestClientWrapper.post(@@config[:services]["opentox-dataset"],{:content_type => "text/x-yaml"},self.to_yaml).strip
end
=begin
diff --git a/lib/environment.rb b/lib/environment.rb
index b46bf19..f89a758 100644
--- a/lib/environment.rb
+++ b/lib/environment.rb
@@ -128,6 +128,7 @@ RDF = Redland::Namespace.new 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
OWL = Redland::Namespace.new 'http://www.w3.org/2002/07/owl#'
DC = Redland::Namespace.new 'http://purl.org/dc/elements/1.1/'
OT = Redland::Namespace.new 'http://www.opentox.org/api/1.1#'
+XML = Redland::Namespace.new 'http://www.w3.org/2001/XMLSchema#'
# Regular expressions for parsing classification data
TRUE_REGEXP = /^(true|active|$1^)/
diff --git a/lib/model.rb b/lib/model.rb
index dfd5886..684873b 100644
--- a/lib/model.rb
+++ b/lib/model.rb
@@ -3,13 +3,22 @@ module OpenTox
class Generic
- attr_accessor :uri, :title, :creator, :date, :format, :predictedVariables, :independentVariables, :dependentVariables, :trainingDataset, :feature_dataset_uri, :effects, :activities, :p_values, :fingerprints, :features, :algorithm
+ MODEL_ATTRIBS = [:uri, :title, :creator, :date, :format, :predictedVariables, :independentVariables, :dependentVariables, :trainingDataset, :algorithm]
+ MODEL_ATTRIBS.each{ |a| attr_accessor(a) }
def self.find(uri)
owl = OpenTox::Owl.from_uri(uri, "Model")
return self.new(owl)
end
+ def self.to_rdf(model)
+ owl = OpenTox::Owl.create 'Model', model.uri
+ (MODEL_ATTRIBS - [:uri]).each do |a|
+ owl.set(a.to_s,model.send(a.to_s))
+ end
+ owl.rdf
+ end
+
protected
def initialize(owl)
[:date, :creator, :title, :format, :algorithm, :dependentVariables,
@@ -17,9 +26,17 @@ module OpenTox
self.send("#{a.to_s}=".to_sym, owl.get(a.to_s))
end
@uri = owl.uri
- RestClientWrapper.raise_uri_error "invalid model:\n"+
- self.to_yaml+"\n",@uri.to_s unless (Utils.is_uri?(@uri) and
- @dependentVariables and @independentVariables and @predictedVariables) if ENV['RACK_ENV'] =~ /test|debug/
+ if ENV['RACK_ENV'] =~ /test|debug/
+ begin
+ raise "uri invalid" unless Utils.is_uri?(@uri)
+ raise "no algorithm" unless @algorithm and @algorithm.size>0
+ raise "no dependent variables" unless @dependentVariables and @dependentVariables.size>0
+ raise "no indenpendent variables" unless @independentVariables
+ raise "no predicted variables" unless @predictedVariables and @predictedVariables.size>0
+ rescue => ex
+ RestClientWrapper.raise_uri_error "invalid model: '"+ex.message+"'\n"+self.to_yaml+"\n",@uri.to_s
+ end
+ end
end
end
@@ -35,6 +52,7 @@ module OpenTox
LOGGER.debug "Build model, algorithm_uri:"+algorithm_uri.to_s+", algorithm_parms: "+algorithm_params.inspect.to_s
uri = OpenTox::RestClientWrapper.post(algorithm_uri,algorithm_params).to_s
+ LOGGER.debug "Build model done: "+uri.to_s
RestClientWrapper.raise_uri_error("Invalid build model result: '"+uri.to_s+"'", algorithm_uri, algorithm_params ) unless Utils.model_uri?(uri)
return PredictionModel.find(uri)
end
@@ -57,6 +75,8 @@ module OpenTox
return false
elsif @uri =~/ambit2/ and @title =~ /pKa/
return false
+ elsif @uri =~/majority/
+ return @uri =~ /class/
else
raise "unknown model, uri:'"+@uri.to_s+"' title:'"+@title.to_s+"'"
end
@@ -65,7 +85,9 @@ module OpenTox
class Lazar < Generic
-
+
+ attr_accessor :feature_dataset_uri, :effects, :activities, :p_values, :fingerprints, :features
+
def initialize
@source = "http://github.com/helma/opentox-model"
@algorithm = File.join(@@config[:services]["opentox-algorithm"],"lazar")
@@ -80,11 +102,11 @@ module OpenTox
def save
@features.uniq!
resource = RestClient::Resource.new(@@config[:services]["opentox-model"], :user => @@users[:users].keys[0], :password => @@users[:users].values[0])
- resource.post(self.to_yaml, :content_type => "application/x-yaml").chomp.to_s
+ resource.post(self.to_yaml, :content_type => "text/x-yaml").chomp.to_s
end
def self.find_all
- RestClient.get(@@config[:services]["opentox-model"]).chomp.split("\n")
+ RestClientWrapper.get(@@config[:services]["opentox-model"]).chomp.split("\n")
end
=begin
@@ -101,7 +123,7 @@ module OpenTox
def self.create(data)
resource = RestClient::Resource.new(@@config[:services]["opentox-model"], :user => @@users[:users].keys[0], :password => @@users[:users].values[0])
- resource.post(data, :content_type => "application/x-yaml").chomp.to_s
+ resource.post(data, :content_type => "text/x-yaml").chomp.to_s
end
def delete
@@ -116,7 +138,7 @@ module OpenTox
# end
# def yaml=(data)
-# RestClient.put(@@uri, data, :content_type => "application/x-yaml").to_s
+# RestClient.put(@@uri, data, :content_type => "text/x-yaml").to_s
# end
def endpoint
diff --git a/lib/owl.rb b/lib/owl.rb
index 43d034d..671220b 100644
--- a/lib/owl.rb
+++ b/lib/owl.rb
@@ -1,16 +1,83 @@
class Redland::Literal
- def self.create(value, datatype)
- Redland::Literal.new(value,nil,Redland::Uri.new(datatype))
+ def self.create(value, datatype=nil)
+ if datatype
+ if datatype.is_a?(Redland::Uri)
+ Redland::Literal.new(value.to_s,nil,datatype)
+ else
+ Redland::Literal.new(value.to_s,nil,Redland::Uri.new(datatype.to_s))
+ end
+ else
+ Redland::Literal.new(value.to_s,nil,Redland::Literal.parse_datatype_uri(value))
+ end
end
# the literal node of the ruby swig api provdides the 'value' of a literal but not the 'datatype'
# found solution in mailing list
- def datatype()
+ def datatype
uri = Redland.librdf_node_get_literal_value_datatype_uri(self.node)
return Redland.librdf_uri_to_string(uri) if uri
end
+ # gets value of literal, value class is se according to literal datatype
+ def get_value
+ Redland::Literal.parse_value( self.value, self.datatype )
+ end
+
+ private
+ @@type_string = XML["string"].uri
+ @@type_uri = XML["anyURI"].uri
+ @@type_float = XML["float"].uri
+ @@type_double = XML["double"].uri
+ @@type_date = XML["date"].uri
+ @@type_boolean = XML["boolean"].uri
+ @@type_datetime = XML["dateTime"].uri
+
+ # parses value according to datatype uri
+ def self.parse_value(string_value, datatype_uri)
+ if (datatype_uri==nil || datatype_uri.size==0)
+ LOGGER.warn("empty datatype for literal with value: "+string_value)
+ return string_value
+ end
+ case datatype_uri
+ when @@type_string.to_s
+ return string_value
+ when @@type_uri.to_s
+ return string_value #PENDING uri as string?
+ when @@type_float.to_s
+ return string_value.to_f
+ when @@type_double.to_s
+ return string_value.to_f
+ when @@type_boolean.to_s
+ return string_value.upcase=="TRUE"
+ when @@type_date.to_s
+ return string_value #PENDING date as string?
+ when @@type_datetime.to_s
+ return string_value #PENDING date as string?
+ else
+ raise "unknown literal datatype: '"+datatype_uri.to_s+"', value is "+string_value
+ end
+ end
+
+ # parse datatype uri accoring to value class
+ def self.parse_datatype_uri(value)
+ if value==nil
+ raise "illegal datatype: value is nil"
+ elsif value.is_a?(String)
+ # PENDING: uri check too slow?
+ if OpenTox::Utils.is_uri?(value)
+ return @@type_uri
+ else
+ return @@type_string
+ end
+ elsif value.is_a?(Float)
+ return @@type_float
+ elsif value.is_a?(TrueClass) or value.is_a?(FalseClass)
+ return @@type_boolean
+ else
+ raise "illegal datatype: "+value.class.to_s+" "+value.to_s
+ end
+ end
end
module OpenTox
@@ -75,7 +142,7 @@ module OpenTox
end
def self.from_uri(uri, ot_class)
- return from_data(RestClient.get(uri,:accept => "application/rdf+xml").to_s, uri, ot_class)
+ return from_data(RestClientWrapper.get(uri,:accept => "application/rdf+xml").to_s, uri, ot_class)
end
def rdf
@@ -83,24 +150,25 @@ module OpenTox
end
def get(name)
- #PENDING remove debug checks
- raise "get identifier deprecated, use uri instead" if name=="identifier"
raise "uri is no prop, use owl.uri instead" if name=="uri"
property_node = node(name.to_s)
- val = @model.object(@root_node, property_node)
- return nil unless val
- if val.is_a?(Redland::Literal)
- return val.value
- elsif val.blank?
+ return get_value( @model.object(@root_node, property_node) )
+ end
+
+ private
+ def get_value( node )
+ return nil unless node
+ if node.is_a?(Redland::Literal)
+ return node.get_value
+ elsif node.blank?
return nil
else
- return val.uri.to_s
+ return node.uri.to_s
end
end
+ public
def set(name, value, datatype=nil)
- #PENDING remove debug checks
- raise "set identifier deprecated, use uri instead" if name=="identifier"
raise "uri is no prop, cannot set uri" if name=="uri"
property_node = node(name.to_s)
begin # delete existing entry
@@ -111,10 +179,8 @@ module OpenTox
if value.is_a?(Redland::Node)
raise "not nil datatype not allowed when setting redland node as value" if datatype
@model.add @root_node, property_node, value
- elsif datatype
+ else # if value is no node, a literal is created
@model.add @root_node, property_node, Redland::Literal.create(value.to_s, datatype)
- else
- @model.add @root_node, property_node, value.to_s
end
end
@@ -135,7 +201,6 @@ module OpenTox
if compound.nil?
compound = @model.create_resource(compound_uri)
@model.add compound, node('type'), node("Compound")
- @model.add compound, node("identifier"), compound_uri
end
features.each do |f|
f.each do |feature_uri,value|
@@ -152,7 +217,7 @@ module OpenTox
@model.add tuple, node('complexValue'), complex_value
@model.add complex_value, node('type'), node("FeatureValue")
@model.add complex_value, node('feature'), f
- @model.add complex_value, node('value'), v.to_s
+ @model.add complex_value, node('value'), Redland::Literal.create(v)
end
# add data entry
data_entry = @model.subject node('compound'), compound
@@ -175,134 +240,118 @@ module OpenTox
@model.add data_entry, node('values'), values
@model.add values, node('type'), node('FeatureValue')
@model.add values, node('feature'), feature
- @model.add values, node('value'), value.to_s
+ @model.add values, node('value'), Redland::Literal.create(value)
end
end
end
- end
+ end
+
+ private
+ def find_feature(feature_uri)
+ # PENDING: more efficiently get feature node?
+ @model.subjects(RDF['type'], OT['Feature']).each do |feature|
+ return feature if feature_uri==get_value(feature)
+ end
+ return nil
+ end
- def find_or_create_feature(feature_uri)
- feature = @model.subject(node("identifier"), feature_uri)
- if feature.nil?
- feature = @model.create_resource(feature_uri)
- @model.add feature, node('type'), node("Feature")
- @model.add feature, node("identifier"), feature_uri
- @model.add feature, node("title"), File.basename(feature_uri).split(/#/)[1]
- @model.add feature, node('creator'), feature_uri
- end
- feature
- end
+ public
+ def find_or_create_feature(feature_uri)
+ feature = find_feature(feature_uri)
+ unless feature
+ feature = @model.create_resource(feature_uri)
+ @model.add feature, node('type'), node("Feature")
+ @model.add feature, node("title"), File.basename(feature_uri).split(/#/)[1]
+ @model.add feature, node('creator'), feature_uri
+ end
+ feature
+ end
- # feature values are not loaded for performance reasons
- # loading compounds and features into arrays that are given as params
- def load_dataset( compounds, features )
- @model.subjects(node('type'), node('DataEntry')).each do |data_entry|
- compound_node = @model.object(data_entry, node('compound'))
- compound_uri = @model.object(compound_node, node('identifier')).to_s
- compounds << compound_uri
- end
- @model.subjects(node('type'), node('Feature')).each do |feature|
- feature_literal = @model.object(feature, node('identifier'))
- raise "feature is no literal" unless feature_literal.is_a?(Redland::Literal)
- # PENDING: to be able to recreate literal nodes for features, the datatype is stored
- @@feature_datatype = feature_literal.datatype
- features << feature_literal.value
- end
- LOGGER.debug "loaded "+compounds.size.to_s+" compounds and "+features.size.to_s+" features"
+ # feature values are not loaded for performance reasons
+ # loading compounds and features into arrays that are given as params
+ def load_dataset( compounds, features )
+
+ @model.subjects(node('type'), node('Compound')).each do |compound|
+ compounds << get_value(compound)
+ end
+ @model.subjects(node('type'), node('Feature')).each do |feature|
+ features << get_value(feature)
end
+ LOGGER.debug "loaded "+compounds.size.to_s+" compounds and "+features.size.to_s+" features"
+ end
- # loading feature values for the specified feature
- # if feature is nil, all feature values are loaded
- #
- # general remark on the rdf loading (found out with some testing):
- # the search methods (subjects/find) are fast, the time consuming parts is creating resources,
- # which cannot be avoided in general (implemented some performance tweaks with uri storing when loading all features)
- def load_dataset_feature_values( compounds, data, feature_uri=nil )
-
- LOGGER.debug("load feature values"+ ( (feature_uri!=nil)?(" for feature: "+feature_uri):"") )
+ # loading feature values for the specified feature
+ # if feature is nil, all feature values are loaded
+ #
+ # general remark on the rdf loading (found out with some testing):
+ # the search methods (subjects/find) are fast, the time consuming parts is creating resources,
+ # which cannot be avoided in general (implemented some performance tweaks with uri storing when loading all features)
+ def load_dataset_feature_values( compounds, data, feature_uri=nil )
+
+ LOGGER.debug("load feature values"+ ( (feature_uri!=nil)?(" for feature: "+feature_uri):"") )
- # values are stored in the data-hash, hash has a key for each compound
- compounds.each{|c| data[c] = [] unless data[c]}
-
- load_all_features = feature_uri==nil
- feature_node = nil
-
- # create feature node for feature uri if specified
- unless load_all_features
- feature_literal = Redland::Literal.new(feature_uri,nil,Redland::Uri.new(@@feature_datatype))
- feature_node = @model.subject(node('identifier'), feature_literal)
- # remark: solution without creating the literal node:
- #@model.subjects(RDF['type'], OT['Feature']).each do |feature|
- # f_uri = @model.object(feature, node('identifier')).value
- # if feature_uri==f_uri
- # feature_node = feature
- # break
- # end
- #end
- raise "feature node not found" unless feature_node
+ # values are stored in the data-hash, hash has a key for each compound
+ compounds.each{|c| data[c] = [] unless data[c]}
+
+ load_all_features = feature_uri==nil
+ feature_node = nil
+
+ # create feature node for feature uri if specified
+ unless load_all_features
+ feature_node = find_feature(feature_uri)
+ raise "feature node not found" unless feature_node
+ end
+
+ count = 0
+
+ # preformance tweak: store uirs to save some resource init time
+ compound_uri_store = {}
+ feature_uri_store = {}
+
+ # search for all feature_value_node with property 'ot_feature'
+ # feature_node is either nil, i.e. a wildcard or specified
+ @model.find(nil, node('feature'), feature_node) do |feature_value_node,p,o|
+
+ # get compound_uri by "backtracking" to values node (property is 'values'), then get compound_node via 'compound'
+ value_nodes = @model.subjects(node('values'),feature_value_node)
+ raise "more than one value node "+value_nodes.size.to_s unless value_nodes.size==1
+ value_node = value_nodes[0]
+ compound_node = @model.object(value_node, node('compound'))
+ compound_uri = compound_uri_store[compound_node.to_s]
+ unless compound_uri
+ compound_uri = get_value(compound_node)
+ compound_uri_store[compound_node.to_s] = compound_uri
end
- count = 0
-
- # preformance tweak: store uirs to save some resource init time
- compound_uri_store = {}
- feature_uri_store = {}
-
- # search for all feature_value_node with property 'ot_feature'
- # feature_node is either nil, i.e. a wildcard or specified
- @model.find(nil, node('feature'), feature_node) do |feature_value_node,p,o|
-
- # get compound_uri by "backtracking" to values node (property is 'values'), then get compound_node via 'compound'
- value_nodes = @model.subjects(node('values'),feature_value_node)
- raise "more than one value node "+value_nodes.size.to_s unless value_nodes.size==1
- value_node = value_nodes[0]
- compound_node = @model.object(value_node, node('compound'))
- compound_uri = compound_uri_store[compound_node.to_s]
- unless compound_uri
- compound_uri = @model.object(compound_node, node('identifier')).to_s
- compound_uri_store[compound_node.to_s] = compound_uri
- end
-
- if load_all_features
- # if load all features, feautre_uri is not specified, derieve from feature_node
- feature_uri = feature_uri_store[o.to_s]
- unless feature_uri
- feature_literal = @model.object(o, node('identifier'))
- raise "feature is no literal" unless feature_literal.is_a?(Redland::Literal)
- feature_uri = feature_literal.value
- feature_uri_store[o.to_s] = feature_uri
- end
+ if load_all_features
+ # if load all features, feautre_uri is not specified, derieve from feature_node
+ feature_uri = feature_uri_store[o.to_s]
+ unless feature_uri
+ feature_uri = get_value(o)
+ feature_uri_store[o.to_s] = feature_uri
end
-
- value_node_type = @model.object(feature_value_node, node('type'))
- if (value_node_type == node('FeatureValue'))
- value_literal = @model.object( feature_value_node, node('value'))
- raise "feature value no literal" unless value_literal.is_a?(Redland::Literal)
-
- case value_literal.datatype
- when /XMLSchema#double/
- data[compound_uri] << {feature_uri => value_literal.value.to_f }
- when /XMLSchema#string/
- data[compound_uri] << {feature_uri => value_literal.value }
- else
- raise "feature value datatype undefined: "+value_literal.datatype
- end
- else
- raise "feature value type not yet implemented "+value_node_type.to_s
- end
- count += 1
- LOGGER.debug "loaded "+count.to_s+" feature values" if (count%500 == 0)
end
- LOGGER.debug "loaded "+count.to_s+" feature values"
+ value_node_type = @model.object(feature_value_node, node('type'))
+ if (value_node_type == node('FeatureValue'))
+ value_literal = @model.object( feature_value_node, node('value'))
+ raise "feature value no literal" unless value_literal.is_a?(Redland::Literal)
+ data[compound_uri] << {feature_uri => value_literal.get_value }
+ else
+ raise "feature value type not yet implemented "+value_node_type.to_s
+ end
+ count += 1
+ LOGGER.debug "loaded "+count.to_s+" feature values" if (count%500 == 0)
+ end
+
+ LOGGER.debug "loaded "+count.to_s+" feature values"
end
@@property_nodes = { "type" => RDF["type"],
"about" => RDF["about"],
"title" => DC["title"],
"creator" => DC["creator"],
- "uri" => DC["identifier"],
- "identifier" => DC["identifier"],
+ #"identifier" => DC["identifier"], identifier is deprecated
"date" => DC["date"],
"format" => DC["format"]}
@@ -310,6 +359,7 @@ module OpenTox
# * distinguishing ot-properties from dc- and rdf- properties
# * caching nodes, as creating nodes is costly
def node(name)
+ raise "dc[identifier] deprecated, use owl.uri" if name=="identifier"
n = @@property_nodes[name]
unless n
n = OT[name]
diff --git a/lib/rest_client_wrapper.rb b/lib/rest_client_wrapper.rb
index f917e35..187f3a9 100644
--- a/lib/rest_client_wrapper.rb
+++ b/lib/rest_client_wrapper.rb
@@ -67,7 +67,7 @@ module OpenTox
begin
#LOGGER.debug "RestCall: "+rest_call.to_s+" "+uri.to_s+" "+headers.inspect
- resource = RestClient::Resource.new(uri,{:timeout => 60, :user => @@users[:users].keys[0], :password => @@users[:users].values[0]})
+ resource = RestClient::Resource.new(uri,{:timeout => 60}) #, :user => @@users[:users].keys[0], :password => @@users[:users].values[0]})
if payload
result = resource.send(rest_call, payload, headers)
elsif headers
@@ -76,9 +76,10 @@ module OpenTox
result = resource.send(rest_call)
end
- # result is a string, with the additional filed content_type
- res = WrapperResult.new(result.to_s)
+ # result is a string, with the additional fields content_type and code
+ res = WrapperResult.new(result.body)
res.content_type = result.headers[:content_type]
+ raise "content-type not set" unless res.content_type
res.code = result.code
return res if res.code==200 || !wait
@@ -118,7 +119,7 @@ module OpenTox
res.split("\n").size > 1 #if uri list contains more then one uri, its not a task
task = OpenTox::Task.find(res.to_s) if Utils.task_uri?(res)
else
- raise "unknown content-type for task: "+res.content_type+" content: "+res[0..200]
+ raise "unknown content-type for task: '"+res.content_type.to_s+"'" #+"' content: "+res[0..200].to_s
end
LOGGER.debug "result is a task '"+task.uri.to_s+"', wait for completion"
diff --git a/lib/task.rb b/lib/task.rb
index b686d24..9cfba88 100644
--- a/lib/task.rb
+++ b/lib/task.rb
@@ -10,7 +10,7 @@ module OpenTox
class Task
# due_to_time is only set in local tasks
- TASK_ATTRIBS = [ :uri, :date, :title, :creator, :title, :description, :hasStatus, :percentageCompleted, :resultURI, :due_to_time ]
+ TASK_ATTRIBS = [ :uri, :date, :title, :creator, :description, :hasStatus, :percentageCompleted, :resultURI, :due_to_time ]
TASK_ATTRIBS.each{ |a| attr_accessor(a) }
attr_accessor :http_code
@@ -134,7 +134,6 @@ module OpenTox
rescue => ex
RestClientWrapper.raise_uri_error(ex.message, @uri)
end
-
end
# returns the task uri
@@ -161,6 +160,7 @@ module OpenTox
task.completed(result)
rescue => ex
LOGGER.error "task failed: "+ex.message
+ #LOGGER.error ": "+ex.backtrace.join("\n")
task.error(ex.message)
end
end
diff --git a/lib/utils.rb b/lib/utils.rb
index 629404c..6b32421 100644
--- a/lib/utils.rb
+++ b/lib/utils.rb
@@ -20,11 +20,22 @@ module OpenTox
def self.is_uri?(uri)
+ return false if uri==nil || uri.to_s.size==0
begin
- URI::parse(uri)
+ u = URI::parse(uri)
+ return (u.scheme!=nil and u.host!=nil)
rescue URI::InvalidURIError
- false
+ return false
end
end
end
+
+# ['rubygems', 'rest_client'].each do |r|
+# require r
+# end
+# ["bla", "google.de", "http://google.de"].each do |u|
+# puts u+"? "+Utils.is_uri?(u).to_s
+# end
+
end
+