class ESBI::Naive_Bayes

Learning Model

Public Class Methods

agent() click to toggle source
# File lib/ESBI.rb, line 194
def self.agent
  require "naive_bayes"

  a = NaiveBayes.load('data/baysian/agent.nb') 

  # b = File.read("data/input/document.txt").split(' ')

  number = File.read("data/input/number.txt").strip.to_i
  input  = File.read("data/input/input.txt")

  b = input[number].downcase.split(" ")

  classification = a.classify(*b)

  print classification[0]
end
baysian_seed() click to toggle source
# File lib/ESBI.rb, line 9
    def self.baysian_seed
      old_greeting  = File.read("data/baysian/archive/greeting_archive.txt")
      old_agent     = File.read("data/baysian/archive/agent_archive.txt")
      old_request   = File.read("data/baysian/archive/request_archive.txt")
      old_gender    = File.read("data/baysian/archive/gender_archive.txt")
      old_object    = File.read("data/baysian/archive/object_archive.txt")
      old_for_from  = File.read("data/baysian/archive/for_from_archive.txt")
      old_direction = File.read("data/baysian/archive/direction_archive.txt")

      print  "Train greeting evaluator on >> "; greeting  = gets.chomp
      print     "Train agent on evaluator >> "; agent     = gets.chomp
      print   "Train request evaluator on >> "; request   = gets.chomp
      print    "Train gender evaluator on >> "; gender    = gets.chomp
      print    "Train object evaluator on >> "; object    = gets.chomp
      print  "Train for_from evaluator on >> "; for_from  = gets.chomp
      print "Train direction evaluator on >> "; direction = gets.chomp

      create_regimen = "def greeting_trainer
  require 'naive_bayes'

  a = NaiveBayes.new(:greeting,
                     :farewell)

  a.db_filepath = 'data/baysian/greeting.nb'

  #{old_greeting}
  #{greeting}

  a.save
end

def agent_trainer
  require 'naive_bayes'

  a = NaiveBayes.new(:inheritor,
                     :notinheritor)

  a.db_filepath = 'data/baysian/agent.nb'

  #{old_agent}
  #{agent}

  a.save
end

def request_trainer
  require 'naive_bayes'

  a = NaiveBayes.new(:request,
                     :demand)

  a.db_filepath = 'data/baysian/request.nb'

  #{old_request}
  #{request}

  a.save
end

def gender_trainer
  require 'naive_bayes'

  a = NaiveBayes.new(:masculine,
                     :feminine,
                     :neuter)

  a.db_filepath = 'data/baysian/gender.nb'

  #{old_gender}
  #{gender}

  a.save
end

def object_trainer
  require 'naive_bayes'

  a = NaiveBayes.new(:object,
                     :abstract)

  a.db_filepath = 'data/baysian/object.nb'

  #{old_object}
  #{object}

  a.save
end

def for_from_trainer
  require 'naive_bayes'

  a = NaiveBayes.new(:for,
                     :from)

  a.db_filepath = 'data/baysian/for_from.nb'

  #{old_for_from}
  #{for_from}

  a.save
end

def direction_trainer
  require 'naive_bayes'

  a = NaiveBayes.new(:standard,
                     :nonstandard)

  a.db_filepath = 'data/baysian/directions.nb'

  #{old_direction}
  #{direction}

  a.save
end

greeting_trainer
agent_trainer
request_trainer
gender_trainer
object_trainer
for_from_trainer
direction_trainer
"

      open("script.rb", "w") { |f|
        f.puts create_regimen
      }

      open("data/baysian/archive/greeting_archive.txt", "w") { |f|
        f.puts "  #{old_greeting}"
        f.puts "  #{greeting}"
      }

      open("data/baysian/archive/agent_archive.txt", "w") { |f|
        f.puts "  #{old_agent}"
        f.puts "  #{agent}"
      }

      open("data/baysian/archive/request_archive.txt", "w") { |f|
        f.puts "  #{old_request}"
        f.puts "  #{request}"
      }

      open("data/baysian/archive/gender_archive.txt", "w") { |f|
        f.puts "  #{old_gender}"
        f.puts "  #{gender}"
      }

      open("data/baysian/archive/object_archive.txt", "w") { |f|
        f.puts "  #{old_object}"
        f.puts "  #{object}"
      }

      open("data/baysian/archive/for_from_archive.txt", "w") { |f|
        f.puts "  #{old_for_from}"
        f.puts "  #{for_from}"
      }

      open("data/baysian/archive/direction_archive.txt", "w") { |f|
        f.puts "  #{old_direction}"
        f.puts "  #{direction}"
      }

      system("ruby script.rb")
    end
direction() click to toggle source
# File lib/ESBI.rb, line 279
def self.direction
  require "naive_bayes"

  a = NaiveBayes.load('data/baysian/direction.nb') 

  # b = File.read("data/input/document.txt").split(' ')

  number = File.read("data/input/number.txt").strip.to_i
  input  = File.read("data/input/input.txt")

  b = input[number].downcase.split(" ")

  classification = a.classify(*b)

  print classification[0]
  puts "."
