summaryrefslogtreecommitdiff
path: root/lib/dataset.rb
diff options
context:
space:
mode:
authormguetlein <martin.guetlein@gmail.com>2010-06-25 20:44:49 +0200
committermguetlein <martin.guetlein@gmail.com>2010-06-25 20:44:49 +0200
commit5cdd09a98b1edfb8be3e4693a4b129b9b35ad9f2 (patch)
treefa70316a483282d7f77306c04bc4aca6dc72ad7a /lib/dataset.rb
parente5838e7607533b5087a89949fea15f694f184b17 (diff)
parentba287d744cdc929df7e3ed3986151b813ddf8fb1 (diff)
resolved conflicts, replace text/x-yaml with application/x-yaml, acceess classification values w/o confidence
Diffstat (limited to 'lib/dataset.rb')
-rw-r--r--lib/dataset.rb145
1 files changed, 18 insertions, 127 deletions
diff --git a/lib/dataset.rb b/lib/dataset.rb
index e506305..1254992 100644
--- a/lib/dataset.rb
+++ b/lib/dataset.rb
@@ -15,15 +15,16 @@ module OpenTox
def self.find(uri, accept_header=nil)
unless accept_header
- if uri.match(@@config[:services]["opentox-dataset"]) || uri=~ /188.40.32.88/ || uri =~ /in-silico.ch/
- accept_header = 'text/x-yaml'
+ #if uri.match(@@config[:services]["opentox-dataset"]) || uri=~ /188.40.32.88/ || uri =~ /informatik/
+ if !@@config[:accept_headers]["opentox-dataset"].grep(/yaml/).empty?
+ accept_header = 'application/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
+ when "application/x-yaml"
+ d = YAML.load RestClientWrapper.get(uri.to_s.strip, :accept => 'application/x-yaml').to_s
d.uri = uri unless d.uri
when "application/rdf+xml"
owl = OpenTox::Owl.from_uri(uri.to_s.strip, "Dataset")
@@ -90,15 +91,16 @@ module OpenTox
else
return "no classification key"
end
- else
- raise "predicted class value is not a hash\n"+
+ elsif v.is_a?(Array)
+ raise "predicted class value is an array\n"+
"value "+v.to_s+"\n"+
"value-class "+v.class.to_s+"\n"+
"dataset "+@uri.to_s+"\n"+
"compound "+compound.to_s+"\n"+
"feature "+feature.to_s+"\n"
+ else
+ return v
end
-
end
# returns prediction confidence if available
@@ -112,12 +114,14 @@ module OpenTox
raise "no confidence key"
end
else
- raise "prediction confidence value is not a hash value\n"+
- "value "+v.to_s+"\n"+
- "value-class "+v.class.to_s+"\n"+
- "dataset "+@uri.to_s+"\n"+
- "compound "+compound.to_s+"\n"+
- "feature "+feature.to_s+"\n"
+ LOGGER.warn "no confidence for compound: "+compound.to_s+", feature: "+feature.to_s
+ return 1
+# raise "prediction confidence value is not a hash value\n"+
+# "value "+v.to_s+"\n"+
+# "value-class "+v.class.to_s+"\n"+
+# "dataset "+@uri.to_s+"\n"+
+# "compound "+compound.to_s+"\n"+
+# "feature "+feature.to_s+"\n"
end
end
@@ -172,122 +176,9 @@ module OpenTox
@features.uniq!
@compounds.uniq!
- OpenTox::RestClientWrapper.post(@@config[:services]["opentox-dataset"],{:content_type => "text/x-yaml"},self.to_yaml).strip.to_s
- end
-
-=begin
- # create/add to entry from uris or Redland::Resources
- def add(compound,feature,value)
- compound = self.find_or_create_compound compound unless compound.class == Redland::Resource
- feature = self.find_or_create_feature feature unless feature.class == Redland::Resource
- data_entry = @model.subject OT['compound'], compound
- if data_entry.nil?
- data_entry = @model.create_resource
- dataset = @model.subject(RDF['type'],OT[self.owl_class])
- @model.add dataset, OT['dataEntry'], data_entry
- @model.add data_entry, RDF['type'], OT["DataEntry"]
- @model.add data_entry, OT['compound'], compound
- end
- values = @model.create_resource
- @model.add data_entry, OT['values'], values
- @model.add values, RDF['type'], OT['FeatureValue']
- @model.add values, OT['feature'], feature
- @model.add values, OT['value'], value.to_s
- end
-
- def add_tuple(compound,tuple)
- compound = self.find_or_create_compound compound unless compound.class == Redland::Resource
- data_entry = @model.subject OT['compound'], compound
- if data_entry.nil?
- data_entry = @model.create_resource
- dataset = @model.subject(RDF['type'],OT[self.owl_class])
- @model.add dataset, OT['dataEntry'], data_entry
- @model.add data_entry, RDF['type'], OT["DataEntry"]
- @model.add data_entry, OT['compound'], compound
- end
- @model.add data_entry, OT['values'], tuple
- end
-
- def create_tuple(feature,t)
- feature = self.find_or_create_feature feature unless feature.class == Redland::Resource
- tuple = @model.create_resource
- @model.add tuple, RDF['type'], OT["Tuple"]
- @model.add tuple, OT['feature'], feature
- t.each do |name,value|
- f = self.find_or_create_feature name unless name.class == Redland::Resource
- complex_value = @model.create_resource
- feature = self.find_or_create_feature(name)
- @model.add tuple, OT['complexValue'], complex_value
- @model.add complex_value, RDF['type'], OT["FeatureValue"]
- @model.add complex_value, OT['feature'], f
- @model.add complex_value, OT['value'], value.to_s
- end
-
- tuple
- end
-
- # find or create a new compound and return the resource
- def find_or_create_compound(uri)
- compound = @model.subject(DC["identifier"], uri)
- if compound.nil?
- compound = @model.create_resource(uri)
- @model.add compound, RDF['type'], OT["Compound"]
- @model.add compound, DC["identifier"], uri
- end
- compound
- end
-
- # find or create a new feature and return the resource
- def find_or_create_feature(uri)
- feature = @model.subject(DC["identifier"], uri)
- if feature.nil?
- feature = @model.create_resource(uri)
- @model.add feature, RDF['type'], OT["Feature"]
- @model.add feature, DC["identifier"], uri
- @model.add feature, DC["title"], File.basename(uri).split(/#/)[1]
- @model.add feature, DC['source'], uri
- end
- feature
- end
-
- def self.create(data, content_type = 'application/rdf+xml')
- resource = RestClient::Resource.new(@@config[:services]["opentox-dataset"], :user => @@users[:users].keys[0], :password => @@users[:users].values[0])
- uri = resource.post data, :content_type => content_type
- dataset = Dataset.new
- dataset.read uri.chomp.to_s
- dataset
- end
-
- def features
- features = []
- @model.subjects(RDF['type'], OT["Feature"]).each do |feature_node|
- features << @model.object(feature_node, DC["identifier"])#
- end
- features
- end
-
- def compounds
- compounds = []
- @model.subjects(RDF['type'], OT["Compound"]).each do |compound_node|
- compounds << @model.object(compound_node, DC["identifier"]).to_s
- end
- compounds
- end
-
- # Delete a dataset
- def delete
- resource = RestClient::Resource.new(@uri, :user => @@users[:users].keys[0], :password => @@users[:users].values[0])
- resource.delete
- end
-
- def to_owl
- end
-
- def from_owl
+ OpenTox::RestClientWrapper.post(@@config[:services]["opentox-dataset"],{:content_type => "application/x-yaml"},self.to_yaml).strip
end
-=end
-
def init_dirty_features(owl)
@dirty_features = @features
@owl = owl