chat_correct 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chat_correct/correct.rb +29 -14
- data/lib/chat_correct/version.rb +1 -1
- data/spec/chat_correct/correct_spec.rb +24 -24
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3c1125d076cc373a05732ae72b73cf765a7c224
|
4
|
+
data.tar.gz: ae70fb4edcbc9496bdb6dba95bdcd132d7232a15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b88d5e0e976dc93adc26d0b2e3ef9e55c45a5c49877b968e9d021bc11c6290c4450b7c1a68d968c90efb53c9da05d563a9bd97bd583baae4691b4b5df5aa9f9
|
7
|
+
data.tar.gz: 37f587c0abfe10c0bf39386ec82d4614a8cbbeed1d95044cb14ed4c160edf10ade74434ff588b0f433e5346580209b23c2f3e4f1cafce73673d3625a839c315e
|
data/lib/chat_correct/correct.rb
CHANGED
@@ -17,20 +17,7 @@ module ChatCorrect
|
|
17
17
|
mistakes_hash = {}
|
18
18
|
analyze.each do |key, value|
|
19
19
|
next if !value['type'].split('_')[-1].eql?('mistake') || value['type'].split('_')[0].eql?('no')
|
20
|
-
|
21
|
-
interim_hash['position'] = key
|
22
|
-
if value['type'].split('_').length > 2
|
23
|
-
interim_hash['error_type'] = value['type'].split('_')[0] + '_' + value['type'].split('_')[1]
|
24
|
-
else
|
25
|
-
interim_hash['error_type'] = value['type'].split('_')[0]
|
26
|
-
end
|
27
|
-
interim_hash['mistake'] = value['token']
|
28
|
-
if correct[key + 1]['type'].split('_')[0].eql?(correct[key]['type'].split('_')[0])
|
29
|
-
interim_hash['correction'] = correct[key + 1]['token']
|
30
|
-
else
|
31
|
-
interim_hash['correction'] = ''
|
32
|
-
end
|
33
|
-
mistakes_hash[mistakes_hash.length] = interim_hash
|
20
|
+
mistakes_hash = build_mistakes_hash(mistakes_hash, key, value)
|
34
21
|
end
|
35
22
|
mistakes_hash
|
36
23
|
end
|
@@ -82,6 +69,34 @@ module ChatCorrect
|
|
82
69
|
build_corrections_hash(correction_hash)
|
83
70
|
end
|
84
71
|
|
72
|
+
def update_interim_hash_with_error(interim_hash, value)
|
73
|
+
if value['type'].split('_').length > 2
|
74
|
+
interim_hash['error_type'] = value['type'].split('_')[0] + '_' + value['type'].split('_')[1]
|
75
|
+
else
|
76
|
+
interim_hash['error_type'] = value['type'].split('_')[0]
|
77
|
+
end
|
78
|
+
interim_hash
|
79
|
+
end
|
80
|
+
|
81
|
+
def update_interim_hash_with_correction(interim_hash, key)
|
82
|
+
if correct[key + 1]['type'].split('_')[0].eql?(correct[key]['type'].split('_')[0])
|
83
|
+
interim_hash['correction'] = correct[key + 1]['token']
|
84
|
+
else
|
85
|
+
interim_hash['correction'] = ''
|
86
|
+
end
|
87
|
+
interim_hash
|
88
|
+
end
|
89
|
+
|
90
|
+
def build_mistakes_hash(mistakes_hash, key, value)
|
91
|
+
interim_hash = {}
|
92
|
+
interim_hash['position'] = key
|
93
|
+
interim_hash = update_interim_hash_with_error(interim_hash, value)
|
94
|
+
interim_hash['mistake'] = value['token']
|
95
|
+
interim_hash = update_interim_hash_with_correction(interim_hash, key) unless correct[key + 1].blank?
|
96
|
+
mistakes_hash[mistakes_hash.length] = interim_hash
|
97
|
+
mistakes_hash
|
98
|
+
end
|
99
|
+
|
85
100
|
def build_corrections_hash(correction_hash)
|
86
101
|
final_hash = {}
|
87
102
|
correction_hash.each do |k, v|
|
data/lib/chat_correct/version.rb
CHANGED
@@ -200,13 +200,13 @@ RSpec.describe ChatCorrect::Correct do
|
|
200
200
|
expect(@cc.correct).to eq({0=>{"token"=>"This", "type"=>"no_mistake"}, 1=>{"token"=>"is", "type"=>"no_mistake"}, 2=>{"token"=>"and", "type"=>"no_mistake"}, 3=>{"token"=>"this", "type"=>"no_mistake"}, 4=>{"token"=>"and", "type"=>"no_mistake"}, 5=>{"token"=>"this", "type"=>"no_mistake"}, 6=>{"token"=>"is", "type"=>"no_mistake"}, 7=>{"token"=>"a", "type"=>"no_mistake"}, 8=>{"token"=>"correct", "type"=>"no_mistake"}, 9=>{"token"=>"double", "type"=>"no_mistake"}, 10=>{"token"=>"word", "type"=>"no_mistake"}, 11=>{"token"=>"check", "type"=>"no_mistake"}, 12=>{"token"=>"!", "type"=>"punctuation_mistake"}, 13=>{"token"=>".", "type"=>"punctuation_correction"}})
|
201
201
|
end
|
202
202
|
|
203
|
-
|
204
|
-
|
205
|
-
|
203
|
+
it 'Counts the number of mistakes' do
|
204
|
+
expect(@cc.number_of_mistakes).to eq(1)
|
205
|
+
end
|
206
206
|
|
207
|
-
|
208
|
-
|
209
|
-
|
207
|
+
it 'Reports the mistakes by mistake type' do
|
208
|
+
expect(@cc.mistake_report).to eq({"missing_word"=>0, "unnecessary_word"=>0, "spelling"=>0, "verb"=>0, "punctuation"=>1, "word_order"=>0, "capitalization"=>0, "duplicate_word"=>0, "word_choice"=>0, "pluralization"=>0, "possessive"=>0, "stylistic_choice"=>0})
|
209
|
+
end
|
210
210
|
end
|
211
211
|
|
212
212
|
context "example correction #011" do
|
@@ -220,13 +220,13 @@ RSpec.describe ChatCorrect::Correct do
|
|
220
220
|
expect(@cc.correct).to eq({0=>{"token"=>"He", "type"=>"no_mistake"}, 1=>{"token"=>"said", "type"=>"no_mistake"}, 2=>{"token"=>",", "type"=>"no_mistake"}, 3=>{"token"=>"\"", "type"=>"no_mistake"}, 4=>{"token"=>"Shhe", "type"=>"spelling_mistake"}, 5=>{"token"=>"She", "type"=>"spelling_correction"}, 6=>{"token"=>"is", "type"=>"no_mistake"}, 7=>{"token"=>"a", "type"=>"no_mistake"}, 8=>{"token"=>"crazy", "type"=>"no_mistake"}, 9=>{"token"=>"girl", "type"=>"no_mistake"}, 10=>{"token"=>".", "type"=>"word_order_mistake"}, 11=>{"token"=>"\"", "type"=>"word_order_mistake"}})
|
221
221
|
end
|
222
222
|
|
223
|
-
|
224
|
-
|
225
|
-
|
223
|
+
it 'Counts the number of mistakes' do
|
224
|
+
expect(@cc.number_of_mistakes).to eq(3)
|
225
|
+
end
|
226
226
|
|
227
|
-
|
228
|
-
|
229
|
-
|
227
|
+
it 'Reports the mistakes by mistake type' do
|
228
|
+
expect(@cc.mistake_report).to eq({"missing_word"=>0, "unnecessary_word"=>0, "spelling"=>1, "verb"=>0, "punctuation"=>0, "word_order"=>2, "capitalization"=>0, "duplicate_word"=>0, "word_choice"=>0, "pluralization"=>0, "possessive"=>0, "stylistic_choice"=>0})
|
229
|
+
end
|
230
230
|
end
|
231
231
|
|
232
232
|
context "example correction #012" do
|
@@ -240,13 +240,13 @@ RSpec.describe ChatCorrect::Correct do
|
|
240
240
|
expect(@cc.correct).to eq({0=>{"token"=>"Test", "type"=>"no_mistake"}, 1=>{"token"=>"the", "type"=>"no_mistake"}, 2=>{"token"=>"word", "type"=>"word_order_mistake"}, 3=>{"token"=>"order", "type"=>"word_order_mistake"}, 4=>{"token"=>".", "type"=>"no_mistake"}})
|
241
241
|
end
|
242
242
|
|
243
|
-
|
244
|
-
|
245
|
-
|
243
|
+
it 'Counts the number of mistakes' do
|
244
|
+
expect(@cc.number_of_mistakes).to eq(2)
|
245
|
+
end
|
246
246
|
|
247
|
-
|
248
|
-
|
249
|
-
|
247
|
+
it 'Reports the mistakes by mistake type' do
|
248
|
+
expect(@cc.mistake_report).to eq({"missing_word"=>0, "unnecessary_word"=>0, "spelling"=>0, "verb"=>0, "punctuation"=>0, "word_order"=>2, "capitalization"=>0, "duplicate_word"=>0, "word_choice"=>0, "pluralization"=>0, "possessive"=>0, "stylistic_choice"=>0})
|
249
|
+
end
|
250
250
|
end
|
251
251
|
|
252
252
|
context "example correction #013" do
|
@@ -260,13 +260,13 @@ RSpec.describe ChatCorrect::Correct do
|
|
260
260
|
expect(@cc.correct).to eq({0=>{"token"=>"This", "type"=>"no_mistake"}, 1=>{"token"=>"is", "type"=>"no_mistake"}, 2=>{"token"=>"a", "type"=>"no_mistake"}, 3=>{"token"=>"double", "type"=>"duplicate_word_mistake"}, 4=>{"token"=>"double", "type"=>"duplicate_word_mistake"}, 5=>{"token"=>"double", "type"=>"duplicate_word_mistake"}, 6=>{"token"=>"double", "type"=>"no_mistake"}, 7=>{"token"=>"word", "type"=>"no_mistake"}, 8=>{"token"=>"check", "type"=>"no_mistake"}, 9=>{"token"=>".", "type"=>"no_mistake"}})
|
261
261
|
end
|
262
262
|
|
263
|
-
|
264
|
-
|
265
|
-
|
263
|
+
it 'Counts the number of mistakes' do
|
264
|
+
expect(@cc.number_of_mistakes).to eq(3)
|
265
|
+
end
|
266
266
|
|
267
|
-
|
268
|
-
|
269
|
-
|
267
|
+
it 'Reports the mistakes by mistake type' do
|
268
|
+
expect(@cc.mistake_report).to eq({"missing_word"=>0, "unnecessary_word"=>0, "spelling"=>0, "verb"=>0, "punctuation"=>0, "word_order"=>0, "capitalization"=>0, "duplicate_word"=>3, "word_choice"=>0, "pluralization"=>0, "possessive"=>0, "stylistic_choice"=>0})
|
269
|
+
end
|
270
270
|
end
|
271
271
|
|
272
272
|
context "example correction #014" do
|