Welcome to mirror list, hosted at ThFree Co, Russian Federation.

filter-excluded-lines.perl « wrappers « training « scripts - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7f9da3efac7305414c08e7ed7d3105f1b141263f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env perl 

use warnings;
use strict;
use Getopt::Long;

my $excludedLinesFile = undef;

GetOptions(
    "excl=s" => \$excludedLinesFile
	   ) or exit(1);

open(EXCLUDED_LINE, $excludedLinesFile) or die("Can't open excluded file $excludedLinesFile");
my @excludedLines = <EXCLUDED_LINE>;
close(EXCLUDED_LINE);

# MAIN LOOP
my $lineNum = 1;
my $linesOut = 0;
my $exclInd = 0;
my $nextLineExcl = -1;

if (@excludedLines > 0)
{
	$nextLineExcl = $excludedLines[0];
}

#open(STDIN);
while(<STDIN>)
{
    my $line = $_;
		    
    if ($nextLineExcl == $lineNum)
    {
    	$exclInd++;
    	if ($exclInd < @excludedLines) 
    	{
	    	$nextLineExcl = $excludedLines[$exclInd];
	    }
    }
    else
    {
    	print $line;
	$linesOut++;
    }
  
    $lineNum++;
}
#close(STDIN);

print STDERR "num of lines=".($lineNum-1)."\n";
print STDERR "num excluded=".(@excludedLines)."\n";
print STDERR "lines out=".($linesOut)."\n";

sub trim($)
{
    my $string = shift;
    $string =~ s/^\s+//;
    $string =~ s/\s+$//;
    return $string;
}