Treex/Core/TredView.pm

filter: Statementstmt 11.0% 59 / 532 Branchbran 0.0% 0 / 210 Conditioncond 0.0% 0 / 75 MC/DCmcdc 0.0% 0 / 43 Subroutinesub 25.0% 12 / 48 Podpod 29.1% 7 / 24 totaltotal 8.3% 78 / 932 CC 173 SCAR 55.3
CC
173
Cov
7%
get_nodelist_hook
870.0
node_style_hook
650.0
get_clickable_sentence_for_a_zone
272.0
CRAP 252.9
« Treex/Core/Phrase/Coordination.pm ↑ Summary Treex/Core/Resource.pm »
1 package Treex::Core::TredView;
2 1 $Treex::Core::TredView::VERSION = '2.20210102';
3 # planned to be used from contrib.mac of tred's extensions
4  
5 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Treex::Core::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Treex::Core::TredView::TreeLayout;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Treex::Core::TredView::Labels;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Treex::Core::TredView::Styles;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Treex::Core::TredView::Vallex;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Treex::Core::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Scalar::Util qw(blessed refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use List::Util qw(first);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Cache::LRU;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 ▶use Treex::Core::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 $Treex::Core::Config::running_in_tred = 1;
18  
19 1 has 'grp' => ( is => 'rw' );
20 1 has 'pml_doc' => ( is => 'rw' );
21 has 'doc_cache' => (
22 is => 'ro',
23 isa => 'Cache::LRU',
24 0 ▶ default => sub { Cache::LRU->new(size => 20); }
Subroutine __ANON__: not called CC=1 SCAR=6.9
25 1 );
26 1 has 'treex_doc' => ( is => 'rw' );
27 has 'tree_layout' => (
28 is => 'ro',
29 isa => 'Treex::Core::TredView::TreeLayout',
30 0 ▶ default => sub { Treex::Core::TredView::TreeLayout->new() }
Subroutine __ANON__: not called CC=1 SCAR=6.9
31 1 );
32  
33 1 has 'labels' => (
34 is => 'ro',
35 isa => 'Treex::Core::TredView::Labels',
36 writer => '_set_labels',
37 );
38  
39 1 has '_styles' => (
40 is => 'ro',
41 isa => 'Treex::Core::TredView::Styles',
42 writer => '_set_styles',
43 );
44  
45 1 has 'vallex' => (
46 is => 'ro',
47 isa => 'Treex::Core::TredView::Vallex',
48 writer => '_set_vallex',
49 );
50  
51 1 has fast_loading => (
52 is => 'ro',
53 isa => 'Bool',
54 default => 1,
55 documentation => 'Do the precomputation lazily for each bundle',
56 );
57  
58 has _displayed_nodes => (
59 is => 'rw',
60 isa => 'HashRef[Treex::Core::Node]',
61 0 ▶ default => sub { {} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
62 1 );
63 has _ptb_index_map => (
64 is => 'rw',
65 isa => 'HashRef[Treex::Core::Node::P]',
66 0 ▶ default => sub { {} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
67 1 );
68 has _ptb_coindex_map => (
69 is => 'rw',
70 isa => 'HashRef[Treex::Core::Node::P]',
71 0 ▶ default => sub { {} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
72 1 );
73  
74 1 has 'clause_collapsing' => ( is => 'rw', isa => 'Bool', default => 0 );
75 1 has 'show_alignment' => ( is => 'rw', isa => 'Bool', default => 1 );
76  
77 0 ▶has 'tree_type_to_wrap' => ( is => 'rw', isa => 'HashRef', default => sub { {} } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
78  
79 0 ▶sub _spread_nodes {
Subroutine _spread_nodes: not called CC=5 SCAR=34.0
80 0 my ( $self, $node ) = @_;
81  
82 0 my ( $left, $right, $gap, $pos ) = ( -1, 0, 0, 0 );
83 0 my ( @buf, @lower );
84 0 for my $child ( $node->children ) {
85 0 ( $pos, @buf ) = $self->_spread_nodes($child);
86 0 ▶ if ( $left < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($left < 0) 0 0 0
87 0 $left = $pos;
88 }
89 0 $right += $gap;
90 0 $gap = scalar(@buf);
91 0 push @lower, @buf;
92 }
93 0 $right += $pos;
94 0 ▶ return ( 0, $node ) if !@lower;
Branch: 1 branch
BranchTrueFalseTotal
unless @lower 0 0 0
95  
96 0 my $mid;
97 0 ▶ if ( scalar( $node->children ) == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar $node->children == 1) { } 0 0 0
98 0 $mid = int( ( $#lower + 1 ) / 2 - 1 );
99 }
100 else {
101 0 $mid = int( ( $left + $right ) / 2 );
102 }
103  
104 0 return ( $mid + 1 ), @lower[ 0 .. $mid ], $node, @lower[ ( $mid + 1 ) .. $#lower ];
105 }
106  
107 0 ▶sub _pmldoc_equals {
Subroutine _pmldoc_equals: not called CC=3 SCAR=24.8
108 0 my ($self, $fsfile) = @_;
109 0 ▶ return ($self->pml_doc && $fsfile && refaddr($self->pml_doc) == refaddr($fsfile));
Condition0%0/6
$self->pml_doc && $fsfile && builtin::refaddr($self->pml_doc) == builtin::refaddr($fsfile)
!ll&&!rl&&r
000
$self->pml_doc and $fsfile
!ll&&!rl&&r
000
MC/DC0%0/3
$self->pml_doc && $fsfile && builtin::refaddr($self->pml_doc) == builtin::refaddr($fsfile)
$self->pml_doc $fsfile builtin::refaddr($self->pml_doc) == builtin::refaddr($fsfile)
Truth table0%0/4
A and B && C
A= $self->pml_docB= $fsfileC= builtin::refaddr($self->pml_doc) == builtin::refaddr($fsfile)
ABCresult
0XX0
10X0
1100
1111
110 }
111  
112 0 ▶sub get_nodelist_hook {
Subroutine get_nodelist_hook: not called CC=29 SCAR=67.7
Pod documented
113 0 my ( $self, $fsfile, $treeNo, $currentNode ) = @_;
114  
115 #return if not $self->pml_doc(); # get_nodelist_hook is invoked also before file_opened_hook
116  
117 0 ▶ unless ($self->_pmldoc_equals($fsfile)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_pmldoc_equals($fsfile)) 0 0 0
118 0 $self->file_opened_hook($fsfile);
119 }
120  
121 0 my $bundle = $fsfile->tree($treeNo);
122 0 bless $bundle, 'Treex::Core::Bundle'; # TODO: how to make this automatically?
123 # Otherwise (in certain circumstances) $bundle->get_all_zones
124 # results in Can't locate object method "get_all_zones" via package "Treex::PML::Node" at /ha/work/people/popel/tectomt/treex/lib/Treex/Core/TredView.pm line 22
125  
126 0 my $layout = $self->tree_layout->get_layout();
127 0 $self->{'_ptb_index_map'} = {};
128 0 $self->{'_ptb_coindex_map'} = {};
129 0 my %nodes;
130  
131 0 ▶ foreach my $tree ( map { ref($_) eq 'Treex::Core::BundleZone' ? $_->get_all_trees : () } $bundle->get_all_zones ) {
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'Treex::Core::BundleZone' ? : 0 0 0
132 0 my $label = $self->tree_layout->get_tree_label($tree);
133 0 my @nodes;
134 0 ▶ if ( $tree->get_layer eq 'p' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($tree->get_layer eq 'p') { } 0 0 0
elsif ($self->tree_type_to_wrap->{$self->_tree_type_signature($tree)}) { } 0 0 0
elsif ($tree->does('Treex::Core::Node::Ordered')) { } 0 0 0
135 0 @nodes = $self->_spread_nodes($tree);
136 0 shift @nodes;
137 0 foreach my $node (@nodes) {
138 0 ▶ $self->{'_ptb_index_map'}->{ $node->{'index'} } = $node if defined $node->{'index'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $node->{"index"} 0 0 0
139 0 ▶ $self->{'_ptb_coindex_map'}->{ $node->{'coindex'} } = $node if defined $node->{'coindex'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $node->{"coindex"} 0 0 0
140 }
141 }
142  
143 elsif ( $self->tree_type_to_wrap->{$self->_tree_type_signature($tree)} ) {
144 0 @nodes = $tree;
145 }
146  
147 elsif ( $tree->does('Treex::Core::Node::Ordered') ) {
148 0 @nodes = $tree->get_descendants( { add_self => 1, ordered => 1 } );
149 }
150 else {
151 0 @nodes = $tree->get_descendants( { add_self => 1 } );
152 }
153 0 $nodes{$label} = \@nodes;
154 }
155  
156 0 ▶ my $pick_next_tree = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
157 0 my @task = @_;
158 0 my $max = 0;
159 0 my $max_index = -1;
160  
161 0 ▶ for ( my $i = 0; $i < scalar @task; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @task) 0 0 0
162 0 my $val = $task[$i]{'left'} / $task[$i]{'total'};
163 0 ▶ if ( $val > $max ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val > $max) 0 0 0
164 0 $max = $val;
165 0 $max_index = $i;
166 }
167 }
168  
169 0 return $max_index;
170 0 };
171  
172 0 my @nodes = ($bundle);
173  
174 0 ▶ for ( my $col = 0; $col < scalar @$layout; $col++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($col < scalar @$layout) 0 0 0
175 0 my @task = ();
176 0 ▶ for ( my $row = 0; $row < scalar @{ $layout->[$col] }; $row++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row < scalar @{$layout->[$col];}) 0 0 0
177 0 ▶ if ( $layout->[$col][$row] and $layout->[$col][$row]->{'visible'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($layout->[$col][$row] and $layout->[$col][$row]{"visible"}) 0 0 0
Condition0%0/3
$layout->[$col][$row] and $layout->[$col][$row]{"visible"}
!ll&&!rl&&r
000
MC/DC0%0/2
$layout->[$col][$row] and $layout->[$col][$row]{"visible"}
$layout->[$col][$row] $layout->[$col][$row]{"visible"}
Truth table0%0/3
A and B
A= $layout->[$col][$row]B= $layout->[$col][$row]{"visible"}
ABresult
0X0
100
111
178 0 my $label = $layout->[$col][$row]->{'label'};
179 0 my %tree_info = ();
180 0 $tree_info{'total'} = $tree_info{'left'} = scalar @{ $nodes{$label} };
181 0 $tree_info{'label'} = $label;
182 0 push @task, \%tree_info;
183 }
184 }
185  
186 0 ▶ while ( ( my $index = &$pick_next_tree(@task) ) >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ((my $index = &$pick_next_tree(@task)) >= 0) 0 0 0
187 0 push @nodes, shift @{ $nodes{ $task[$index]{'label'} } };
188 0 $task[$index]{'left'}--;
189 }
190 }
191  
192 # only nodes having different clause number from their parents are
193 # displayed if node-collapsing is switched on
194 0 ▶ if ( ( $self->clause_collapsing || 0 ) != ( $bundle->{_is_collapsed} || 0 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($self->clause_collapsing || 0) != ($bundle->{"_is_collapsed"} || 0)) 0 0 0
Condition0%0/4
$self->clause_collapsing || 0
l!l
00
$bundle->{'_is_collapsed'} || 0
l!l
00
MC/DC0%0/1
$self->clause_collapsing || 0
$self->clause_collapsing
MC/DC0%0/1
$bundle->{'_is_collapsed'} || 0
$bundle->{'_is_collapsed'}
Truth table0%0/2
A
A= $self->clause_collapsing
Aresult
11
00
Truth table0%0/2
A
A= $bundle->{'_is_collapsed'}
Aresult
11
00
195 0 $self->clause_collapsing( $bundle->{_is_collapsed} );
196 }
197 0 ▶ if ( $self->clause_collapsing ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->clause_collapsing) 0 0 0
198 0 my %root;
199 0 foreach my $node ( grep { $_->isa('Treex::Core::Node::A') } @nodes ) {
200 0 ▶ if ( defined $node->clause_number ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $node->clause_number) 0 0 0
201 0 $root{$node} = $node->get_clause_root;
202 }
203 }
204 0 my %hide;
205 0 foreach my $node ( grep { $_->isa('Treex::Core::Node::A') } @nodes ) {
206 0 ▶ if ( defined $node->clause_number and $root{$node} ne $node ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $node->clause_number and $root{$node} ne $node) 0 0 0
Condition0%0/3
defined $node->clause_number and $root{$node} ne $node
!ll&&!rl&&r
000
MC/DC0%0/2
defined $node->clause_number and $root{$node} ne $node
defined $node->clause_number $root{$node} ne $node
Truth table0%0/3
A and B
A= defined $node->clause_numberB= $root{$node} ne $node
ABresult
0X0
100
111
207 0 $hide{$node} = 1;
208 }
209 }
210 0 @nodes = grep { !$hide{$_} } @nodes;
211 0 foreach my $node ( grep { $_->isa('Treex::Core::Node::A') } @nodes ) {
212 0 my $parent = $node->get_parent;
213 0 ▶ if ( $parent and $hide{$parent} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent and $hide{$parent}) 0 0 0
Condition0%0/3
$parent and $hide{$parent}
!ll&&!rl&&r
000
MC/DC0%0/2
$parent and $hide{$parent}
$parent $hide{$parent}
Truth table0%0/3
A and B
A= $parentB= $hide{$parent}
ABresult
0X0
100
111
214 0 $node->set_parent( $root{$parent} );
215 }
216 }
217 }
218  
219 0 $self->{'_displayed_nodes'} = { map { $_->attr('id') => 1 } @nodes };
220  
221 0 ▶ unless ( $currentNode and ( first { $_ == $currentNode } @nodes ) ) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless ($currentNode and &first(sub { $_ == $currentNode; } , @nodes)) 0 0 0
Condition0%0/3
$currentNode and &first(sub { $_ == $currentNode; } , @nodes)
!ll&&!rl&&r
000
MC/DC0%0/2
$currentNode and &first(sub { $_ == $currentNode; } , @nodes)
$currentNode &first(sub { $_ == $currentNode; } , @nodes)
Truth table0%0/3
A and B
A= $currentNodeB= &first(sub { $_ == $currentNode; } , @nodes)
ABresult
0X0
100
111
222 0 $currentNode = $nodes[0];
223 }
224  
225 0 return [ \@nodes, $currentNode ];
226 }
227  
228 0 ▶sub recompute_visualization {
Subroutine recompute_visualization: not called CC=1 SCAR=6.9
Pod undocumented
229 0 my ( $self, $bundle ) = @_;
230 0 $self->precompute_tree_depths($bundle);
231 0 $self->precompute_tree_shifts($bundle);
232 0 $self->precompute_visualization($bundle);
233 0 $self->precompute_value_line($bundle);
234 0 return;
235 }
236  
237 0 ▶sub file_opened_hook {
Subroutine file_opened_hook: not called CC=11 SCAR=48.8
Pod documented
238 0 my ($self, $fsfile) = @_;
239 0 ▶ my $pmldoc = $fsfile || $self->grp()->{FSFile};
Condition0%0/3
$fsfile || $self->grp->{'FSFile'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$fsfile || $self->grp->{'FSFile'}
$fsfile $self->grp->{'FSFile'}
Truth table0%0/3
A || B
A= $fsfileB= $self->grp->{'FSFile'}
ABresult
1X1
011
000
240  
241 0 ▶ return unless $pmldoc && $pmldoc->metaData('schema') &&
Branch: 1 branch
BranchTrueFalseTotal
unless $pmldoc and $pmldoc->metaData("schema") and $pmldoc->metaData("schema")->get_root_name eq "treex_document" 0 0 0
Condition0%0/6
$pmldoc and $pmldoc->metaData("schema") and $pmldoc->metaData("schema")->get_root_name eq "treex_document"
!ll&&!rl&&r
000
$pmldoc and $pmldoc->metaData("schema")
!ll&&!rl&&r
000
MC/DC0%0/3
$pmldoc and $pmldoc->metaData("schema") and $pmldoc->metaData("schema")->get_root_name eq "treex_document"
$pmldoc $pmldoc->metaData("schema") $pmldoc->metaData("schema")->get_root_name eq "treex_document"
Truth table0%0/4
A and B and C
A= $pmldocB= $pmldoc->metaData("schema")C= $pmldoc->metaData("schema")->get_root_name eq "treex_document"
ABCresult
0XX0
10X0
1100
1111
242 $pmldoc->metaData('schema')->get_root_name() eq 'treex_document';
243  
244 0 ▶ return if $self->_pmldoc_equals($pmldoc);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_pmldoc_equals($pmldoc) 0 0 0
245  
246 0 $self->pml_doc($pmldoc);
247  
248 0 my $treex_doc = $self->doc_cache->get(refaddr($self->pml_doc));
249 0 ▶ unless ($treex_doc) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($treex_doc) 0 0 0
250 0 ▶ if ( defined $pmldoc->[13]->{_treex_core_document} ) { # if it comes from storable (i.e., already with moose)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pmldoc->[13]{'_treex_core_document'}) { } 0 0 0
251 0 $treex_doc = $pmldoc->[13]->{_treex_core_document};
252  
253 # streex files do not have "wild_dump" filled, but we want to show this in ttred
254 0 $treex_doc->_serialize_all_wild();
255 } else {
256 0 $treex_doc = Treex::Core::Document->new( { pmldoc => $pmldoc } );
257 }
258 0 $self->doc_cache->set(refaddr($self->pml_doc), $treex_doc);
259 }
260  
261 0 $self->treex_doc($treex_doc);
262  
263 # labels, styles and vallex must be created again for each file
264 0 $self->_set_labels( Treex::Core::TredView::Labels->new( _treex_doc => $treex_doc ) );
265 0 $self->_set_styles( Treex::Core::TredView::Styles->new( _treex_doc => $treex_doc ) );
266 0 $self->_set_vallex( Treex::Core::TredView::Vallex->new( _treex_doc => $treex_doc ) );
267  
268 0 foreach my $bundle ( $treex_doc->get_bundles() ) {
269  
270 # If we don't care about slow loading of the whole file,
271 # we can precompute all bundles now, so browsing through bundles
272 # will be a bit faster.
273 0 ▶ if ( !$self->fast_loading && !$bundle->{_precomputed} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->fast_loading or $bundle->{"_precomputed"}) 0 0 0
Condition0%0/3
$self->fast_loading or $bundle->{"_precomputed"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->fast_loading or $bundle->{"_precomputed"}
$self->fast_loading $bundle->{"_precomputed"}
Truth table0%0/3
A or B
A= $self->fast_loadingB= $bundle->{"_precomputed"}
ABresult
1X1
011
000
274 0 $self->precompute_tree_depths($bundle);
275 0 $self->precompute_tree_shifts($bundle);
276 0 $self->precompute_visualization($bundle);
277 0 $bundle->{_precomputed} = 1;
278 }
279  
280 # Root style cannot be precomputed lazily, because
281 # root_style_hook is executed after reading the precomputed root style,
282 # so there is no hook where to place the lazy precomputation.
283 0 $bundle->{_precomputed_root_style} = $self->_styles->bundle_style($bundle);
284 }
285 0 return;
286 }
287  
288 0 ▶sub get_value_line_hook {
Subroutine get_value_line_hook: not called CC=3 SCAR=24.8
Pod documented
289 0 my ( $self, $fsfile, $treeNo ) = @_; # the unused argument stands for $fsfile
290 #return if not $self->pml_doc();
291  
292 0 ▶ unless ($self->_pmldoc_equals($fsfile)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_pmldoc_equals($fsfile)) 0 0 0
293 0 $self->file_opened_hook($fsfile);
294 }
295  
296 0 my $bundle = $self->pml_doc->tree($treeNo);
297 0 ▶ if ( !$bundle->{_precomputed_value_line} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($bundle->{"_precomputed_value_line"}) 0 0 0
298 0 $self->precompute_value_line($bundle);
299 }
300 0 return $bundle->{_precomputed_value_line};
301 }
302  
303 0 ▶sub value_line_doubleclick_hook {
Subroutine value_line_doubleclick_hook: not called CC=10 SCAR=47.0
Pod documented
304 0 my ( $self, @tags ) = @_;
305 0 my %tags;
306 0 @tags{@tags} = 1;
307  
308 0 my $bundle = $TredMacro::root;
309  
310 0 my $layout = $self->tree_layout->get_layout;
311 0 my %ordering;
312 my %visible;
313 0 my $i = 0;
314 0 my $row = 0;
315 0 my $found = 1;
316  
317 0 ▶ while ($found) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found) 0 0 0
318 0 $found = 0;
319 0 ▶ for ( my $col = 0; $col < scalar @$layout; $col++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($col < scalar @$layout) 0 0 0
320 0 ▶ if ( defined $layout->[$col][$row] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $layout->[$col][$row]) 0 0 0
321 0 ▶ if ( $layout->[$col][$row]->{'visible'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($layout->[$col][$row]{"visible"}) 0 0 0
322 0 $ordering{ $layout->[$col][$row]->{'label'} } = $i++;
323 0 $visible{ $layout->[$col][$row]->{'label'} } = 1;
324 }
325 0 $found = 1;
326 }
327 }
328 0 $row++;
329 }
330 my @trees = sort {
331 0 $ordering{ $self->tree_layout->get_tree_label($a) } <=> $ordering{ $self->tree_layout->get_tree_label($b) }
332 } grep {
333 0 exists $visible{ $self->tree_layout->get_tree_label($_) }
334 } $bundle->get_all_trees;
335  
336 0 for my $tree (@trees) {
337 0 for my $node ( $tree->get_descendants ) {
338 0 ▶ next if $node->get_layer eq 'p' and not $node->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $node->get_layer eq "p" and not $node->is_terminal 0 0 0
Condition0%0/3
$node->get_layer eq "p" and not $node->is_terminal
!ll&&!rl&&r
000
MC/DC0%0/2
$node->get_layer eq "p" and not $node->is_terminal
$node->get_layer eq "p" not $node->is_terminal
Truth table0%0/3
A and not(B)
A= $node->get_layer eq "p"B= not $node->is_terminal
ABresult
0X0
100
111
339 0 ▶ return $node if exists $tags{"$node"};
Branch: 1 branch
BranchTrueFalseTotal
if exists $tags{"$node"} 0 0 0
340 }
341 }
342  
343 0 return 'stop';
344 }
345  
346 # --------------- PRECOMPUTING VISUALIZATION (node labels, styles, coreference links, groups...) ---
347  
348 1 my @layers = map {lc} Treex::Core::Types::layers();
349  
350 # To be run only once when the file is opened. Tree depths never change.
351 0 ▶sub precompute_tree_depths {
Subroutine precompute_tree_depths: not called CC=8 SCAR=42.8
Pod undocumented
352 0 my ( $self, $bundle ) = @_;
353 0 foreach my $zone ( $bundle->get_all_zones ) {
354 0 ▶ foreach my $tree ( ref($zone) eq 'Treex::Core::BundleZone' ? $zone->get_all_trees : () ) {
Branch: 1 branch
BranchTrueFalseTotal
ref $zone eq 'Treex::Core::BundleZone' ? : 0 0 0
355 0 my $max_depth = 1;
356 0 my @front = ( 1, $tree );
357  
358 0 ▶ while (@front) {
Branch: 1 branch
BranchTrueFalseTotal
if (@front) 0 0 0
359 0 my $cur_depth = shift @front;
360 0 my $node = shift @front;
361 0 ▶ $max_depth = $cur_depth if $cur_depth > $max_depth;
Branch: 1 branch
BranchTrueFalseTotal
if $cur_depth > $max_depth 0 0 0
362 0 for my $child ( $node->get_children ) {
363 0 push @front, $cur_depth + 1, $child;
364 0 ▶ $child->{_depth} = $cur_depth + 1 if $child->get_layer eq 'p';
Branch: 1 branch
BranchTrueFalseTotal
if $child->get_layer eq "p" 0 0 0
365 }
366 }
367  
368 0 $tree->{_tree_depth} = $max_depth;
369 }
370 }
371 0 return;
372 }
373  
374 0 ▶sub node_release_hook {
Subroutine node_release_hook: not called CC=5 SCAR=34.0
Pod undocumented
375 0 my ($self, $node, $target, $mod) = @_;
376 0 my @roots = map { $_->get_root } $node, $target;
377 0 my @zones = map { $_->get_zone } $node, $target;
378  
379 0 ▶ if ($self->show_alignment
Branch: 1 branch
BranchTrueFalseTotal
if ($self->show_alignment and $roots[0] != $roots[1] and $zones[0] != $zones[1]) 0 0 0
Condition0%0/6
$self->show_alignment and $roots[0] != $roots[1] and $zones[0] != $zones[1]
!ll&&!rl&&r
000
$self->show_alignment and $roots[0] != $roots[1]
!ll&&!rl&&r
000
MC/DC0%0/3
$self->show_alignment and $roots[0] != $roots[1] and $zones[0] != $zones[1]
$self->show_alignment $roots[0] != $roots[1] $zones[0] != $zones[1]
Truth table0%0/4
A and B and C
A= $self->show_alignmentB= $roots[0] != $roots[1]C= $zones[0] != $zones[1]
ABCresult
0XX0
10X0
1100
1111
380 and
381 $roots[0] != $roots[1] and $zones[0] != $zones[1]) {
382  
383 0 ▶ if ($node->is_directed_aligned_to($target, {rel_types => ['alignment']})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->is_directed_aligned_to($target, {'rel_types', ['alignment']})) { } 0 0 0
384 0 $node->delete_aligned_node($target, 'alignment');
385 } else {
386 0 $node->add_aligned_node($target, 'alignment');
387 }
388  
389 # TODO: Is there more treexy way to do it?
390 0 TredMacro::Redraw();
391  
392 0 return 'stop';
393 }
394 }
395  
396 # Has to be run whenever the tree layout changes.
397 0 ▶sub precompute_tree_shifts {
Subroutine precompute_tree_shifts: not called CC=9 SCAR=45.0
Pod undocumented
398 0 my ( $self, $bundle ) = @_;
399  
400 0 my $layout = $self->tree_layout->get_layout($bundle);
401 0 my %forest = ();
402  
403 0 foreach my $zone ( $bundle->get_all_zones ) {
404 0 ▶ foreach my $tree ( ref($zone) eq 'Treex::Core::BundleZone' ? $zone->get_all_trees : () ) {
Branch: 1 branch
BranchTrueFalseTotal
ref $zone eq 'Treex::Core::BundleZone' ? : 0 0 0
405 0 $forest{ $self->tree_layout->get_tree_label($tree) } = $tree;
406 }
407 }
408  
409 0 my @trees = ('foo');
410 0 my $row = 0;
411 0 my $cur_shift = 0;
412 0 ▶ while (@trees) {
Branch: 1 branch
BranchTrueFalseTotal
if (@trees) 0 0 0
413 0 my $max_depth = 0;
414 0 @trees = ();
415 0 ▶ for ( my $col = 0; $col < scalar @$layout; $col++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($col < scalar @$layout) 0 0 0
416 0 ▶ if ( defined $layout->[$col][$row] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $layout->[$col][$row]) 0 0 0
417 0 my $label = $layout->[$col][$row]->{'label'};
418 0 my $depth = $forest{$label}{_tree_depth};
419 0 push @trees, $label;
420 0 ▶ $max_depth = $depth if $depth > $max_depth;
Branch: 1 branch
BranchTrueFalseTotal
if $depth > $max_depth 0 0 0
421 0 $forest{$label}{'_shift_right'} = $col;
422 }
423 }
424  
425 0 for my $label (@trees) {
426 0 $forest{$label}{'_shift_down'} = $cur_shift;
427 }
428 0 $cur_shift += $max_depth;
429 0 $row++;
430 }
431 0 return;
432 }
433  
434 0 ▶sub precompute_visualization {
Subroutine precompute_visualization: not called CC=9 SCAR=45.0
Pod undocumented
435 0 my ( $self, $bundle ) = @_;
436  
437 0 $bundle->{_precomputed_node_style} = '#{Node-hide:1}';
438  
439 0 foreach my $zone ( $bundle->get_all_zones ) {
440 0 foreach my $layer (@layers) {
441 0 ▶ if ( ref($zone) eq 'Treex::Core::BundleZone' && $zone->has_tree($layer) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $zone eq "Treex::Core::BundleZone" and $zone->has_tree($layer)) 0 0 0
Condition0%0/3
ref $zone eq "Treex::Core::BundleZone" and $zone->has_tree($layer)
!ll&&!rl&&r
000
MC/DC0%0/2
ref $zone eq "Treex::Core::BundleZone" and $zone->has_tree($layer)
ref $zone eq "Treex::Core::BundleZone" $zone->has_tree($layer)
Truth table0%0/3
A and B
A= ref $zone eq "Treex::Core::BundleZone"B= $zone->has_tree($layer)
ABresult
0X0
100
111
442 0 my $root = $zone->get_tree($layer);
443 0 my $limits = $self->labels->get_limits($layer);
444  
445 0 $root->{_precomputed_labels} = $self->labels->root_labels($root);
446 0 $root->{_precomputed_node_style} = $self->_styles->node_style($root);
447 0 $root->{_precomputed_hint} = '';
448  
449 0 ▶ if ( $root->get_zone->sentence ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($root->get_zone->sentence) 0 0 0
450 0 $root->{_precomputed_hint} = 'sentence: ' . $root->get_zone->sentence;
451 }
452  
453 0 foreach my $node ( $root->get_descendants ) {
454 0 $node->{_precomputed_node_style} = $self->_styles->node_style($node);
455 0 $node->{_precomputed_hint} = $self->node_hint( $node, $layer );
456 0 $node->{_precomputed_buffer} = $self->labels->node_labels( $node, $layer );
457 0 $self->labels->set_labels($node);
458  
459 0 ▶ if ( !$limits ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($limits) 0 0 0
460 0 ▶ for ( my $i = 0; $i < 3; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 3) 0 0 0
461 0 $self->labels->set_limit( $layer, $i, scalar( @{ $node->{_precomputed_buffer}[$i] } ) - 1 );
462 }
463 0 $limits = 1;
464 }
465 }
466 }
467 }
468 }
469 0 return;
470 }
471  
472 0 ▶sub get_clickable_sentence_for_a_zone {
Subroutine get_clickable_sentence_for_a_zone: not called CC=16 SCAR=56.1
Pod undocumented
473 0 my ( $self, $zone, $alignment ) = @_;
474 0 ▶ return if !$zone->has_atree();
Branch: 1 branch
BranchTrueFalseTotal
unless $zone->has_atree 0 0 0
475 0 my %refs = ();
476  
477 0 ▶ if ( $zone->has_ttree() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zone->has_ttree) 0 0 0
478 0 for my $tnode ( $zone->get_ttree->get_descendants ) {
479 0 for my $aux ( TredMacro::ListV( $tnode->attr('a/aux.rf') ) ) {
480 0 push @{ $refs{$aux} }, $tnode;
481 0 ▶ if ( exists $alignment->{ $tnode->get_attr('id') } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$alignment{$tnode->get_attr("id")}) 0 0 0
482 0 push @{ $refs{$aux} }, @{ $alignment->{ $tnode->get_attr('id') } };
483 }
484 }
485 0 ▶ if ( $tnode->attr('a/lex.rf') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tnode->attr("a/lex.rf")) 0 0 0
486 0 push @{ $refs{ $tnode->attr('a/lex.rf') } }, $tnode;
487 0 ▶ if ( exists $alignment->{ $tnode->get_attr('id') } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$alignment{$tnode->get_attr("id")}) 0 0 0
488 0 push @{ $refs{ $tnode->attr('a/lex.rf') } }, @{ $alignment->{ $tnode->get_attr('id') } };
489 }
490 }
491 }
492 }
493  
494 0 my @anodes = $zone->get_atree->get_descendants( { ordered => 1 } );
495 0 for my $anode (@anodes) {
496 0 my $id = $anode->id;
497 0 push @{ $refs{$id} }, $anode;
498 0 ▶ if ( exists $alignment->{$id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $alignment->{$id}) 0 0 0
499 0 push @{ $refs{$id} }, @{ $alignment->{$id} };
500 }
501 0 ▶ if ( $anode->attr('p_terminal.rf') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($anode->attr("p_terminal.rf")) 0 0 0
502 0 my $pnode = $self->treex_doc->get_node_by_id( $anode->attr('p_terminal.rf') );
503 0 push @{ $refs{$id} }, $pnode;
504 0 ▶ while ( $pnode->parent ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pnode->parent) 0 0 0
505 0 $pnode = $pnode->parent;
506 0 push @{ $refs{$id} }, $pnode;
507 }
508 }
509 }
510  
511 0 my @out;
512 0 for my $anode (@anodes) {
513 0 ▶ push @out, [ $anode->form, @{ $refs{ $anode->id } || [] } ];
Condition0%0/2
$refs{$anode->id} || []
l!l
00
MC/DC0%0/1
$refs{$anode->id} || []
$refs{$anode->id}
Truth table0%0/2
A
A= $refs{$anode->id}
Aresult
11
00
514 0 ▶ if ( $anode->clause_number ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($anode->clause_number) 0 0 0
515 0 my $clr = $self->_styles->_colors->get_clause_color( $anode->clause_number );
516 0 push @{ $out[-1] }, "-foreground => $clr";
517 }
518 0 ▶ if ( !$anode->no_space_after ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($anode->no_space_after) 0 0 0
519 0 push @out, [ ' ', 'space' ];
520 }
521 }
522  
523 0 push @out, [ "\n", 'newline' ];
524 0 return \@out;
525 }
526  
527 0 ▶sub precompute_value_line {
Subroutine precompute_value_line: not called CC=12 SCAR=50.5
Pod undocumented
528 0 my ( $self, $bundle ) = @_;
529  
530 0 my %alignment = ();
531  
532 0 foreach my $zone ( $bundle->get_all_zones() ) {
533 0 foreach my $layer (@layers) {
534 0 ▶ if ( $zone->has_tree($layer) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zone->has_tree($layer)) 0 0 0
535 0 my $root = $zone->get_tree($layer);
536 0 foreach my $node ( $root, $root->get_descendants ) {
537 0 ▶ if ( exists $node->{'alignment'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $node->{"alignment"}) 0 0 0
538 0 foreach my $ref ( @{ $node->get_attr('alignment') } ) {
539 0 ▶ next if !defined $ref || ! defined $ref->{'counterpart.rf'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ref and defined $ref->{"counterpart.rf"} 0 0 0
Condition0%0/3
defined $ref and defined $ref->{"counterpart.rf"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ref and defined $ref->{"counterpart.rf"}
defined $ref defined $ref->{"counterpart.rf"}
Truth table0%0/3
A and B
A= defined $refB= defined $ref->{"counterpart.rf"}
ABresult
0X0
100
111
540 0 push @{ $alignment{ $node->{id} } }, $self->treex_doc->get_node_by_id( $ref->{'counterpart.rf'} );
541 0 push @{ $alignment{ $ref->{'counterpart.rf'} } }, $node;
542 }
543 }
544 }
545 }
546 }
547 }
548  
549 0 my @out = ();
550 0 foreach my $zone ( $bundle->get_all_zones() ) {
551 0 push @out, ( [ '[' . $zone->get_label . ']', 'label' ], [ ' ', 'space' ] );
552 0 ▶ if ( my $sentence = $self->get_clickable_sentence_for_a_zone( $zone, \%alignment ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $sentence = $self->get_clickable_sentence_for_a_zone($zone, \%alignment)) { } 0 0 0
elsif (defined $zone->sentence) { } 0 0 0
553 0 push @out, @$sentence;
554 }
555 elsif ( defined $zone->sentence ) {
556 0 push @out, [ $zone->sentence . "\n", 'text' ];
557 }
558 else {
559 0 push @out, [ "\n", 'newline' ]
560 }
561 }
562  
563 0 $bundle->{_precomputed_value_line} = \@out;
564 0 return;
565 }
566  
567 # ---- info displayed when mouse stops over a node - "hint" (should return a string, that may contain newlines) ---
568  
569 0 ▶sub node_hint { # silly code just to avoid the need for eval
Subroutine node_hint: not called CC=2 SCAR=17.9
Pod undocumented
570 0 my $layer = pop @_;
571 0 my %subs;
572 0 $subs{t} = \&tnode_hint;
573 0 $subs{a} = \&anode_hint;
574 0 $subs{n} = \&nnode_hint;
575 0 $subs{p} = \&pnode_hint;
576  
577 0 ▶ if ( defined $subs{$layer} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $subs{$layer}) { } 0 0 0
578 0 return &{ $subs{$layer} }(@_);
579 }
580 else {
581 0 log_fatal "Undefined or unknown layer: $layer";
582 }
583  
584 0 return;
585 }
586  
587 0 ▶sub anode_hint {
Subroutine anode_hint: not called CC=7 SCAR=40.3
Pod undocumented
588 0 my ( $self, $node ) = @_;
589 0 my @lines = ();
590  
591 0 ▶ push @lines, "Parenthesis root" if $node->{is_parenthesis_root};
Branch: 1 branch
BranchTrueFalseTotal
if $node->{"is_parenthesis_root"} 0 0 0
592 0 ▶ if ( $node->language eq 'cs' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->language eq "cs") 0 0 0
593 0 ▶ push @lines, "Full lemma: " . ( $node->{lemma} ? $node->{lemma} : '' );
Branch: 1 branch
BranchTrueFalseTotal
$node->{'lemma'} ? : 0 0 0
594 0 ▶ push @lines, "Full tag: " . ( $node->{tag} ? $node->{tag} : '' );
Branch: 1 branch
BranchTrueFalseTotal
$node->{'tag'} ? : 0 0 0
595 }
596  
597 # List all non-empty Interset features.
598 0 ▶ if ( $node->does('Treex::Core::Node::Interset') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->does("Treex::Core::Node::Interset")) 0 0 0
599 0 my @ifeat = $node->iset()->get_nonempty_features();
600 0 foreach my $f ( @ifeat ) {
601 0 my $v = $node->iset()->get_joined($f);
602 0 push(@lines, "$f: $v");
603 }
604 }
605  
606 0 return join "\n", @lines;
607 }
608  
609 0 ▶sub tnode_hint {
Subroutine tnode_hint: not called CC=10 SCAR=47.0
Pod undocumented
610 0 my ( $self, $node ) = @_;
611 0 my @lines = ();
612  
613 0 ▶ if ( ref $node->get_attr('gram') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $node->get_attr("gram")) 0 0 0
614 0 foreach my $gram ( keys %{ $node->get_attr('gram') } ) {
615 0 ▶ push @lines, "gram/$gram : " . ( $node->get_attr( 'gram/' . $gram ) || '' );
Condition0%0/2
$node->get_attr('gram/' . $gram) || ''
l!l
00
MC/DC0%0/1
$node->get_attr('gram/' . $gram) || ''
$node->get_attr('gram/' . $gram)
Truth table0%0/2
A
A= $node->get_attr('gram/' . $gram)
Aresult
11
00
616 }
617 }
618  
619 0 ▶ push @lines, "Direct speech root" if $node->get_attr('is_dsp_root');
Branch: 1 branch
BranchTrueFalseTotal
if $node->get_attr("is_dsp_root") 0 0 0
620 0 ▶ push @lines, "Parenthesis" if $node->get_attr('is_parenthesis');
Branch: 1 branch
BranchTrueFalseTotal
if $node->get_attr("is_parenthesis") 0 0 0
621 0 ▶ push @lines, "Name of person" if $node->get_attr('is_name_of_person');
Branch: 1 branch
BranchTrueFalseTotal
if $node->get_attr("is_name_of_person") 0 0 0
622 0 ▶ push @lines, "Name" if $node->get_attr('is_name');
Branch: 1 branch
BranchTrueFalseTotal
if $node->get_attr("is_name") 0 0 0
623 0 ▶ push @lines, "State" if $node->get_attr('is_state');
Branch: 1 branch
BranchTrueFalseTotal
if $node->get_attr("is_state") 0 0 0
624 0 ▶ push @lines, "Quotation : " . join ", ", map { $_->{type} } TredMacro::ListV( $node->get_attr('quot') ) if $node->get_attr('quot');
Branch: 1 branch
BranchTrueFalseTotal
if $node->get_attr("quot") 0 0 0
625  
626 0 return join "\n", @lines;
627 }
628  
629 0 ▶sub nnode_hint {
Subroutine nnode_hint: not called CC=1 SCAR=6.9
Pod undocumented
630 0 my ( $self, $node ) = @_;
631 0 return;
632 }
633  
634 0 ▶sub pnode_hint {
Subroutine pnode_hint: not called CC=3 SCAR=24.8
Pod undocumented
635 0 my ( $self, $node ) = @_;
636 0 my @lines = ();
637  
638 0 ▶ if ( $node->is_terminal ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->is_terminal) { } 0 0 0
639 0 ▶ push @lines, map { "$_: " . ( defined $node->{$_} ? $node->{$_} : '' ) } qw(lemma tag form);
Branch: 1 branch
BranchTrueFalseTotal
defined $node->{$_} ? : 0 0 0
640 }
641 else {
642 0 push @lines, "phrase: " . $node->{phrase};
643 0 push @lines, "functions: " . join( ', ', TredMacro::ListV( $node->{functions} ) );
644 }
645  
646 0 return join "\n", @lines;
647 }
648  
649 # --- arrows ----
650  
651 # copied from TectoMT_TredMacros.mak
652 0 ▶sub node_style_hook {
Subroutine node_style_hook: not called CC=25 SCAR=64.8
Pod documented
653 0 my ( $self, $node, $styles ) = @_;
654  
655 0 ▶ return if ref($node) eq 'Treex::Core::Bundle';
Branch: 1 branch
BranchTrueFalseTotal
if ref $node eq "Treex::Core::Bundle" 0 0 0
656  
657 0 my %line = TredMacro::GetStyles( $styles, 'Line' );
658 0 my @target_ids;
659 my @arrow_types;
660  
661 0 foreach my $ref_attr ( 'coref_gram', 'coref_text', 'compl', 'bridging' ) {
662 0 ▶ if ( defined $node->attr( $ref_attr . '.rf' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $node->attr($ref_attr . '.rf')) { } 0 0 0
elsif (defined $node->attr($ref_attr)) { } 0 0 0
663 0 foreach my $target_id ( @{ $node->attr( $ref_attr . '.rf' ) } ) {
664 0 push @target_ids, $target_id;
665 0 push @arrow_types, $ref_attr;
666 }
667 }
668 elsif ( defined $node->attr( $ref_attr ) ) {
669 0 my $links = $node->attr( $ref_attr );
670 0 foreach my $link (@$links) {
671 0 push @target_ids, $link->{'target_node.rf'};
672 0 push @arrow_types, $ref_attr;
673 }
674 }
675 }
676  
677  
678 # P-layer indexes and coindexes
679 0 ▶ if ( $node->get_layer eq 'p' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->get_layer eq "p") 0 0 0
680 0 my $coindex;
681 0 ▶ if ( $node->attr('form') and $node->attr('form') =~ m/-(\d+)$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($node->attr('form') and $node->attr('form') =~ /-(\d+)$/) { } 0 0 0
elsif ($node->attr('coindex')) { } 0 0 0
Condition0%0/3
$node->attr("form") and $node->attr("form") =~ /-(\d+)$/
!ll&&!rl&&r
000
MC/DC0%0/2
$node->attr("form") and $node->attr("form") =~ /-(\d+)$/
$node->attr("form") $node->attr("form") =~ /-(\d+)$/
Truth table0%0/3
A and B
A= $node->attr("form")B= $node->attr("form") =~ /-(\d+)$/
ABresult
0X0
100
111
682 0 $coindex = $1;
683 }
684 elsif ( $node->attr('coindex') ) {
685 0 $coindex = $node->attr('coindex');
686 }
687  
688 0 ▶ if ($coindex) {
Branch: 1 branch
BranchTrueFalseTotal
if ($coindex) 0 0 0
689 0 my $target_node;
690 0 ▶ if ( exists $self->{'_ptb_index_map'}->{$coindex} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->{'_ptb_index_map'}{$coindex}) { } 0 0 0
elsif ($node->is_terminal and exists $self->{'_ptb_coindex_map'}{$coindex}) { } 0 0 0
691 0 $target_node = $self->{'_ptb_index_map'}->{$coindex};
692 }
693 ▶ elsif ( $node->is_terminal and exists $self->{'_ptb_coindex_map'}->{$coindex} ) {
Condition0%0/3
$node->is_terminal and exists $self->{"_ptb_coindex_map"}{$coindex}
!ll&&!rl&&r
000
MC/DC0%0/2
$node->is_terminal and exists $self->{"_ptb_coindex_map"}{$coindex}
$node->is_terminal exists $self->{"_ptb_coindex_map"}{$coindex}
Truth table0%0/3
A and B
A= $node->is_terminalB= exists $self->{"_ptb_coindex_map"}{$coindex}
ABresult
0X0
100
111
694 0 $target_node = $self->{'_ptb_coindex_map'}->{$coindex};
695 }
696  
697 0 ▶ if ($target_node) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target_node) 0 0 0
698 0 push @target_ids, $target_node->{'id'};
699 0 push @arrow_types, 'coindex';
700 }
701 }
702 }
703  
704 # alignment
705 0 ▶ if ( $self->show_alignment and my $links = $node->attr('alignment') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->show_alignment and my $links = $node->attr("alignment")) 0 0 0
Condition0%0/3
$self->show_alignment and my $links = $node->attr("alignment")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->show_alignment and my $links = $node->attr("alignment")
$self->show_alignment my $links = $node->attr("alignment")
Truth table0%0/3
A and B
A= $self->show_alignmentB= my $links = $node->attr("alignment")
ABresult
0X0
100
111
706 0 foreach my $link (@$links) {
707 0 push @target_ids, $link->{'counterpart.rf'};
708 0 push @arrow_types, $link->{'type'};
709 }
710 }
711  
712 0 $self->_styles->draw_arrows( $node, $styles, \%line, \@target_ids, \@arrow_types, );
713  
714 # TODO: Would it be possible to move this code to the "_precomputed_node_style" attr?
715 0 my %n = TredMacro::GetStyles( $styles, 'Node' );
716 0 ▶ TredMacro::AddStyle( $styles, 'Node', -tag => ( $n{-tag} || '' ) . '#' . $node->{id} );
Condition0%0/2
$n{'-tag'} || ''
l!l
00
MC/DC0%0/1
$n{'-tag'} || ''
$n{'-tag'}
Truth table0%0/2
A
A= $n{'-tag'}
Aresult
11
00
717  
718 0 my $xadj = $node->root->{'_shift_right'} * 50;
719 0 ▶ if (ref($node)
Branch: 1 branch
BranchTrueFalseTotal
if (ref($node) =~ /^Treex::Core::Node/ and $node->get_layer eq "p" and not $node->is_root and scalar $node->parent->children == 1) 0 0 0
Condition0%0/9
ref($node) =~ /^Treex::Core::Node/ and $node->get_layer eq "p" and not $node->is_root and scalar $node->parent->children == 1
!ll&&!rl&&r
000
ref($node) =~ /^Treex::Core::Node/ and $node->get_layer eq "p" and not $node->is_root
!ll&&!rl&&r
000
ref($node) =~ /^Treex::Core::Node/ and $node->get_layer eq "p"
!ll&&!rl&&r
000
MC/DC0%0/4
ref($node) =~ /^Treex::Core::Node/ and $node->get_layer eq "p" and not $node->is_root and scalar $node->parent->children == 1
ref($node) =~ /^Treex::Core::Node/ $node->get_layer eq "p" not $node->is_root scalar $node->parent->children == 1
Truth table0%0/5
A and B and not(C) and D
A= ref($node) =~ /^Treex::Core::Node/B= $node->get_layer eq "p"C= not $node->is_rootD= scalar $node->parent->children == 1
ABCDresult
0XXX0
10XX0
110X0
11100
11111
720 =~ m/^Treex::Core::Node/
721 and $node->get_layer eq 'p'
722 and not $node->is_root and scalar $node->parent->children == 1
723 )
724 {
725 0 $xadj += 15;
726 }
727 0 ▶ TredMacro::AddStyle( $styles, 'Node', -xadj => $xadj ) if $xadj;
Branch: 1 branch
BranchTrueFalseTotal
if $xadj 0 0 0
728  
729 0 return;
730 }
731  
732 0 ▶sub root_style_hook {
Subroutine root_style_hook: not called CC=3 SCAR=24.8
Pod undocumented
733 0 my ( $self, $bundle, $styles ) = @_;
734  
735 # Sometimes TrEd calls this on e.g. t-nodes (after node_click_hook)
736 0 ▶ return if !$bundle->isa('Treex::Core::Bundle');
Branch: 1 branch
BranchTrueFalseTotal
unless $bundle->isa("Treex::Core::Bundle") 0 0 0
737  
738 0 ▶ return if $bundle->{_precomputed};
Branch: 1 branch
BranchTrueFalseTotal
if $bundle->{"_precomputed"} 0 0 0
739 0 $self->precompute_tree_depths($bundle);
740 0 $self->precompute_tree_shifts($bundle);
741 0 $self->precompute_visualization($bundle);
742 0 $bundle->{_precomputed} = 1;
743 0 return;
744 }
745  
746 # ---- END OF PRECOMPUTING VISUALIZATION ------
747  
748 0 ▶sub conf_dialog {
Subroutine conf_dialog: not called CC=4 SCAR=30.0
Pod documented
749 0 my $self = shift;
750 0 ▶ if ( $self->tree_layout->conf_dialog() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->tree_layout->conf_dialog) 0 0 0
751 0 foreach my $bundle ( $self->treex_doc->get_bundles() ) {
752 0 ▶ if ( !$self->fast_loading ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->fast_loading) { } 0 0 0
753 0 $bundle->{_precomputed_root_style} = $self->_styles->bundle_style($bundle);
754 0 $self->precompute_tree_shifts($bundle);
755 0 $self->precompute_visualization($bundle);
756 0 $bundle->{_precomputed} = 1;
757 }
758 else {
759 0 $bundle->{_precomputed} = 0;
760 }
761 }
762 }
763 0 return;
764 }
765  
766 0 ▶sub _divide_clause_string {
Subroutine _divide_clause_string: not called CC=2 SCAR=17.9
767 0 my ( $self, $anode ) = @_;
768 0 ▶ if ( !$anode->clause_number ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($anode->clause_number) 0 0 0
769 0 return [ $anode->form,, ];
770 }
771 0 my @forms = map { $_->form } $anode->get_clause_nodes;
772 0 my $forms_per_line = int( @forms / 3 );
773 return [
774 0 ( join ' ', @forms[ 0 .. $forms_per_line ] ),
775 ( join ' ', @forms[ $forms_per_line + 1 .. 2 * $forms_per_line ] ),
776 ( join ' ', @forms[ 2 * $forms_per_line + 1 .. $#forms ] ),
777 ];
778 }
779  
780 0 ▶sub toggle_clause_collapsing {
Subroutine toggle_clause_collapsing: not called CC=6 SCAR=37.4
Pod documented
781 0 my ( $self, $bundle ) = @_;
782 0 $self->clause_collapsing( not $self->clause_collapsing );
783 0 $bundle->{_is_collapsed} = $self->clause_collapsing;
784 0 print "Toggle: " . $self->clause_collapsing . "\n";
785  
786 # fold clauses - display word from the clause instead of node labels
787  
788 0 foreach my $zone ( $bundle->get_all_zones ) {
789 0 ▶ if ( $zone->has_tree('a') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zone->has_tree("a")) 0 0 0
790 0 my $aroot = $zone->get_atree;
791 0 foreach my $anode ( $aroot->get_descendants ) {
792  
793 # fold clauses - display word from the clause instead of node labels
794 0 ▶ if ( $self->clause_collapsing ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->clause_collapsing) { } 0 0 0
795 0 $anode->{_parent_backup} = $anode->get_parent;
796 0 $anode->{_precomputed_labels_backup} = $anode->{_precomputed_labels};
797 0 $anode->{_precomputed_labels} = $self->_divide_clause_string($anode);
798 }
799  
800 # unfold clauses - return to full attribute labes
801 else {
802 0 $anode->{_precomputed_labels} = $anode->{_precomputed_labels_backup};
803 0 ▶ $anode->set_parent( $anode->{_parent_backup} ) if $anode->{_parent_backup};
Branch: 1 branch
BranchTrueFalseTotal
if $anode->{"_parent_backup"} 0 0 0
804 }
805 }
806 }
807 }
808 0 return;
809 }
810  
811 0 ▶sub toggle_alignment {
Subroutine toggle_alignment: not called CC=1 SCAR=6.9
Pod undocumented
812 0 my $self = shift;
813 0 $self->show_alignment( not $self->show_alignment );
814 0 return;
815 }
816  
817 0 ▶sub toggle_tree_wrapping {
Subroutine toggle_tree_wrapping: not called CC=1 SCAR=6.9
Pod undocumented
818 0 my ( $self, $node ) = @_;
819 0 my $signature = $self->_tree_type_signature($node);
820 0 $self->tree_type_to_wrap->{$signature} = not $self->tree_type_to_wrap->{$signature};
821 0 print "Toggle wrapping of trees of type: $signature\n";
822 0 return;
823 }
824  
825 0 ▶sub _tree_type_signature {
Subroutine _tree_type_signature: not called CC=2 SCAR=17.9
826 0 my ( $self, $node) = @_;
827 0 my $zone = $node->get_root->get_zone;
828 0 ▶ return join "-", ( ref($node), $zone->language, $zone->selector()||'');
Condition0%0/2
$zone->selector || ''
l!l
00
MC/DC0%0/1
$zone->selector || ''
$zone->selector
Truth table0%0/2
A
A= $zone->selector
Aresult
11
00
829 }
830  
831 1 ▶use Treex::Core::TredView::AnnotationCommand;
Subroutine BEGIN: called CC=1 SCAR=0.0
832 0 ▶sub run_annotation_command {
Subroutine run_annotation_command: not called CC=1 SCAR=6.9
Pod undocumented
833 0 my ( $self, $command, $node ) = @_;
834 0 Treex::Core::TredView::AnnotationCommand::run( $command, $node );
835 0 $self->recompute_visualization($node->get_bundle);
836 0 return;
837 }
838  
839  
840  
841 1 my $HIGHLIGHT_STYLE = '#{Line-decoration:shape=oval;coords=-20,-10,20,10;outline=#ff0000;width=3;dash=5,5 }';
842 1 my $HIGHLIGHT_TEXT = '-background => #ffbbaa';
843 1 my @highlighted = ();
844 0 ▶sub node_click_hook {
Subroutine node_click_hook: not called CC=9 SCAR=45.0
Pod undocumented
845 0 my ( $self, $node, $modifier, $xevent ) = @_;
846 0 my $ali_id = eval {$node->wild->{ali_root}};
847 0 ▶ if ($ali_id){
Branch: 1 branch
BranchTrueFalseTotal
if ($ali_id) 0 0 0
848 # remove all highlighting
849 0 foreach my $n (@highlighted){
850 0 $n->{_precomputed_node_style} =~ s/\Q$HIGHLIGHT_STYLE\E//;
851 }
852 0 @highlighted = ();
853 # add new highlighted nodes (a minimal treelet consistent with alignment)
854 0 my $al_node = $self->treex_doc->get_node_by_id($ali_id);
855 0 my @queue = ($node, $al_node);
856 0 ▶ while (@queue){
Branch: 1 branch
BranchTrueFalseTotal
if (@queue) 0 0 0
857 0 my $n = shift @queue;
858 0 push @highlighted, $n;
859 0 push @queue, grep {!$_->wild->{ali_root}} $n->get_children();
860 }
861 0 foreach my $n (@highlighted){
862 0 $n->{_precomputed_node_style} .= $HIGHLIGHT_STYLE;
863 }
864 # highlight also the relevant words in the text window above trees
865 0 my $bundle = $node->get_bundle();
866 0 my %h; $h{$_}=1 for (@highlighted);
867 0 foreach my $token (@{$bundle->{_precomputed_value_line}}){
868 0 ▶ pop @$token if $token->[-1] eq $HIGHLIGHT_TEXT;
Branch: 1 branch
BranchTrueFalseTotal
if $token->[-1] eq $HIGHLIGHT_TEXT 0 0 0
869 0 ▶ push @$token, $HIGHLIGHT_TEXT if $h{$token->[1]};
Branch: 1 branch
BranchTrueFalseTotal
if $h{$token->[1]} 0 0 0
870 }
871 0 TredMacro::Redraw();
872 }
873 0 return;
874 }
875  
876 1 1;
877  
878 __END__
« Treex/Core/Phrase/Coordination.pm ↑ Summary Treex/Core/Resource.pm »