Skip to content

Instantly share code, notes, and snippets.

@gummibeatz
Created August 1, 2013 09:18
Show Gist options
  • Save gummibeatz/6129804 to your computer and use it in GitHub Desktop.
Save gummibeatz/6129804 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'naive_bayes'
cls = NaiveBayes.new(:yes,:no,:maybe)
#put in words to ignore inside single quotes separated by commas
file=File.readlines('train_alc.txt')
temp = " "
temps = 2
#classifies tweets from each row
file.each do |line|
a = line.split("\t")
d = a[0].split(' ')
counter=0
if !d.empty?
d.each do
# puts a[1]
# puts d[counter]
if a[1].to_i == 0
cls.train(:no,d[counter])
print d[counter]
puts "0"
end
if a[1].to_i == 1
cls.train(:yes,d[counter])
print d[counter]
puts "1"
end
if a[1].to_i == 2
cls.train(:maybe,d[counter])
print d[counter]
puts "2"
end
counter=counter+1
end
end
temp = d[counter]
temps=a[1]
end
# puts temp
# puts temps
tester = File.readlines('comp_alc.txt')
File.open('alcohol_classify.txt','a') do |s|
tester.each do |line|
b = line.split("\t")
# puts b[0]
r = b[0].split(' ')
if !r.empty?
s.print cls.classify(r)
s.puts ""
print r
# puts cls.classify(r)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment