Class: RCPNetwork::DanglingModifiers

Inherits:
Object
  • Object
show all
Defined in:
lib/RCP_Network.rb

Class Method Summary collapse

Class Method Details

.make_choiceObject

Generate Dangling Modifiers



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
# File 'lib/RCP_Network.rb', line 9

def self.make_choice
  bot_name = File.read("bot_identity/bot_name.txt").strip

  old_data = File.read("data/output/modifier_list.txt")
  
  # Grammar A
  present_action      = File.readlines("dictionary/present_action.txt").sample.strip
  present_preposition = File.readlines("dictionary/present_preposition.txt").sample.strip
  first_object        = File.readlines("dictionary/first_object.txt").sample.strip
  
  # Grammar B
  second_object       = File.readlines("dictionary/second_object.txt").sample.strip
  next_preposition    = File.readlines("dictionary/next_preposition.txt").sample.strip
  next_action         = File.readlines("dictionary/next_action.txt").sample.strip
  
  # Final object
  third_object        = File.readlines("dictionary/third_object.txt").sample.strip
  
  # Inquire
  why_did = " Why did the"
  why_was = " why was the"
  
  grammar_a = "#{present_action}ing #{present_preposition} #{first_object}, "
  grammar_b = "#{second_object} #{next_action}s #{next_preposition} #{third_object}."
  
  inquire   = "#{why_did} #{second_object} #{next_action} #{next_preposition} #{third_object}?"
  for_that  = "For that matter,#{why_was} #{first_object} #{present_action} anything?"
  
  open("data/output/modifier_list.txt", "w") { |f|
    f.puts old_data
    
    f.puts "#{bot_name}: #{grammar_a}#{grammar_b} #{inquire} #{for_that}"
  }
end

.predict_from_dataObject

Main decision tree



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/RCP_Network.rb', line 60

def self.predict_from_data
  require "decisiontree"
  
  input = File.read("data/input/modifier_ratio.txt").to_f
  
  attributes = ["Modifier"]
  
  training = [
    [13.75,      'Very Low'], [20.625, 'Somewhat Low'], [27.5,     'Normal Low'],
    [37.3125,      'Medium'], [54.0,           'High'], [67.5,         'Urgent'],
    [81.0,         'Danger'], [94.5,       'Critical'], [108.0,     'Automatic'],
  ]
  
  dec_tree = DecisionTree::ID3Tree.new(attributes, training, 1, :continuous)
  dec_tree.train
  
  test = [input]
  
  decision = dec_tree.predict(test)
  
  if decision == "Automatic" or 108.8
    RCPNetwork::DanglingModifiers.make_choice
  else
    RCPNetwork::DanglingModifiers.random_modifier
  end
  
  new_input = input += 0.5
  
  open("data/input/modifier_ratio.txt", "w") { |f|
    f.puts new_input
  }
end

.random_modifierObject

Pick Dangling Modifier From Data



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/RCP_Network.rb', line 45

def self.random_modifier
  require "espeak"

  modifier_list = File.readlines("data/output/modifier_list.txt")
  
  dangling_modifier = modifier_list.sample
  
  phrase = dangling_modifier
  
  puts phrase
  # speech = ESpeak::Speech.new(phrase)
  # speech.speak
end