Hi, I need to make a program that can extract the wrong verb in an input file. Note that the input file contains the sentence or essay that have been parsed using a parser. the sentence or essay in the input file is like below :
Ramli/NNP does/VBZ cherish/VB you/PRP.
The/DT teacher/NN does/VBZ not/RB cherish/VB you/PRP.
My/PRP family/NN does/VBZ not/RB know/VB about/IN it/PRP.
He/PRP does/VBZ not/RB like/IN you/PRP.
The problem is the output show that the fourth sentence is wrong but in english grammar, we know that this sentence is okey. I don't know how to fix this error

.
This is the code of my program:
CODE
$noun1 = '\w+\/NN '; #a variable to define noun singular
$noun2 = '\w+\/NNP '; #a variable to define proper noun singular
$noun3 = '\w+\/NNS'; #a variable to define noun plural
$noun4 = '\w+\/NNPS'; #a variable to define proper noun plural
$verb1 = '\w+\/VB'; #a variable to define verb base
$verb2 = '\w+\/VBZ'; #a variable to define verb 3rd person singular present
$verb3 = '\w+\/VBP'; #a variable to define verb non 3rd person singular present
$verb4 = '\w+\/VBG'; #a variable to define verb, gerund or present participle
$verb5 = '\w+\/VBD'; #a variable to define verb past tense
$verb6 = '\w+\/VBN'; #a variable to define verb past participle
$prpplural = 'I|You|We|They|i|you|we|they\/PRP';
$prpsingular = 'He|She|It|he|she|it\/PRP';
print "Enter a file name:\n"; # get input from user for a filename
$namafail= <STDIN>;
$fail="$namafail";
open (in, $fail) || die "Cannot open $fail for read :$!\n";
$outfile="c:/out.txt";
open (OUT, ">$outfile") || die "Can't open $outfile for writing :$!\n";
print OUT "This is the output for file: $fail";
while ($line =<in>) {
@word = split/\n/, $line; # splits each word in the line including leading whitespace
foreach $info (@word) {
$firstindex = $word[0];
if ($word[$firstindex]=~ /$noun1/){
&check_presenttense_singularNN;
}elsif ($word[$firstindex]=~ /$noun3/){
&check_presenttense_pluralNNS;
}elsif ($word[$firstindex]=~ /$noun2/){
&check_presenttense_singularNNP;
}elsif ($word[$firstindex]=~ /$prpplural/){
&check_presenttense_pluralPRP;
}elsif ($word[$firstindex]=~ /$prpsingular/){
&check_presenttense_singularPRP;
}#end of 1st while
sub check_presenttense_singularNN{
if ($word[$firstindex]=~ /$noun1/){
if ($word[$firstindex]=~ /$verb2/){
printf OUT "\nThis sentence has no grammatical error: \n$word[$firstindex] \n";
}
else
{
printf OUT "\nThis sentence has grammatical error: \n$word[$info]";
@sentence = split / /, $word[$firstindex];
for $error (@sentence) {
if ($error=~ /$verb1/|/$verb4/|/$verb5/|/$verb6/ )
{
printf OUT "\nError in tense in the above sentence is at:\n$error \n";
}
}#end of for
}#end of else
}#end of if
}#end of sub
sub check_presenttense_singularNNP{
if ($word[$firstindex]=~ /$noun2/){
if ($word[$firstindex]=~ /$verb2/|/$verb3/){
printf OUT "\nThis sentence has no grammatical error: \n$word[$firstindex] \n";
}
else
{
printf OUT "\nThis sentence has grammatical error: \n$word[$firstindex]";
@sentence = split / /, $word[$firstindex];
for $error (@sentence) {
if ($error=~ /$verb1/|/$verb4/|/$verb5/|/$verb6/ )
{
printf OUT "\nError in tense in the above sentence is at:\n$error \n";
}
}
}#end of else
}#end of if
}#end of sub
sub check_presenttense_pluralNNS{
if ($word[$firstindex]=~ /$noun3/){
if ($word[$firstindex]=~ /$verb2/){
printf OUT "\nThis sentence has grammatical error: \n$word[$firstindex] \n";
@sentence = split / /, $word[$firstindex];
for $error (@sentence) {
if ($error=~ /$verb2/|/$verb3/|/$verb4/|/$verb5/|/$verb6/ )
{
printf OUT "Error in tense in the above sentence is at:\n$error \n";
}
}
}
else
{
printf OUT "\nThis sentence has no grammatical error: \n$word[$firstindex] \n";
}
}#end of sub
sub check_presenttense_pluralPRP{
if ($word[$firstindex]=~ /$prpplural/){
if ($word[$firstindex]=~ /$verb2/){
printf OUT "\nThis sentence has grammatical error: \n$word[$firstindex] \n";
@sentence = split / /, $word[$firstindex];
for $error (@sentence) {
if ($error=~ /$verb2/|/$verb4/|/$verb5/|/$verb6/ )
{
printf OUT "Error in tense in the above sentence is at:\n$error \n";
}
}
}
else
{
printf OUT "\nThis sentence has no grammatical error: \n$word[$firstindex] \n";
}
}#end of sub
sub check_presenttense_singularPRP{
if ($word[$firstindex]=~ /$prpsingular/){
if ($word[$firstindex]=~ /$verb1/){
printf OUT "\nThis sentence has grammatical error: \n$word[$firstindex] \n";
@sentence = split / /, $word[$firstindex];
for $error (@sentence) {
if ($error=~ /$verb1/|/$verb3/|/$verb4/|/$verb5/ )
{
printf OUT "Error in tense in the above sentence is at:\n$error \n";
}
}
}
else
{
printf OUT "\nThis sentence has no grammatical error: \n$word[$firstindex] \n";
}
}#end of sub
}
}
}
}
}
This post has been edited by abadi: 23 Apr, 2008 - 12:33 AM