MSTperl/samples/test_labeller_tsv.pl untested

filter: Statementstmt 0.0% 0 / 52 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod n/a totaltotal 0.0% 0 / 61 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::Labeller;
14  
15 my ( $test_file, $model_file, $config_file, $algorithm ) = @ARGV;
16  
17 if (!defined $algorithm) {
18 $algorithm = 0;
19 }
20 my $config = Treex::Tool::Parser::MSTperl::Config->new(
21 config_file => $config_file,
22 labeller_algorithm => $algorithm,
23 );
24  
25 my $reader = Treex::Tool::Parser::MSTperl::Reader->new(
26 config => $config
27 );
28 my $test_data = $reader->read_tsv($test_file);
29 my $sentence_count = scalar( @{$test_data} );
30 print "Going to test on $sentence_count sentences.\n";
31  
32 my $labeller = Treex::Tool::Parser::MSTperl::Labeller->new(
33 config => $config
34 );
35 $labeller->load_model($model_file);
36  
37 my $total_words = 0;
38 my $total_errors = 0;
39 my @sentences;
40 foreach my $correct_sentence ( @{$test_data} ) {
41 # print "SENTENCE: " . $test_sentence->toString() . "\n";
42  
43 #parse
44 #$labeller->parse_sentence($test_sentence);
45 my $test_sentence = $labeller->label_sentence_internal($correct_sentence);
46 push @sentences, $test_sentence;
47 my $sentenceLength = $test_sentence->len();
48 my $errorCount = $test_sentence->count_errors_labelling($correct_sentence);
49  
50 # my $score = 100 - (100*$errorCount/$sentenceLength);
51 # print "score: $score% ($errorCount errors in $sentenceLength words)\n";
52 $total_words += $sentenceLength;
53 $total_errors += $errorCount;
54  
55 #output
56 # foreach my $child (@{$test_sentence->nodes}) {
57 # print $child->parent->form." -> ".$child->form."\n";
58 # }
59 }
60 my $writer = Treex::Tool::Parser::MSTperl::Writer->new(
61 config => $config
62 );
63 $writer->write_tsv( $test_file . '.out', [@sentences] );
64  
65 my $total_score = 100 - ( 100 * $total_errors / $total_words );
66 print "\n";
67 print "TOTAL SCORE: " .
68 "$total_score% ($total_errors errors in $total_words words)\n";
69