get-by-line-number.perl

This commit is contained in:
Hieu Hoang 2014-04-24 17:48:12 +01:00
commit da6ade7d94
5 changed files with 70 additions and 3 deletions

View File

@ -0,0 +1,33 @@
#! /usr/bin/perl -w
use strict;
sub trim($);
my $file1 = $ARGV[0];
my $file2 = $ARGV[1];
open (FILE1, $file1);
open (FILE2, $file2);
my $countEqual = 0;
while (my $line1 = <FILE1>) {
my $line2 = <FILE2>;
if (trim($line1) eq trim($line2)) {
++$countEqual;
}
}
print $countEqual ."\n";
######################
# Perl trim function to remove whitespace from the start and end of the string
sub trim($) {
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}

View File

@ -0,0 +1,29 @@
#! /usr/bin/perl -w
use strict;
binmode(STDIN, ":utf8");
binmode(STDOUT, ":utf8");
binmode(STDERR, ":utf8");
my $fileLineNum = $ARGV[0];
open (FILE_LINE_NUM, $fileLineNum);
my $nextLineNum = <FILE_LINE_NUM>;
my $lineNum = 1;
while (my $line = <STDIN>) {
if (defined($nextLineNum) && $lineNum == $nextLineNum) {
# matches. output line
chomp($line);
print "$line\n";
# next line number
$nextLineNum = <FILE_LINE_NUM>;
}
++$lineNum;
}

View File

@ -168,8 +168,8 @@ float ChartTranslationOptionList::GetBestScore(const ChartCellLabel *chartCell)
return 0;
}
else {
const ChartHypothesis &bestHypo = **(stack->begin());
return bestHypo.GetTotalScore();
const ChartHypothesis &bestHypo = **(stack->begin());
return bestHypo.GetTotalScore();
}
}

View File

@ -218,7 +218,7 @@ bool RuleTableLoaderStandard::Load(FormatType format
// parse source & find pt node
// constituent labels
Word *sourceLHS;
Word *sourceLHS = NULL;
Word *targetLHS;
// create target phrase obj
@ -251,6 +251,9 @@ bool RuleTableLoaderStandard::Load(FormatType format
TargetPhraseCollection &phraseColl = GetOrCreateTargetPhraseCollection(ruleTable, sourcePhrase, *targetPhrase, sourceLHS);
phraseColl.Add(targetPhrase);
// not implemented correctly in memory pt. just delete it for now
delete sourceLHS;
count++;
}

View File

@ -59,3 +59,5 @@ sub DeleteScore
return $string;
}