class FetchGenerator::Generate_Fetch
Public Class Methods
agent()
click to toggle source
Create a decision tree for determining the agent.
# File lib/FetchGenerator.rb, line 34 def self.agent require "decisiontree" input = File.read("input/agent.txt").strip.to_i attribute = ["Agent"] training = [ [ 20.0, "Sarah, "], [ 40.0, "John, "], [ 60.0, "Mary, "], [ 80.0, "Holly, "], [100.0, "Cora, "], ] dec_tree = DecisionTree::ID3Tree.new(attribute, training, 1, :continuous) dec_tree.train test = [input] decision = dec_tree.predict(test) actuality = test.last $do_agent = decision end
for_from()
click to toggle source
Create a decision tree determining for or from.
# File lib/FetchGenerator.rb, line 113 def self.for_from require "decisiontree" input = File.read("input/for_from.txt").strip.to_i attribute = ["For_From"] training = [ [ 50.0, "for "], [100.0, "from "], ] dec_tree = DecisionTree::ID3Tree.new(attribute, training, 1, :continuous) dec_tree.train test = [input] decision = dec_tree.predict(test) actuality = test.last $do_for_from = decision end
generate_example()
click to toggle source
# File lib/FetchGenerator.rb, line 185 def self.generate_example open("data/examples.txt", "w") { |f| f.print $do_greeting; f.print $do_agent; f.print $do_request; f.print $do_item; f.print $do_for_from; f.print $do_neighbor; f.puts $do_place; } end
greeting()
click to toggle source
Create a decision tree for determining greeting.
# File lib/FetchGenerator.rb, line 9 def self.greeting require "decisiontree" input = File.read("input/greeting.txt").strip.to_i attribute = ["Greeter"] training = [ [ 14.3, "Hello "], [ 28.6, "Hey "], [ 42.9, "Heyo "], [ 57.2, "Hi "], [ 71.5, "Ahoy "], [ 85.8, "Hola "], [100.1, "Ola "], ] dec_tree = DecisionTree::ID3Tree.new(attribute, training, 1, :continuous) dec_tree.train test = [input] decision = dec_tree.predict(test) actuality = test.last $do_greeting = decision end
item()
click to toggle source
Create a decision tree for determining the item.
# File lib/FetchGenerator.rb, line 83 def self.item require "decisiontree" input = File.read("input/item.txt").strip.to_i attribute = ["Item"] training = [ [ 6.25, "some books "], [ 12.50, "some clothes "], [ 18.75, "some food "], [ 25.0, "some coffee "], [ 31.25, "some sex "], [ 37.50, "some beer "], [ 43.75, "some ham "], [ 50.0, "some eggs "], [ 56.25, "some milk "], [ 62.5, "some lettuce "], [ 68.75, "some carrots "], [ 75.0, "some peppers "], [ 81.25, "some onions "], [ 87.5, "some broccoli "], [ 93.75, "some eggplant "], [100.0, "some potatoes "], ] dec_tree = DecisionTree::ID3Tree.new(attribute, training, 1, :continuous) dec_tree.train test = [input] decision = dec_tree.predict(test) actuality = test.last $do_item = decision end
neighbor()
click to toggle source
Create a decision tree determing which neighbor's place.
# File lib/FetchGenerator.rb, line 136 def self.neighbor require "decisiontree" input = File.read("input/item.txt").strip.to_i attribute = ["Neighbor"] training = [ [20.0, "Sarah's "], [40.0, "John's "], [60.0, "Mary's "], [80.0, "Holly's "], ] dec_tree = DecisionTree::ID3Tree.new(attribute, training, 1, :continuous) dec_tree.train test = [input] decision = dec_tree.predict(test) actuality = test.last $do_neighbor = decision end
place()
click to toggle source
Creates a decision tree determining which place is being referred.
# File lib/FetchGenerator.rb, line 160 def self.place require "decisiontree" input = File.read("input/item.txt").strip.to_i attribute = ["Greeter"] training = [ [ 9.10, "garage."], [ 18.20, "living room."], [27.30, "dining room."], [ 36.40, "kitchen."], [ 45.46, "bedroom."], [55.0, "backyard."], [ 64.0, "church."], [ 73.0, "arcade."], [82.0, "theater."], [ 91.0, "grocery."], [100.0, "hardware"], ] dec_tree = DecisionTree::ID3Tree.new(attribute, training, 1, :continuous) dec_tree.train test = [input] decision = dec_tree.predict(test) actuality = test.last $do_place = decision end
request()
click to toggle source
Create a decision tree for determining the request.
# File lib/FetchGenerator.rb, line 58 def self.request require "decisiontree" input = File.read("input/request.txt").strip.to_i attribute = ["Request"] training = [ [ 20.0, "can I have "], [ 40.0, "will I have "], [ 60.0, "can I get "], [ 80.0, "will I get "], [100.0, "may I have "], [120.0, "may I get "], ] dec_tree = DecisionTree::ID3Tree.new(attribute, training, 1, :continuous) dec_tree.train test = [input] decision = dec_tree.predict(test) actuality = test.last $do_request = decision end
use_examples()
click to toggle source
# File lib/FetchGenerator.rb, line 194 def self.use_examples require "gabbler" require "espeak" gabbler = Gabbler.new data = File.read("data/examples.txt") gabbler.learn(data) phrase = gabbler.sentence speech = ESpeak::Speech.new(phrase) speech.speak end