jkproof 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0addda3ea12086f43d3170f5e24aae959c91c6c37b6ef2a493f2308c4cb0650c
4
- data.tar.gz: 88f34a95526329f102c061f9f6cc99568437b36257a70724f18435b87b89344c
3
+ metadata.gz: fc1fc2ca6a94e4111aacb7222c70ec6c502ab1d44d99cf7cb0810f5d689e4737
4
+ data.tar.gz: 7b2cf8c0abfa848a30c5b5c58952fe08083bbc567479dc04af4c3ca6c582a36c
5
5
  SHA512:
6
- metadata.gz: 82beac07b25fa4677d459301af44475d03ffafdb1fcf31e550fd81eb63c95726db6d81551c1dcac0ca45ea098cc0746a357bffecae5c1a91f91644ecbe0d21ac
7
- data.tar.gz: 87bcf0b06d7dc56fe73ebc658abc95d990e2f97cbdb2859c0c5e2f9abbb6b2e779819442a133377fc8b192e289e8e991347bd53f07181e2aad624f8c479bde68
6
+ metadata.gz: bdb436cc0c1505c34bf24c684556831a3600b174f0faaf8f7c3255e3a9766cb6df77b54a26e9362698fe55dedee426757f0f1e9866f9f29d50dddd0dfb720d0f
7
+ data.tar.gz: 4b71c58b834c68fd435812bbe305679cb395f213829a538f789256bb543430e2e8f2c78c33ae1ada357889fe2c255c04f362d35ea37be0b1549528755c119771
data/.env.sample CHANGED
@@ -1,2 +1,3 @@
1
1
  YAHOO_API_KEY="ref: https://e.developer.yahoo.co.jp/dashboard/"
2
- DICTIONARY_YML_PATH="your own dicionary file(ex: ./spec/dictionary.yml)"
2
+ DICTIONARY_YML_PATH="your own dicionary file(ex: ./spec/dictionary.yml)"
3
+ NO_FILTER="ref: https://developer.yahoo.co.jp/webapi/jlp/kousei/v1/kousei.html #no_filter"
data/CHANGELOG.md ADDED
@@ -0,0 +1,36 @@
1
+ # ChangeLog
2
+
3
+ ## v1.1.0
4
+
5
+ - 辞書ファイルの記述を簡略化できるよう修正した
6
+ - API側の検知レベルを `.env` から調整できるようにした
7
+ - `正しい単語の文字長 < 誤りのある単語の文字長` を検知できるようにした
8
+
9
+ ```ruby
10
+ # dictionary.yml
11
+ # -
12
+ # correct: word
13
+ # wrongs:
14
+ # - words
15
+
16
+ # 修正前:
17
+ Jkproof.detect_words_has_error("words is wrong.")
18
+ # => []
19
+
20
+ # 修正後:
21
+ Jkproof.detect_words_has_error("words is wrong.")
22
+ # => [{ correct: "word", wrong: "words" }]
23
+
24
+ # これは内部的な処理が次のようになっていたため発生していた。
25
+ # 1.正しい単語を除去
26
+ # 2.誤りのある単語を検知
27
+ ```
28
+
29
+ ## v1.0.0
30
+
31
+ - APIキー・辞書ファイルのパス( `dictionary.yml` )を `.env` に記述できるようにした
32
+
33
+ 正式版としてリリース。
34
+
35
+ ## v0.1.0
36
+ プレリリース。
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jkproof (0.1.0)
4
+ jkproof (1.0.0)
5
5
  activesupport
6
6
  dotenv
7
7
  highline
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
+ <img src="https://github.com/tosite0345/jkproof/blob/master/docs/logo.png" style="width: 100% !important;">
2
+
1
3
  # [Jkproof](https://rubygems.org/gems/jkproof)
2
4
 
