Class: ChatCorrect::CorrectionsHash
- Inherits:
-
Object
- Object
- ChatCorrect::CorrectionsHash
- Defined in:
- lib/chat_correct/corrections_hash.rb
Constant Summary collapse
- PUNCTUATION_SYMBOLS =
['∯', '∬', '∫', '∮']
Instance Attribute Summary collapse
-
#corrected_sentence_info_hash ⇒ Object
readonly
Returns the value of attribute corrected_sentence_info_hash.
-
#original_sentence_info_hash ⇒ Object
readonly
Returns the value of attribute original_sentence_info_hash.
Instance Method Summary collapse
- #create ⇒ Object
-
#initialize(original_sentence_info_hash:, corrected_sentence_info_hash:) ⇒ CorrectionsHash
constructor
A new instance of CorrectionsHash.
Constructor Details
#initialize(original_sentence_info_hash:, corrected_sentence_info_hash:) ⇒ CorrectionsHash
Returns a new instance of CorrectionsHash.
5 6 7 8 9 10 |
# File 'lib/chat_correct/corrections_hash.rb', line 5 def initialize(original_sentence_info_hash:, corrected_sentence_info_hash:) @original_sentence_info_hash = original_sentence_info_hash @corrected_sentence_info_hash = corrected_sentence_info_hash @combined_hash = {} @final_matched_array = [] end |
Instance Attribute Details
#corrected_sentence_info_hash ⇒ Object (readonly)
Returns the value of attribute corrected_sentence_info_hash.
4 5 6 |
# File 'lib/chat_correct/corrections_hash.rb', line 4 def corrected_sentence_info_hash @corrected_sentence_info_hash end |
#original_sentence_info_hash ⇒ Object (readonly)
Returns the value of attribute original_sentence_info_hash.
4 5 6 |
# File 'lib/chat_correct/corrections_hash.rb', line 4 def original_sentence_info_hash @original_sentence_info_hash end |
Instance Method Details
#create ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/chat_correct/corrections_hash.rb', line 12 def create @j = 0 @i = 0 while @i < corrected_sentence_info_hash.length do @correct_info = {} @mistake_info = {} if @j >= original_sentence_info_hash.length if corrected_sentence_info_hash[@i]['token'].gsub(/[[:punct:]]/, '').eql?('') @correct_info[corrected_sentence_info_hash[@i]['token']] = 'missing_punctuation_correction' @combined_hash[@combined_hash.length] = @correct_info else @correct_info[corrected_sentence_info_hash[@i]['token']] = 'missing_word_mistake' @combined_hash[@combined_hash.length] = @correct_info end @i +=1 else case when original_sentence_info_hash[@j]['match_id'].to_s[0].eql?('c') && original_sentence_info_hash[@j]['match_id'].to_s[1..original_sentence_info_hash[@j]['match_id'].to_s.length].eql?(@i.to_s) matching_ids_error_analysis(original_sentence_info_hash[@j], corrected_sentence_info_hash[@i]) when original_sentence_info_hash[@j]['match_id'].to_s[0].eql?('c') && original_sentence_info_hash[@j]['match_id'].to_s[1..original_sentence_info_hash[@j]['match_id'].to_s.length] != @i.to_s unmatched_ids_error_analysis when original_sentence_info_hash[@j]['match_id'].to_s[0].eql?('s') special_error_analysis when original_sentence_info_hash[@j]['match_id'].to_s[0].eql?('d') duplicate_error_analysis end end end original_sentence_info_hash.each do |k, v| if v['match_id'].to_s[0].eql?('s') && !@final_matched_array.include?(v['match_id'].to_s) if v['token'].gsub(/[[:punct:]]/, '').eql?('') || PUNCTUATION_SYMBOLS.include?(v['token']) @mistake_info = {} @mistake_info[v['token']] = 'punctuation_mistake' @combined_hash[@combined_hash.length] = @mistake_info @final_matched_array << v['match_id'].to_s else @mistake_info = {} @mistake_info[v['token']] = 'unnecessary_word_mistake' @combined_hash[@combined_hash.length] = @mistake_info @final_matched_array << v['match_id'].to_s end end end @combined_hash.each do |k, v| v.each do |k1, v1| next unless k1.include?('ƪ') case when v1.include?('missing_word_mistake') && @combined_hash[k - 1].to_s.include?('unnecessary_word_mistake') && @combined_hash[k - 2].to_s.include?('unnecessary_word_mistake') next if !ChatCorrect::Contraction.new(token_a: @combined_hash[k - 2].key('unnecessary_word_mistake').to_s, token_b: @combined_hash[k - 1].key('unnecessary_word_mistake').to_s, contraction: k1.to_s).contraction? @combined_hash[k][k1] = 'stylistic_choice_correction' @combined_hash[k - 1][@combined_hash[k - 1].key('unnecessary_word_mistake')] = 'stylistic_choice' @combined_hash[k - 2][@combined_hash[k - 2].key('unnecessary_word_mistake')] = 'stylistic_choice' when v1.include?('missing_word_mistake') && @combined_hash[k + 1].to_s.include?('unnecessary_word_mistake') && @combined_hash[k + 2].to_s.include?('unnecessary_word_mistake') next if !ChatCorrect::Contraction.new(token_a: @combined_hash[k + 2].key('unnecessary_word_mistake').to_s, token_b: @combined_hash[k + 1].key('unnecessary_word_mistake').to_s, contraction: k1.to_s).contraction? @combined_hash[k][k1] = 'stylistic_choice_correction' @combined_hash[k + 1][@combined_hash[k + 1].key('unnecessary_word_mistake')] = 'stylistic_choice' @combined_hash[k + 2][@combined_hash[k + 2].key('unnecessary_word_mistake')] = 'stylistic_choice' when v1.include?('unnecessary_word_mistake') && @combined_hash[k + 1].to_s.include?('missing_word_mistake') && @combined_hash[k + 2].to_s.include?('missing_word_mistake') next if !ChatCorrect::Contraction.new(token_a: @combined_hash[k + 1].key('missing_word_mistake').to_s, token_b: @combined_hash[k + 2].key('missing_word_mistake').to_s, contraction: k1.to_s).contraction? @combined_hash[k][k1] = 'stylistic_choice' @combined_hash[k + 1][@combined_hash[k + 1].key('missing_word_mistake')] = 'stylistic_choice_correction' @combined_hash[k + 2][@combined_hash[k + 2].key('missing_word_mistake')] = 'stylistic_choice_correction' when v1.include?('unnecessary_word_mistake') && @combined_hash[k - 1].to_s.include?('missing_word_mistake') && @combined_hash[k - 2].to_s.include?('missing_word_mistake') next if !ChatCorrect::Contraction.new(token_a: @combined_hash[k - 2].key('missing_word_mistake').to_s, token_b: @combined_hash[k - 1].key('missing_word_mistake').to_s, contraction: k1.to_s).contraction? @combined_hash[k][k1] = 'stylistic_choice' @combined_hash[k - 1][@combined_hash[k - 1].key('missing_word_mistake')] = 'stylistic_choice_correction' @combined_hash[k - 2][@combined_hash[k - 2].key('missing_word_mistake')] = 'stylistic_choice_correction' when v1.include?('verb_mistake') && @combined_hash[k + 1].to_s.include?('verb_mistake_correction') next if !ChatCorrect::Contraction.new(token_a: @combined_hash[k + 1].key('verb_mistake_correction').to_s.split[0].to_s, token_b: @combined_hash[k + 1].key('verb_mistake_correction').to_s.split[1].to_s, contraction: k1.gsub(/ƪ/o, "'").split[0].to_s.gsub(/'/o, 'ƪ')).contraction? @combined_hash[k][k1] = 'stylistic_choice' @combined_hash[k + 1][@combined_hash[k + 1].key('verb_mistake_correction')] = 'stylistic_choice_correction' when v1.include?('verb_mistake_correction') && @combined_hash[k - 1].to_s.include?('verb_mistake') next if !ChatCorrect::Contraction.new(token_a: @combined_hash[k - 1].key('verb_mistake').to_s.split[0].to_s, token_b: @combined_hash[k - 1].key('verb_mistake').to_s.split[1].to_s, contraction: k1.gsub(/ƪ/o, "'").split[0].to_s.gsub(/'/o, 'ƪ')).contraction? @combined_hash[k][k1] = 'stylistic_choice_correction' @combined_hash[k - 1][@combined_hash[k - 1].key('verb_mistake')] = 'stylistic_choice' end end end @combined_hash end |