gingerice 1.0.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
+ SHA1:
3
+ metadata.gz: 5aa2568c764a2f1d844124cfc9983d22ba4e06aa
4
+ data.tar.gz: 4ebbb86b37f1e2f43fba0d1aa02741fe76c0c0a3
5
+ SHA512:
6
+ metadata.gz: fc8610f79b813b40fed1bec8127e1d807f380e257fe46299cdf265b8b163257aa16ad8096461df4e587e3bf407b37c8d5ebffcb17239e7b5cdb6a3c9a869c896
7
+ data.tar.gz: 7ecb04214a5f721e583aae3dc6d830acbcdc790096166e74f094799312f7f68379a45d634a7ac860e5d54268ee3b3a8f4ee68822c5d5b650efb7670398e8604f
data/.editorconfig ADDED
@@ -0,0 +1,12 @@
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = space
5
+ indent_size = 2
6
+ end_of_line = lf
7
+ charset = utf-8
8
+ trim_trailing_whitespace = true
9
+ insert_final_newline = true
10
+
11
+ [*.markdown]
12
+ indent_size = 4
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gingerice.gemspec
4
+ gemspec
data/README.markdown ADDED
@@ -0,0 +1,74 @@
1
+ # Gingerice [![Gem Version](https://badge.fury.io/rb/gingerice.png)](http://badge.fury.io/rb/gingerice) [![Build Status](https://travis-ci.org/subosito/gingerice.png)](https://travis-ci.org/subosito/gingerice) [![Coverage Status](https://coveralls.io/repos/subosito/gingerice/badge.png)](https://coveralls.io/r/subosito/gingerice)
2
+
3
+ Ruby wrapper of Ginger Proofreader which corrects spelling and grammar mistakes based on the context of complete sentences by comparing each sentence to billions of similar sentences from the web.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'gingerice'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install gingerice
18
+
19
+ ## Usage
20
+
21
+ require 'gingerice'
22
+
23
+ text = 'The smelt of fliwers bring back memories.'
24
+
25
+ parser = Gingerice::Parser.new
26
+ parser.parse text
27
+
28
+ # or you can:
29
+ #
30
+ # Gingerice::Tool.check text
31
+
32
+ # output:
33
+ #
34
+ # => {
35
+ # "text" => "The smelt of fliwers bring back memories.",
36
+ # "result" => "The smell of flowers brings back memories.",
37
+ # "corrections" => [
38
+ # [0] {
39
+ # "text" => "smelt",
40
+ # "correct" => "smell",
41
+ # "definition" => nil
42
+ # },
43
+ # [1] {
44
+ # "text" => "fliwers",
45
+ # "correct" => "flowers",
46
+ # "definition" => "a plant cultivated for its blooms or blossoms"
47
+ # },
48
+ # [2] {
49
+ # "text" => "bring",
50
+ # "correct" => "brings",
51
+ # "definition" => nil
52
+ # }
53
+ # ]
54
+ # }
55
+
56
+ This gem also provides executable which can be executed:
57
+
58
+ % gingerice "Edwards will be sick yesterday"
59
+
60
+ # output :
61
+ #
62
+ # Edwards was sick yesterday
63
+
64
+ ## Contributing
65
+
66
+ 1. Fork it
67
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
68
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
69
+ 4. Push to the branch (`git push origin my-new-feature`)
70
+ 5. Create new Pull Request
71
+
72
+ ## Thanks
73
+
74
+ Thank you for [Ginger Proofreader](http://www.gingersoftware.com/) for such awesome service. Hope they will keep it free :)
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ end
7
+
8
+ desc "Run tests"
9
+ task :default => :test
data/bin/gingerice ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File::join(File::dirname(File::dirname(__FILE__)), "lib"))
4
+
5
+ require 'gingerice/parser'
6
+ require 'gingerice/tool'
7
+
8
+ STDOUT.puts(Gingerice::Tool.check(ARGV.shift)['result'])
9
+
data/gingerice.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gingerice/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gingerice"
8
+ spec.version = Gingerice::VERSION
9
+ spec.authors = ["Alif Rachmawadi"]
10
+ spec.email = ["subosito@gmail.com"]
11
+ spec.description = %q{Corrects spelling and grammar mistakes based on the context of complete sentences.}
12
+ spec.summary = spec.description
13
+ spec.homepage = "https://github.com/subosito/gingerice"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency "addressable"
25
+ end
@@ -0,0 +1,73 @@
1
+ require 'open-uri'
2
+ require 'addressable/uri'
3
+ require 'json'
4
+
5
+ module Gingerice
6
+ class Parser
7
+ GINGER_ENDPOINT = 'http://services.gingersoftware.com/Ginger/correct/json/GingerTheText'
8
+ GINGER_VERSION = '2.0'
9
+ GINGER_API_KEY = '6ae0c3a0-afdc-4532-a810-82ded0054236'
10
+ DEFAULT_LANG = 'US'
11
+
12
+ attr_reader :lang, :api_key, :api_version, :api_endpoint
13
+
14
+ def initialize(options = {})
15
+ @lang = options.fetch(:lang, DEFAULT_LANG)
16
+ @api_key = options.fetch(:api_key, GINGER_API_KEY)
17
+ @api_version = options.fetch(:api_version, GINGER_VERSION)
18
+ @api_endpoint = options.fetch(:api_endpoint, GINGER_ENDPOINT)
19
+ end
20
+
21
+ def parse(text)
22
+ uri = Addressable::URI.parse(api_endpoint)
23
+ uri.query_values = request_params.merge({ 'text' => text })
24
+
25
+ begin
26
+ open(uri) do |stream|
27
+ content = stream.read
28
+ data = JSON.parse(content)
29
+
30
+ i = 0
31
+ result = ''
32
+ corrections = []
33
+
34
+ data.fetch('LightGingerTheTextResult', []).each do |r|
35
+ from = r['From']
36
+ to = r['To']
37
+
38
+ if i <= from
39
+ result += text[i..from-1] unless from.zero?
40
+ result += r['Suggestions'][0]['Text']
41
+
42
+ corrections << {
43
+ 'text' => text[from..to],
44
+ 'correct' => r['Suggestions'][0]['Text'],
45
+ 'definition' => r['Suggestions'][0]['Definition']
46
+ }
47
+ end
48
+
49
+ i = to+1
50
+ end
51
+
52
+ if i < text.length
53
+ result += text[i..-1]
54
+ end
55
+
56
+ { 'text' => text, 'result' => result, 'corrections' => corrections}
57
+ end
58
+ rescue Exception => e
59
+ raise StandardError, e.message
60
+ end
61
+ end
62
+
63
+ protected
64
+ def request_params
65
+ {
66
+ 'lang' => lang,
67
+ 'apiKey' => api_key,
68
+ 'clientVersion' => api_version
69
+ }
70
+ end
71
+ end
72
+ end
73
+
@@ -0,0 +1,11 @@
1
+ module Gingerice
2
+ class Tool
3
+ class << self
4
+ def check(text, lang = 'US')
5
+ parser = Parser.new(lang: lang)
6
+ parser.parse(text)
7
+ end
8
+ end
9
+ end
10
+ end
11
+
@@ -0,0 +1,3 @@
1
+ module Gingerice
2
+ VERSION = "1.0.0"
3
+ end
data/lib/gingerice.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'gingerice/version'
2
+ require 'gingerice/parser'
@@ -0,0 +1,38 @@
1
+ require 'test/unit'
2
+ require 'gingerice'
3
+
4
+ class TestGingerice < Test::Unit::TestCase
5
+ def setup
6
+ @parser = Gingerice::Parser.new
7
+ end
8
+
9
+ def test_default_settings
10
+ assert_equal @parser.api_endpoint, Gingerice::Parser::GINGER_ENDPOINT
11
+ assert_equal @parser.api_version, Gingerice::Parser::GINGER_VERSION
12
+ assert_equal @parser.api_key, Gingerice::Parser::GINGER_API_KEY
13
+ assert_equal @parser.lang, Gingerice::Parser::DEFAULT_LANG
14
+ end
15
+
16
+ def test_override_settings
17
+ custom_parser = Gingerice::Parser.new({
18
+ lang: 'ID',
19
+ api_endpoint: 'http://example.com/',
20
+ api_version: '1.0',
21
+ api_key: '123456'
22
+ })
23
+
24
+ assert_equal custom_parser.lang, 'ID'
25
+ assert_equal custom_parser.api_endpoint, 'http://example.com/'
26
+ assert_equal custom_parser.api_version, '1.0'
27
+ assert_equal custom_parser.api_key, '123456'
28
+ end
29
+
30
+ def test_parsed_results
31
+ text = 'The smelt of fliwers bring back memories.'
32
+ result = @parser.parse(text)
33
+
34
+ assert_equal result['text'], text
35
+ assert_equal result['result'], 'The smell of flowers brings back memories.'
36
+ assert_equal result['corrections'].count, 3
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gingerice
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Alif Rachmawadi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-27 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: addressable
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Corrects spelling and grammar mistakes based on the context of complete
56
+ sentences.
57
+ email:
58
+ - subosito@gmail.com
59
+ executables:
60
+ - gingerice
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - .editorconfig
65
+ - .gitignore
66
+ - .travis.yml
67
+ - Gemfile
68
+ - README.markdown
69
+ - Rakefile
70
+ - bin/gingerice
71
+ - gingerice.gemspec
72
+ - lib/gingerice.rb
73
+ - lib/gingerice/parser.rb
74
+ - lib/gingerice/tool.rb
75
+ - lib/gingerice/version.rb
76
+ - test/test_gingerice.rb
77
+ homepage: https://github.com/subosito/gingerice
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.0.0
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Corrects spelling and grammar mistakes based on the context of complete sentences.
101
+ test_files:
102
+ - test/test_gingerice.rb