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
data/spec/textstat_spec.rb
CHANGED
@@ -1,192 +1,192 @@
|
|
1
|
-
require 'rspec'
|
2
|
-
require_relative '../lib/textstat.rb'
|
3
|
-
|
4
|
-
describe TextStat do
|
5
|
-
before do
|
6
|
-
@long_test = 'Playing ... games has always been thought to be ' \
|
7
|
-
'important to the development of well-balanced and ' \
|
8
|
-
'creative children; however, what part, if any, ' \
|
9
|
-
'they should play in the lives of adults has never ' \
|
10
|
-
'been researched that deeply. I believe that ' \
|
11
|
-
'playing games is every bit as important for adults ' \
|
12
|
-
'as for children. Not only is taking time out to ' \
|
13
|
-
'play games with our children and other adults ' \
|
14
|
-
'valuable to building interpersonal relationships ' \
|
15
|
-
'but is also a wonderful way to release built up ' \
|
16
|
-
"tension.\n" \
|
17
|
-
"There's nothing my husband enjoys more after a " \
|
18
|
-
'hard day of work than to come home and play a game ' \
|
19
|
-
'of Chess with someone. This enables him to unwind ' \
|
20
|
-
"from the day's activities and to discuss the highs " \
|
21
|
-
'and lows of the day in a non-threatening, kick back ' \
|
22
|
-
'environment. One of my most memorable wedding ' \
|
23
|
-
'gifts, a Backgammon set, was received by a close ' \
|
24
|
-
'friend. I asked him why in the world he had given ' \
|
25
|
-
'us such a gift. He replied that he felt that an ' \
|
26
|
-
'important aspect of marriage was for a couple to ' \
|
27
|
-
'never quit playing games together. Over the years, ' \
|
28
|
-
'as I have come to purchase and play, with other ' \
|
29
|
-
'couples & coworkers, many games like: Monopoly, ' \
|
30
|
-
'Chutes & Ladders, Mastermind, Dweebs, Geeks, & ' \
|
31
|
-
'Weirdos, etc. I can reflect on the integral part ' \
|
32
|
-
'they have played in our weekends and our ' \
|
33
|
-
'"shut-off the T.V. and do something more ' \
|
34
|
-
'stimulating" weeks. They have enriched my life and ' \
|
35
|
-
'made it more interesting. Sadly, many adults ' \
|
36
|
-
'forget that games even exist and have put them ' \
|
37
|
-
'away in the cupboards, forgotten until the ' \
|
38
|
-
"grandchildren come over.\n" \
|
39
|
-
'All too often, adults get so caught up in working ' \
|
40
|
-
'to pay the bills and keeping up with the ' \
|
41
|
-
"\"Joneses'\" that they neglect to harness the fun " \
|
42
|
-
'in life; the fun that can be the reward of ' \
|
43
|
-
'enjoying a relaxing game with another person. It ' \
|
44
|
-
'has been said that "man is that he might have ' \
|
45
|
-
'joy" but all too often we skate through life ' \
|
46
|
-
'without much of it. Playing games allows us to: ' \
|
47
|
-
'relax, learn something new and stimulating, ' \
|
48
|
-
'interact with people on a different more ' \
|
49
|
-
'comfortable level, and to enjoy non-threatening ' \
|
50
|
-
'competition. For these reasons, adults should ' \
|
51
|
-
'place a higher priority on playing games in their ' \
|
52
|
-
'lives'
|
53
|
-
end
|
54
|
-
|
55
|
-
context 'When testing the TextStat class' do
|
56
|
-
it 'should return the correct number of chars' do
|
57
|
-
count = TextStat.char_count(@long_test)
|
58
|
-
count_spaces = TextStat.char_count(@long_test, false)
|
59
|
-
|
60
|
-
expect(count).to eql 1750
|
61
|
-
expect(count_spaces).to eql 2123
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'should return the correct number of lexicons' do
|
65
|
-
count = TextStat.lexicon_count(@long_test)
|
66
|
-
count_punctuation = TextStat.lexicon_count(@long_test, false)
|
67
|
-
|
68
|
-
expect(count).to eql 372
|
69
|
-
expect(count_punctuation).to eql 376
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'should return the correct number of syllables' do
|
73
|
-
count = TextStat.syllable_count(@long_test)
|
74
|
-
expect(count).to eql 559
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'should return the correct number of sentences' do
|
78
|
-
count = TextStat.sentence_count(@long_test)
|
79
|
-
expect(count).to eql 16
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'should return the correct average sentence length' do
|
83
|
-
avg = TextStat.avg_sentence_length(@long_test)
|
84
|
-
expect(avg).to eql 23.3
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'should return the correct average syllables per word' do
|
88
|
-
avg = TextStat.avg_syllables_per_word(@long_test)
|
89
|
-
expect(avg).to eql 1.5
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'should return the correct average letters per word' do
|
93
|
-
avg = TextStat.avg_letter_per_word(@long_test)
|
94
|
-
expect(avg).to eql 4.7
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'should return the correct average sentence per word' do
|
98
|
-
avg = TextStat.avg_sentence_per_word(@long_test)
|
99
|
-
expect(avg).to eql 0.04
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'should return the correct Flesch reading-ease test score' do
|
103
|
-
score = TextStat.flesch_reading_ease(@long_test)
|
104
|
-
expect(score).to eql 56.29
|
105
|
-
end
|
106
|
-
|
107
|
-
it 'should return the correct Flesch–Kincaid grade' do
|
108
|
-
score = TextStat.flesch_kincaid_grade(@long_test)
|
109
|
-
expect(score).to eql 11.2
|
110
|
-
end
|
111
|
-
|
112
|
-
it 'should return the correct number of polysyllab' do
|
113
|
-
count = TextStat.polysyllab_count(@long_test)
|
114
|
-
expect(count).to eql 43
|
115
|
-
end
|
116
|
-
|
117
|
-
it 'should return the correct smog index' do
|
118
|
-
index = TextStat.smog_index(@long_test)
|
119
|
-
expect(index).to eql 12.5
|
120
|
-
end
|
121
|
-
|
122
|
-
it 'should return the correct Coleman–Liau index' do
|
123
|
-
index = TextStat.coleman_liau_index(@long_test)
|
124
|
-
expect(index).to eql 10.65
|
125
|
-
end
|
126
|
-
|
127
|
-
it 'should return the correct automated readability index' do
|
128
|
-
index = TextStat.automated_readability_index(@long_test)
|
129
|
-
expect(index).to eql 12.4
|
130
|
-
end
|
131
|
-
|
132
|
-
it 'should return the correct linsear write formula result' do
|
133
|
-
result = TextStat.linsear_write_formula(@long_test)
|
134
|
-
expect(result).to eql 14.875
|
135
|
-
end
|
136
|
-
|
137
|
-
it 'should return the correct difficult words result' do
|
138
|
-
result = TextStat.difficult_words(@long_test)
|
139
|
-
expect(result).to eql 58
|
140
|
-
end
|
141
|
-
|
142
|
-
it 'should return the correct Dale–Chall readability score' do
|
143
|
-
score = TextStat.dale_chall_readability_score(@long_test)
|
144
|
-
expect(score).to eql 7.25
|
145
|
-
end
|
146
|
-
|
147
|
-
it 'should return the correct Gunning fog score' do
|
148
|
-
score = TextStat.gunning_fog(@long_test)
|
149
|
-
expect(score).to eql 17.56
|
150
|
-
end
|
151
|
-
|
152
|
-
it 'should return the correct Lix readability test score' do
|
153
|
-
score = TextStat.lix(@long_test)
|
154
|
-
expect(score).to eql 45.11
|
155
|
-
end
|
156
|
-
|
157
|
-
it 'should return the correct FORCAST readability test score' do
|
158
|
-
score = TextStat.forcast(@long_test)
|
159
|
-
expect(score).to eql 10
|
160
|
-
end
|
161
|
-
|
162
|
-
it 'should return the correct Powers Sumner Kearl readability test score' do
|
163
|
-
score = TextStat.powers_sumner_kearl(@long_test)
|
164
|
-
expect(score).to eql 25.04
|
165
|
-
end
|
166
|
-
|
167
|
-
it 'should return the correct SPACHE readability test score' do
|
168
|
-
score = TextStat.spache(@long_test)
|
169
|
-
expect(score).to eql 4.12
|
170
|
-
end
|
171
|
-
|
172
|
-
it 'should return the readability consensus score' do
|
173
|
-
standard = TextStat.text_standard(@long_test)
|
174
|
-
expect(standard).to eql '10th and 11th grade'
|
175
|
-
end
|
176
|
-
|
177
|
-
describe '.dictionary_path' do
|
178
|
-
subject(:dictionary_path) { described_class.dictionary_path }
|
179
|
-
|
180
|
-
it 'returns the Gem dictionary path by default' do
|
181
|
-
gem_root = File.dirname(File.dirname(__FILE__))
|
182
|
-
default_path = File.join(gem_root, 'lib', 'dictionaries')
|
183
|
-
expect(dictionary_path).to eq default_path
|
184
|
-
end
|
185
|
-
|
186
|
-
it 'allows dictionary path to be overridden' do
|
187
|
-
described_class.dictionary_path = '/some/other/path'
|
188
|
-
expect(dictionary_path).to eq '/some/other/path'
|
189
|
-
end
|
190
|
-
end
|
191
|
-
end
|
1
|
+
require 'rspec'
|
2
|
+
require_relative '../lib/textstat.rb'
|
3
|
+
|
4
|
+
describe TextStat do
|
5
|
+
before do
|
6
|
+
@long_test = 'Playing ... games has always been thought to be ' \
|
7
|
+
'important to the development of well-balanced and ' \
|
8
|
+
'creative children; however, what part, if any, ' \
|
9
|
+
'they should play in the lives of adults has never ' \
|
10
|
+
'been researched that deeply. I believe that ' \
|
11
|
+
'playing games is every bit as important for adults ' \
|
12
|
+
'as for children. Not only is taking time out to ' \
|
13
|
+
'play games with our children and other adults ' \
|
14
|
+
'valuable to building interpersonal relationships ' \
|
15
|
+
'but is also a wonderful way to release built up ' \
|
16
|
+
"tension.\n" \
|
17
|
+
"There's nothing my husband enjoys more after a " \
|
18
|
+
'hard day of work than to come home and play a game ' \
|
19
|
+
'of Chess with someone. This enables him to unwind ' \
|
20
|
+
"from the day's activities and to discuss the highs " \
|
21
|
+
'and lows of the day in a non-threatening, kick back ' \
|
22
|
+
'environment. One of my most memorable wedding ' \
|
23
|
+
'gifts, a Backgammon set, was received by a close ' \
|
24
|
+
'friend. I asked him why in the world he had given ' \
|
25
|
+
'us such a gift. He replied that he felt that an ' \
|
26
|
+
'important aspect of marriage was for a couple to ' \
|
27
|
+
'never quit playing games together. Over the years, ' \
|
28
|
+
'as I have come to purchase and play, with other ' \
|
29
|
+
'couples & coworkers, many games like: Monopoly, ' \
|
30
|
+
'Chutes & Ladders, Mastermind, Dweebs, Geeks, & ' \
|
31
|
+
'Weirdos, etc. I can reflect on the integral part ' \
|
32
|
+
'they have played in our weekends and our ' \
|
33
|
+
'"shut-off the T.V. and do something more ' \
|
34
|
+
'stimulating" weeks. They have enriched my life and ' \
|
35
|
+
'made it more interesting. Sadly, many adults ' \
|
36
|
+
'forget that games even exist and have put them ' \
|
37
|
+
'away in the cupboards, forgotten until the ' \
|
38
|
+
"grandchildren come over.\n" \
|
39
|
+
'All too often, adults get so caught up in working ' \
|
40
|
+
'to pay the bills and keeping up with the ' \
|
41
|
+
"\"Joneses'\" that they neglect to harness the fun " \
|
42
|
+
'in life; the fun that can be the reward of ' \
|
43
|
+
'enjoying a relaxing game with another person. It ' \
|
44
|
+
'has been said that "man is that he might have ' \
|
45
|
+
'joy" but all too often we skate through life ' \
|
46
|
+
'without much of it. Playing games allows us to: ' \
|
47
|
+
'relax, learn something new and stimulating, ' \
|
48
|
+
'interact with people on a different more ' \
|
49
|
+
'comfortable level, and to enjoy non-threatening ' \
|
50
|
+
'competition. For these reasons, adults should ' \
|
51
|
+
'place a higher priority on playing games in their ' \
|
52
|
+
'lives'
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'When testing the TextStat class' do
|
56
|
+
it 'should return the correct number of chars' do
|
57
|
+
count = TextStat.char_count(@long_test)
|
58
|
+
count_spaces = TextStat.char_count(@long_test, false)
|
59
|
+
|
60
|
+
expect(count).to eql 1750
|
61
|
+
expect(count_spaces).to eql 2123
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should return the correct number of lexicons' do
|
65
|
+
count = TextStat.lexicon_count(@long_test)
|
66
|
+
count_punctuation = TextStat.lexicon_count(@long_test, false)
|
67
|
+
|
68
|
+
expect(count).to eql 372
|
69
|
+
expect(count_punctuation).to eql 376
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should return the correct number of syllables' do
|
73
|
+
count = TextStat.syllable_count(@long_test)
|
74
|
+
expect(count).to eql 559
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should return the correct number of sentences' do
|
78
|
+
count = TextStat.sentence_count(@long_test)
|
79
|
+
expect(count).to eql 16
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should return the correct average sentence length' do
|
83
|
+
avg = TextStat.avg_sentence_length(@long_test)
|
84
|
+
expect(avg).to eql 23.3
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should return the correct average syllables per word' do
|
88
|
+
avg = TextStat.avg_syllables_per_word(@long_test)
|
89
|
+
expect(avg).to eql 1.5
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should return the correct average letters per word' do
|
93
|
+
avg = TextStat.avg_letter_per_word(@long_test)
|
94
|
+
expect(avg).to eql 4.7
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'should return the correct average sentence per word' do
|
98
|
+
avg = TextStat.avg_sentence_per_word(@long_test)
|
99
|
+
expect(avg).to eql 0.04
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should return the correct Flesch reading-ease test score' do
|
103
|
+
score = TextStat.flesch_reading_ease(@long_test)
|
104
|
+
expect(score).to eql 56.29
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should return the correct Flesch–Kincaid grade' do
|
108
|
+
score = TextStat.flesch_kincaid_grade(@long_test)
|
109
|
+
expect(score).to eql 11.2
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'should return the correct number of polysyllab' do
|
113
|
+
count = TextStat.polysyllab_count(@long_test)
|
114
|
+
expect(count).to eql 43
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'should return the correct smog index' do
|
118
|
+
index = TextStat.smog_index(@long_test)
|
119
|
+
expect(index).to eql 12.5
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'should return the correct Coleman–Liau index' do
|
123
|
+
index = TextStat.coleman_liau_index(@long_test)
|
124
|
+
expect(index).to eql 10.65
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'should return the correct automated readability index' do
|
128
|
+
index = TextStat.automated_readability_index(@long_test)
|
129
|
+
expect(index).to eql 12.4
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'should return the correct linsear write formula result' do
|
133
|
+
result = TextStat.linsear_write_formula(@long_test)
|
134
|
+
expect(result).to eql 14.875
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'should return the correct difficult words result' do
|
138
|
+
result = TextStat.difficult_words(@long_test)
|
139
|
+
expect(result).to eql 58
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'should return the correct Dale–Chall readability score' do
|
143
|
+
score = TextStat.dale_chall_readability_score(@long_test)
|
144
|
+
expect(score).to eql 7.25
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'should return the correct Gunning fog score' do
|
148
|
+
score = TextStat.gunning_fog(@long_test)
|
149
|
+
expect(score).to eql 17.56
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'should return the correct Lix readability test score' do
|
153
|
+
score = TextStat.lix(@long_test)
|
154
|
+
expect(score).to eql 45.11
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'should return the correct FORCAST readability test score' do
|
158
|
+
score = TextStat.forcast(@long_test)
|
159
|
+
expect(score).to eql 10
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'should return the correct Powers Sumner Kearl readability test score' do
|
163
|
+
score = TextStat.powers_sumner_kearl(@long_test)
|
164
|
+
expect(score).to eql 25.04
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'should return the correct SPACHE readability test score' do
|
168
|
+
score = TextStat.spache(@long_test)
|
169
|
+
expect(score).to eql 4.12
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'should return the readability consensus score' do
|
173
|
+
standard = TextStat.text_standard(@long_test)
|
174
|
+
expect(standard).to eql '10th and 11th grade'
|
175
|
+
end
|
176
|
+
|
177
|
+
describe '.dictionary_path' do
|
178
|
+
subject(:dictionary_path) { described_class.dictionary_path }
|
179
|
+
|
180
|
+
it 'returns the Gem dictionary path by default' do
|
181
|
+
gem_root = File.dirname(File.dirname(__FILE__))
|
182
|
+
default_path = File.join(gem_root, 'lib', 'dictionaries')
|
183
|
+
expect(dictionary_path).to eq default_path
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'allows dictionary path to be overridden' do
|
187
|
+
described_class.dictionary_path = '/some/other/path'
|
188
|
+
expect(dictionary_path).to eq '/some/other/path'
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
192
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: textstat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jakub Polak
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: text-hyphen
|