Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

Need Help, looking for spell checker code


  • Please log in to reply

#1
BSNCAPBYY

BSNCAPBYY

    Member

  • Member
  • PipPipPip
  • 216 posts
I need help guys, i have to many stuff to do, because i am in my last 2 weeks of the university, my last assinment is to do a spell checker in C++, i have an idea but nothing is coming out. I really need help, coulde someone do, anything to help me i dont have much time, here are the instructions:

Instructions:
In this project, you are asked to develop your own spell-checker utility. We make suggestions to help get you started. You should then consider adding more capabilities. You might find it helpful to use a computerized dictionary as a source of words.
Why do we type so many words with incorrect spellings? In some cases, it is because we simply do not know the correct spelling, so we make a "best guess." In some cases, it is because we transpose two letters (e.g., "defualt" instead of "default"). Sometimes we double-type a letter accidentally (e.g., "hanndy" instead of "handy"). Sometimes we type a nearby key instead of the one we intended (e.g., "biryhday" instead of "birthday"). And so on.
Design and implement a spell-checker program. Your program will access a file called Dictionary.txt which contains the available words.
Your program asks a user to enter a word. The program then looks up that word in the file. If the word is present in the file, your program should print "Word is spelled correctly".
If the word is not present in the file, your program should print "Word is not spelled correctly." Then your program should try to locate other words in the file that might be the word the user intended to type. For example, you can try all possible single transpositions of adjacent letters to discover that the word "default" is a direct match to a word in the file. Of course, this implies that your program will check all other single transpositions, such as "edfault," "dfeault," "deafult," "defalut" and "defautl." When you find a new word that matches one in the file, print that word in a message such as "Did you mean "default?"."
Implement other tests, such as the replacing of each double letter with a single letter and any other tests you can develop to improve the value of your spell checker.

For this assingment you dont need a complete dictionary, only a mínimum of 1000 words...

Please help me out, i have to much things to do i dont have time to break my head doing this in such little time, thanks
  • 0

Advertisements


#2
mpfeif101

mpfeif101

    Member 1K

  • Retired Staff
  • 1,411 posts
I don't think it would really be right to do your last assignment in your university for you. If you start to program it and run in to troubles then we would be happy to help you, but we're not going to start from ground 0 for you.

If you don't know where/how to start, step 1 should be just a simple code to check whether the word is in the text file or not. Once you've got that down then you can start programing algorithms to check for possible corrections (one possible algorithm that would work very well would be to switch any two vowels that are right next to each and see if the new word matches in the text file, e.g. defualt becomes default).
  • 0

#3
BSNCAPBYY

BSNCAPBYY

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 216 posts
I started to make the spell checker this is what i got but i doesnt work, please help me out:

#include <iostream>
#include <fstream>
#include <iomanip>
#include "string.h"

struct dictionary
{
int fileword;
};

using namespace std;

int main()
{
int word;
dictionary book;
char again = 0;

do
{
ifstream inword("c:\\Dictionary.txt", ios::out);

cout << "Enter a word" << endl;
cin >> word;

while ( inword >> book.fileword )
//inword.read( reinterpret_cast<char *>( &book ), sizeof( dictionary ) );
// inword.seekg((book.fileword-1) * sizeof(dictionary));


if( book.fileword == word )
{
cout << "Bryan's Spell Checker" << endl;
cout << "The word you picked is: "<<endl;
cout << word << endl;
}

cout << "Do you want to continue?(y = yes, n = no)" << endl;
cin >> again;

} while(again == 'y');

//cout<<"Program Terminated"<<endl;
return 0;
}


Here is the dictionary text file with 25,000 words.
Attached File  Dictionary.txt   248.56KB   11896 downloads
  • 0

#4
Kurenai

Kurenai

    Retired Staff

  • Retired Staff
  • 494 posts
Well, the program you've written just checks to see if the set of characters entered exactly matches any set of characters in your struct, and if so, outputs it. There is no checking past that.

Your embedded while loop to extract your dictionary file to your struct looks a bit suspicious as well...and why is it in your do?
  • 0

#5
BSNCAPBYY

BSNCAPBYY

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 216 posts
Could you fix my problem, its not that hard, its that i don't know very well or be more specific
  • 0

#6
warriorscot

