Tool/Parser/JDEPP.pm

filter: Statementstmt 27.9% 24 / 86 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 77.7% 7 / 9 Podpod 50.0% 1 / 2 totaltotal 24.8% 32 / 129 CC 15 SCAR 50.6
CC
15
Cov
21%
parse_sentence
240.0
BUILD
2.0
BEGIN
1.0
CRAP 156.9
↑ Summary Block/W2A/JA/FixInterpunction.pm »
1 package Treex::Tool::Parser::JDEPP;
2 4 $Treex::Tool::Parser::JDEPP::VERSION = '0.13095';
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Treex::Core::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Treex::Core::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Treex::Tool::ProcessUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Treex::Core::Resource;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 4 has model_dir => ( isa => 'Str', is => 'rw', required => 1 );
13  
14 0 ▶sub BUILD {
Subroutine BUILD: not called CC=1 SCAR=6.9
Pod undocumented
15 0 my ($self) = @_;
16  
17 # TODO find architecture independent solution
18 0 my $bin_path = require_file_from_share(
19 'installed_tools/parser/jdepp/bin/jdepp',
20 ref($self)
21 );
22
23 #TODO: fix setting up of the model_dir via Treex (see W2A::JA::ParseJDEPP)
24 # right now only way of selecting model_dir is via configuring Jdepp
25 # my $model_dir = $self->model_dir;
26  
27 # in the worst case, it will use default model
28 0 my $cmd = "$bin_path".' 2>/dev/null';
29
30 # start JDEPP parser
31 0 my ( $reader, $writer, $pid ) = Treex::Tool::ProcessUtils::bipipe( $cmd, ':encoding(utf-8)' );
32  
33 0 $self->{reader} = $reader;
34 0 $self->{writer} = $writer;
35 0 $self->{pid} = $pid;
36  
37 0 return;
38 }
39  
40 0 ▶sub parse_sentence {
Subroutine parse_sentence: not called CC=15 SCAR=54.8
Pod documented
41  
42 0 my ( $self, $forms_rf, $tags_rf ) = @_;
43  
44 0 ▶ if ( ref($forms_rf) ne "ARRAY" or ref($tags_rf) ne "ARRAY" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $forms_rf ne "ARRAY" or ref $tags_rf ne "ARRAY") 0 0 0
Condition0%0/3
ref $forms_rf ne "ARRAY" or ref $tags_rf ne "ARRAY"
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $forms_rf ne "ARRAY" or ref $tags_rf ne "ARRAY"
ref $forms_rf ne "ARRAY" ref $tags_rf ne "ARRAY"
Truth table0%0/3
A or B
A= ref $forms_rf ne "ARRAY"B= ref $tags_rf ne "ARRAY"
ABresult
1X1
011
000
45 0 log_fatal('Both arguments must be array references.');
46 }
47  
48 0 ▶ if ( $#{$forms_rf} != $#{$tags_rf} or @$forms_rf == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#{$forms_rf;} != $#{$tags_rf;} or @$forms_rf == 0) 0 0 0
Condition0%0/3
$#{$forms_rf;} != $#{$tags_rf;} or @$forms_rf == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$#{$forms_rf;} != $#{$tags_rf;} or @$forms_rf == 0
$#{$forms_rf;} != $#{$tags_rf;} @$forms_rf == 0
Truth table0%0/3
A or B
A= $#{$forms_rf;} != $#{$tags_rf;}B= @$forms_rf == 0
ABresult
1X1
011
000
49 0 log_warn "FORMS: @$forms_rf\n";
50 0 log_warn "TAGS: @$tags_rf\n";
51 0 log_fatal('Both arguments must be references to nonempty arrays of equal length.');
52 }
53  
54 0 ▶ if ( my @ret = grep { $_ =~ /^\s+$/ } ( @{$forms_rf}, @{$tags_rf} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@ret) = grep({$_ =~ /^\s+$/;} @{$forms_rf;}, @{$tags_rf;})) 0 0 0
55 0 log_debug("@ret");
56 0 log_fatal('Elements of argument arrays must not be empty and must not contain white-space characters');
57 }
58  
59 0 my @parents;
60 0 my $input = "";
61 0 my $writer = $self->{writer};
62 0 my $reader = $self->{reader};
63  
64 0 foreach my $form ( @$forms_rf ) {
65 0 my $tag = shift @$tags_rf;
66 0 $tag =~ s{-}{,}g;
67 0 $input .= $form . "\t" . $tag . "\n";
68 }
69 0 $input .= "EOS\n";
70  
71 0 print $writer $input;
72  
73 0 my $line = <$reader>;
74
75
76 #JDEPP uses different token ordering than Treex, because it creates "bunsetsus" out of multiple tokens (parsing is done on these "bunsetsus"
77 0 my @bun_heads;
78 0 my $current_token = 1;
79 0 ▶ while ( $line !~ "EOS") {
Branch: 1 branch
BranchTrueFalseTotal
unless ($line =~ /EOS/) 0 0 0
80  
81 0 ▶ log_fatal("Unitialized line (perhaps JDEPP was not initialized correctly).") if (!defined $line);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 0 0 0
82  
83 0 $line = <$reader>;
84 #log_info($_);
85 0 ▶ next if $line =~ /^#|EOS/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^#|EOS/ 0 0 0
86 0 ▶ if ( $line =~ /^\*/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\*/) { } 0 0 0
87 0 $line =~ s{^\*\s+}{};
88 0 (my $bun, my $parent) = split / /, $line;
89 0 $bun_heads[ $bun ] = $current_token;
90 0 $parent =~ s{D\n}{};
91 0 $parents[ $current_token - 1 ] = $parent
92 }
93 else {
94 0 ▶ if ( !defined $parents[ $current_token - 1 ] ) { $parents[ $current_token - 1 ] = -2; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $parents[$current_token - 1]) 0 0 0
95 0 $current_token += 1;
96 }
97 }
98  
99 0 $current_token = 1;
100 0 my $i = 0;
101 0 ▶ while ( defined $parents[ $i ] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parents[$i]) 0 0 0
102 0 ▶ if ( $parents[ $i ] >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parents[$i] >= 0) { } 0 0 0
103 0 my $parent = $bun_heads[ $parents[ $i ] ];
104 0 $parents[ $i ] = $parent;
105 0 $current_token = $i + 1;
106 } else {
107 0 ▶ if ( $parents[ $i ] == -2 ) { $parents[ $i ] = $current_token; }
Branch: 1 branch
BranchTrueFalseTotal
if ($parents[$i] == -2) { } 0 0 0
108 else {
109 0 $parents[ $i ] = 0;
110 0 $current_token = $i + 1;
111 }
112 }
113 0 $i += 1;
114 }
115
116 0 return \@parents;
117  
118 }
119  
120 # ----------------- cleaning up ------------------
121 # TODO : cleanup
122  
123 4 1;
124  
125 __END__
↑ Summary Block/W2A/JA/FixInterpunction.pm »