Module: Dwarf::ExampleManagement

Included in:
Classifier, Information
Defined in:
lib/dwarf/example_management.rb

Instance Method Summary collapse

Instance Method Details

#attribute_map(example_subset, attribute) ⇒ Object



21
22
23
24
25
# File 'lib/dwarf/example_management.rb', line 21

def attribute_map(example_subset, attribute)
  example_map = {}
  example_subset.each {|example| example_map[example] = eval_attribute(example, attribute)}
  example_map
end

#classification_map(example_subset, classifications) ⇒ Object



4
5
6
7
8
# File 'lib/dwarf/example_management.rb', line 4

def classification_map(example_subset, classifications)
  classification_map = {}
  example_subset.each {|example| classification_map[example] = classifications[example]}
  classification_map
end

#eval_attribute(example, attribute) ⇒ Object



17
18
19
# File 'lib/dwarf/example_management.rb', line 17

def eval_attribute(example,attribute)
  example.method(attribute.to_sym).call
end

#filter_classifications(classifications, example_subset) ⇒ Object



27
28
29
# File 'lib/dwarf/example_management.rb', line 27

def filter_classifications(classifications,example_subset)
  example_subset.map {|example| classifications[example]}.uniq
end

#invert_with_dups(hash) ⇒ Object



10
11
12
13
14
15
# File 'lib/dwarf/example_management.rb', line 10

def invert_with_dups(hash)
  inversion = { }
  hash.values.each {|value| inversion[value] = []}
  hash.keys.each {|key| inversion[hash[key]] << key}
  inversion
end