warriorscot

    Member 5k

  • Retired Staff
  • 8,889 posts
If this is a project we cant do it for you, it would be cheating, and if you are in your final year and cant write a spell checker you have bigger problems.
  • 0

#7
BSNCAPBYY

BSNCAPBYY

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 216 posts
I understand, but i dont want you do the program for me i want you to help me do it well, there is nothing bad to have help... I did a code and its not funtioning, i dont know where is the problem, what i ment is if you can fix the problem i can keep on making the spell check thats all, so if you can help me it would be great, thanks
  • 0

#8
Kurenai

Kurenai

    Retired Staff

  • Retired Staff
  • 494 posts
We are not willing to "fix the problem," as that would amount to doing your assignment for you. We can help point out where problem areas may be, but I think that's as far into help as we are comfortable getting.
  • 0

#9
warriorscot

warriorscot

    Member 5k

  • Retired Staff
  • 8,889 posts
Dont you have a lecturer and Tutor to help you out like that, its a little over the line for us to help you i know at my uni it would be against the code of conduct.
  • 0

#10
IO-error

IO-error

    Member

  • Member
  • PipPipPip
  • 276 posts
I don't know anything of C++, but I'm a fast learner and I interprete things fast. So here's my guess of logical structure, if you still have problems with that.

First build a simple standard inputbox.
Then when the word is entered, let the script break up that word into different words and save it in an array.
Let the code run down the array, there's some code that says something like Read till end of Array.... Anyway, let the script check every word in the array.
If there is something that looks like it (which can be checked with InStr, or something that looks like it.) let a simple msgbox Cout that word.
The most difficult part in here and the one that needs most attention, because new ideas keep spawning, is the code that breaks up the word into other possibilities. A word can be mis-typed like this:
birthday, biryhday, but also bidrthay. So more complex word-mixing is needed.

I hope you understand it, if not, sorry.
Good luck man.
  • 0

#11
BSNCAPBYY

BSNCAPBYY

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 216 posts
I have tried to do this program and i am stuck here, the profesor doesnt appear so i am trying to find help here please help me find what i am doing wrong here is the code:

#include <iostream>
#include <fstream>
#include <iomanip>
#include "string.h"

struct dictionary
{
int fileword;
};
using namespace std;

int binarySearch( ifstream&, int, int, int, int );

int main()
{
int word;
dictionary book;

ifstream inword("c:\\Dictionary.txt", ios::out);

cout << "Enter a word" << endl;
cin >> word;

//while ( inword >> book.fileword )
//inword.read( reinterpret_cast<char *>( &book ), sizeof( dictionary ) );
// inword.seekg((book.fileword-1) * sizeof(dictionary));
//book.fileword = binarySearch(inword, word, 0, 10000 - 1, 10000 );
int fileword = binarySearch(inword, word, 0, 10000 - 1, 10000 );

//if( book.fileword == word )
//if(fileword == word )
//{
cout << "Bryan's Spell Checker" << endl;
cout << "The word you picked is: "<<endl;
cout << fileword << endl;
//}

return 0;
}
int binarySearch( ifstream &inword, int word, int low, int high, int size )
{
int middle;

while ( low <= high ) {

middle = ( low + high ) / 2;
//inword.seekg((middle - 1) * sizeof(dictionary));
inword.seekg((middle - 1));
if ( word == middle )
return middle;
else
if ( word < middle )
high = middle - 1;

else
low = middle + 1;
}
return -1;
}

Here is the file:Attached File  Dictionary.txt   8.52KB   223 downloads (you should save as this to the local disk C folder)

Edited by BSNCAPBYY, 29 November 2006 - 10:07 PM.

  • 0

#12
BSNCAPBYY

BSNCAPBYY

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 216 posts
Forget it, my friend help me out, he saved my life...
  • 0

#13
mpfeif101

mpfeif101

    Member 1K

  • Retired Staff
  • 1,411 posts
Sorry we couldn't have been of more help, but I'm glad it worked out :whistling:
  • 0

#14
IO-error

IO-error

    Member

  • Member
  • PipPipPip
  • 276 posts
One error I found was that you misplaced a &-sign.

int binarySearch( ifstream&, int, int, int, int );

Shouldn't it be:

int binarySearch(&ifstream, int, int, int, int );
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP