Class: OpenTox::Feature

Inherits:
Object
  • Object
show all
Includes:
OpenTox
Defined in:
lib/feature.rb

Instance Attribute Summary collapse

Attributes included from OpenTox

#metadata, #uri

Class Method Summary collapse

Instance Method Summary collapse

Methods included from OpenTox

#add_metadata, all, #delete, #initialize, #load_metadata, sign_in, text_to_html, #to_rdfxml

Instance Attribute Details

#subjectidObject

Returns the value of attribute subjectid.



5
6
7
# File 'lib/feature.rb', line 5

def subjectid
  @subjectid
end

Class Method Details

.find(uri, subjectid = nil) ⇒ OpenTox::Task

Find a feature

Parameters:

  • uri (String)

    Feature URI

Returns:



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/feature.rb', line 10

def self.find(uri, subjectid=nil)
  return nil unless uri   
  feature = Feature.new uri
  if (CONFIG[:json_hosts].include?(URI.parse(uri).host))
    feature. YAML.load(RestClientWrapper.get(uri,{:accept => "application/x-yaml", :subjectid => subjectid}))
  else
    feature.  Parser::Owl::Dataset.new(uri).
  end
  feature.subjectid = subjectid
  feature
end

Instance Method Details

#feature_typeString

provides feature type, possible types are “regression” or “classification”

Returns:

  • (String)

    feature type, unknown if OT.isA property is unknown/ not set

Raises:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/feature.rb', line 24

def feature_type
  raise OpenTox::BadRequestError.new("rdf type of feature '"+uri.to_s+"' not set") unless [RDF.type]
  if [RDF.type].to_a.flatten.include?(OT.NominalFeature)
    "classification"
  elsif [RDF.type].to_a.flatten.include?(OT.NumericFeature)
    "regression"
  elsif [OWL.sameAs]
    [OWL.sameAs].each do |f|
      begin
        type = Feature.find(f, subjectid).feature_type
        return type unless type=="unknown"
      rescue => ex
        LOGGER.warn "could not load same-as-feature '"+f.to_s+"' for feature '"+uri.to_s+"' : "+ex.message.to_s
      end
    end
    "unknown"
  else
    "unknown"
  end
end