Spell Checker in Database..

  • Hi guys,

    I have to implement spell checker from database side..

    suppose i have entered wrong word from application which is text field..

    like "cay"..so it will found very nearly correct word "cat" from dictonary..means it will give correct word and find rows from table using correct word.

    I have created full text index on that text field.

    So, spell checker is possible with full text?

    or any other altername way?

    _____________________________________________________________________________________________________________
    Paresh Prajapati
    ➡ +919924626601
    http://paresh-sqldba.blogspot.com/[/url]
    LinkedIn | Tweet Me | FaceBook | Brijj

  • Paresh Prajapati (11/27/2008)


    Hi guys,

    I have to implement spell checker from database side..

    suppose i have entered wrong word from application which is text field..

    like "cay"..so it will found very nearly correct word "cat" from dictonary..means it will give correct word and find rows from table using correct word.

    I have created full text index on that text field.

    So, spell checker is possible with full text?

    or any other altername way?

    yes the idea is gud but for that you will have to arrange a dictionary, a big dictionary and that will surely slow down the processing/output. If i were at your place, I simply use Ms-office dictionary class as a new spell check layer between the database and the application. and that class is also very easily to update from the microsoft website.

    kshitij kumar
    kshitij@krayknot.com
    www.krayknot.com

  • Can you give me information, how can i intregrate MS-office dictonary with database?

    _____________________________________________________________________________________________________________
    Paresh Prajapati
    ➡ +919924626601
    http://paresh-sqldba.blogspot.com/[/url]
    LinkedIn | Tweet Me | FaceBook | Brijj

  • Hi paresh this is raj i got the way you can get the answer of true or false

    like if you enter wrong spelling word then it will check and tell us true or false

    but still don't get the way of suggestions

    Raj Acharya

  • Paresh Prajapati (11/28/2008)


    Can you give me information, how can i intregrate MS-office dictonary with database?

    check out this

    using System;

    using System.IO;

    using System.Net;

    // uncomment using System.Diagnostics; for debuging

    // using System.Diagnostics;

    using System.Text.RegularExpressions;

    using System.Collections;

    using System.Collections.Specialized;

    namespace Word

    {

    ///

    /// Public Class for Word.

    ///

    public class SpellCheck

    {

    ///

    /// Public Method Word

    ///

    public SpellCheck()

    {

    }

    // private variable to store a copy of returned raw HTML

    private string rawHtml;

    ///

    /// This Method will determine if the word is correct will return Ture

    /// or else if incorrect then it will return False

    ///

    public bool CheckSpelling(string word)

    {

    bool result = false;

    // Initialize the process

    result = Initialize(word);

    if( result == true )

    {

    result = true;

    }

    else

    if (result == false)

    {

    result = false;

    }

    return result;

    }

    ///

    /// Method to return the collection of words

    ///

    public StringCollection GetSpellingSuggestions(string word)

    {

    StringCollection s = new StringCollection();

    bool result = false;

    try

    {

    result = Initialize(word);

    // if misspelled then process

    if( result == false )

    {

    // extractWords will return the string of StringCollection

    s = extractWords();

    }

    return s;

    }

    catch

    {

    return s;

    }

    }

    ///

    /// This Method will initialize the process

    ///

    private bool Initialize(string word)

    {

    bool result = false;

    string url = "";

    string returnHtml = "";

    url = buildUrl(word);

    returnHtml = readHtmlPage(url);

    // add returnHtml to rawHtml

    rawHtml = returnHtml;

    result = statusWord(returnHtml);

    return result;

    }

    ///

    /// Build the URL by passing a word for a spell checker

    ///

    private string buildUrl(string word)

    {

    string url = "http://www.spellcheck.net/cgi-bin/spell.exe?action=CHECKWORD&string=";

    url += word;

    return url;

    }

    ///

    /// Method to find the index of the string indicated

    /// starting at the position passed in

    ///

    private int Find(string strSearch, int nStart)

    {

    return rawHtml.IndexOf(strSearch, nStart);

    }

    ///

    /// Method to return the length of a string in integer

    ///

    private int Length(string str)

    {

    return(str.Length);

    }

    ///

    /// Connect to web site by passing a URL and word

    /// Method to return the result in HTML

    ///

    private String readHtmlPage(string url)

    {

    string result = "";

    try

    {

    WebRequest objRequest = HttpWebRequest.Create(url);

    WebResponse objResponse = objRequest.GetResponse();

    Stream stream = objResponse.GetResponseStream();

    StreamReader sr = new StreamReader(stream);

    result = sr.ReadToEnd();

    }

    catch(Exception e)

    {

    return e.Message;

    }

    // convert the result to lower case and return it

    return(result).ToLower();

    }

    ///

    /// This Method will determine if the word is

    /// Correct or inCorrect

    ///

    private bool statusWord(string rawHtml)

    {

    bool result = false;

    string found = "";

    string correct = "correctly.";

    string uncorrect = "misspelled.";

    Regex match = new Regex(@"(correctly.)|(misspelled.)");

    found = match.Match(rawHtml).ToString();

    if (found == correct)

    {

    result = true;

    }

    else

    if(found == uncorrect)

    {

    result = false;

    }

    return result;

    }

    ///

    /// Method to extract the words from the HTML page and return the

    /// regular expression group as a string collection

    ///

    private StringCollection extractWords()

    {

    StringCollection s = new StringCollection();

    string found = "";

    string correct = "suggestions:";

    // uncomment these lines if you are using second technique

    //

    //int nIndexStart = 0;

    //int nIndexEnd = 0;

    //int nIndex = 0;

    //string suggestionTag = "suggestions:";

    //string blockquoteStartTag = " ";

    //string blockquoteEndTag = " ";

    // look for the suggestion tag in HTML

    Regex matchS = new Regex(@"(suggestions:)");

    // rawHtml is private string variable which was initialize earlier

    // within Initialize function

    found = matchS.Match(rawHtml).ToString();

    // if we have suggestion Tag then process

    if (found == correct)

    {

    /*

    * regular expression is used to parse the string

    * we are trying to parse the following string from the HTML page

    *

    * string1

    *string2

    * string3

    * ...

    * ...

    *

    */

    Regex rg = new Regex(

    @" # match tag

    (?:\s*([^<]+)

    \s*)+ # match spaces capture string,

    spaces

    # match end tag",

    RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);

    MatchCollection matches = rg.Matches(rawHtml);

    if (matches.Count > 0)

    {

    // Get the first match

    Match match = (Match) matches[0];

    // Get the second group in the match

    Group grp = match.Groups[1];

    // print each capture within group to debug window

    foreach (Capture cap in grp.Captures)

    {

    // print out the output in debug window

    // Debug.WriteLine(cap.Value);

    // print out the output to DOS console window

    // Console.WriteLine(cap.Value);

    // add the values to the StringCollection

    s.Add(cap.Value);

    }

    }

    //

    // this is another technique to parse the string

    // but we will have to parse the string again

    // to remove the

    tag

    //

    /*

    // Look for the suggestion Tag information if found return the index

    if( (nIndex = Find(suggestionTag, 0)) > 0 )

    {

    // If it is found start looking for the first beginning blockquote tag

    nIndexStart = Find(blockquoteStartTag, nIndex);

    if(nIndexStart > 0 )

    {

    // Need to find the second end blockquote tag

    nIndexEnd = Find(blockquoteEndTag, nIndex);

    if(nIndexEnd > 0 )

    {

    //

    // this will return the string like

    // string1

    // string2

    // string3

    // ...

    // ...

    // we will then have to parse this string again

    // to remove

    from the string

    //

    returnString = (rawHtml.Substring(nIndexStart+Length(blockquoteStartTag), (nIndexEnd - nIndexStart)-Length(blockquoteEndTag)));

    }

    }

    }

    */

    }

    // return the collection of strings to next function

    return s;

    }

    }

    }

    using System;

    //Word.dll

    using Word;

    ///

    /// Test Harness for SpellCheck Class

    ///

    class TestHarness

    {

    ///

    /// testing Word Class

    ///

    [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 or not

    // 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 );

    }

    }

    }

    and dont forget to add the word reference

    kshitij kumar
    kshitij@krayknot.com
    www.krayknot.com

  • Thanks,

    But if i have to implement spell checker in sql server 2005 ,

    not using any vd,asp or asp.net script,

    i want to develop using sql server scrips.

    any idea???

    _____________________________________________________________________________________________________________
    Paresh Prajapati
    ➡ +919924626601
    http://paresh-sqldba.blogspot.com/[/url]
    LinkedIn | Tweet Me | FaceBook | Brijj

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply