MSTperl/samples/test_tsv.pl untested

filter: Statementstmt 0.0% 0 / 50 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod n/a totaltotal 0.0% 0 / 57 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 use utf8;
5  
6 binmode STDIN, ':encoding(utf8)';
7 binmode STDOUT, ':encoding(utf8)';
8 binmode STDERR, ':encoding(utf8)';
9  
10 use Treex::Tool::Parser::MSTperl::Config;
11 use Treex::Tool::Parser::MSTperl::Reader;
12 use Treex::Tool::Parser::MSTperl::Writer;
13 use Treex::Tool::Parser::MSTperl::Parser;
14  
15 my ( $test_file, $model_file, $config_file ) = @ARGV;
16  
17 my $config = Treex::Tool::Parser::MSTperl::Config->new(
18 config_file => $config_file
19 );
20  
21 my $reader = Treex::Tool::Parser::MSTperl::Reader->new(
22 config => $config
23 );
24 my $test_data = $reader->read_tsv($test_file);
25 my $sentence_count = scalar( @{$test_data} );
26 print "Going to test on $sentence_count sentences.\n";
27  
28 my $parser = Treex::Tool::Parser::MSTperl::Parser->new(
29 config => $config
30 );
31 $parser->load_model($model_file);
32  
33 my $total_words = 0;
34 my $total_errors = 0;
35 my @sentences;
36 foreach my $correct_sentence ( @{$test_data} ) {
37 # print "SENTENCE: " . $test_sentence->toString() . "\n";
38  
39 #parse
40 #$parser->parse_sentence($test_sentence);
41 my $test_sentence = $parser->parse_sentence_internal($correct_sentence);
42 push @sentences, $test_sentence;
43 my $sentenceLength = $test_sentence->len();
44 my $errorCount = $test_sentence->count_errors_attachement($correct_sentence);
45  
46 # my $score = 100 - (100*$errorCount/$sentenceLength);
47 # print "score: $score% ($errorCount errors in $sentenceLength words)\n";
48 $total_words += $sentenceLength;
49 $total_errors += $errorCount;
50  
51 #output
52 # foreach my $child (@{$test_sentence->nodes}) {
53 # print $child->parent->form." -> ".$child->form."\n";
54 # }
55 }
56 my $writer = Treex::Tool::Parser::MSTperl::Writer->new(
57 config => $config
58 );
59 $writer->write_tsv( $test_file . '.out', [@sentences] );
60  
61 my $total_score = 100 - ( 100 * $total_errors / $total_words );
62 print "\n";
63 print "TOTAL SCORE: " .
64 "$total_score% ($total_errors errors in $total_words words)\n";
65