Hello Monks,
I am a beginner programmer, and the use of Strategy(http://www.perl.com/pub/2003/08/07/design2.html) was recommended to make my code better.
The whole idea is a little beyond my knowledge. SO I am just asking for help getting started.
If you could just give me a few hints and point me in the right direction, like Step 1. It would be greatly appreciated!
Thanks!
Here's the portion of the code that is to changed:
#Dependencies (relations and arguments):
if ($category_id eq "all") {
my @lines = split ("\n",$sentblock); ##Split by a newl
+ine
foreach my $line (@lines) {
my @matches;
next unless ($line =~ /\b$verbform\b/i); ##Ensure
+dependency contains searchword
##NEXT LINE IS DIFFERENCE:
next unless ($line =~ /subj\w*\(|obj\w*\(|prep\w*\
+(|xcomp\w*\(|agent\w*\(|purpcl\w*\(|conj_and\w*\(/); ##Ensure depende
+ncy only contains desired grammar relations
next unless ($line =~ /(\w+)\((\w+)\-\d+\,\s(\w+)\
+-\d+\)/); ##Ensure dependency is a dependency AND get info from it
$grammar_relation = $1;
$argument1 = $2;
$argument2 = $3;
next if ($argument1 eq $argument2); ##Ensure 1st a
+nd 2nd argument aren't the same
next if ($grammar_relation =~ /xcomp/i and $argume
+nt2 !~ /\b$verbform\b/i); ##Ensure for xcomp the searchword is the 2n
+d argument
next if ($argument1 =~ /^\S$/ or $argument2 =~ /^\
+S$/); ##Exclude if argument is only 1 character
push(@matches, $chapternumber, $sentencenumber, $s
+entence, $grammar_relation, $argument1, $argument2); ##All here, so e
+ither all get pushed or none (no holes in array)
push @all_matches, \@matches;
}
}
elsif ($category_id eq "subj") {
my @lines = split ("\n",$sentblock); ##Split by a newl
+ine
foreach my $line (@lines) {
my @matches;
next unless ($line =~ /\b$verbform\b/i); ##Ensure
+dependency contains searchword
next unless ($line =~ /subj\w*\(|agent\w*\(/); ##E
+nsure dependency only contains desired grammar relations
next unless ($line =~ /(\w+)\((\w+)\-\d+\,\s(\w+)\
+-\d+\)/); ##Ensure dependency is a dependency AND get info from it
$grammar_relation = $1;
$argument1 = $2;
$argument2 = $3;
next if ($argument1 eq $argument2); ##Ensure 1st a
+nd 2nd argument aren't the same
next if ($argument1 =~ /^\S$/ or $argument2 =~ /^\
+S$/); ##Exclude if argument is only 1 character
push(@matches, $chapternumber, $sentencenumber, $s
+entence, $grammar_relation, $argument1, $argument2);
push @all_matches, \@matches;
}
}
...etc... for a few more elsifs
#To make the if elsif into subroutine: Name:get_all_matches Pass
+In: ($sentblock, $verbform, $chapternumber, $sentencenumber, $sentenc
+e) Return: @allmatches (if needed, return reference)
Or just tell me if this is not meant for me yet. Or if I should ask this question better. Thanks for your time.
If you want a full look at my code:
(
http://codereview.stackexchange.com/questions/2911/to-make-a-subroutine-or-not-general-code-tips)