jkproof 1.1.3 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +3 -3
- data/README.md +49 -14
- data/jkproof.gemspec +11 -6
- data/lib/jkproof/sentence.rb +23 -9
- data/lib/jkproof/version.rb +1 -1
- data/lib/jkproof.rb +2 -2
- metadata +22 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cee32de691a9c30a7e5d4fb319128f7d1827650c8810e3c02194cbe268794301
|
4
|
+
data.tar.gz: 5db6b4644f9345b152162b592bbd6ecdf4aa2c716e394bfaaaf1aafea8cdb921
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c92b5916cdecd22ef8010a6f0cce2705dc4b8cdf1d35cccd4862917674fe230d63dda3bacf25603061f6669bb0da55ca0b483a3f0dc2846ddda8125124cfb183
|
7
|
+
data.tar.gz: b654be09edc8ae6fc88f400c2fead7507f7a919359c3c98e26d9dbf72c34df7f7fa571102861857c79e965d539f52dfd4c54387f498ffe36cd640783a4ac2f48
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# ChangeLog
|
2
2
|
|
3
|
+
## v1.2.2
|
4
|
+
- JSON形式に対応した
|
5
|
+
- `Jkproof.detect_words_has_error(sentence, json_dictionary)` のように第二引数にJSONデータを渡すことで対応可能
|
6
|
+
- `type` の `local` を `yml` と `json` に細分化した
|
7
|
+
|
3
8
|
## v1.1.3
|
4
9
|
- 表記揺らぎのある用語が複数個あった場合にすべて表示されないバグの修正
|
5
10
|
- 例:`"問合せ/問い合わせ/問い合せ" => [{wrong: "問い合わせ" correct: "お問い合わせ"}]`
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
jkproof (1.
|
4
|
+
jkproof (1.2.0)
|
5
5
|
activesupport
|
6
6
|
dotenv
|
7
7
|
highline
|
@@ -17,9 +17,9 @@ GEM
|
|
17
17
|
tzinfo (~> 1.1)
|
18
18
|
concurrent-ruby (1.1.4)
|
19
19
|
diff-lcs (1.3)
|
20
|
-
dotenv (2.
|
20
|
+
dotenv (2.6.0)
|
21
21
|
highline (2.0.0)
|
22
|
-
i18n (1.
|
22
|
+
i18n (1.5.1)
|
23
23
|
concurrent-ruby (~> 1.0)
|
24
24
|
minitest (5.11.3)
|
25
25
|
rake (10.5.0)
|
data/README.md
CHANGED
@@ -29,34 +29,57 @@ Or install it yourself as:
|
|
29
29
|
|
30
30
|
**config/dictionary.yml**
|
31
31
|
```yml
|
32
|
-
|
32
|
+
-
|
33
33
|
correct : correct_word_1
|
34
34
|
wrongs :
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
- wrong-word-1
|
36
|
+
- WrongWord1
|
37
|
+
-
|
38
38
|
correct : CorrectWord2
|
39
39
|
wrongs :
|
40
|
-
|
41
|
-
|
40
|
+
- wrong_word_2
|
41
|
+
- wrongword2
|
42
42
|
```
|
43
43
|
|
44
44
|
一つの単号に対して、誤りのある単語を複数追加できます。
|
45
45
|
|
46
46
|
必ず文字数が多いものから降順になるように並べてください。
|
47
47
|
|
48
|
+
|
48
49
|
```yml
|
49
50
|
# いい例
|
50
51
|
wrongs :
|
51
|
-
|
52
|
-
|
53
|
-
|
52
|
+
- wrong-word-1
|
53
|
+
- WrongWord1
|
54
|
+
- Word1
|
54
55
|
|
55
56
|
# 悪い例
|
56
57
|
wrongs :
|
57
|
-
|
58
|
-
|
59
|
-
|
58
|
+
- Word1
|
59
|
+
- WrongWord1
|
60
|
+
- wrong-word-1
|
61
|
+
# 悪い例では文章に "WrongWord1" が与えられた場合、 "Word1" を返してしまう
|
62
|
+
```
|
63
|
+
|
64
|
+
### JSONデータを用意する場合
|
65
|
+
|
66
|
+
```json
|
67
|
+
[
|
68
|
+
{
|
69
|
+
"correct" : "correct-json-word-1",
|
70
|
+
"wrongs" : [
|
71
|
+
"wrong_json_word_1",
|
72
|
+
"WrongJsonWord1"
|
73
|
+
]
|
74
|
+
},
|
75
|
+
{
|
76
|
+
"correct" : "correct-json-word-2",
|
77
|
+
"wrongs" : [
|
78
|
+
"WrongJson2",
|
79
|
+
"Wrong2"
|
80
|
+
]
|
81
|
+
}
|
82
|
+
]
|
60
83
|
```
|
61
84
|
|
62
85
|
### Yahoo APIキーを生成する
|
@@ -70,23 +93,35 @@ https://e.developer.yahoo.co.jp/dashboard/ からAPIキーを生成してくだ
|
|
70
93
|
|
71
94
|
**追記する場合**
|
72
95
|
|
96
|
+
ref: https://github.com/tosite0345/jkproof/blob/master/.env.sample
|
97
|
+
|
73
98
|
```
|
74
99
|
YAHOO_API_KEY=""
|
75
100
|
DICTIONARY_YML_PATH=""
|
101
|
+
NO_FILTER=""
|
76
102
|
```
|
77
103
|
|
78
|
-
先に作成した辞書ファイルのパスを `DICTIONARY_YML_PATH` に、Yahoo APIキーを `
|
104
|
+
先に作成した辞書ファイルのパスを `DICTIONARY_YML_PATH` に、Yahoo APIキーを `YAHOO_API_KEY` にそれぞれ登録してください。
|
105
|
+
|
106
|
+
`NO_FILTER` を設定することで検出する精度を調整することができます。
|
107
|
+
設定値については [こちら](https://developer.yahoo.co.jp/webapi/jlp/kousei/v1/kousei.html) のno_filterをご覧ください。
|
108
|
+
|
109
|
+
なお、複数の除外項目を設定する場合は `NO_FILTER="11,12,13"` のようにカンマ区切りの文字列で指定するようお願いいたします。
|
79
110
|
|
80
111
|
## Usage
|
81
112
|
|
82
113
|
```ruby
|
83
114
|
# 検出された場合
|
84
115
|
Jkproof.detect_words_has_error("検知したい文章")
|
85
|
-
# => [{ wrong: WrongWord, correct:CorrectWord }]
|
116
|
+
# => [{ type: "yml", wrong: WrongWord, correct:CorrectWord }]
|
86
117
|
|
87
118
|
# 検出されなかった場合
|
88
119
|
Jkproof.detect_words_has_error("")
|
89
120
|
# => []
|
121
|
+
|
122
|
+
# JSONを渡す場合
|
123
|
+
Jkproof.detect_words_has_error("検知したい文章", json_dictionary)
|
124
|
+
# => [{ type: "json", wrong: WrongWord, correct:CorrectWord }]
|
90
125
|
```
|
91
126
|
|
92
127
|
## Development
|
data/jkproof.gemspec
CHANGED
@@ -9,9 +9,15 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.version = Jkproof::VERSION
|
10
10
|
spec.authors = ['tosite']
|
11
11
|
spec.email = ['tl091264@gmail.com']
|
12
|
-
spec.summary = 'This performs sentence proofreading using a dictionary.yml.'
|
13
|
-
spec.description =
|
12
|
+
spec.summary = 'This performs sentence proofreading using a dictionary.yml or JSON.'
|
13
|
+
spec.description = <<-EOF
|
14
|
+
This performs sentence proofreading using a dictionary.yml.
|
15
|
+
Alternatively, by passing dictionary data in JSON format, we return an error word as an array.
|
16
|
+
ex1.use yml) Jkproof.detect_words_has_error(sentence)
|
17
|
+
ex2.use JSON) Jkproof.detect_words_has_error(sentence, json)
|
18
|
+
EOF
|
14
19
|
spec.homepage = 'https://github.com/tosite0345/jkproof'
|
20
|
+
spec.license = "MIT"
|
15
21
|
|
16
22
|
# spec.summary = %q{TODO: Write a short summary, because RubyGems requires one.}
|
17
23
|
# spec.description = %q{TODO: Write a longer description or delete this line.}
|
@@ -42,8 +48,7 @@ Gem::Specification.new do |spec|
|
|
42
48
|
spec.add_development_dependency 'bundler', '~> 1.17'
|
43
49
|
spec.add_development_dependency 'rake', '~> 10.0'
|
44
50
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
45
|
-
spec.add_dependency 'activesupport'
|
46
|
-
spec.add_dependency 'dotenv'
|
47
|
-
spec.add_dependency '
|
48
|
-
spec.add_dependency 'xml-simple'
|
51
|
+
spec.add_dependency 'activesupport', '~> 5.2'
|
52
|
+
spec.add_dependency 'dotenv', '~> 2.6'
|
53
|
+
spec.add_dependency 'xml-simple', '~> 1.1'
|
49
54
|
end
|
data/lib/jkproof/sentence.rb
CHANGED
@@ -9,17 +9,13 @@ module Jkproof
|
|
9
9
|
require 'active_support'
|
10
10
|
require 'active_support/core_ext'
|
11
11
|
|
12
|
-
def initialize(buf)
|
12
|
+
def initialize(buf, json_dictionary)
|
13
13
|
Dotenv.load
|
14
|
-
yml_path = ENV['DICTIONARY_YML_PATH']
|
15
14
|
@yahoo_api_key = ENV['YAHOO_API_KEY']
|
16
15
|
@no_filter = ENV['NO_FILTER'].blank? ? '' : ENV['NO_FILTER']
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
rescue StandardError => e
|
21
|
-
raise "#{e}(file_path: '#{yml_path}')"
|
22
|
-
end
|
17
|
+
set_dictionary(json_dictionary)
|
18
|
+
|
23
19
|
@yahoo_words = []
|
24
20
|
@buf = buf
|
25
21
|
fetch_yahoo_lint_words
|
@@ -35,7 +31,7 @@ module Jkproof
|
|
35
31
|
wrongs = fetch_wrong_words_than_long_correct_word(word['correct'], word['wrongs'])
|
36
32
|
wrongs.each do |wrong|
|
37
33
|
if excluded_correct_word.include?(wrong)
|
38
|
-
wrong_words.push(type:
|
34
|
+
wrong_words.push(type: @type, correct: word['correct'], wrong: wrong)
|
39
35
|
excluded_correct_word = excluded_correct_word.gsub(wrong, '####')
|
40
36
|
end
|
41
37
|
end
|
@@ -47,7 +43,7 @@ module Jkproof
|
|
47
43
|
correct_word = word['correct']
|
48
44
|
word['wrongs'].each do |wrong|
|
49
45
|
if excluded_correct_word.include?(wrong)
|
50
|
-
wrong_words.push(type:
|
46
|
+
wrong_words.push(type: @type, wrong: wrong, correct: correct_word)
|
51
47
|
excluded_correct_word = excluded_correct_word.gsub(wrong, '####')
|
52
48
|
end
|
53
49
|
end
|
@@ -57,6 +53,24 @@ module Jkproof
|
|
57
53
|
|
58
54
|
private
|
59
55
|
|
56
|
+
def set_dictionary(json_dictionary)
|
57
|
+
# JSON形式で辞書データが送られてきた場合
|
58
|
+
unless json_dictionary.blank?
|
59
|
+
@type = 'json'
|
60
|
+
@dictionary_words = json_dictionary
|
61
|
+
return
|
62
|
+
end
|
63
|
+
|
64
|
+
# ローカルの辞書データを使う場合
|
65
|
+
yml_path = ENV['DICTIONARY_YML_PATH']
|
66
|
+
begin
|
67
|
+
@type ='yml'
|
68
|
+
@dictionary_words = yml_path.blank? ? [] : YAML.load_file(yml_path)
|
69
|
+
rescue StandardError => e
|
70
|
+
raise "#{e}(file_path: '#{yml_path}')"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
60
74
|
def fetch_yahoo_lint_words
|
61
75
|
if @yahoo_api_key.blank? || @yahoo_api_key.size < 10
|
62
76
|
raise "There is no Yahoo API Key.Please set API Key in 'jkproof/.env'.(ref: https://e.developer.yahoo.co.jp/dashboard/)"
|
data/lib/jkproof/version.rb
CHANGED
data/lib/jkproof.rb
CHANGED
@@ -6,8 +6,8 @@ require 'jkproof/sentence'
|
|
6
6
|
module Jkproof
|
7
7
|
class Error < StandardError; end
|
8
8
|
|
9
|
-
def self.detect_words_has_error(sentence)
|
10
|
-
obj = Sentence.new(sentence)
|
9
|
+
def self.detect_words_has_error(sentence, json_dictionary = '')
|
10
|
+
obj = Sentence.new(sentence, json_dictionary)
|
11
11
|
obj.fetch_wrong_words
|
12
12
|
end
|
13
13
|
end
|
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.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tosite
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -56,59 +56,49 @@ dependencies:
|
|
56
56
|
name: activesupport
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '5.2'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '5.2'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: dotenv
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :runtime
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: highline
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
73
|
+
- - "~>"
|
88
74
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
75
|
+
version: '2.6'
|
90
76
|
type: :runtime
|
91
77
|
prerelease: false
|
92
78
|
version_requirements: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
|
-
- - "
|
80
|
+
- - "~>"
|
95
81
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
82
|
+
version: '2.6'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: xml-simple
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
|
-
- - "
|
87
|
+
- - "~>"
|
102
88
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
89
|
+
version: '1.1'
|
104
90
|
type: :runtime
|
105
91
|
prerelease: false
|
106
92
|
version_requirements: !ruby/object:Gem::Requirement
|
107
93
|
requirements:
|
108
|
-
- - "
|
94
|
+
- - "~>"
|
109
95
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
111
|
-
description:
|
96
|
+
version: '1.1'
|
97
|
+
description: |2
|
98
|
+
This performs sentence proofreading using a dictionary.yml.
|
99
|
+
Alternatively, by passing dictionary data in JSON format, we return an error word as an array.
|
100
|
+
ex1.use yml) Jkproof.detect_words_has_error(sentence)
|
101
|
+
ex2.use JSON) Jkproof.detect_words_has_error(sentence, json)
|
112
102
|
email:
|
113
103
|
- tl091264@gmail.com
|
114
104
|
executables: []
|
@@ -132,7 +122,8 @@ files:
|
|
132
122
|
- lib/jkproof/sentence.rb
|
133
123
|
- lib/jkproof/version.rb
|
134
124
|
homepage: https://github.com/tosite0345/jkproof
|
135
|
-
licenses:
|
125
|
+
licenses:
|
126
|
+
- MIT
|
136
127
|
metadata:
|
137
128
|
allowed_push_host: https://rubygems.org
|
138
129
|
homepage_uri: https://twitter.com/mao_sum
|
@@ -157,5 +148,5 @@ rubyforge_project:
|
|
157
148
|
rubygems_version: 2.7.6
|
158
149
|
signing_key:
|
159
150
|
specification_version: 4
|
160
|
-
summary: This performs sentence proofreading using a dictionary.yml.
|
151
|
+
summary: This performs sentence proofreading using a dictionary.yml or JSON.
|
161
152
|
test_files: []
|