Class: Jkproof::Sentence
- Inherits:
-
Object
- Object
- Jkproof::Sentence
- Defined in:
- lib/jkproof/sentence.rb
Instance Method Summary collapse
- #fetch_wrong_words ⇒ Object
-
#initialize(buf, json_dictionary) ⇒ Sentence
constructor
A new instance of Sentence.
Constructor Details
#initialize(buf, json_dictionary) ⇒ Sentence
Returns a new instance of Sentence.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/jkproof/sentence.rb', line 12 def initialize(buf, json_dictionary) Dotenv.load @yahoo_api_key = ENV['YAHOO_API_KEY'] @no_filter = ENV['NO_FILTER'].blank? ? '' : ENV['NO_FILTER'] set_dictionary(json_dictionary) @yahoo_words = [] @buf = buf end |
Instance Method Details
#fetch_wrong_words ⇒ Object
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 |
# File 'lib/jkproof/sentence.rb', line 23 def fetch_wrong_words = [] wrong_words = [] excluded_correct_word = @buf begin fetch_yahoo_lint_words rescue StandardError => e .push "yahoo api. (#{e})" end # 正しいワードを取り除く begin @dictionary_words.each do |word| # 誤りのある単語の文字数 > 正しい単語の文字数の場合、先に検知する wrongs = fetch_wrong_words_than_long_correct_word(word['correct'], word['wrongs']) wrongs.each do |wrong| if excluded_correct_word.include?(wrong) wrong_words.push(type: 'local', correct: word['correct'], wrong: wrong) excluded_correct_word = excluded_correct_word.gsub(wrong, '####') end end # 正しいワードを取り除く excluded_correct_word = excluded_correct_word.gsub(word['correct'], '****') end @dictionary_words.each do |word| correct_word = word['correct'] word['wrongs'].each do |wrong| if excluded_correct_word.include?(wrong) wrong_words.push(type: 'local', wrong: wrong, correct: correct_word) excluded_correct_word = excluded_correct_word.gsub(wrong, '####') end end end rescue StandardError => e .push "yml or json dictionary. (#{e})" end = .empty? ? '' : "#{error_messages.count} ERROR(s) : #{error_messages.join(', ')}" words = wrong_words.concat(@yahoo_words).uniq { message: , count: words.size, type: @type, words: words } end |