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