| 1 | package Treex::Core::TredView::Labels; | ||||||||||||||||||||||||||||||||||
| 2 | 2 | $Treex::Core::TredView::Labels::VERSION = '2.20151210'; | |||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Treex::Core::TredView::Common; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Treex::Core::Log; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||
| 7 | 2 | has '_label_variants' => ( | |||||||||||||||||||||||||||||||||
| 8 | is => 'rw', | ||||||||||||||||||||||||||||||||||
| 9 | isa => 'HashRef[ArrayRef[Int]]', | ||||||||||||||||||||||||||||||||||
| 10 | builder => '_build_label_variants' | ||||||||||||||||||||||||||||||||||
| 11 | ); | ||||||||||||||||||||||||||||||||||
| 12 | 2 | has '_treex_doc' => ( | |||||||||||||||||||||||||||||||||
| 13 | is => 'ro', | ||||||||||||||||||||||||||||||||||
| 14 | isa => 'Treex::Core::Document', | ||||||||||||||||||||||||||||||||||
| 15 | weak_ref => 1, | ||||||||||||||||||||||||||||||||||
| 16 | required => 1 | ||||||||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||||||||
| 18 | has '_colors' => ( | ||||||||||||||||||||||||||||||||||
| 19 | is => 'ro', | ||||||||||||||||||||||||||||||||||
| 20 | isa => 'Treex::Core::TredView::Colors', | ||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | default => sub { Treex::Core::TredView::Colors->new() } | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 22 | 2 | ); | |||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||
| 24 | sub _build_label_variants { | ||||||||||||||||||||||||||||||||||
| 25 | return { | ||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | 'p' => [ 0, 0, 0 ], | ||||||||||||||||||||||||||||||||
|
Subroutine
_build_label_variants: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 27 | 'a' => [ 0, 0, 0 ], | ||||||||||||||||||||||||||||||||||
| 28 | 't' => [ 0, 0, 0 ], | ||||||||||||||||||||||||||||||||||
| 29 | 'n' => [ 0, 0, 0 ] | ||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||
| 33 | sub _get_label_variant { | ||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||
|
Subroutine
_get_label_variant: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||
| 35 | 0 | my ( $obj, $line ) = @_; | |||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | if ( ref $obj and not exists $obj->{_label_variants} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $obj and not exists $obj->{"_label_variants"}
MC/DC0%0/2
ref $obj and not exists $obj->{"_label_variants"}
ref $obj
not exists $obj->{"_label_variants"}
Truth table0%0/3
A and not(B)
A= ref $objB= not exists $obj->{"_label_variants"}
| |||||||||||||||||||||||||||||||||||
| 38 | 0 | $obj = $obj->get_layer; | |||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | if ( ref $obj ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||
| 43 | # $obj is a single node | ||||||||||||||||||||||||||||||||||
| 44 | 0 | return $obj->{_label_variants}[$line]; | |||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||
| 46 | else { | ||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||
| 48 | # $obj is the name of a layer | ||||||||||||||||||||||||||||||||||
| 49 | 0 | return $self->{_label_variants}{$obj}[$line]; | |||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||
| 53 | # a) $obj is a node => rotating label variant of the given node | ||||||||||||||||||||||||||||||||||
| 54 | # b) $obj is the name of a layer => rotating label variant of all nodes on the given layer | ||||||||||||||||||||||||||||||||||
| 55 | sub _rotate_label_variant { | ||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | my ( $self, $obj, $line ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
_rotate_label_variant: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||
| 57 | 0 | my $layer; | |||||||||||||||||||||||||||||||||
| 58 | my $current; | ||||||||||||||||||||||||||||||||||
| 59 | 0 | my $new; | |||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if ( ref $obj ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 62 | 0 | $layer = $obj->get_layer; | |||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if ( not exists $obj->{_label_variants} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | for ( my $i = 0; $i < 3; $i++ ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 65 | 0 | $obj->{_label_variants}[$i] = $self->_get_label_variant( $layer, $i ); | |||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||
| 68 | 0 | $current = $obj->{_label_variants}[$line]; | |||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||
| 70 | else { | ||||||||||||||||||||||||||||||||||
| 71 | 0 | $layer = $obj; | |||||||||||||||||||||||||||||||||
| 72 | 0 | $current = $self->_get_label_variant( $obj, $line ); | |||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||
| 74 | 0 | my $limit = $self->_label_variants->{ $layer . '_limit' }[$line]; | |||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | $new = $current >= $limit ? 0 : $current + 1; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | return if $current == $new; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if ( ref $obj ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 80 | 0 | $obj->{_label_variants}[$line] = $new | |||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||
| 82 | else { | ||||||||||||||||||||||||||||||||||
| 83 | 0 | $self->{_label_variants}{$layer}[$line] = $new | |||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||
| 86 | 0 | return 1; | |||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||
| 89 | sub set_labels { | ||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | my ( $self, $node ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
set_labels: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||
| 92 | 0 | my $buf = $node->{_precomputed_buffer}; | |||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | for ( my $i = 0; $i < 3; $i++ ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 94 | 0 | $node->{_precomputed_labels}[$i] = $buf->[$i][ $self->_get_label_variant( $node, $i ) ]; | |||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||
| 96 | 0 | return; | |||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||
| 99 | sub shift_labels { | ||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | my ( $self, $line, $mode ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
shift_labels: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 101 | 0 | my $node = Treex::Core::TredView::Common::cur_node(); | |||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | return if $node->is_root and $mode eq 'node'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$node->is_root and $mode eq "node"
MC/DC0%0/2
$node->is_root and $mode eq "node"
$node->is_root
$mode eq "node"
Truth table0%0/3
A and B
A= $node->is_rootB= $mode eq "node"
| |||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||
| 104 | 0 | my $layer = $node->get_layer; | |||||||||||||||||||||||||||||||||
| 105 | 0 | my @nodes; | |||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if ( $mode eq 'node' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | return if !$self->_rotate_label_variant( $node, $line ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 108 | 0 | @nodes = ($node); | |||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||
| 110 | else { | ||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | return if !$self->_rotate_label_variant( $layer, $line ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 112 | 0 | foreach my $bundle ( $self->_treex_doc->get_bundles ) { | |||||||||||||||||||||||||||||||||
| 113 | 0 | foreach my $zone ( $bundle->get_all_zones ) { | |||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | if ( $zone->has_tree($layer) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 115 | 0 | push @nodes, $zone->get_tree($layer)->get_descendants; | |||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||
| 119 | 0 | @nodes = grep { not exists $_->{_label_variants} } @nodes; | |||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||
| 122 | 0 | for my $node (@nodes) { | |||||||||||||||||||||||||||||||||
| 123 | 0 | $self->set_labels($node); | |||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||
| 125 | 0 | return; | |||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||
| 128 | sub reset_labels { | ||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | my ( $self, $mode ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
reset_labels: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 130 | 0 | my $node = Treex::Core::TredView::Common::cur_node(); | |||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | return if $node->is_root; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||
| 133 | 0 | my @nodes; | |||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | if ( $mode eq 'node' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 135 | 0 | @nodes = ($node); | |||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||
| 137 | else { | ||||||||||||||||||||||||||||||||||
| 138 | 0 | @nodes = $node->get_root->get_descendants; | |||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||
| 141 | 0 | for my $n (@nodes) { | |||||||||||||||||||||||||||||||||
| 142 | 0 | delete $n->{_label_variants}; | |||||||||||||||||||||||||||||||||
| 143 | 0 | $self->set_labels($n); | |||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||
| 145 | 0 | return; | |||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||
| 148 | sub set_limit { | ||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | my ( $self, $layer, $line, $limit ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
set_limit: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 150 | 0 | return $self->_label_variants->{ $layer . '_limit' }[$line] = $limit; | |||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||
| 153 | sub get_limits { | ||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | my ( $self, $layer ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
get_limits: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 155 | 0 | return $self->_label_variants->{ $layer . '_limit' }; | |||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||
| 158 | sub root_labels { | ||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | my ( $self, $root ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
root_labels: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | if ( $root->get_layer eq 'p' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 162 | 0 | my $buf = $self->_pnode_labels($root); | |||||||||||||||||||||||||||||||||
| 163 | 0 | return [ $buf->[0][0], $buf->[1][0], $buf->[2][0] ]; | |||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||
| 165 | else { | ||||||||||||||||||||||||||||||||||
| 166 | return [ | ||||||||||||||||||||||||||||||||||
| 167 | 0 | $root->get_layer . "-tree", | |||||||||||||||||||||||||||||||||
| 168 | "zone=" . $root->get_zone->get_label, | ||||||||||||||||||||||||||||||||||
| 169 | '' | ||||||||||||||||||||||||||||||||||
| 170 | ]; | ||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||
| 174 | sub node_labels { | ||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | my ( $self, $node ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
node_labels: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 176 | 0 | my $layer = $node->get_layer; | |||||||||||||||||||||||||||||||||
| 177 | 0 | my %subs; | |||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||
| 179 | 0 | $subs{t} = \&_tnode_labels; | |||||||||||||||||||||||||||||||||
| 180 | 0 | $subs{a} = \&_anode_labels; | |||||||||||||||||||||||||||||||||
| 181 | 0 | $subs{n} = \&_nnode_labels; | |||||||||||||||||||||||||||||||||
| 182 | 0 | $subs{p} = \&_pnode_labels; | |||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | if ( defined $subs{$layer} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 184 | 0 | return &{ $subs{$layer} }( $self, $node ); | |||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||
| 186 | else { | ||||||||||||||||||||||||||||||||||
| 187 | 0 | log_fatal "Undefined or unknown layer: $layer"; | |||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||
| 191 | sub _anode_labels { | ||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | my ( $self, $node ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
_anode_labels: not called CC=24 SCAR=64.0
| |||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||
| 194 | 0 | my $line1 = ''; | |||||||||||||||||||||||||||||||||
| 195 | 0 | my $par = 0; | |||||||||||||||||||||||||||||||||
| 196 | 0 | my $n = $node; | |||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | while ( ( not $par ) and $n ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $par and $n
MC/DC0%0/2
not $par and $n
not $par
$n
Truth table0%0/3
not(A) and B
A= not $parB= $n
| |||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | if ( $n->{is_parenthesis_root} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 199 | 0 | $par = 1; | |||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||
| 201 | 0 | $n = $n->parent; | |||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | if ($par) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 204 | 0 | $line1 = $self->_colors->get( 'parenthesis', 1 ); | |||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | if ( defined($node->form) ){ | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 207 | 0 | $line1 .= $node->form; | |||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||
| 209 | elsif ( defined($node->lemma) ){ | ||||||||||||||||||||||||||||||||||
| 210 | 0 | $line1 .= $self->_colors->get( 'error', 1 ) . $node->lemma; | |||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | my $edge_label = $node->deprel || $node->afun || $node->conll_deprel; | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
$node->deprel || $node->afun || $node->conll_deprel
$node->deprel or $node->afun
MC/DC0%0/3
$node->deprel || $node->afun || $node->conll_deprel
$node->deprel
$node->afun
$node->conll_deprel
Truth table0%0/4
A or B || C
A= $node->deprelB= $node->afunC= $node->conll_deprel
| |||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | my $color = $edge_label && $edge_label ne 'NR' ? $self->_colors->get( 'afun', 1 ) : $self->_colors->get( 'error', 1 ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$edge_label and $edge_label ne "NR"
MC/DC0%0/2
$edge_label and $edge_label ne "NR"
$edge_label
$edge_label ne "NR"
Truth table0%0/3
A and B
A= $edge_labelB= $edge_label ne "NR"
| |||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | my $line2 = $color . ( $edge_label || '!!' ); | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$edge_label || '!!'
MC/DC0%0/1
$edge_label || '!!'
$edge_label
Truth table0%0/2
A
A= $edge_label
| |||||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | if ( $node->is_member ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 217 | 0 | my $parent = $node->parent; | |||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | while ( $parent && ( ( $parent->afun || '' ) =~ m/^Aux[CP]$/ ) ) #skip AuxCP | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$parent and ($parent->afun || "") =~ /^Aux[CP]$/
$parent->afun || ''
MC/DC0%0/2
$parent and ($parent->afun || "") =~ /^Aux[CP]$/
$parent
$parent->afun
Truth table0%0/3
A and B
A= $parentB= $parent->afun
| |||||||||||||||||||||||||||||||||||
| 219 | { | ||||||||||||||||||||||||||||||||||
| 220 | 0 | $parent = $parent->parent; | |||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | if ( $parent->afun =~ m/^(Ap)os|(Co)ord/ ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | $line2 .= '_' . $self->_colors->get( 'member', 1 ) . ( $1 ? $1 : $2 ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | if ( $node->translit ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 227 | 0 | $line2 .= ' ' . $self->_colors->get( 'translit', 1 ) . $node->translit; | |||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | if ( $node->gloss ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 230 | 0 | $line2 .= ' ' . $self->_colors->get( 'gloss', 1 ) . $node->gloss; | |||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | my $line3_1 = $node->tag ? $node->tag : ''; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | my $line3_2 = $node->lemma ? $node->lemma : ''; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||
| 236 | # DZ: This hack tries to distinguish Dan's CoNLL trees from Pepa's PEDT trees | ||||||||||||||||||||||||||||||||||
| 237 | # so that Czech tags don't get crippled in the former. | ||||||||||||||||||||||||||||||||||
| 238 | # if ( $node->language eq 'cs' ) { | ||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | if ( $node->language eq 'cs' && !$node->conll_cpos ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$node->language eq "cs" and not $node->conll_cpos
MC/DC0%0/2
$node->language eq "cs" and not $node->conll_cpos
$node->language eq "cs"
not $node->conll_cpos
Truth table0%0/3
A and not(B)
A= $node->language eq "cs"B= not $node->conll_cpos
| |||||||||||||||||||||||||||||||||||
| 240 | 0 | $line3_1 = $self->_shorten_czech_tag( $line3_1 ); | |||||||||||||||||||||||||||||||||
| 241 | 0 | $line3_2 =~ s/(.)(?:-[1-9][0-9]*)?(?:(?:`|_[:;,^]).*)?$/$1/; | |||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||
| 244 | 0 | $line3_1 = $self->_colors->get( 'tag', 1 ) . $line3_1; | |||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||
| 246 | return [ | ||||||||||||||||||||||||||||||||||
| 247 | 0 | [$line1], | |||||||||||||||||||||||||||||||||
| 248 | [$line2], | ||||||||||||||||||||||||||||||||||
| 249 | [ $line3_1, $line3_2 ] | ||||||||||||||||||||||||||||||||||
| 250 | ]; | ||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||
| 253 | sub _shorten_czech_tag { | ||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | my ($self, $tag) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
_shorten_czech_tag: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||
| 256 | # nouns, adjectives, pronouns, declinable numerals: gender, number, case | ||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | if ($tag =~ m/^(N|C[adhjklnrwyz\?]|P|A)/){ | ||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||
| 258 | 0 | $tag = substr( $tag, 0, 2 ) . $self->_colors->get( 'tag_feat', 1 ) . substr( $tag, 2, 3 ); | |||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||
| 260 | # prepositions: just case | ||||||||||||||||||||||||||||||||||
| 261 | elsif ($tag =~ m/^R/ ){ | ||||||||||||||||||||||||||||||||||
| 262 | 0 | $tag = substr( $tag, 0, 2 ) . $self->_colors->get( 'tag_feat', 1 ) . substr( $tag, 4, 1 ); | |||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||
| 264 | # verbs (except infinitives, conditionals): gender, number, person, tense, voice | ||||||||||||||||||||||||||||||||||
| 265 | elsif ($tag =~ m/^V[^cf]/ ){ | ||||||||||||||||||||||||||||||||||
| 266 | 0 | $tag = substr( $tag, 0, 2) . $self->_colors->get( 'tag_feat', 1 ) | |||||||||||||||||||||||||||||||||
| 267 | . substr( $tag, 2, 2 ) . substr( $tag, 7, 2 ) . substr( $tag, 11, 1 ); | ||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||
| 269 | else { | ||||||||||||||||||||||||||||||||||
| 270 | 0 | $tag = substr( $tag, 0, 2 ); | |||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||
| 272 | 0 | return $tag; | |||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||
| 275 | sub _tnode_labels { | ||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | my ( $self, $node ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
_tnode_labels: not called CC=19 SCAR=59.4
| |||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||
| 278 | 0 | my $line1 = $node->t_lemma; | |||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | if ( $node->is_parenthesis ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 280 | 0 | $line1 = $self->_colors->get( 'parenthesis', 1 ) . $line1; | |||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | if ( $node->sentmod ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 283 | 0 | $line1 .= $self->_colors->get( 'sentmod', 1 ) . '.' . $node->sentmod; | |||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||
| 286 | 0 | foreach my $type ( 'compl', 'coref_text', 'coref_gram' ) { | |||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | if ( defined $node->{ $type . '.rf' } ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 288 | 0 | foreach my $ref ( TredMacro::ListV( $node->{ $type . '.rf' } ) ) { | |||||||||||||||||||||||||||||||||
| 289 | 0 | my $ref_node = $self->_treex_doc->get_node_by_id($ref); | |||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | if ( $node->get_bundle->get_position() != $ref_node->get_bundle->get_position() ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 291 | 0 | $line1 .= ' ' . $self->_colors->get( $type, 1 ) . $ref_node->{t_lemma}; | |||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||
| 297 | 0 | my $line2 = $node->{functor}; | |||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | $line2 .= $self->_colors->get( 'subfunctor', 1 ) . '.' . $node->{subfunctor} if $node->{subfunctor}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 299 | 0 | ▶ | $line2 .= $self->_colors->get( 'subfunctor', 1 ) . '.state' if $node->{is_state}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | $line2 .= $self->_colors->get( 'subfunctor', 1 ) . '.dsp_root' if $node->{is_dsp_root}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | $line2 .= $self->_colors->get( 'member', 1 ) . '.member' if $node->{is_member}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | $line2 .= $self->_colors->get( 'formeme', 1 ) . ' ' . $node->formeme if $node->formeme; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||
| 304 | 0 | my @a_nodes = (); | |||||||||||||||||||||||||||||||||
| 305 | 0 | my $line3_1 = ''; | |||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | if ( defined $node->attr('a/aux.rf') ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 307 | 0 | @a_nodes = TredMacro::ListV( $node->attr('a/aux.rf') ); | |||||||||||||||||||||||||||||||||
| 308 | 0 | @a_nodes = map { $self->_treex_doc->get_node_by_id($_) } @a_nodes; | |||||||||||||||||||||||||||||||||
| 309 | 0 | @a_nodes = map { { form => $_->{form}, ord => $_->{ord}, type => 'aux' } } @a_nodes; | |||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | if ( defined $node->attr('a/lex.rf') ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 312 | 0 | my $a_node = $self->_treex_doc->get_node_by_id( $node->attr('a/lex.rf') ); | |||||||||||||||||||||||||||||||||
| 313 | 0 | push @a_nodes, { form => $a_node->{form}, ord => $a_node->{ord}, type => 'lex' }; | |||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | if (@a_nodes) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 316 | 0 | @a_nodes = sort { $a->{ord} <=> $b->{ord} } @a_nodes; | |||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | @a_nodes = map { ( $_->{type} eq 'lex' ? $self->_colors->get( 'lex', 1 ) : $self->_colors->get( 'aux', 1 ) ) . ( $_->{form} // '' ) } @a_nodes; #/ | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$_->{"form"} // ""
MC/DC0%0/1
$_->{"form"} // ""
$_->{"form"}
Truth table0%0/2
A
A= $_->{"form"}
| |||||||||||||||||||||||||||||||||||
| 318 | 0 | $line3_1 = join " ", @a_nodes; | |||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | my $line3_2 = $self->_colors->get( 'nodetype', 1 ) . ($node->{nodetype} || ''); | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$node->{'nodetype'} || ''
MC/DC0%0/1
$node->{'nodetype'} || ''
$node->{'nodetype'}
Truth table0%0/2
A
A= $node->{'nodetype'}
| |||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | $line3_2 .= $self->_colors->get( 'sempos', 1 ) . '.' . $node->attr('gram/sempos') if $node->attr('gram/sempos'); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||
| 324 | return [ | ||||||||||||||||||||||||||||||||||
| 325 | 0 | [$line1], | |||||||||||||||||||||||||||||||||
| 326 | [$line2], | ||||||||||||||||||||||||||||||||||
| 327 | [ $line3_1, $line3_2 ] | ||||||||||||||||||||||||||||||||||
| 328 | ]; | ||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||
| 331 | sub _nnode_labels { | ||||||||||||||||||||||||||||||||||
| 332 | 0 | ▶ | my ( $self, $node ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
_nnode_labels: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 333 | return [ | ||||||||||||||||||||||||||||||||||
| 334 | [ $node->{normalized_name} ], | ||||||||||||||||||||||||||||||||||
| 335 | 0 | [ $node->{ne_type} ], | |||||||||||||||||||||||||||||||||
| 336 | [] | ||||||||||||||||||||||||||||||||||
| 337 | ]; | ||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||
| 340 | sub _pnode_labels { | ||||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | my ( $self, $node ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
_pnode_labels: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||
| 343 | # my $terminal = $node->get_pml_type_name eq 'p-terminal.type' ? 1 : 0; | ||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||
| 345 | 0 | my $line1 = ''; | |||||||||||||||||||||||||||||||||
| 346 | 0 | my $line2 = ''; | |||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | my $edgelabel = $node->edgelabel() ? '/'.$node->edgelabel() : ''; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 348 | # print "$node is_leaf ".$node->is_leaf."\n"; | ||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | if ( $node->is_leaf ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 350 | 0 | $line1 = $node->{form}; | |||||||||||||||||||||||||||||||||
| 351 | 0 | $line2 = $node->{tag}.$edgelabel; | |||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | $line2 = '-' if $line2 eq '-NONE-'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||
| 354 | else { | ||||||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | my $phrase = $node->{phrase} ? $node->{phrase} : ''; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 356 | 0 | $line1 = $self->_colors->get( 'phrase', 1 ) . $phrase.$edgelabel . '#{black}' . join( '', map {"-$_"} TredMacro::ListV( $node->{functions} ) ); | |||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||
| 359 | return [ | ||||||||||||||||||||||||||||||||||
| 360 | 0 | [$line1], | |||||||||||||||||||||||||||||||||
| 361 | [$line2], | ||||||||||||||||||||||||||||||||||
| 362 | [''] | ||||||||||||||||||||||||||||||||||
| 363 | ]; | ||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||
| 366 | 2 | 1; | |||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||
| 368 | __END__ | ||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||
| 370 | =pod | ||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||
| 372 | =encoding utf-8 | ||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||
| 374 | =head1 NAME | ||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||
| 376 | Treex::Core::TredView::Labels - Labels of tree nodes in Tred | ||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||
| 378 | =head1 VERSION | ||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||
| 380 | version 2.20151210 | ||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||
| 382 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||
| 384 | This packages provides labels for the nodes displayed in Tred and related | ||||||||||||||||||||||||||||||||||
| 385 | functionality. | ||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||
| 387 | =head1 METHODS | ||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||
| 389 | =head2 Public methods | ||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||
| 391 | =over 4 | ||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||
| 393 | =item set_labels | ||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||
| 395 | =item shift_labels | ||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||
| 397 | =item reset_labels | ||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||
| 399 | =item set_limit | ||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||
| 401 | =item root_labels | ||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||
| 403 | =item node_labels | ||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||
| 405 | =back | ||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||
| 407 | =head2 Private methods | ||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||
| 409 | =over 4 | ||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||
| 411 | =item _build_label_variants | ||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||
| 413 | =item _get_label_variant | ||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||
| 415 | =item _rotate_label_variant | ||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||
| 417 | =item _anode_labels | ||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||
| 419 | =item _tnode_labels | ||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||
| 421 | =item _nnode_labels | ||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||
| 423 | =item _pnode_labels | ||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||
| 425 | =back | ||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||
| 427 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||
| 429 | Josef Toman <toman@ufal.mff.cuni.cz> | ||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||
| 431 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||
| 433 | Copyright © 2011 by Institute of Formal and Applied Linguistics, Charles University in Prague | ||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||
| 435 | This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||