C# Library for Grammar and Spell Checking

8 ביוני 2011

2 תגובות

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 also on the official AtD site.

 

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:

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

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

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

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

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

The InitService method just sets an application key and user key you should generate according to the following 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 plugin for Windows Live Writer that uses this library to provide grammar checking.

That’s it for now,
Arik Poznanski.

הוסף תגובה
facebook linkedin twitter email

כתיבת תגובה

האימייל לא יוצג באתר. (*) שדות חובה מסומנים

2 תגובות

  1. PhoenixArt23 בינואר 2012 ב 10:02

    After I download and test it I found a problem about a key, so did you find a problem about this before or how can we generate a key to use in this API?

    Thank you for your kindness.

    להגיב
  2. PhoenixArt23 בינואר 2012 ב 10:02

    After I download and test it I found a problem about a key, so did you find a problem about this before or how can we generate a key to use in this API?

    Thank you for your kindness.

    להגיב