File: bayes.rb

package info (click to toggle)
ruby-classifier 1.3.4-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 224 kB
  • sloc: ruby: 739; makefile: 5
file content (36 lines) | stat: -rwxr-xr-x 818 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env ruby

begin
	require 'rubygems'
	require 'classifier'
rescue
	require 'classifier'
end

require 'madeleine'

m = SnapshotMadeleine.new(File.expand_path("~/.bayes_data")) {
	Classifier::Bayes.new 'Interesting', 'Uninteresting'
}

case ARGV[0]
when "add"
	case ARGV[1].downcase
	when "interesting"
		m.system.train_interesting File.open(ARGV[2]).read
		puts "#{ARGV[2]} has been classified as interesting"
	when "uninteresting"
		m.system.train_uninteresting File.open(ARGV[2]).read
		puts "#{ARGV[2]} has been classified as uninteresting"
	else
		puts "Invalid category: choose between interesting and uninteresting"
		exit(1)
	end
when "classify"
	puts m.system.classify(File.open(ARGV[1]).read)
else
	puts "Invalid option: choose add [category] [file] or clasify [file]"
	exit(-1)
end

m.take_snapshot