Class: Saasagi::NewFunctions

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

Class Method Summary collapse

Class Method Details

.operate_treeObject



333
334
335
336
337
# File 'lib/saasagi.rb', line 333

def self.operate_tree
  print "Operate which tree? >> "; input = gets.chomp

  system("#{input}.rb"); sleep(3)
end

.self_repairObject



316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# File 'lib/saasagi.rb', line 316

def self.self_repair
  print "Which file is missing? >> "
  input = gets.chomp

  if File.exists?("#{input}.rb")
    puts "I'm still here in your folder."
  else
    back_up = File.read(".backup/#{input}.rb").strip
  
    open("#{input}.rb", "w") { |f|
      f.puts back_up
    }
  
    puts "You should be more careful how you treat your files."; sleep(3)
  end
end

.sequenceObject



214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# File 'lib/saasagi.rb', line 214

def self.sequence
  print "Give a method name >> ";              method_name              = gets.chomp; ratio       =   "_ratio"
  print "Create a meter attribute >> ";        attribute                = gets.chomp;
  print "Name a robot action >> ";             action                   = gets.chomp;
  print "Write automamtic robot dialogue >> "; robot_dialogue_automatic = gets.chomp;

  open("data/input/#{method_name}#{ratio}.txt", "w") { |f|
    starting_value = 0.5
  
    f.puts starting_value
  }

  open("tree_#{action}.rb", "w") { |f|        
    f.puts "# Auto training, motivation, and action."
    f.puts "def experience_#{method_name}"
    f.puts "  current_value = File.read('data/input/#{method_name}_ratio.txt')"
    f.puts "  current_value = current_value.to_i"
    f.puts "  current_value = current_value + 10"
    f.puts " "
    f.puts "  # Writes current value to file."
    f.puts "  open('data/input/#{method_name}_ratio.txt', 'w') { |f|"
    f.puts "    puts 'Training AI to self learn.'"
    f.puts " "
    f.puts "    f.puts current_value"
    f.puts "  }"
    f.puts " "
    f.puts "  sleep(3)"
    f.puts " "
    f.puts "  #{method_name[0]} = #{method_name}#{ratio}"
    f.puts "end"
    f.puts " "
    f.puts "def #{method_name}#{ratio}"
    f.puts "  require 'decisiontree'"
    f.puts " "
    f.puts "  def confirm_deny"
    f.puts "    decision = $decision"
    f.puts " "
    f.puts "    if decision == 'Automatic'"
    f.puts "      ai = ai_#{action}"
    f.puts "    else"
    f.puts "      print 'Robot is increasingly restless, #{action} or stay? >> '"
    f.puts "      input = gets.chomp"
    f.puts " "
    f.puts "      if    input == '#{action}'"      
    f.puts "        a = ai_#{action}"
    f.puts "      elsif input == 'stay'"
    f.puts "        require 'espeak'"
    f.puts " "
    f.puts "        speech = ESpeak::Speech.new('I chose to stay.')"
    f.puts "        speech.speak"
    f.puts "      else"
    f.puts "        require 'espeak'"
    f.puts " "
    f.puts "        speech = ESpeak::Speech.new('Command not understood.')"
    f.puts "        speech.speak"
    f.puts "      end"
    f.puts "    end"
    f.puts "  end"
    f.puts " "
    f.puts "  input      = File.read('data/input/#{method_name}#{ratio}.txt').strip.to_i"
    f.puts " "
    f.puts "  attributes = ['#{attribute}']"
    f.puts " "
    f.puts "  training   = ["
    f.puts "    [13.75,      'Very Low'], [20.625, 'Somewhat Low'], [27.5,     'Normal Low'],"
    f.puts "    [37.3125,      'Medium'], [54.0,           'High'], [67.5,         'Urgent'],"
    f.puts "    [81.0,         'Danger'], [94.5,       'Critical'], [108.0,     'Automatic'],"
    f.puts "  ]"
    f.puts " "
    f.puts "  dec_tree = DecisionTree::ID3Tree.new(attributes, training, 1, :continuous); dec_tree.train"
    f.puts "  test = [input]"
    f.puts " "
    f.puts "  $decision      = dec_tree.predict(test)"
    f.puts "  $true_decision = test.last"
    f.puts " "
    f.puts "  print '#{method_name.upcase}: '; print $decision"
    f.puts "  puts '\n\N'"
    f.puts " "
    f.puts "  if    $decision ==     'Very Low' or   13.75; c = confirm_deny"
    f.puts "  elsif $decision == 'Somewhat Low' or  20.625; c = confirm_deny"
    f.puts "  elsif $decision ==   'Normal Low' or    67.5; c = confirm_deny"
    f.puts "  elsif $decision ==       'Medium' or 37.3125; c = confirm_deny"
    f.puts "  elsif $decision ==         'High' or    54.0; c = confirm_deny"
    f.puts "  elsif $decision ==       'Urgent' or    67.5; c = confirm_deny"
    f.puts "  elsif $decision ==       'Danger' or    81.0; c = confirm_deny"
    f.puts "  elsif $decision ==     'Critical' or    94.5; c = confirm_deny"
    f.puts "  elsif $decision ==    'Automatic' or   108.0; r = robot_#{method_name}"
    f.puts "  end"
    f.puts " "
    f.puts "end"
    f.puts " "
    f.puts "def ai_#{action}"
    f.puts "  require 'espeak'"
    f.puts " "
    f.puts "  speech = ESpeak::Speech.new('#{action}')"
    f.puts "  speech.speak"
    f.puts "end"
    f.puts " "
    f.puts "\n e = experience_#{method_name}"
  }
end