Click here to Skip to main content
Click here to Skip to main content
Technical Blog

Tagged as

C# Library for Grammar and Spell Checking

, 10 Jun 2011 Ms-PL
Rate this:
Please Sign up or sign in to vote.
“After the Deadline” provides a web based API for both grammar and spell checking, free for non-commercial use!

Introduction

I recently had the idea to create a plug-in for Windows Live Writer that will provide grammar checks in addition to the built-in spell checks. As I’ve showed before, creating plug-ins for Windows Live Writer is easy, the problem was to get the code for doing the grammar checking. I’ve found this wonderful site named “After the Deadline” that provides a web based API for both grammar and spell checking, free for non-commercial use!

The site also provides several wrapper libraries for using these APIs. Unfortunately, C# (or any other .NET language) is not among them. Until now.

I present you a C# wrapper library for easily using the “After the Deadline” APIs from any .NET application. I’ve uploaded the C# wrapper to CodePlex and I’ll try to publish it on the official AtD site too.

Features

  • Check both grammar and spelling of a given document
  • Check only grammar of a given document (faster)
  • Get extra information (in HTML format) about specific errors
  • Get general statistics on a given document

APIs

These previously mentioned features are exposed by the following simple interface:

/// <span class="code-SummaryComment"><summary>
</span>/// Initializes the After the Deadline service
/// <span class="code-SummaryComment"></summary>
</span>/// <span class="code-SummaryComment"><param name="applicationKey">The application key.</param>
</span>/// <span class="code-SummaryComment"><param name="userKey">The user key.</param>
</span>public static void InitService(string applicationKey, string userKey);

/// <span class="code-SummaryComment"><summary>
</span>/// Checks a document and returns errors and suggestions
/// <span class="code-SummaryComment"></summary>
</span>/// <span class="code-SummaryComment"><param name="data">The data to check</param>
</span>/// <span class="code-SummaryComment"><returns>Enumerable of error objects</returns>
</span>public static IEnumerable<Error> CheckDocument(string data);

/// <span class="code-SummaryComment"><summary>
</span>/// Checks a document (sans spelling) returns errors and suggestions
/// <span class="code-SummaryComment"></summary>
</span>/// <span class="code-SummaryComment"><param name="data">The data to check</param>
</span>/// <span class="code-SummaryComment"><returns>Enumerable of error objects</returns>
</span>public static IEnumerable<Error> CheckGrammar(string data);

/// <span class="code-SummaryComment"><summary>
</span>/// Returns HTML describing an error
/// <span class="code-SummaryComment"></summary>
</span>/// <span class="code-SummaryComment"><param name="text">The text that triggered an error</param>
</span>/// <span class="code-SummaryComment"><returns>The HTML response</returns>
</span>public static string Info(string text);

/// <span class="code-SummaryComment"><summary>
</span>/// Returns statistics about the writing quality of a document
/// <span class="code-SummaryComment"></summary>
</span>/// <span class="code-SummaryComment"><param name="data">The data to check</param>
</span>public static IEnumerable<Metric> Stats(string data);

The InitService method just sets an application key and user key you should generate according to the these instructions.

The most useful method is CheckDocument which accepts the text to check and returns a collection of error objects.

Since this is simply a wrapper around the original REST API, I strongly suggest you check out the original API documentation to get more details about the parameters and return values.

Can you provide some details about the implementation?

Sure. The API which is exposes by “After the Deadline” site is based on REST and XML responses.

I simply use WebClient’s DownloadString method to get access to the REST interface and then parse the XML using LINQ to XML. Nice and easy.

What's next?

On my next post, I'll show you a cool implementation of a plug-in for Windows Live Writer that uses this library to provide grammar checking.

That’s it for now,
Arik Poznanski.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

Share

About the Author

Arik Poznanski
Software Developer (Senior) Verint
Israel Israel
Arik Poznanski is a senior software developer at Verint. He completed two B.Sc. degrees in Mathematics & Computer Science, summa cum laude, from the Technion in Israel.

Arik has extensive knowledge and experience in many Microsoft technologies, including .NET with C#, WPF, Silverlight, WinForms, Interop, COM/ATL programming, C++ Win32 programming and reverse engineering (assembly, IL).
Follow on   Twitter   Google+

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150414.1 | Last Updated 10 Jun 2011
Article Copyright 2011 by Arik Poznanski
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid