after_the_deadline 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +73 -0
- data/Rakefile +1 -0
- data/after_the_deadline.gemspec +22 -0
- data/lib/after_the_deadline.rb +134 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NmYxNGYwNTY3YjJkMTQwNmNkYzNjODRkOTNkNjBmMjY0Yjk0YTAwZg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NzAyMzk4ODgzNzc5ZGQxMjY0NjA0NmMwNWRiMDA5ZTRhMmFhMWVkZQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MzVhNTM3MGY2ZmQwZDViY2JlY2ZjY2Y2YTA4NTllOTc4MTE4ZGY4Y2Y5NWFl
|
10
|
+
YWYzZDVlYzM3MGRmYTc3ZjlkMGY5MmVjMTZiM2NjMWI5YjcyMDZkY2JiZjRi
|
11
|
+
MWQ3OTcxMjdiNjZiYTI3ODk3ZTExZDFkZjg2YjUxNjY1NmFkYjI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NWIwNWM1NGIxZGIyZDhjYjcxZWJmYTRjM2I1Njc2Yjc0NzUyMDEwZWNmNTMz
|
14
|
+
MzY3YTc0MWY4OThjNGM0NjNiZTNkOGU4NzExNzg3N2YwYjQ1MWU2NjE1OTBm
|
15
|
+
ZGU1Y2U1YzA1ODQ5ZDllZTRlMjVkMmMwM2UyMTE4ZjA0ZTMzNmI=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2010 Michael J. Sepcot
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# After The Deadline - Ruby Library
|
2
|
+
|
3
|
+
Ruby library for working with After The Deadline service.
|
4
|
+
See http://www.afterthedeadline.com/api.slp for the API documentation.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'after_the_deadline'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install after_the_deadline
|
19
|
+
|
20
|
+
## Standard Usage
|
21
|
+
|
22
|
+
require 'after_the_deadline'
|
23
|
+
AfterTheDeadline(nil, nil) # no custom dictionary, accept all error types
|
24
|
+
|
25
|
+
### No Errors
|
26
|
+
|
27
|
+
AfterTheDeadline.check 'this text is clean.'
|
28
|
+
=> []
|
29
|
+
|
30
|
+
### Error: Missing Apostrophe
|
31
|
+
|
32
|
+
AfterTheDeadline.check 'this text isnt clean.'
|
33
|
+
=> [#<AfterTheDeadline::Error:0x101614e80 @url=nil, @description="Missing apostrophe", @string="isnt", @suggestions=["isn't"], @type="grammar", @precontext="text">]
|
34
|
+
|
35
|
+
### Error: Passive Voice
|
36
|
+
|
37
|
+
errors = AfterTheDeadline.check 'this text should be written in a passive voice.'
|
38
|
+
=> [#<AfterTheDeadline::Error:0x1015c1960 @url="http://service.afterthedeadline.com/info.slp?text=should+be&tags=MD%2FVB", @description="Passive voice", @string="should be", @suggestions=[], @type="grammar", @precontext="text">]
|
39
|
+
|
40
|
+
### Information on the Passive Voice Error
|
41
|
+
|
42
|
+
errors.first.info
|
43
|
+
=> "<h3>Revise <em>should be</em> with active voice</h3>\n\n<p>Active voice makes it clear who is doing what. In an active sentence, the person that is acting is the subject. Passive sentences obscure or omit the sentence \nsubject.<br><br>Use passive voice when the sentence object is more important than the subject. The active voice is generally easier to read.\n<br>\n<br><b>Examples</b> (<i><b>subject</b></i>, <u>object</u>)\n<br>\n<br>Before: <u>Our results</u> will be discussed.\n<br>After: <i><b>We</b></i> will discuss <u>our results</u>.\n<br>\n<br>Before: <i><b>Wolverine</b></i> was made to be a <u>weapon</u>.\n<br>After: <i><b>The government</b></i> made <u>Wolverine</u>. <i><b>Wolverine</b></i> is a <u>weapon</u>. </p>"
|
44
|
+
|
45
|
+
### Metrics
|
46
|
+
|
47
|
+
AfterTheDeadline.metrics 'this text should be written in a passive voice. another sentence is used to get more data in the metrics.'
|
48
|
+
=> #<AfterTheDeadline::Metrics:0x10159d4e8 @stats={"words"=>"20", "sentences"=>"1"}, @grammer={}, @spell={}, @style={"passive voice"=>"2"}>
|
49
|
+
|
50
|
+
## Ignoring Specific Types of Errors
|
51
|
+
|
52
|
+
require 'after_the_deadline'
|
53
|
+
AfterTheDeadline(nil, ['Passive voice'])
|
54
|
+
|
55
|
+
### Skip the Passive Voice Error
|
56
|
+
|
57
|
+
errors = AfterTheDeadline.check 'this text should be written in a passive voice.'
|
58
|
+
=> []
|
59
|
+
|
60
|
+
## Using a Custom Dictionary
|
61
|
+
|
62
|
+
require 'after_the_deadline'
|
63
|
+
AfterTheDeadline(['Sepcot']) # or AfterTheDeadline('path/to/filename')
|
64
|
+
AfterTheDeadline.check "My last name, Sepcot, is very unique."
|
65
|
+
=> []
|
66
|
+
|
67
|
+
## Contributing
|
68
|
+
|
69
|
+
1. Fork it
|
70
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
71
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
72
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
73
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'after_the_deadline'
|
5
|
+
spec.version = '0.1.1'
|
6
|
+
spec.authors = ['Michael J. Sepcot']
|
7
|
+
spec.email = ['developer@sepcot.com']
|
8
|
+
spec.description = %q{A ruby library for working with the After The Deadline service.}
|
9
|
+
spec.summary = %q{A ruby library for working with the After The Deadline service.}
|
10
|
+
spec.homepage = 'https://github.com/msepcot/after_the_deadline'
|
11
|
+
spec.license = 'MIT'
|
12
|
+
|
13
|
+
spec.files = `git ls-files`.split($/)
|
14
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
15
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
16
|
+
spec.require_paths = ['lib']
|
17
|
+
|
18
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
19
|
+
spec.add_development_dependency 'rake'
|
20
|
+
|
21
|
+
spec.add_dependency 'crack'
|
22
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'crack'
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
def AfterTheDeadline(dictionary = nil, types = AfterTheDeadline::DEFAULT_IGNORE_TYPES)
|
6
|
+
AfterTheDeadline.set_custom_dictionary(dictionary)
|
7
|
+
AfterTheDeadline.set_ignore_types(types)
|
8
|
+
nil
|
9
|
+
end
|
10
|
+
|
11
|
+
class AfterTheDeadline
|
12
|
+
@@custom_dictionary = []
|
13
|
+
@@ignore_types = []
|
14
|
+
@@api_key = nil
|
15
|
+
|
16
|
+
BASE_URI = 'http://service.afterthedeadline.com'
|
17
|
+
DEFAULT_IGNORE_TYPES = ['Bias Language', 'Cliches', 'Complex Expression', 'Diacritical Marks', 'Double Negatives', 'Hidden Verbs', 'Jargon Language', 'Passive voice', 'Phrases to Avoid', 'Redundant Expression']
|
18
|
+
|
19
|
+
class <<self
|
20
|
+
def set_custom_dictionary(dict)
|
21
|
+
if dict.kind_of?(Array)
|
22
|
+
@@custom_dictionary = dict
|
23
|
+
elsif dict.kind_of?(String)
|
24
|
+
File.open(dict) { |f| @@custom_dictionary = f.readlines.map &:strip }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def set_ignore_types(types)
|
29
|
+
@@ignore_types = types if types.kind_of?(Array)
|
30
|
+
end
|
31
|
+
|
32
|
+
def set_api_key(key)
|
33
|
+
@@api_key = key
|
34
|
+
end
|
35
|
+
|
36
|
+
# Invoke the checkDocument service with provided text.
|
37
|
+
#
|
38
|
+
# Returns list of AfterTheDeadline::Error objects.
|
39
|
+
def check(data)
|
40
|
+
results = Crack::XML.parse(perform('/checkDocument', :data => data))['results']
|
41
|
+
return [] if results.nil? # we have no errors in our data
|
42
|
+
|
43
|
+
raise "Server returned an error: #{results['message']}" if results['message']
|
44
|
+
errors = if results['error'].kind_of?(Array)
|
45
|
+
results['error'].map { |e| AfterTheDeadline::Error.new(e) }
|
46
|
+
else
|
47
|
+
[AfterTheDeadline::Error.new(results['error'])]
|
48
|
+
end
|
49
|
+
|
50
|
+
# Remove any error types we don't care about
|
51
|
+
errors.reject! { |e| @@ignore_types.include?(e.description) }
|
52
|
+
|
53
|
+
# Remove spelling errors from our custom dictionary
|
54
|
+
errors.reject! { |e| e.type == 'spelling' && @@custom_dictionary.include?(e.string) }
|
55
|
+
return errors
|
56
|
+
end
|
57
|
+
alias :check_document :check
|
58
|
+
|
59
|
+
# Invoke the stats service with provided text.
|
60
|
+
#
|
61
|
+
# Returns AfterTheDeadline::Metrics object.
|
62
|
+
def metrics(data)
|
63
|
+
results = Crack::XML.parse(perform('/stats', :data => data))['scores']
|
64
|
+
return if results.nil? # we have no stats about our data
|
65
|
+
AfterTheDeadline::Metrics.new results['metric']
|
66
|
+
end
|
67
|
+
alias :stats :metrics
|
68
|
+
|
69
|
+
def perform(action, params)
|
70
|
+
params[:key] = @@api_key if @@api_key
|
71
|
+
response = Net::HTTP.post_form URI.parse(BASE_URI + action), params
|
72
|
+
raise "Unexpected response code from AtD service: #{response.code} #{response.message}" unless response.is_a? Net::HTTPSuccess
|
73
|
+
response.body
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
private_class_method :perform
|
78
|
+
end
|
79
|
+
|
80
|
+
class AfterTheDeadline::Error
|
81
|
+
attr_reader :string, :description, :precontext, :type, :suggestions, :url
|
82
|
+
|
83
|
+
def initialize(hash)
|
84
|
+
raise "#{self.class} must be initialized with a Hash" unless hash.kind_of?(Hash)
|
85
|
+
[:string, :description, :precontext, :type, :url].each do |attribute|
|
86
|
+
self.send("#{attribute}=", hash[attribute.to_s])
|
87
|
+
end
|
88
|
+
self.suggestions = hash['suggestions'].nil? ? [] : [*hash['suggestions']['option']]
|
89
|
+
end
|
90
|
+
|
91
|
+
def info(theme = nil)
|
92
|
+
return unless self.url
|
93
|
+
uri = URI.parse self.url
|
94
|
+
uri.query = (uri.query || '') + "&theme=#{theme}"
|
95
|
+
Net::HTTP.get(uri).strip
|
96
|
+
end
|
97
|
+
|
98
|
+
def to_s
|
99
|
+
"#{self.string} (#{self.description})"
|
100
|
+
end
|
101
|
+
|
102
|
+
def eql?(other)
|
103
|
+
self.class.equal?(other.class) &&
|
104
|
+
string == other.string &&
|
105
|
+
description == other.description &&
|
106
|
+
type == other.type
|
107
|
+
end
|
108
|
+
alias_method :==, :eql?
|
109
|
+
|
110
|
+
def hash
|
111
|
+
string.hash ^ description.hash ^ type.hash
|
112
|
+
end
|
113
|
+
|
114
|
+
private
|
115
|
+
attr_writer :string, :description, :precontext, :type, :suggestions, :url
|
116
|
+
end
|
117
|
+
|
118
|
+
class AfterTheDeadline::Metrics
|
119
|
+
attr_reader :spell, :grammer, :stats, :style
|
120
|
+
|
121
|
+
def initialize(array)
|
122
|
+
unless array.kind_of?(Array) && array.all? {|i| i.kind_of?(Hash) }
|
123
|
+
raise "#{self.class} must be initialized with an Array of Hashes"
|
124
|
+
end
|
125
|
+
|
126
|
+
self.spell, self.grammer, self.stats, self.style = {}, {}, {}, {}
|
127
|
+
array.each do |metric|
|
128
|
+
self.send(metric['type'])[metric['key']] = metric['value']
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
private
|
133
|
+
attr_writer :spell, :grammer, :stats, :style
|
134
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: after_the_deadline
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael J. Sepcot
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-05 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: crack
|
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: A ruby library for working with the After The Deadline service.
|
56
|
+
email:
|
57
|
+
- developer@sepcot.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- Gemfile.lock
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- after_the_deadline.gemspec
|
69
|
+
- lib/after_the_deadline.rb
|
70
|
+
homepage: https://github.com/msepcot/after_the_deadline
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.0.3
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: A ruby library for working with the After The Deadline service.
|
94
|
+
test_files: []
|