class RearrangeBayesianSymbolic::ProductTrends
Public Class Methods
eliminate_relationships()
click to toggle source
# File lib/rearrange_bayesian_symbolic.rb, line 7 def self.eliminate_relationships # Reads in nouns, verbs, and actions from a file. persons = File.readlines("data/symbolic/persons.txt") descriptions = File.readlines("data/symbolic/descriptions.txt") actions = File.readlines("data/symbolic/actions.txt") # Rearranges them out of order on a table. person_list = persons.shuffle descriptions_list = description.shuffle actions_list = actions.shuffle active_person = person_list.sample active_description = descriptions_list.sample actiive_action = actions_list.sample # Apply symbolic catagorization of customers to products. create_relationship = "#{active_person}(#{active_description}, #{active_action})" # Use bayesian probability to determine how likely customer to product relationship is. require "naive_bayes" require "tts" a = NaiveBayes.new(:customer, :notcustomer) # Train On Data ## Is A Customer a.train(:customer, "college_student(working, drinking_coffee)", "word") ## Is Not A Customer a.train(:notcustomer, "lawyer(dishonest, representing)", "word") # Don't edit below here. a_class = a.classify(*b) result = a_class[0] decision = result.to_s # Relay to evaluator customer relationship likelihood if decision == "customer" puts "This is a likely customer relationship: #{create_relationship}" old_data = File.read("output/result.txt") open("output/result.txt", "w") { |f| f.puts old_data f.puts "This is a likely customer relationship: #{create_relationship}" } elsif decision == "notcustomer" puts "This is not a likely customer relationship: #{create_relationship}" old_data = File.read("output/result.txt") open("output/result.txt", "w") { |f| f.puts old_data f.puts "This is not a likely customer relationship: #{create_relationship}" } else puts "Could not reliably determine relationship likelihood: #{create_relationship}" open("output/result.txt", "w") { |f| f.puts old_data old_data = File.read("output/result.txt") f.puts "Could not reliably determine relationship likelihood: #{create_relationship}" } end end
open_in_default()
click to toggle source
# File lib/rearrange_bayesian_symbolic.rb, line 120 def self.open_in_default content = File.read("output/result.txt") website = ' <html> <head> <title>Output</title> <style> body { background-color: black; border: solid lime 1px; padding-left: 23px; padding-right: 23px; padding-top: 23px; padding-right: 23@x; } h1, h2, h3, h4, h5, h6, p, pre { color: lime; font-family: monospace; } a { color: blue; font-family: monospace; } </style> </head> <body> <pre>#{content}</pre> </body> </html> ' open("index.html", "w") { |f| f.puts website } system("firefox index.html; shred --remove index.html") end
open_in_w3m()
click to toggle source
# File lib/rearrange_bayesian_symbolic.rb, line 78 def self.open_in_w3m content = File.read("output/result.txt") website = ' <html> <head> <title>Output</title> <style> body { background-color: black; border: solid lime 1px; padding-left: 23px; padding-right: 23px; padding-top: 23px; padding-right: 23@x; } h1, h2, h3, h4, h5, h6, p, pre { color: lime; font-family: monospace; } a { color: blue; font-family: monospace; } </style> </head> <body> <pre>#{content}</pre> </body> </html> ' open("index.html", "w") { |f| f.puts website } system("w3m index.html; shred --remove index.html") end