end
evaluate() click to toggle source
# File lib/ESBI.rb, line 176
def self.evaluate
  def self.greeting
    require "naive_bayes"

    a = NaiveBayes.load('data/baysian/greeting.nb') 

    # b = File.read("data/input/document.txt").split(' ')

    number = File.read("data/input/number.txt").strip.to_i
    input  = File.read("data/input/input.txt")

    b = input[number].downcase.split(" ")

    classification = a.classify(*b)

    print classification[0]
  end

  def self.agent
    require "naive_bayes"

    a = NaiveBayes.load('data/baysian/agent.nb') 

    # b = File.read("data/input/document.txt").split(' ')

    number = File.read("data/input/number.txt").strip.to_i
    input  = File.read("data/input/input.txt")

    b = input[number].downcase.split(" ")

    classification = a.classify(*b)

    print classification[0]
  end

  def self.request
    require "naive_bayes"

    a = NaiveBayes.load('data/baysian/request.nb') 

    # b = File.read("data/input/document.txt").split(' ')

    number = File.read("data/input/number.txt").strip.to_i
    input  = File.read("data/input/input.txt")

    b = input[number].downcase.split(" ")

    classification = a.classify(*b)

    print classification[0]
  end

  def self.gender
    require "naive_bayes"

    a = NaiveBayes.load('data/baysian/gender.nb') 

    # b = File.read("data/input/document.txt").split(' ')

    number = File.read("data/input/number.txt").strip.to_i
    input  = File.read("data/input/input.txt")

    b = input[number].downcase.split(" ")

    classification = a.classify(*b)

    print classification[0]
  end

  def self.object
    require "naive_bayes"

    a = NaiveBayes.load('data/baysian/object.nb') 

    # b = File.read("data/input/document.txt").split(' ')

    number = File.read("data/input/number.txt").strip.to_i
    input  = File.read("data/input/input.txt")

    b = input[number].downcase.split(" ")

    classification = a.classify(*b)

    print classification[0]
  end

  def self.for_from
    require "naive_bayes"

    a = NaiveBayes.load('data/baysian/for_from.nb') 

    # b = File.read("data/input/document.txt").split(' ')

    number = File.read("data/input/number.txt").strip.to_i
    input  = File.read("data/input/input.txt")

    b = input[number].downcase.split(" ")

    classification = a.classify(*b)

    print classification[0]
  end

  def self.direction
    require "naive_bayes"

    a = NaiveBayes.load('data/baysian/direction.nb') 

    # b = File.read("data/input/document.txt").split(' ')

    number = File.read("data/input/number.txt").strip.to_i
    input  = File.read("data/input/input.txt")

    b = input[number].downcase.split(" ")

    classification = a.classify(*b)

    print classification[0]
    puts "."
  end

  ESBI::Naive_Bayes.evaluate.greeting
  ESBI::Naive_Bayes.evaluate.agent
  ESBI::Naive_Bayes.evaluate.request
  ESBI::Naive_Bayes.evaluate.gender
  ESBI::Naive_Bayes.evaluate.object
  ESBI::Naive_Bayes.evaluate.for_from
  ESBI::Naive_Bayes.evaluate.direction
end
for_from() click to toggle source
# File lib/ESBI.rb, line 262
def self.for_from
  require "naive_bayes"

  a = NaiveBayes.load('data/baysian/for_from.nb') 

  # b = File.read("data/input/document.txt").split(' ')

  number = File.read("data/input/number.txt").strip.to_i
  input  = File.read("data/input/input.txt")

  b = input[number].downcase.split(" ")

  classification = a.classify(*b)

  print classification[0]
end
gender() click to toggle source
# File lib/ESBI.rb, line 228
def self.gender
  require "naive_bayes"

  a = NaiveBayes.load('data/baysian/gender.nb') 

  # b = File.read("data/input/document.txt").split(' ')

  number = File.read("data/input/number.txt").strip.to_i
  input  = File.read("data/input/input.txt")

  b = input[number].downcase.split(" ")

  classification = a.classify(*b)

  print classification[0]
end
greeting() click to toggle source
# File lib/ESBI.rb, line 177
def self.greeting
  require "naive_bayes"

  a = NaiveBayes.load('data/baysian/greeting.nb') 

  # b = File.read("data/input/document.txt").split(' ')

  number = File.read("data/input/number.txt").strip.to_i
  input  = File.read("data/input/input.txt")

  b = input[number].downcase.split(" ")

  classification = a.classify(*b)

  print classification[0]
end
object() click to toggle source
# File lib/ESBI.rb, line 245
def self.object
  require "naive_bayes"

  a = NaiveBayes.load('data/baysian/object.nb') 

  # b = File.read("data/input/document.txt").split(' ')

  number = File.read("data/input/number.txt").strip.to_i
  input  = File.read("data/input/input.txt")

  b = input[number].downcase.split(" ")

  classification = a.classify(*b)

  print classification[0]
end
request() click to toggle source
# File lib/ESBI.rb, line 211
def self.request
  require "naive_bayes"

  a = NaiveBayes.load('data/baysian/request.nb') 

  # b = File.read("data/input/document.txt").split(' ')

  number = File.read("data/input/number.txt").strip.to_i
  input  = File.read("data/input/input.txt")

  b = input[number].downcase.split(" ")

  classification = a.classify(*b)

  print classification[0]
end