lib/Treex/Core/TredView.pm

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