summaryrefslogtreecommitdiff
path: root/test/validation_util.rb
blob: 0e82aec16642264ed614d68f4c4b12f551b5948c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class String 
  def uri?
    uri = URI.parse(self)
    %w( http https ).include?(uri.scheme)
  rescue URI::BadURIError
    false
  rescue URI::InvalidURIError
    false
  end
end

class ValidationTestUtil    
  
  @@dataset_uris = {}
  @@prediction_features = {}

  def self.upload_dataset(file, dataset_service=$dataset[:uri])
    internal_server_error "File not found: "+file.path.to_s unless File.exist?(file.path)
    if @@dataset_uris[file.path.to_s]==nil
      puts "uploading file: "+file.path.to_s
      if (file.path =~ /csv$/)
        d = OpenTox::Dataset.new
        d.upload file.path
        internal_server_error "num features not 1 (="+d.features.size.to_s+"), what to predict??" if d.features.size != 1
        @@prediction_features[file.path.to_s] = d.features[0].uri
        @@dataset_uris[file.path.to_s] = d.uri
      else
        internal_server_error "unknown file type: "+file.path.to_s
      end
      puts "uploaded dataset: "+d.uri
    else
      puts "file already uploaded: "+@@dataset_uris[file.path.to_s]
    end
    return @@dataset_uris[file.path.to_s]
  end
  
  def self.prediction_feature_for_file(file)
    raise "no prediction feature available for #{file.path}" unless @@prediction_features[file.path.to_s]
    @@prediction_features[file.path.to_s]
  end

end