jkproof 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a5b40a5b66b05016fe7f0e165aa934a276a161a2135512a5d19e0ea51d805e58
4
+ data.tar.gz: 830c43770bed8434d4f57626f4b564a056022b28e25b9df8fadf9effdccc3811
5
+ SHA512:
6
+ metadata.gz: 5785d7aa4b1dced88f426151ddfc29c765340219d46693b84f606a5da65ecbc1a1858907ec02e8edcffe6e755aefad95c92b92927b29fc4ea3560d64a508e9e2
7
+ data.tar.gz: af5c999b529a289c52419595f8466afcb92cfb9f0d051e84245227734fb589f5b62d8c59443b52f9d33150ac0f140a76d96b96d9d021247c00f73a3f8edee9cd
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /vendor
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 1.17.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in maoproof.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ jkproof (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ activesupport (5.2.2)
10
+ concurrent-ruby (~> 1.0, >= 1.0.2)
11
+ i18n (>= 0.7, < 2)
12
+ minitest (~> 5.1)
13
+ tzinfo (~> 1.1)
14
+ concurrent-ruby (1.1.4)
15
+ diff-lcs (1.3)
16
+ i18n (1.3.0)
17
+ concurrent-ruby (~> 1.0)
18
+ minitest (5.11.3)
19
+ rake (10.5.0)
20
+ rspec (3.8.0)
21
+ rspec-core (~> 3.8.0)
22
+ rspec-expectations (~> 3.8.0)
23
+ rspec-mocks (~> 3.8.0)
24
+ rspec-core (3.8.0)
25
+ rspec-support (~> 3.8.0)
26
+ rspec-expectations (3.8.2)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.8.0)
29
+ rspec-mocks (3.8.0)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.8.0)
32
+ rspec-support (3.8.0)
33
+ thread_safe (0.3.6)
34
+ tzinfo (1.2.5)
35
+ thread_safe (~> 0.1)
36
+ xml-simple (1.1.5)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ activesupport
43
+ bundler (~> 1.17)
44
+ jkproof!
45
+ rake (~> 10.0)
46
+ rspec (~> 3.0)
47
+ xml-simple
48
+
49
+ BUNDLED WITH
50
+ 1.17.1
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Maoproof
2
+
3
+ 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/maoproof`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'maoproof'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install maoproof
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/maoproof.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'jkproof'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/jkproof.gemspec ADDED
@@ -0,0 +1,47 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'jkproof/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'jkproof'
7
+ spec.version = Jkproof::VERSION
8
+ spec.authors = ['tosite']
9
+ spec.email = ['tl091264@gmail.com']
10
+
11
+ spec.summary = 'test.'
12
+ spec.description = 'test.'
13
+ spec.homepage = 'https://github.com/tosite0345/jkproof'
14
+
15
+ # spec.summary = %q{TODO: Write a short summary, because RubyGems requires one.}
16
+ # spec.description = %q{TODO: Write a longer description or delete this line.}
17
+ # spec.homepage = "TODO: Put your gem's website or public repo URL here."
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+ if spec.respond_to?(:metadata)
21
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
22
+
23
+ # spec.metadata["homepage_uri"] = spec.homepage
24
+ spec.metadata['homepage_uri'] = 'https://github.com/tosite0345/jkproof'
25
+ spec.metadata['source_code_uri'] = 'https://github.com/tosite0345/jkproof'
26
+ spec.metadata['changelog_uri'] = 'https://github.com/tosite0345/jkproof'
27
+ else
28
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
29
+ 'public gem pushes.'
30
+ end
31
+
32
+ # Specify which files should be added to the gem when it is released.
33
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
34
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
35
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
36
+ end
37
+ spec.bindir = 'exe'
38
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
39
+ spec.require_paths = ['lib']
40
+
41
+ spec.add_development_dependency 'bundler', '~> 1.17'
42
+ spec.add_development_dependency 'rake', '~> 10.0'
43
+ spec.add_development_dependency 'rspec', '~> 3.0'
44
+ # spec.add_runtime_dependency 'active_support'
45
+ spec.add_development_dependency 'activesupport'
46
+ spec.add_development_dependency 'xml-simple'
47
+ end
@@ -0,0 +1,66 @@
1
+ module Jkproof
2
+ class Sentence
3
+ require 'yaml'
4
+ require 'uri'
5
+ require 'net/https'
6
+ require 'active_support'
7
+ require 'active_support/core_ext'
8
+
9
+ def initialize(buf, yml_path)
10
+ @dictionary_words = YAML.load_file(yml_path)
11
+ @yahoo_words = []
12
+ @buf = buf
13
+ fetch_yahoo_lint_words
14
+ end
15
+
16
+ def fetch_wrong_words
17
+ wrong_words = []
18
+
19
+ # 正しいワードを取り除く
20
+ @dictionary_words.each do |_key, word|
21
+ @buf.gsub!(word['correct'], '')
22
+ end
23
+
24
+ @dictionary_words.each do |_key, word|
25
+ correct_word = word['correct']
26
+ word['wrongs'].each do |_wkey, wrong|
27
+ if @buf.include?(wrong)
28
+ wrong_words.push(wrong: wrong, correct: correct_word)
29
+ break
30
+ end
31
+ end
32
+ end
33
+ wrong_words.concat(@yahoo_words).uniq
34
+ end
35
+
36
+ private
37
+
38
+ def fetch_yahoo_lint_words
39
+ # ref: http://developer.yahoo.co.jp/webapi/jlp/kousei/v1/kousei.html
40
+ uri = URI.parse('https://jlp.yahooapis.jp/KouseiService/V1/kousei')
41
+ http = Net::HTTP.new(uri.host, uri.port)
42
+ http.use_ssl = true
43
+ reqest = Net::HTTP::Post.new(uri.path)
44
+ reqest.set_form_data(
45
+ appid: 'dj00aiZpPXM0WksyN2NJaHhCZSZzPWNvbnN1bWVyc2VjcmV0Jng9ZTk-',
46
+ sentence: @buf,
47
+ no_filter: '11'
48
+ # no_filter: "11,12,14,15"
49
+ )
50
+ s = http.request(reqest).body
51
+ unless Hash.from_xml(s)['ResultSet']['Result'].nil?
52
+ [Hash.from_xml(s)['ResultSet']['Result']].flatten.each do |r|
53
+ next unless r['Surface']
54
+ next unless r['ShitekiWord']
55
+
56
+ # p r
57
+ @yahoo_words.push(correct: r['ShitekiWord'], wrong: r['Surface'])
58
+ end
59
+ end
60
+ end
61
+
62
+ def remove_correct_word(key, correct_word)
63
+ @buf.gsub!(correct_word, "[###{key}##]")
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,3 @@
1
+ module Jkproof
2
+ VERSION = '0.1.0'.freeze
3
+ end
data/lib/jkproof.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'jkproof/version'
2
+ require 'jkproof/sentence'
3
+ require 'yaml'
4
+ require 'uri'
5
+ require 'net/https'
6
+ require 'active_support'
7
+ require 'active_support/core_ext'
8
+
9
+ module Jkproof
10
+ class Error < StandardError; end
11
+
12
+ def self.detect_words_has_error(sentence, dictionary_yml_path)
13
+ obj = Sentence.new(sentence, dictionary_yml_path)
14
+ obj.fetch_wrong_words
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jkproof
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - tosite
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-12-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: xml-simple
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: test.
84
+ email:
85
+ - tl091264@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - jkproof.gemspec
100
+ - lib/jkproof.rb
101
+ - lib/jkproof/sentence.rb
102
+ - lib/jkproof/version.rb
103
+ homepage: https://github.com/tosite0345/jkproof
104
+ licenses: []
105
+ metadata:
106
+ allowed_push_host: https://rubygems.org
107
+ homepage_uri: https://github.com/tosite0345/jkproof
108
+ source_code_uri: https://github.com/tosite0345/jkproof
109
+ changelog_uri: https://github.com/tosite0345/jkproof
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.7.6
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: test.
130
+ test_files: []