5
+ **Author:[@mao_sum](https://twitter.com/mao_sum)**
6
+
3
7
  Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/jkproof`. To experiment with that code, run `bin/console` for an interactive prompt.
4
8
 
5
- TODO: Delete this and the text above, and describe your gem
6
9
 
7
10
  ## Installation
8
11
 
@@ -56,15 +59,33 @@ wrongs :
56
59
  word3 : wrong-word-1
57
60
  ```
58
61
 
62
+ ### Yahoo APIキーを生成する
63
+ https://e.developer.yahoo.co.jp/dashboard/ からAPIキーを生成してください。
64
+
65
+ `Client ID` を使用します。
66
+
67
+ ### .envファイルを修正する
68
+
69
+ `jkproof/.env.sample` をコピーして編集、もしくは既存の `.env` ファイルに追記してください。
70
+
71
+ **追記する場合**
72
+
73
+ ```
74
+ YAHOO_API_KEY=""
75
+ DICTIONARY_YML_PATH=""
76
+ ```
77
+
78
+ 先に作成した辞書ファイルのパスを `DICTIONARY_YML_PATH` に、Yahoo APIキーを `YAHPP_API_KEY` にそれぞれ登録してください。
79
+
59
80
  ## Usage
60
81
 
61
82
  ```ruby
62
83
  # 検出された場合
63
- Jkproof.detect_words_has_error("検知したい文章", "config/dictionary.yml")
84
+ Jkproof.detect_words_has_error("検知したい文章")
64
85
  # => [{ wrong: WrongWord, correct:CorrectWord }]
65
86
 
66
87
  # 検出されなかった場合
67
- Jkproof.detect_words_has_error("", "config/dictionary.yml")
88
+ Jkproof.detect_words_has_error("")
68
89
  # => []
69
90
  ```
70
91
 
@@ -76,4 +97,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
76
97
 
77
98
  ## Contributing
78
99
 
79
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/jkproof.
100
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tosite0345/jkproof.
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
 
data/bin/console CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'jkproof'
data/docs/logo.png ADDED
Binary file
data/jkproof.gemspec CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  lib = File.expand_path('lib', __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require 'jkproof/version'
@@ -17,7 +19,7 @@ Gem::Specification.new do |spec|
17
19
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
20
  # to allow pushing to a single host or delete this section to allow pushing to any host.
19
21
  if spec.respond_to?(:metadata)
20
- spec.metadata['allowed_push_host'] = "https://rubygems.org"
22
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
23
 
22
24
  # spec.metadata["homepage_uri"] = spec.homepage
23
25
  spec.metadata['homepage_uri'] = 'https://github.com/tosite0345/jkproof'
@@ -41,7 +43,7 @@ Gem::Specification.new do |spec|
41
43
  spec.add_development_dependency 'rake', '~> 10.0'
42
44
  spec.add_development_dependency 'rspec', '~> 3.0'
43
45
  spec.add_dependency 'activesupport'
44
- spec.add_dependency 'xml-simple'
45
46
  spec.add_dependency 'dotenv'
46
47
  spec.add_dependency 'highline'
48
+ spec.add_dependency 'xml-simple'
47
49
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Jkproof
2
4
  class Sentence
3
5
  require 'yaml'
@@ -9,26 +11,42 @@ module Jkproof
9
11
 
10
12
  def initialize(buf)
11
13
  Dotenv.load
12
- yml_path = ENV["DICTIONARY_YML_PATH"]
13
- @yahoo_api_key = ENV["YAHOO_API_KEY"]
14
- @dictionary_words = (yml_path.blank?) ? [] : YAML.load_file(yml_path)
15
- @yahoo_words = []
16
- @buf = buf
14
+ yml_path = ENV['DICTIONARY_YML_PATH']
15
+ @yahoo_api_key = ENV['YAHOO_API_KEY']
16
+ @no_filter = ENV['NO_FILTER'].blank? ? '11' : ENV['NO_FILTER']
17
+
18
+ begin
19
+ @dictionary_words = yml_path.blank? ? [] : YAML.load_file(yml_path)
20
+ rescue StandardError => e
21
+ raise "#{e}(file_path: '#{yml_path}')"
22
+ end
23
+ @yahoo_words = []
24
+ @buf = buf
17
25
  fetch_yahoo_lint_words
18
26
  end
19
27
 
20
28
  def fetch_wrong_words
21
- wrong_words = []
29
+ wrong_words = []
30
+ excluded_correct_word = @buf
22
31
 
23
32
  # 正しいワードを取り除く
24
- @dictionary_words.each do |_key, word|
25
- @buf.gsub!(word['correct'], '')
33
+ @dictionary_words.each do |word|
34
+ # 誤りのある単語の文字数 > 正しい単語の文字数の場合、先に検知する
35
+ wrongs = fetch_wrong_words_than_long_correct_word(word['correct'], word['wrongs'])
36
+ wrongs.each do |wrong|
37
+ if excluded_correct_word.include?(wrong)
38
+ wrong_words.push(correct: word['correct'], wrong: wrong)
39
+ excluded_correct_word = excluded_correct_word.gsub(wrong, '####')
40
+ end
41
+ end
42
+ # 正しいワードを取り除く
43
+ excluded_correct_word = excluded_correct_word.gsub(word['correct'], '****')
26
44
  end
27
45
 
28
- @dictionary_words.each do |_key, word|
46
+ @dictionary_words.each do |word|
29
47
  correct_word = word['correct']
30
- word['wrongs'].each do |_wkey, wrong|
31
- if @buf.include?(wrong)
48
+ word['wrongs'].each do |wrong|
49
+ if excluded_correct_word.include?(wrong)
32
50
  wrong_words.push(wrong: wrong, correct: correct_word)
33
51
  break
34
52
  end
@@ -43,6 +61,7 @@ module Jkproof
43
61
  if @yahoo_api_key.blank? || @yahoo_api_key.size < 10
44
62
  raise "There is no Yahoo API Key.Please set API Key in 'jkproof/.env'.(ref: https://e.developer.yahoo.co.jp/dashboard/)"
45
63
  end
64
+
46
65
  # ref: http://developer.yahoo.co.jp/webapi/jlp/kousei/v1/kousei.html
47
66
  uri = URI.parse('https://jlp.yahooapis.jp/KouseiService/V1/kousei')
48
67
  http = Net::HTTP.new(uri.host, uri.port)
@@ -51,21 +70,24 @@ module Jkproof
51
70
  reqest.set_form_data(
52
71
  appid: @yahoo_api_key,
53
72
  sentence: @buf,
54
- no_filter: '11'
55
- # no_filter: "11,12,14,15"
73
+ no_filter: @no_filter
56
74
  )
57
75
  s = http.request(reqest).body
58
76
  unless Hash.from_xml(s)['ResultSet']['Result'].nil?
59
77
  [Hash.from_xml(s)['ResultSet']['Result']].flatten.each do |r|
60
78
  next unless r['Surface']
61
79
  next unless r['ShitekiWord']
80
+
62
81
  @yahoo_words.push(correct: r['ShitekiWord'], wrong: r['Surface'])
63
82
  end
64
83
  end
65
84
  end
66
85
 
67
- def remove_correct_word(key, correct_word)
68
- @buf.gsub!(correct_word, "[###{key}##]")
86
+ def fetch_wrong_words_than_long_correct_word(correct_word, wrong_words)
87
+ return_words = []
88
+ c_length = correct_word.length
89
+ wrong_words.each { |wrong_word| return_words.push(wrong_word) if c_length < wrong_word.length }
90
+ return_words
69
91
  end
70
92
  end
71
93
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Jkproof
2
- VERSION = '1.0.0' # バージョンアップ
4
+ VERSION = '1.1.0' # バージョンアップ
3
5
  end
data/lib/jkproof.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'jkproof/version'
2
4
  require 'jkproof/sentence'
3
5
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jkproof
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tosite
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-31 00:00:00.000000000 Z
11
+ date: 2019-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: xml-simple
70
+ name: dotenv
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: dotenv
84
+ name: highline
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -95,7 +95,7 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: highline
98
+ name: xml-simple
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="
@@ -119,12 +119,14 @@ files:
119
119
  - ".gitignore"
120
120
  - ".rspec"
121
121
  - ".travis.yml"
122
+ - CHANGELOG.md
122
123
  - Gemfile
123
124
  - Gemfile.lock
124
125
  - README.md
125
126
  - Rakefile
126
127
  - bin/console
127
128
  - bin/setup
129
+ - docs/logo.png
128
130
  - jkproof.gemspec
129
131
  - lib/jkproof.rb
130
132
  - lib/jkproof/sentence.rb