Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add custom dictionary support, ignore specific error types, update ex…

…amples.
  • Loading branch information...
commit 13c36e7b24097e3e81eb04063b7f441b820a5e6e 1 parent d5b1fdc
@msepcot authored
Showing with 51 additions and 6 deletions.
  1. +22 −2 README
  2. +29 −4 after_the_deadline.rb
View
24 README
@@ -8,8 +8,8 @@ See http://www.afterthedeadline.com/api.slp for the API documentation.
Examples
========
-require 'after_the_deadline'
-AfterTheDeadline('xxx') # this is the same as: AfterTheDeadline.set_api_key('xxx')
+require 'after_the_deadline'
+AfterTheDeadline('xxx', nil, nil) # set the API Key, no custom dictionary, accept all error types
# No Errors
AfterTheDeadline.check 'this text is clean.'
@@ -30,3 +30,23 @@ errors.first.info
# Metrics
AfterTheDeadline.metrics 'this text should be written in a passive voice. another sentence is used to get more data in the metrics.'
=> #<AfterTheDeadline::Metrics:0x10159d4e8 @stats={"words"=>"20", "sentences"=>"1"}, @grammer={}, @spell={}, @style={"passive voice"=>"2"}>
+
+
+Ignoring Specific Types of Errors
+=================================
+
+require 'after_the_deadline'
+AfterTheDeadline('xxx', nil, ['Passive voice'])
+
+# Skip the Passive Voice Error
+errors = AfterTheDeadline.check 'this text should be written in a passive voice.'
+=> []
+
+
+Using a Custom Dictionary
+=========================
+
+require 'after_the_deadline'
+AfterTheDeadline('xxx', ['Sepcot']) # or AfterTheDeadline('xxx', 'path/to/filename')
+AfterTheDeadline.check "My last name, Sepcot, is very unique."
+=> []
View
33 after_the_deadline.rb
@@ -2,20 +2,38 @@
require 'net/http'
require 'uri'
-def AfterTheDeadline(key)
+def AfterTheDeadline(key, dictionary = nil, types = AfterTheDeadline::DEFAULT_IGNORE_TYPES)
AfterTheDeadline.set_api_key(key)
+ AfterTheDeadline.set_custom_dictionary(dictionary)
+ AfterTheDeadline.set_ignore_types(types)
+ nil
end
class AfterTheDeadline
@@api_key = nil
+ @@custom_dictionary = []
+ @@ignore_types = []
BASE_URI = 'http://service.afterthedeadline.com'
+ DEFAULT_IGNORE_TYPES = ['Bias Language', 'Cliches', 'Complex Expression', 'Diacritical Marks', 'Double Negatives', 'Hidden Verbs', 'Jargon Language', 'Passive voice', 'Phrases to Avoid', 'Redundant Expression']
class <<self
def set_api_key(key)
@@api_key = key
end
+ def set_custom_dictionary(dict)
+ if dict.kind_of?(Array)
+ @@custom_dictionary = dict
+ elsif dict.kind_of?(String)
+ File.open(dict) { |f| @@custom_dictionary = f.readlines.map &:strip }
+ end
+ end
+
+ def set_ignore_types(types)
+ @@ignore_types = types if types.kind_of?(Array)
+ end
+
# Invoke checkDocument service with provided text and optional key.
# If no key is provided, a default key is used.
#
@@ -25,11 +43,18 @@ def check(data, key = nil)
return [] if results.nil? # we have no errors in our data
raise "Server returned an error: #{results['message']}" if results['message']
- if results['error'].kind_of?(Array)
- return results['error'].map { |e| AfterTheDeadline::Error.new(e) }
+ errors = if results['error'].kind_of?(Array)
+ results['error'].map { |e| AfterTheDeadline::Error.new(e) }
else
- return [AfterTheDeadline::Error.new(results['error'])]
+ [AfterTheDeadline::Error.new(results['error'])]
end
+
+ # Remove any error types we don't care about
+ errors.reject! { |e| @@ignore_types.include?(e.description) }
+
+ # Remove spelling errors from our custom dictionary
+ errors.reject! { |e| e.type == 'spelling' && @@custom_dictionary.include?(e.string) }
+ return errors
end
alias :check_document :check
Please sign in to comment.
Something went wrong with that request. Please try again.