Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Help finding mistakes in spellings using Perl

by 2teez (Vicar)
on Oct 09, 2013 at 23:50 UTC ( #1057640=note: print w/replies, xml ) Need Help??

in reply to Help finding mistakes in spellings using Perl

Hi shamat,

Dear Monks, I am a newbie in Pearl,..
Let me start by saying, if you are still new to Perl is not late to start good habit like use warnings and strict in your script.
Secondly, make your script readable use perltidy
The first entry in the list always refers to the correct spelling. I would like to find the mistakes in the entries 1-3, checking against the reference word. I would like to obtain an output like this:
One way to go is to compare each of the string with the first entry, letter by letter.
I will give a head up below.
use warnings; use strict; my @words = qw(believe beleive beeliv pelief); spelling_check( $words[0], $_ ) for @words[ 1 .. $#words ]; sub spelling_check { no warnings 'uninitialized'; my @wrds; push @wrds, [ split //, $_ ] for @_; my ( $right, $wrong ) = q{} x 2; for ( 0 .. $#{ $wrds[0] } ) { if ( $wrds[0]->[$_] ne $wrds[1]->[$_] ) { $right .= defined( $wrds[1]->[$_] ) ? $wrds[1]->[$_] : qw' +-'; $wrong .= defined( $wrds[0]->[$_] ) ? $wrds[0]->[$_] : qw' +-'; } } print join( ' ~ ' => ( $right, $wrong ) ), $/; }
ei ~ ie eli- ~ liee pf- ~ bve
NOTE: Please, note that if either of the strings comparing per time is longer, you have "uninitialized value" thus I used no warnings 'uninitialized'
2. The printing is not as the OP wanted, but simply showed the difference in the letter of each string compared.
3. The OP is to use this as a guide.
Hope this helps

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me

Replies are listed 'Best First'.
Re^2: Help finding mistakes in spellings using Perl
by shamat (Acolyte) on Oct 10, 2013 at 15:33 UTC
    Hi 2teez, thank you very much for your suggestions. The difficult part to me comes when there are multiple misspellings, randomly scattered in the word to be checked against the reference one. In this case, it is crucial to capture sets of variations, which is the reason why I was using an array, to which a new element is appended when a new variation is found. In any case, I might use your code as a starting point to rewrite mine, which compared to yours looks really ugly. Philosophical consideration: The more I work on this script, the more I realize how flexible our brain is in dealing with language, and how difficult is to bring to conscience all the processes involved in this task.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1057640]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2018-02-21 11:40 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (279 votes). Check out past polls.