diff options
author | Martin Gütlein <martin.guetlein@gmail.com> | 2010-03-26 17:08:15 +0100 |
---|---|---|
committer | Martin Gütlein <martin.guetlein@gmail.com> | 2010-03-26 17:08:15 +0100 |
commit | 79e5b48a59e9f2178f94f07788e93932bdad816f (patch) | |
tree | b774ae257f73257259535409211b907da69785cd /lib | |
parent | 7b8d85cb91c0a0a6ec530fc527be6ec67f70df99 (diff) |
adding ambit/ntua hacks
Diffstat (limited to 'lib')
-rw-r--r-- | lib/dataset.rb | 11 | ||||
-rw-r--r-- | lib/model.rb | 35 | ||||
-rw-r--r-- | lib/owl.rb | 58 |
3 files changed, 79 insertions, 25 deletions
diff --git a/lib/dataset.rb b/lib/dataset.rb index c472d84..0baec2f 100644 --- a/lib/dataset.rb +++ b/lib/dataset.rb @@ -29,11 +29,20 @@ module OpenTox d.data.each do |compound,features| d.compounds << compound features.each do |f,v| - d.features << f + d.features << f.keys[0] end end d.compounds.uniq! d.features.uniq! + + #PENDING: remove debug checks + d.data.each do |c,f| + f.each do |ff,v| + raise "illegal data: feature is no string "+ff.inspect unless ff.is_a?(Hash) + end + end + raise "illedal dataset data\n"+d.data.inspect+"\n" unless d.data.is_a?(Hash) and d.data.values.is_a?(Array) + raise "illegal dataset features:\n"+d.features.inspect+"\n" unless d.features.size>0 and d.features[0].is_a?(String) end return d end diff --git a/lib/model.rb b/lib/model.rb index 9f03c4b..d8d751b 100644 --- a/lib/model.rb +++ b/lib/model.rb @@ -15,13 +15,13 @@ module OpenTox @title = owl.title @source = owl.source @identifier = owl.identifier.sub(/^\[/,'').sub(/\]$/,'') - @uri = @identifier + @uri = owl.uri.to_s #@identifier @algorithm = owl.algorithm @dependent_variables = owl.dependentVariables @independent_variables = owl.independentVariables @predicted_variables = owl.predictedVariables - raise "invalid model: "+self.to_yaml unless @dependent_variables.to_s.size>0 && @independent_variables.to_s.size>0 && @predicted_variables.to_s.size>0 + raise "invalid model:\n"+self.to_yaml+"\n" unless Utils.is_uri?(@uri) && @dependent_variables.to_s.size>0 && @independent_variables.to_s.size>0 && @predicted_variables.to_s.size>0 end end @@ -47,18 +47,37 @@ module OpenTox uri += line end end - uri = OpenTox::Task.find(uri).wait_for_resource.to_s if Utils.task_uri?(uri) - return uri if Utils.dataset_uri?(uri) - raise "not sure about prediction result: "+uri.to_s + + if uri.to_s =~ /ambit.*task/ + #HACK handle redirect + LOGGER.debug "AMBIT TASK "+uri.to_s + redirect = "" + while (redirect.size == 0) + IO.popen("bin/redirect.sh "+uri.to_s) do |f| + while line = f.gets + redirect += line.chomp + end + end + sleep 0.3 + end + LOGGER.debug "REDIRECT to: "+redirect.to_s + raise "invalid redirect result" unless redirect =~ /ambit.*dataset/ + return uri + else + uri = OpenTox::Task.find(uri).wait_for_resource.to_s if Utils.task_uri?(uri) + return uri if Utils.dataset_uri?(uri) + raise "not sure about prediction result: "+uri.to_s + end end def classification? #HACK replace with request to ontology server - case @title - when /lazar classification/ + if @title =~ /lazar classification/ return true + elsif @uri =~/ntua/ and @title =~ /mlr/ + return false else - raise "unknown model: "+@title.to_s + raise "unknown model, uri:"+@uri.to_s+" title:"+@title.to_s end end end @@ -15,29 +15,34 @@ module OpenTox owl.model.add owl.uri, RDF['type'], OT[owl.ot_class] owl.model.add owl.uri, DC['identifier'], owl.uri owl - end + end - def self.from_uri(uri) - owl = OpenTox::Owl.new - parser = Redland::Parser.new - begin - data = RestClient.get(uri,:accept => "application/rdf+xml").to_s - parser.parse_string_into_model(owl.model, data, uri) - #parser.parse_into_model(owl.model,uri) - rescue => e - raise "Error parsing #{uri}: "+e.message - #raise "Error parsing #{uri}: #{e.message.to_s + e.backtrace.to_s}" - end - owl.uri = Redland::Uri.new(uri.chomp) - owl + def self.from_data(data,uri) + owl = OpenTox::Owl.new + parser = Redland::Parser.new + begin + parser.parse_string_into_model(owl.model, data, uri) + rescue => e + raise "Error parsing #{uri}: "+e.message + end + owl.uri = Redland::Uri.new(uri.chomp) + owl + end + + def self.from_uri(uri) + return from_data(RestClient.get(uri,:accept => "application/rdf+xml").to_s, uri) end def rdf @model.to_string end + #def predictedVariables + # + #end + def method_missing(name, *args) - methods = ['title', 'source', 'identifier', 'algorithm', 'independentVariables', 'dependentVariables', 'predictedVariables', 'date','trainingDataset' ] + methods = ['title', 'source', 'identifier', 'algorithm', 'independentVariables', 'dependentVariables', 'predictedVariables', 'date','trainingDataset', 'hasStatus', "percentageCompleted" ] if methods.include? name.to_s.sub(/=/,'') if /=/ =~ name.to_s # setter name = name.to_s.sub(/=/,'') @@ -48,6 +53,16 @@ module OpenTox end @model.add @uri, DC[name], args.first else # getter + #HACK for reading Panteli's models + if @uri.to_s =~ /ntua.*model/ and !["title", "source", "identifier"].include?(name.to_s) + me = @model.subject(RDF['type'],OT['Model']) + #puts "going for "+name.to_s + return @model.object(me, OT[name.to_s]).uri.to_s + elsif @uri.to_s =~ /ambit.*task/ and ["hasStatus", "percentageCompleted"].include?(name.to_s) + me = @model.subject(RDF['type'],OT['Task']) + return @model.object(me, OT[name.to_s]).literal.value.to_s + end + #raise "stop there "+name.to_s @model.object(@uri, DC[name.to_s]).to_s end else @@ -145,8 +160,19 @@ module OpenTox value = true when FALSE_REGEXP # defined in environment.rb value = false + when /.*\^\^<.*XMLSchema#.*>/ + #HACK for reading ambit datasets + case value.to_s + when /XMLSchema#string/ + value = value.to_s[0..(value.to_s.index("^^")-1)] + when /XMLSchema#double/ + value = value.to_s[0..(value.to_s.index("^^")-1)].to_f + else + LOGGER.warn " ILLEGAL TYPE "+compound_uri + " has value '" + value.to_s + "' for feature " + feature_uri + value = nil + end else - LOGGER.warn compound_uri + " has value '" + value.to_s + "' for feature " + feature_uri + LOGGER.warn compound_uri + " has value '" + value.to_s + "' for feature " + feature_uri value = nil end data[compound_uri] = [] unless data[compound_uri] |