class RCPNetwork::DanglingModifiers

Public Class Methods

make_choice() click to toggle source

Generate Dangling Modifiers

# 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_data() click to toggle source

Main decision tree

# 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_modifier() click to toggle source

Pick Dangling Modifier From Data

# 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