in reply to Perl pattern matching question
That just shows how to use the module to check for errors. It should be easy to tweak the example a bit so as to fix them.#!/usr/bin/env perl use strict; use warnings; use Lingua::EN::Inflect 'A'; while (<DATA>) { while ( /\b (an? \s (\w+))/gx ) { my ( $phrase, $word ) = ( $1, $2 ); if ( $phrase eq A( $word )) { print "RIGHT: $phrase\n"; } else { print "WRONG: $phrase\n"; } } } __DATA__ I am a howling maniac in an hospital. It takes a hour to win an honorable mention. Calling him a umpire is a euphemism. This is a united front against a evil empire.
(updated to fix a typo in the cpan link.)
One more update: a bit more logic is needed to handle various kinds and amounts of punctuation that might occur between the article and the word that follows:
while (<DATA>) { while ( /\b ((an?) \s\W* (\w+))/gx ) { my ( $phrase, $article, $word ) = ( $1, $2, $3 ); my $bigram = "$article $word"; if ( $bigram eq A( $word )) { print "RIGHT: $phrase\n"; } else { print "WRONG: $phrase\n"; } } } __DATA__ Suitable for a (older) child or an 'early adult'.
|
|---|