textstat 0.1.7 → 0.1.9
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 +313 -309
- data/spec/textstat_spec.rb +197 -192
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88480347f6e6a1c232dc30a7ee14e4cf98154936e28a9fb2d1aaa6fe0f176aed
|
4
|
+
data.tar.gz: bce6f0fc8222542dba6a8e0961d20fd3b68313571769f1cd7c7dd13c5fc28926
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3490d4920b60d1a6defa19eb80a2918bd92fafcf265b8f55aae50f617da88becaeba562a73fe20b91020f0ed21a2e912556c6cbb8314bc5f8210a8debcbe82c
|
7
|
+
data.tar.gz: f4a7c7aba924df2005da79cf48a675e6d1f2655d56debe90590e748b56fdc1bccffa80ce245ba644d5fe0e5119d5b66159946569a05f715579bfaaa8185edb61
|
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
|