ankusa 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,33 @@
1
+ require 'fast_stemmer'
2
+ require 'ankusa/stopwords'
3
+
4
+ module Ankusa
5
+
6
+ class TextHash < Hash
7
+ attr_reader :word_count
8
+
9
+ def initialize(text=nil)
10
+ super 0
11
+ @word_count = 0
12
+ add_text(text) if not text.nil?
13
+ end
14
+
15
+ def add_text(text)
16
+ # replace dashes with spaces, then get rid of non-word/non-space characters,
17
+ # then split by space to get words
18
+ words = text.tr('-', ' ').gsub(/[^\w\s]/,"").split
19
+ words.each { |word| add_word word }
20
+ self
21
+ end
22
+
23
+ def add_word(word)
24
+ word = word.downcase
25
+ if not Ankusa::STOPWORDS.include? word
26
+ @word_count += 1
27
+ key = word.stem.intern
28
+ store key, fetch(key, 0)+1
29
+ end
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,15 @@
1
+ module Ankusa
2
+
3
+ class NBClass
4
+ attr_reader :doc_count, :word_count
5
+
6
+ def initialize(name, summary_table, freq_table)
7
+ @name = name
8
+ @summary_table = summary_table
9
+ @freq_table = freq_table
10
+ @word_count = @summary_table.get(@name, "totals:wordcount").first.to_i64.to_f
11
+ @doc_count = @summary_table.get(@name, "totals:doccount").first.to_i64.to_f
12
+ end
13
+ end
14
+
15
+ end
@@ -0,0 +1,4 @@
1
+ module Ankusa
2
+ # These are taken from MySQL - http://dev.mysql.com/tech-resources/articles/full-text-revealed.html
3
+ STOPWORDS = "a able about above according accordingly across actually after afterwards again against ain't all allow allows almost alone along already also although always am among amongst an and another any anybody anyhow anyone anything anyway anyways anywhere apart appear appreciate appropriate are aren't around as aside ask asking associated at available away awfully be became because become becomes becoming been before beforehand behind being believe below beside besides best better between beyond both brief but by c'mon c's came can can't cannot cant cause causes certain certainly changes clearly co com come comes concerning consequently consider considering contain containing contains corresponding could couldn't course currently definitely described despite did didn't different do does doesn't doing don't done down downwards during each edu eg eight either else elsewhere enough entirely especially et etc even ever every everybody everyone everything everywhere ex exactly example except far few fifth first five followed following follows for former formerly forth four from further furthermore get gets getting given gives go goes going gone got gotten greetings had hadn't happens hardly has hasn't have haven't having he he's hello help hence her here here's hereafter hereby herein hereupon hers herself hi him himself his hither hopefully how howbeit however i'd i'll i'm i've ie if ignored immediate in inasmuch inc indeed indicate indicated indicates inner insofar instead into inward is isn't it it'd it'll it's its itself just keep keeps kept know knows known last lately later latter latterly least less lest let let's like liked likely little look looking looks ltd mainly many may maybe me mean meanwhile merely might more moreover most mostly much must my myself name namely nd near nearly necessary need needs neither never nevertheless new next nine no nobody non none noone nor normally not nothing novel now nowhere obviously of off often oh ok okay old on once one ones only onto or other others otherwise ought our ours ourselves out outside over overall own particular particularly per perhaps placed please plus possible presumably probably provides que quite qv rather rd re really reasonably regarding regardless regards relatively respectively right said same saw say saying says second secondly see seeing seem seemed seeming seems seen self selves sensible sent serious seriously seven several shall she should shouldn't since six so some somebody somehow someone something sometime sometimes somewhat somewhere soon sorry specified specify specifying still sub such sup sure t's take taken tell tends th than thank thanks thanx that that's thats the their theirs them themselves then thence there there's thereafter thereby therefore therein theres thereupon these they they'd they'll they're they've think third this thorough thoroughly those though three through throughout thru thus to together too took toward towards tried tries truly try trying twice two un under unfortunately unless unlikely until unto up upon us use used useful uses using usually value various very via viz vs want wants was wasn't way we we'd we'll we're we've welcome well went were weren't what what's whatever when whence whenever where where's whereafter whereas whereby wherein whereupon wherever whether which while whither who who's whoever whole whom whose why will willing wish with within without won't wonder would would wouldn't yes yet you you'd you'll you're you've your yours yourself yourselves zero".split
4
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ankusa
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Brian Muller
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-29 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: hbaserb
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 29
30
+ segments:
31
+ - 0
32
+ - 0
33
+ - 1
34
+ version: 0.0.1
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: fast-stemmer
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 23
46
+ segments:
47
+ - 1
48
+ - 0
49
+ - 0
50
+ version: 1.0.0
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ description: Naive Bayes classifier with HBase storage
54
+ email: brian.muller@livingsocial.com
55
+ executables: []
56
+
57
+ extensions: []
58
+
59
+ extra_rdoc_files: []
60
+
61
+ files:
62
+ - lib/ankusa/classifier.rb
63
+ - lib/ankusa/hasher.rb
64
+ - lib/ankusa/nbclass.rb
65
+ - lib/ankusa/stopwords.rb
66
+ - lib/ankusa.rb
67
+ - LICENSE
68
+ - Rakefile
69
+ - README.rdoc
70
+ - docs/classes/Ankusa/Classifier.html
71
+ - docs/classes/Ankusa/NBClass.html
72
+ - docs/classes/Ankusa/TextHash.html
73
+ - docs/classes/Ankusa.html
74
+ - docs/created.rid
75
+ - docs/files/lib/ankusa/classifier_rb.html
76
+ - docs/files/lib/ankusa/hasher_rb.html
77
+ - docs/files/lib/ankusa/nbclass_rb.html
78
+ - docs/files/lib/ankusa/stopwords_rb.html
79
+ - docs/files/lib/ankusa_rb.html
80
+ - docs/files/README_rdoc.html
81
+ - docs/fr_class_index.html
82
+ - docs/fr_file_index.html
83
+ - docs/fr_method_index.html
84
+ - docs/index.html
85
+ - docs/rdoc-style.css
86
+ has_rdoc: true
87
+ homepage: https://github.com/livingsocial/ankusa
88
+ licenses: []
89
+
90
+ post_install_message:
91
+ rdoc_options: []
92
+
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ requirements: []
114
+
115
+ rubyforge_project:
116
+ rubygems_version: 1.3.7
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: Naive Bayes classifier in Ruby that uses Hadoop's HBase for storage
120
+ test_files: []
121
+