Block/Write/CoNLLX.pm

filter: Statementstmt 35.0% 27 / 77 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 20 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 50.0% 4 / 8 Podpod 0.0% 0 / 3 totaltotal 20.5% 31 / 151 CC 24 SCAR 51.2
CC
24
Cov
21%
process_atree
272.0
get_attribute
90.0
get_coarse_grained_tag
2.0
CRAP 166.7
« Block/W2A/BaseChunkParser.pm ↑ Summary Block/W2A/ResegmentSentences.pm »
1 package Treex::Block::Write::CoNLLX;
2 1 $Treex::Block::Write::CoNLLX::VERSION = '2.20151102';
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Treex::Core::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 extends 'Treex::Block::Write::BaseTextWriter';
8  
9 1 my %FALLBACK_FOR = ( 'pos' => 'tag', 'deprel' => 'afun', );
10  
11 1 has '+language' => ( required => 1 );
12 1 has 'deprel_attribute' => ( is => 'rw', isa => 'Str', default => 'autodetect' );
13 1 has 'pos_attribute' => ( is => 'rw', isa => 'Str', default => 'autodetect' );
14 1 has 'cpos_attribute' => ( is => 'rw', isa => 'Str', default => 'conll/cpos' );
15 1 has 'feat_attribute' => ( is => 'rw', isa => 'Str', default => 'conll/feat' );
16 1 has 'is_member_within_afun' => ( is => 'rw', isa => 'Bool', default => 0 );
17 1 has 'is_shared_modifier_within_afun' => ( is => 'rw', isa => 'Bool', default => 0 );
18 1 has 'is_coord_conjunction_within_afun' => ( is => 'rw', isa => 'Bool', default => 0 );
19 1 has 'randomly_select_sentences_ratio' => ( is => 'rw', isa => 'Num', default => 1 );
20  
21 0 ▶has _was => ( is => 'rw', default => sub{{}} );
Subroutine __ANON__: not called CC=1 SCAR=1.2
22  
23 1 has '+extension' => ( default => '.conll' );
24  
25 0 ▶sub process_atree {
Subroutine process_atree: not called CC=16 SCAR=56.1
Pod undocumented
26 0 my ( $self, $atree ) = @_;
27  
28 # if only random sentences are printed
29 0 ▶ return if rand() > $self->randomly_select_sentences_ratio;
Branch: 1 branch
BranchTrueFalseTotal
if rand() > $self->randomly_select_sentences_ratio 0 0 0
30 0 foreach my $anode ( $atree->get_descendants( { ordered => 1 } ) ) {
31 my ( $lemma, $pos, $cpos, $deprel ) =
32 0 map { $self->get_attribute( $anode, $_ ) }
33 (qw(lemma pos cpos deprel)); # "conll/" will be prefixed if needed; see get_attribute()
34  
35 #my $ctag = $self->get_coarse_grained_tag($tag);
36  
37 # append suffices to afuns
38 0 my $suffix = '';
39 0 ▶ $suffix .= 'M' if $self->is_member_within_afun && $anode->is_member;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_member_within_afun and $anode->is_member 0 0 0
Condition0%0/3
$self->is_member_within_afun and $anode->is_member
!ll&&!rl&&r
000
MC/DC0%0/2
$self->is_member_within_afun and $anode->is_member
$self->is_member_within_afun $anode->is_member
Truth table0%0/3
A and B
A= $self->is_member_within_afunB= $anode->is_member
ABresult
0X0
100
111
40 0 ▶ $suffix .= 'S' if $self->is_shared_modifier_within_afun && $anode->is_shared_modifier;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_shared_modifier_within_afun and $anode->is_shared_modifier 0 0 0
Condition0%0/3
$self->is_shared_modifier_within_afun and $anode->is_shared_modifier
!ll&&!rl&&r
000
MC/DC0%0/2
$self->is_shared_modifier_within_afun and $anode->is_shared_modifier
$self->is_shared_modifier_within_afun $anode->is_shared_modifier
Truth table0%0/3
A and B
A= $self->is_shared_modifier_within_afunB= $anode->is_shared_modifier
ABresult
0X0
100
111
41 0 ▶ $suffix .= 'C' if $self->is_coord_conjunction_within_afun && $anode->wild->{is_coord_conjunction};
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_coord_conjunction_within_afun and $anode->wild->{"is_coord_conjunction"} 0 0 0
Condition0%0/3
$self->is_coord_conjunction_within_afun and $anode->wild->{"is_coord_conjunction"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->is_coord_conjunction_within_afun and $anode->wild->{"is_coord_conjunction"}
$self->is_coord_conjunction_within_afun $anode->wild->{"is_coord_conjunction"}
Truth table0%0/3
A and B
A= $self->is_coord_conjunction_within_afunB= $anode->wild->{"is_coord_conjunction"}
ABresult
0X0
100
111
42 0 ▶ $deprel .= "_$suffix" if $suffix;
Branch: 1 branch
BranchTrueFalseTotal
if $suffix 0 0 0
43  
44 0 my $feat;
45 0 ▶ if ( $self->feat_attribute eq 'conll/feat' && defined $anode->conll_feat() ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->feat_attribute eq 'conll/feat' and defined $anode->conll_feat) { } 0 0 0
elsif ($self->feat_attribute eq 'iset') { } 0 0 0
Condition0%0/3
$self->feat_attribute eq "conll/feat" and defined $anode->conll_feat
!ll&&!rl&&r
000
MC/DC0%0/2
$self->feat_attribute eq "conll/feat" and defined $anode->conll_feat
$self->feat_attribute eq "conll/feat" defined $anode->conll_feat
Truth table0%0/3
A and B
A= $self->feat_attribute eq "conll/feat"B= defined $anode->conll_feat
ABresult
0X0
100
111
46 0 $feat = $anode->conll_feat();
47 }
48 elsif ( $self->feat_attribute eq 'iset' ) {
49 0 $feat = $anode->iset()->as_string_conllx();
50 }
51 else {
52 0 $feat = '_';
53 }
54 0 my $p_ord = $anode->get_parent->ord;
55 # Make sure that values are not empty and that they do not contain spaces.
56 0 my @values = ($anode->ord, $anode->form, $lemma, $cpos, $pos, $feat, $p_ord, $deprel);
57 @values = map
58 {
59 0 ▶ my $x = $_ // '_';
Condition0%0/2
$_ // "_"
l!l
00
MC/DC0%0/1
$_ // "_"
$_
Truth table0%0/2
A
A= $_
Aresult
11
00
60 0 $x =~ s/^\s+//;
61 0 $x =~ s/\s+$//;
62 0 $x =~ s/\s+/_/g;
63 0 ▶ $x = '_' if($x eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $x eq "" 0 0 0
64 0 $x
65 }
66 (@values);
67 0 print { $self->_file_handle } join( "\t", @values ) . "\n";
68 }
69 0 ▶ print { $self->_file_handle } "\n" if $atree->get_descendants;
Branch: 1 branch
BranchTrueFalseTotal
if $atree->get_descendants 0 0 0
70 0 return;
71 }
72  
73 0 ▶sub get_attribute {
Subroutine get_attribute: not called CC=9 SCAR=45.0
Pod undocumented
74 0 my ( $self, $anode, $name ) = @_;
75 0 ▶ my $from = $self->{ $name . '_attribute' } || $name; # TODO don't expect blessed hashref
Condition0%0/3
$$self{$name . '_attribute'} || $name
l!l&&r!l&&!r
000
MC/DC0%0/2
$$self{$name . '_attribute'} || $name
$$self{$name . '_attribute'} $name
Truth table0%0/3
A || B
A= $$self{$name . '_attribute'}B= $name
ABresult
1X1
011
000
76 0 my $value;
77 0 ▶ if ( $from eq 'autodetect' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from eq 'autodetect') { } 0 0 0
78 0 my $before = $self->_was->{$name};
79 0 ▶ if ( !defined $before ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $before) { } 0 0 0
80 0 $value = $anode->get_attr("conll/$name");
81 0 ▶ if ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 0 0 0
82 0 $self->_was->{$name} = "conll/$name";
83 }
84 else {
85 0 ▶ my $fallback = $FALLBACK_FOR{$name}
Branch: 1 branch
BranchTrueFalseTotal
my $fallback = $FALLBACK_FOR{$name} or log_fatal("No fallback for attribute $name") 0 0 0
86 or log_fatal "No fallback for attribute $name";
87 0 $value = $anode->get_attr($fallback);
88 0 $self->_was->{$name} = $fallback;
89 }
90 }
91 else {
92 0 $value = $anode->get_attr($before);
93 0 ▶ if ( !defined $value && $before =~ /^conll/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $value and $before =~ /^conll/) 0 0 0
Condition0%0/3
not defined $value and $before =~ /^conll/
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $value and $before =~ /^conll/
not defined $value $before =~ /^conll/
Truth table0%0/3
not(A) and B
A= not defined $valueB= $before =~ /^conll/
ABresult
0X0
100
111
94 0 my $id = $anode->get_address();
95 0 log_warn "Attribute $before not defined in $id"
96 . " but it was filled in some previous nodes."
97 . " Consider Write::CoNLLX with parameter ${name}_attribute != autodetect.";
98 }
99 }
100 }
101 else {
102 0 $value = $anode->get_attr($from);
103 }
104  
105 0 ▶ return defined $value ? $value : '_';
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 0 0 0
106 }
107  
108 0 ▶sub get_coarse_grained_tag {
Subroutine get_coarse_grained_tag: not called CC=1 SCAR=6.9
Pod undocumented
109 0 my ( $self, $tag ) = @_;
110 0 return substr $tag, 0, 2;
111 }
112  
113 1 1;
114  
115 __END__
« Block/W2A/BaseChunkParser.pm ↑ Summary Block/W2A/ResegmentSentences.pm »