Welcome to Dream.In.Code
Getting Help is Easy!

Join 86,383 Programmers. There are 1,376 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

I need a help

 
Reply to this topicStart new topic

I need a help

abadi
post 22 Apr, 2008 - 08:15 PM
Post #1


New D.I.C Head

*
Joined: 22 Apr, 2008
Posts: 4



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 tongue.gif .

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
User is offlineProfile CardPM
Go to the top of the page
+Quote Post


KevinADC
post 22 Apr, 2008 - 10:15 PM
Post #2


D.I.C Head

Group Icon
Joined: 23 Jan, 2007
Posts: 168

Use the code tags when posting code and try and narrow down the scope of the problem, nobody is going to try and debug your entire script especially since the problem is vague to begin with. You only say the forth line is not correct but you dont say why it's not correct.

This line:

CODE
if ($word[$firstindex]=~ /$singularplural/){


the scalar $singularplural is only used once in the code so it can't be doing anything useful.

Add "strict" and warnings" and get your perl program to run with both those pragmas turned on:

CODE
use strict;
use warnings;


Few people will help you unless you do that first.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

abadi
post 23 Apr, 2008 - 12:34 AM
Post #3


New D.I.C Head

*
Joined: 22 Apr, 2008
Posts: 4

QUOTE(KevinADC @ 22 Apr, 2008 - 10:15 PM) *

Use the code tags when posting code and try and narrow down the scope of the problem, nobody is going to try and debug your entire script especially since the problem is vague to begin with. You only say the forth line is not correct but you dont say why it's not correct.

This line:

CODE
if ($word[$firstindex]=~ /$singularplural/){


the scalar $singularplural is only used once in the code so it can't be doing anything useful.

Add "strict" and warnings" and get your perl program to run with both those pragmas turned on:

CODE
use strict;
use warnings;


Few people will help you unless you do that first.

User is offlineProfile CardPM
Go to the top of the page
+Quote Post

abadi
post 23 Apr, 2008 - 12:54 AM
Post #4


New D.I.C Head

*
Joined: 22 Apr, 2008
Posts: 4

I'd already edit my code into code tags tongue.gif

I'd said that the fourth sentence wrong comes from the ouput of the program. If I parsed a sentence like He/PRP does/VBZ not/RB like/IN cats/NNS, it's still display that the 'does/VBZ' is an error in the sentence.

I think that my program confuse wheter to use sub check_presenttense_plural or sub check_presenttense_singularPRP.

Because the sentence also have cats/NNS and also He/PRP, my program choose to use the first sub which is sub check_presenttense_plural.

Actually this program need to choose the sub check_presenttense_singularPRP.

QUOTE(abadi @ 23 Apr, 2008 - 12:52 AM) *

the first that the program need to look is the first element in the array or input file. I try to configure again this code but stiil can't. If any one can help or suggest idea is appreciated. Thank you.

User is offlineProfile CardPM
Go to the top of the page
+Quote Post

KevinADC
post 23 Apr, 2008 - 02:13 AM
Post #5


D.I.C Head

Group Icon
Joined: 23 Jan, 2007
Posts: 168

I can't understand what you say and you can't explain the problem clearly so I will step aside and hope someone else can figure out your explanation of the problem and why your code does not do what you think it should.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

abadi
post 23 Apr, 2008 - 11:51 PM
Post #6


New D.I.C Head

*
Joined: 22 Apr, 2008
Posts: 4

okey thanks..
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 5/17/08 03:46AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month