vocab_counter 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -5
- data/VERSION +1 -1
- data/bin/vocab_counter +5 -6
- data/lib/vocab_counter.rb +13 -8
- data/vocab_counter.gemspec +1 -1
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -18,11 +18,8 @@ mat,1
|
|
18
18
|
|
19
19
|
* Fork the project.
|
20
20
|
* Make your feature addition or bug fix.
|
21
|
-
* Add tests for it. This is important so I don't break it in a
|
22
|
-
|
23
|
-
* Commit, do not mess with rakefile, version, or history.
|
24
|
-
(if you want to have your own version, that is fine but
|
25
|
-
bump version in a commit by itself I can ignore when I pull)
|
21
|
+
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
22
|
+
* Commit, do not mess with rakefile, version, or history.(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
26
23
|
* Send me a pull request. Bonus points for topic branches.
|
27
24
|
|
28
25
|
== Copyright
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
1.0.0
|
data/bin/vocab_counter
CHANGED
@@ -3,12 +3,11 @@
|
|
3
3
|
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
4
4
|
require 'vocab_counter'
|
5
5
|
|
6
|
-
|
7
|
-
puts "Vocab counter: please specify a file"
|
8
|
-
Process.exit
|
9
|
-
end
|
6
|
+
v = VocabCounter.new
|
10
7
|
|
11
|
-
|
8
|
+
ARGF.each do |line|
|
9
|
+
v.count(line)
|
10
|
+
end
|
12
11
|
|
13
|
-
puts
|
12
|
+
puts v.report
|
14
13
|
|
data/lib/vocab_counter.rb
CHANGED
@@ -1,16 +1,21 @@
|
|
1
1
|
class VocabCounter
|
2
2
|
|
3
|
-
def
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
def initialize
|
4
|
+
@count = Hash.new(0)
|
5
|
+
end
|
6
|
+
|
7
|
+
def count(line)
|
8
|
+
line.downcase!
|
9
|
+
line.gsub!(/[^a-z0-9']/, ' ')
|
10
|
+
line.gsub!(/\s'|'\s/, ' ')
|
11
|
+
line.split(/\s+/).each do |term|
|
12
|
+
@count[term.to_sym] += 1
|
10
13
|
end
|
14
|
+
end
|
11
15
|
|
16
|
+
def report
|
12
17
|
out = ""
|
13
|
-
count.sort { |a,b| b[1] <=> a[1] }.each do |k,v|
|
18
|
+
@count.sort { |a,b| b[1] <=> a[1] }.each do |k,v|
|
14
19
|
out << "#{k.to_s},#{v}\n"
|
15
20
|
end
|
16
21
|
out
|
data/vocab_counter.gemspec
CHANGED