Class: Treat::Learning::Question

Inherits:
Object
  • Object
show all
Defined in:
lib/treat/learning/question.rb

Overview

Defines a question to answer in the context of a classification problem.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, target, default = nil, type = :continuous) ⇒ Question

Initialize the question.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/treat/learning/question.rb', line 21

def initialize(name, target, default = nil, type = :continuous)
  unless name.is_a?(Symbol)
    raise Treat::Exception, 
    "Question name should be a symbol."
  end
  unless Treat.core.entities.list.include?(target)
    raise Treat::Exception, "Target type should be " +
    "a symbol and should be one of the following: " +
    Treat.core.entities.list.inspect
  end
  unless [:continuous, :discrete].include?(type)
    raise Treat::Exception, "Type should be " +
    "continuous or discrete."
  end
  @name, @target, @type, @default = 
   name,  target,  type,  default
end

Instance Attribute Details

#defaultObject (readonly)

Default for the answer to the question.



18
19
20
# File 'lib/treat/learning/question.rb', line 18

def default
  @default
end

#nameObject (readonly)

Defines an arbitrary label for the question we are trying to answer (e.g. is_key_sentence), which will also be used as the annotation name for the answer to the question.



10
11
12
# File 'lib/treat/learning/question.rb', line 10

def name
  @name
end

#targetObject (readonly)

Defines the target of the question (e.g. :sentence, :paragraph, etc.)



13
14
15
# File 'lib/treat/learning/question.rb', line 13

def target
  @target
end

#typeObject (readonly)

Can be :continuous or :discrete, depending on the features used.



16
17
18
# File 'lib/treat/learning/question.rb', line 16

def type
  @type
end

Instance Method Details

#==(question) ⇒ Object

Custom comparison operator for questions.



40
41
42
43
44
45
# File 'lib/treat/learning/question.rb', line 40

def ==(question)
  @name == question.name &&
  @type == question.type &&
  @target == question.target &&
  @default == question.default
end