CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Comparing words

 



perlkid
stranger

Sep 22, 2000, 10:24 AM

Post #1 of 5 (1058 views)
Comparing words Can't Post

 Hi everyone,

I'm trying to make a spell checker,

And the code I'm using now, takes %60 of a word and compares it with field1 in a data base.

I don't like it becase if you type in masereti it should come back and say maserati But it only looks for the part masere so the word maserati won't be picked up.

There is only one letter that is different it should be picked up, Is there a way to do this,

compare the two words and if there is only a one, two, three or whatever letter difference then it will count it as a match.

I can't even think of what the code would like and this is very important for me to finish.

Thank you for all you help,

perlkid

[This message has been edited by perlkid (edited 09-22-2000).]


fashimpaur
User / Moderator

Sep 22, 2000, 7:33 AM

Post #2 of 5 (1058 views)
Re: Comparing words [In reply to] Can't Post

Perlkid,

There may be an easier way to do this.

This is the logic, you can do the code:

Take the first letter of the word being validated.
Start comparing it to all words that have the same starting letter in your reference lookup.
Split the test word and the reference word into a character by character test.
Score the test word on a basis of the number of matches each reference word.
List suggested replacements based on a set percentage match. (i.e. list all reference words that get 60% of the characters right).
Display the list in decending order of closeness to match.

The End.

HTH,

Dennis


Kanji
User

Sep 22, 2000, 8:15 AM

Post #3 of 5 (1058 views)
Re: Comparing words [In reply to] Can't Post

Why bother reinventing the wheel when Lingua::Ispell already does this?


perlkid
stranger

Sep 22, 2000, 12:09 PM

Post #4 of 5 (1058 views)
Re: Comparing words [In reply to] Can't Post

 fashimpaur,

That's a really good idea, but I though of that last night and I though of a way to do it but it doesn't work very well, I mean, on a few words it works great, but up against my whole data base, it doesn't ever finish searching. I know why too, see for your self,

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


open(keywords, "</path/$letter1.db");
flock(keywords, 1);
while(<keywords> ){
(@res2)=split(/\|/, $_);
$res2[0] = lc($res2[0]);
###################################
if (substr($res2[0], 0, 2) eq substr($in{'qry'}, 0, 2)){
push(@begin, $_)
}
###################################
}
close(keywords);
flock(keyword, 8);
foreach $instance (@begin){
(@words)=split(/\|/, $instance);
$word = "$words[0]";
$word2 = "$in{'qry'}";
$length = length($word);
$length2 = length($word2);
(@wrd)=split(//, $word);
(@wrd2)=split(//, $word2);
foreach $line (@wrd){
foreach $line2 (@wrd2){
if ($line eq "$line2"){
$c++;
if ($c / $length2 > .8){
push(@wrord3545, $instance);
}
}
}}
undef %seen;
@results = grep(!$seen{$_}++, @wrord3545);
}
</pre><HR></BLOCKQUOTE>

See what I mean,

And kanji,

I looked into lingua::spell, but my server doesn't have it installed. Frown

I'm going to tell my admin to install it though. Also, I have no idea how to use it.

Thanks A Lot Guys,

perlkid

[This message has been edited by perlkid (edited 09-22-2000).]


perlkid
stranger

Sep 22, 2000, 12:26 PM

Post #5 of 5 (1058 views)
Re: Comparing words [In reply to] Can't Post

 
Never mind, I read the docs, Thx Kanji,

But do you know how that code above could work?

Thanks,

perlkid

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives