rginger 0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -3
- data/bin/rginger +6 -2
- data/lib/rginger/parser.rb +2 -2
- data/lib/rginger/version.rb +1 -1
- data/rginger.gemspec +0 -1
- metadata +1 -2
- data/rginger.rb +0 -86
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d3d60dd57c49d9e26fbc0fa54639c8b24fbc5ec
|
4
|
+
data.tar.gz: 79e4497c675d3d4736090b523611664018ecd63a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa40976054afa7d7f927bc0c024156378a9469c928d99d3172de77297c533e0aaeb1c91f597b0fd31a78e20f9b8493f5ecc56088c3a4266deb7ed9272451e5fb
|
7
|
+
data.tar.gz: aab0d46b496dc94de893406aa00569cc5ca1a185acc448dcd669ffa6144b379b219e1898761e2a39976d2e9bf84355764808c161dd9962138ea97d0129d533c1
|
data/README.md
CHANGED
@@ -25,8 +25,7 @@ RGinger takes an English sentence and gives correction and rephrasing suggestion
|
|
25
25
|
|
26
26
|
### Output Sample
|
27
27
|
|
28
|
-
|
29
|
-
|
28
|
+
<a href="http://www.flickr.com/photos/yo_hasebe/11097279325/" title="rginger by yo_hasebe, on Flickr"><img src="http://farm4.staticflickr.com/3673/11097279325_a382163d57_o.jpg" width="383" height="255" alt="rginger"></a>
|
30
29
|
|
31
30
|
## Library Usage
|
32
31
|
|
@@ -57,4 +56,4 @@ Alif Rachmawadi's [Gingerice](https://github.com/subosito/gingerice) may be a be
|
|
57
56
|
|
58
57
|
### Thanks
|
59
58
|
|
60
|
-
Ginger Software for the great software and services that support learners aspiring for skills of writing good English.
|
59
|
+
Ginger Software for the great software and services that support learners aspiring for skills of writing good English.
|
data/bin/rginger
CHANGED
@@ -33,7 +33,7 @@ begin
|
|
33
33
|
|
34
34
|
ginger = RGinger::Parser.new
|
35
35
|
corrected = nil
|
36
|
-
|
36
|
+
|
37
37
|
puts ""
|
38
38
|
|
39
39
|
if opts[:correction]
|
@@ -94,5 +94,9 @@ begin
|
|
94
94
|
puts ""
|
95
95
|
|
96
96
|
rescue Exception => e
|
97
|
-
puts e.message
|
97
|
+
# puts e.message
|
98
|
+
|
99
|
+
print "\n[ERROR]".foreground(:red)
|
100
|
+
puts "Something went wrong. Network error maybe?"
|
101
|
+
exit
|
98
102
|
end
|
data/lib/rginger/parser.rb
CHANGED
@@ -109,11 +109,11 @@ module RGinger
|
|
109
109
|
get_json(location, limit - 1)
|
110
110
|
else
|
111
111
|
# Error
|
112
|
-
|
112
|
+
throw [uri.to_s, response.value].join(" : ")
|
113
113
|
end
|
114
114
|
rescue => e
|
115
115
|
# Error
|
116
|
-
|
116
|
+
throw [uri.to_s, e.class, e].join(" : ")
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
data/lib/rginger/version.rb
CHANGED
data/rginger.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rginger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yoichiro Hasebe
|
@@ -83,7 +83,6 @@ files:
|
|
83
83
|
- lib/rginger/parser.rb
|
84
84
|
- lib/rginger/version.rb
|
85
85
|
- rginger.gemspec
|
86
|
-
- rginger.rb
|
87
86
|
- test/test_rginger.rb
|
88
87
|
homepage: https://github.com/yohasebe/rginger
|
89
88
|
licenses:
|
data/rginger.rb
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
require 'uri'
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
GINGER_API_ENDPOINT = 'http://services.gingersoftware.com/Ginger/correct/json/GingerTheText'
|
6
|
-
GINGER_REPHRASE_ENDPOINT = 'http://ro.gingersoftware.com/rephrase/rephrase'
|
7
|
-
GINGER_API_VERSION = '2.0'
|
8
|
-
GINGER_API_KEY = '6ae0c3a0-afdc-4532-a810-82ded0054236'
|
9
|
-
DEFAULT_LANG = 'US'
|
10
|
-
|
11
|
-
def get_json(location, limit = 10)
|
12
|
-
raise ArgumentError, 'too many HTTP redirects' if limit == 0
|
13
|
-
uri = URI.parse(location)
|
14
|
-
|
15
|
-
begin
|
16
|
-
response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
17
|
-
http.open_timeout = 5
|
18
|
-
http.read_timeout = 10
|
19
|
-
http.get(uri.request_uri)
|
20
|
-
end
|
21
|
-
|
22
|
-
case response
|
23
|
-
when Net::HTTPSuccess
|
24
|
-
json = response.body
|
25
|
-
JSON.parse(json)
|
26
|
-
when Net::HTTPRedirection
|
27
|
-
location = response['location']
|
28
|
-
warn "redirected to #{location}"
|
29
|
-
# Recursive method call
|
30
|
-
get_json(location, limit - 1)
|
31
|
-
else
|
32
|
-
# Error
|
33
|
-
puts [uri.to_s, response.value].join(" : ")
|
34
|
-
end
|
35
|
-
rescue => e
|
36
|
-
# Error
|
37
|
-
puts [uri.to_s, e.class, e].join(" : ")
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
puts "# => ORIGINAL"
|
42
|
-
puts original = "I am suffring from a desease, amn't I"
|
43
|
-
width = original.length
|
44
|
-
corrected = []
|
45
|
-
|
46
|
-
text = URI.escape(original)
|
47
|
-
|
48
|
-
correction = "#{GINGER_API_ENDPOINT}?lang=#{DEFAULT_LANG}&clientVersion=#{GINGER_API_VERSION}&apiKey=#{GINGER_API_KEY}&text=#{text}"
|
49
|
-
|
50
|
-
results = get_json(correction)["LightGingerTheTextResult"]
|
51
|
-
|
52
|
-
if results.empty?
|
53
|
-
puts "# No need to correct"
|
54
|
-
a_better = original
|
55
|
-
else
|
56
|
-
new_string = original
|
57
|
-
results.each do |r|
|
58
|
-
if r["Mistakes"].size == r["Suggestions"].size
|
59
|
-
r["Mistakes"].each_with_index do |m, i|
|
60
|
-
from = -(width - m["From"])
|
61
|
-
to = -(width - m["To"])
|
62
|
-
new_string[from .. to] = r["Suggestions"][i]["Text"]
|
63
|
-
end
|
64
|
-
else
|
65
|
-
from = -(width - r["From"])
|
66
|
-
to = -(width - r["To"])
|
67
|
-
new_string[from .. to] = r["Suggestions"][0]["Text"] rescue ""
|
68
|
-
end
|
69
|
-
end
|
70
|
-
puts "# => CORRECTED"
|
71
|
-
puts a_better = new_string
|
72
|
-
end
|
73
|
-
|
74
|
-
text = URI.escape(a_better)
|
75
|
-
|
76
|
-
rephrase = "#{GINGER_REPHRASE_ENDPOINT}?s=#{text}"
|
77
|
-
results = get_json(rephrase)
|
78
|
-
|
79
|
-
if results.empty? || results["Sentences"].empty?
|
80
|
-
puts "# No alternative expressions"
|
81
|
-
else
|
82
|
-
puts "# => ALTERNATIVES"
|
83
|
-
results["Sentences"].each do |item|
|
84
|
-
puts item["Sentence"]
|
85
|
-
end
|
86
|
-
end
|