Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
First of all you have to build the set of suggetions.

For this purpose, you have to avoid string distance as Hamming, Text::Levenshtein or Text::WagnerFischer (but you can use them later)
Instead you can use a phonetic algorithm like Text::Soundex (that you should find along with Perl), Text::Metaphone and Text::DoubleMetaphone.
They transform a word in a phonetic code that you can use to retrive suggested words:

hello->(phonetic alg.)->h2l3
hullo->(phonetic alg.)->h2l3 (note: same code for phonetic similarity)
harry->(phonetic alg.)->h549

So you can made an hash on disk (e.g. with DB_File) with phonetic codes as keys and as values the words that have the same phonetic code:


and so on.

After the hash (that you have built before running the spell checker), you parse the text; you have to:

1) isolate the word
2) calculate the phonetic code of the word.
3) retrive the suggestions for this word (i.e. words that have the same phonetic code)
4) see if the word is in the set of suggestions
4a) if yes, parse another word (i.e. the word is in my corpus)
4b) if not, prompt the user THIS set of suggetions
4ba) now you can use the distance string algorithms to sort the suggested words (e.g. with Levensthein).

To retrive the words you can do for example:
my $sentence="worda wordb, wordc"; my @sentence = split(//, $sentence); my $current_word; foreach my $s (0..$#sentence) { if ($sentence[$s] =~ /($\W|_|\d)/) { # process current word $current_word='' ; } else { $current_word.= $sentence[$s]; } }

In reply to Re: Spell Check Logic by dree
in thread Spell Check Logic by arashi

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (12)
    As of 2021-01-28 11:26 GMT
    Find Nodes?
      Voting Booth?