textstat 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/counter.rb +37 -37
- data/lib/dictionaries/ca.txt +2487 -2487
- data/lib/dictionaries/cs.txt +2499 -2499
- data/lib/dictionaries/en_us.txt +2944 -2944
- data/lib/dictionaries/nl.txt +2549 -2549
- data/lib/textstat/version.rb +3 -3
- data/lib/textstat.rb +309 -309
- data/spec/textstat_spec.rb +191 -191
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61ef6dcf0e938af4c3c30ad4b45c3241f10ffc01e4d63e566a74d993b57309ac
|
4
|
+
data.tar.gz: 20f6412df8d5a8658d4113ddb48e808697b7e1489ba5acb4fae9d97346393acd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef7dee598e3db4c26e2e305f464fbebf6b3757429a72ae66b887ab7f068a34a0d2b6c2e5c52771b2c342e8c06d2ec9a69fa1d60065eaa37b3ccf76eb232f647d
|
7
|
+
data.tar.gz: 5ca1f7c6dcb11a81457b87339ab153ac95125542378875fd451c9ba58659925fc018d38af4bbc61149cb5f8f53765f67363029d8eb698ad80effa969d7ecbbeb
|
data/lib/counter.rb
CHANGED
@@ -1,37 +1,37 @@
|
|
1
|
-
class Counter < Hash
|
2
|
-
def initialize(other = nil)
|
3
|
-
super(0)
|
4
|
-
other.each { |e| self[e] += 1 } if other.is_a? Array
|
5
|
-
other.each { |k, v| self[k] = v } if other.is_a? Hash
|
6
|
-
other.each_char { |e| self[e] += 1 } if other.is_a? String
|
7
|
-
end
|
8
|
-
|
9
|
-
def +(rhs)
|
10
|
-
raise TypeError, "cannot add #{rhs.class} to a Counter" unless rhs.is_a? Counter
|
11
|
-
|
12
|
-
result = Counter.new(self)
|
13
|
-
rhs.each { |k, v| result[k] += v }
|
14
|
-
result
|
15
|
-
end
|
16
|
-
|
17
|
-
def -(rhs)
|
18
|
-
raise TypeError, "cannot subtract #{rhs.class} to a Counter" unless rhs.is_a? Counter
|
19
|
-
|
20
|
-
result = Counter.new(self)
|
21
|
-
rhs.each { |k, v| result[k] -= v }
|
22
|
-
result
|
23
|
-
end
|
24
|
-
|
25
|
-
def most_common(n = nil)
|
26
|
-
s = sort_by { |_k, v| -v }
|
27
|
-
n ? s.take(n) : s
|
28
|
-
end
|
29
|
-
|
30
|
-
def to_s
|
31
|
-
"Counter(#{super})"
|
32
|
-
end
|
33
|
-
|
34
|
-
def inspect
|
35
|
-
to_s
|
36
|
-
end
|
37
|
-
end
|
1
|
+
class Counter < Hash
|
2
|
+
def initialize(other = nil)
|
3
|
+
super(0)
|
4
|
+
other.each { |e| self[e] += 1 } if other.is_a? Array
|
5
|
+
other.each { |k, v| self[k] = v } if other.is_a? Hash
|
6
|
+
other.each_char { |e| self[e] += 1 } if other.is_a? String
|
7
|
+
end
|
8
|
+
|
9
|
+
def +(rhs)
|
10
|
+
raise TypeError, "cannot add #{rhs.class} to a Counter" unless rhs.is_a? Counter
|
11
|
+
|
12
|
+
result = Counter.new(self)
|
13
|
+
rhs.each { |k, v| result[k] += v }
|
14
|
+
result
|
15
|
+
end
|
16
|
+
|
17
|
+
def -(rhs)
|
18
|
+
raise TypeError, "cannot subtract #{rhs.class} to a Counter" unless rhs.is_a? Counter
|
19
|
+
|
20
|
+
result = Counter.new(self)
|
21
|
+
rhs.each { |k, v| result[k] -= v }
|
22
|
+
result
|
23
|
+
end
|
24
|
+
|
25
|
+
def most_common(n = nil)
|
26
|
+
s = sort_by { |_k, v| -v }
|
27
|
+
n ? s.take(n) : s
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_s
|
31
|
+
"Counter(#{super})"
|
32
|
+
end
|
33
|
+
|
34
|
+
def inspect
|
35
|
+
to_s
|
36
|
+
end
|
37
|
+
end
|