5,667,575 members and growing! (9,062 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, Windows, .NET, Visual Studio, Dev

Posted: 19 Jun 2002
Updated: 19 Jun 2002
Views: 74,807
Bookmarked: 34 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
8 votes for this Article.
Popularity: 4.15 Rating: 4.60 out of 5
0 votes, 0.0%
1
0 votes, 0.0%
2
0 votes, 0.0%
3
1 vote, 25.0%
4
3 votes, 75.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


Currently working with C# and ASP.NET.

Occupation: Web Developer
Location: United States United States

Other popular Algorithms & Recipes articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 17 of 17 (Total in Forum: 17) (Refresh)FirstPrevNext
GeneralRelated DictionariesmemberVasudevan Deepak Kumar0:39 30 Jan '07  
GeneralDictionariesmemberFranck Quintana8:36 25 Oct '06  
GeneralRe: DictionariesmemberVasudevan Deepak Kumar7:15 19 Mar '07  
GeneralRe: DictionariesmemberFranck Quintana7:37 19 Mar '07  
GeneralCopyright?memberjmw9:33 17 Aug '06  
GeneralRe: Copyright?memberVasudevan Deepak Kumar7:15 19 Mar '07  
GeneralDeveloping a spell checkermembermad_68420:41 21 Jan '05  
GeneralRe: Developing a spell checkermemberVasudevan Deepak Kumar7:13 19 Mar '07  
Generalcheck existance of word.dllsussbunny rabbit18:29 4 Feb '04  
GeneralRe: check existance of word.dllmemberVasudevan Deepak Kumar7:13 19 Mar '07  
GeneralWord.dllmemberhalegua20:58 9 Mar '03  
GeneralRe: Word.dllmemberVasudevan Deepak Kumar7:14 19 Mar '07  
GeneralThe Google VersionmemberBlake Coverett18:42 20 Jun '02  
GeneralRe: The Google VersionmemberNick Parker18:39 23 Jun '02  
GeneralRe: The Google Versionmemberpareshgheewala0:06 30 Mar '05  
GeneralRe: The Google VersionprotectorNick Parker2:52 30 Mar '05  
GeneralRe: The Google VersionmemberVasudevan 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-2008
Web19 | Advertise on the Code Project