Click here to Skip to main content
6,634,665 members and growing! (20,067 online)
Email Password   helpLost your password?
General Programming » Algorithms & Recipes » Regular Expressions     Intermediate

SpellCheck.net spell checking parsing using C#

By Waheed Khan

Online spell checking using C# and regular expressions.
C#.NET 1.0, Win2K, WinXP, Visual Studio, Dev
Posted:19 Jun 2002
Views:87,251
Bookmarked:41 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
9 votes for this article.
Popularity: 4.41 Rating: 4.63 out of 5

1

2

3
1 vote, 20.0%
4
4 votes, 80.0%
5

Introduction

SpellCheck.NET is free online spell checking site. Whenever I need to check my spelling I visit this site, so I decided to write a parser for this site. I wrote this parser with C# and wrapped it up in a DLL file and called it Word.dll. In this article I will show you how to parse a HTML page using regular expressions. I will not explain all the source code since it is available for download. My main purpose of this project is to demonstrate how to parse a HTML page using regular expressions. 

Before this project I have never worked with regular expressions seriously, so I decided to use regular expressions. In this project I have learned a lot about C# regular expressions and .NET framework. The difficult part was in this project writing regular expressions pattern. So I referred to different sites and books to get the right pattern.

Here are some useful sites to check out.

About Word.dll

Word.dll has one public class and two public methods

  1. Public Class SpellCheck

       Include "using Word.dll" at the top of file for the object reference.

       SpellCheck word = new SpellCheck();
  2. Public Method CheckSpelling

    This method will check the word and return true or false. If the word is correct then it will return true otherwise false.

       bool status = false;
       status = word.CheckSpelling("a word");
  3. Public Method GetSpellingSuggestions

    This method will return the collection of suggested words.

     foreach(string suggestion in word.GetSpellingSuggestions("a word")) 
     {
        System.Console.WriteLine( suggestion ); 
     }

Parser Technique

  1. Connect to spellcheck.net site and pass the word.
  2. Look for the word "correctly." in html file, if found return true
  3. else look for the word "misspelled.", if found return false.
    regular expression pattern @"(correctly.)|(misspelled.)"
  4. If the word misspelled found in html then look for the word "suggestions:"
    regular expression pattern  @"(suggestions:)"
  5. and parse the string between <blockquote>
    regular expression pattern  @"<blockquote>(?:\s*([^<]+) \s*)+ </blockquote>"
  6. and finally return the collection of suggested words.

C# code:

Source file is included in zip format for download.

Calling Word.dll wrapper class:

This is how you would call this wrapper class in your application.

using System;

//Word.dll

using Word;

/// <summary>

/// Test Harness for SpellCheck Class

/// </summary>

class TestHarness
{
    /// <summary>

    /// testing Word Class

    /// </summary>

    [STAThread]
    static void Main(string[] args)
    {
        SpellCheck word = new SpellCheck();

        bool status = false;
        string s = "youes";

        Console.WriteLine("Checking for word : " + s );
            
        // check to see if the word is not correct  

        // return the bool (true|false)

        status = word.CheckSpelling(s);

        if (status == false)
        {
            Console.WriteLine("This word is misspelled : " + s);
            Console.WriteLine("Here are some suggestions");
            Console.WriteLine("-------------------------");

            foreach( string suggestion in word.GetSpellingSuggestions(s) ) 
            {
                System.Console.WriteLine( suggestion ); 
            }
        }
        else if (status == true)
        {
            Console.WriteLine("This word is correct : " + s );
        }

    }
}

Compiling:

Run the "compile.bat" file at the DOS prompt, it will create necessary files.

Output:

This is how your screen would look like after you execute TestHarness.exe file.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Waheed Khan


Member
Currently working with C# and ASP.NET.

Occupation: Web Developer
Location: United States United States

Other popular Algorithms & Recipes articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 18 of 18 (Total in Forum: 18) (Refresh)FirstPrevNext
GeneralOpen Office Spellchecker for .NET + Hyphenation + Thesaurus PinmemberThomas Maierhofer7:22 16 Nov '09  
GeneralRelated Dictionaries PinmemberVasudevan Deepak Kumar0:39 30 Jan '07  
GeneralDictionaries PinmemberFranck Quintana8:36 25 Oct '06  
GeneralRe: Dictionaries PinmemberVasudevan Deepak Kumar7:15 19 Mar '07  
GeneralRe: Dictionaries PinmemberFranck Quintana7:37 19 Mar '07  
GeneralCopyright? Pinmemberjmw9:33 17 Aug '06  
GeneralRe: Copyright? PinmemberVasudevan Deepak Kumar7:15 19 Mar '07  
GeneralDeveloping a spell checker Pinmembermad_68420:41 21 Jan '05  
GeneralRe: Developing a spell checker PinmemberVasudevan Deepak Kumar7:13 19 Mar '07  
Generalcheck existance of word.dll Pinsussbunny rabbit18:29 4 Feb '04  
GeneralRe: check existance of word.dll PinmemberVasudevan Deepak Kumar7:13 19 Mar '07  
GeneralWord.dll Pinmemberhalegua20:58 9 Mar '03  
GeneralRe: Word.dll PinmemberVasudevan Deepak Kumar7:14 19 Mar '07  
GeneralThe Google Version PinmemberBlake Coverett18:42 20 Jun '02  
GeneralRe: The Google Version PinmemberNick Parker18:39 23 Jun '02  
GeneralRe: The Google Version Pinmemberpareshgheewala0:06 30 Mar '05  
GeneralRe: The Google Version PinprotectorNick Parker2:52 30 Mar '05  
GeneralRe: The Google Version PinmemberVasudevan Deepak Kumar7:14 19 Mar '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 19 Jun 2002
Editor: Chris Maunder
Copyright 2002 by Waheed Khan
Everything else Copyright © CodeProject, 1999-2009
Web17 | Advertise on the Code Project