lib/Treex/Core/Node/InClause.pm

filter: Statementstmt 33.3% 17 / 51 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 44.4% 4 / 9 Podpod 100% 4 / 4 totaltotal 22.1% 25 / 113 CC 19 SCAR 40.9
CC
19
Cov
19%
get_clause_root
132.0
get_clause_head
20.0
__ANON__
12.0
CRAP 60.0
« lib/Treex/Core/DocumentReader/Base.pm ↑ Summary lib/Treex/Core/Node/A.pm »
1 package Treex::Core::Node::InClause;
2 {
3 62 $Treex::Core::Node::InClause::VERSION = '0.08633_1';
4 }
5 62 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # with Moose >= 2.00, this must be present also in roles
8 62 ▶use MooseX::SemiAffordanceAccessor;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 62 ▶use Treex::Core::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 62 ▶use List::Util qw(first); # TODO: this wouldn't be needed if there was Treex::Core::Common for roles
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 62 has clause_number => (
13 is => 'rw',
14 isa => 'Maybe[Int]',
15 documentation => 'ordinal number that is shared by all nodes of a clause',
16 );
17  
18 62 has is_clause_head => (
19 is => 'rw',
20 isa => 'Bool',
21 documentation => 'Is this node a head of a finite clause?',
22 );
23  
24 sub get_clause_root {
25 0 ▶ log_fatal 'Incorrect number of arguments' if @_ != 1;
Subroutine get_clause_root: not called CC=11 SCAR=48.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 1 0 0 0
26 0 my $self = shift;
27 0 my $my_number = $self->get_attr('clause_number');
28 0 ▶ log_warn( 'Attribut clause_number not defined in ' . $self->get_attr('id') )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $my_number 0 0 0
29 if !defined $my_number;
30 0 ▶ return $self if !$my_number;
Branch: 1 branch
BranchTrueFalseTotal
unless $my_number 0 0 0
31  
32 0 my $highest = $self;
33 0 my $parent = $self->get_parent();
34 0 ▶ while ( $parent && ( $parent->get_attr('clause_number') || 0 ) == $my_number ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent and ($parent->get_attr("clause_number") || 0) == $my_number) 0 0 0
Condition0%0/5
$parent and ($parent->get_attr("clause_number") || 0) == $my_number
!ll&&!rl&&r
000
$parent->get_attr('clause_number') || 0
l!l
00
MC/DC0%0/2
$parent and ($parent->get_attr("clause_number") || 0) == $my_number
$parent $parent->get_attr('clause_number')
Truth table0%0/3
A and B
A= $parentB= $parent->get_attr('clause_number')
ABresult
0X0
100
111
35 0 $highest = $parent;
36 0 $parent = $parent->get_parent();
37 }
38 0 ▶ if ( $parent && !$highest->get_attr('is_member') && $parent->is_coap_root() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent and not $highest->get_attr("is_member") and $parent->is_coap_root) 0 0 0
Condition0%0/6
$parent and not $highest->get_attr("is_member") and $parent->is_coap_root
!ll&&!rl&&r
000
$parent and not $highest->get_attr("is_member")
!ll&&!rl&&r
000
MC/DC0%0/3
$parent and not $highest->get_attr("is_member") and $parent->is_coap_root
$parent not $highest->get_attr("is_member") $parent->is_coap_root
Truth table0%0/4
A and not(B) and C
A= $parentB= not $highest->get_attr("is_member")C= $parent->is_coap_root
ABCresult
0XX0
10X0
1100
1111
39 0 ▶ my $eff_parent = first { $_->get_attr('is_member') && ( $_->get_attr('clause_number') || 0 ) == $my_number } $parent->get_children();
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
$_->get_attr("is_member") and ($_->get_attr("clause_number") || 0) == $my_number 0 0 0
Condition0%0/2
$_->get_attr('clause_number') || 0
l!l
00
MC/DC0%0/1
$_->get_attr('clause_number') || 0
$_->get_attr('clause_number')
Truth table0%0/2
A
A= $_->get_attr('clause_number')
Aresult
11
00
40 0 ▶ return $eff_parent if $eff_parent;
Branch: 1 branch
BranchTrueFalseTotal
if $eff_parent 0 0 0
41 }
42 0 return $highest;
43 }
44  
45 # Clauses may by split in more subtrees ("Peter eats and drinks.")
46 sub get_clause_nodes {
47 0 ▶ log_fatal 'Incorrect number of arguments' if @_ != 1;
Subroutine get_clause_nodes: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 1 0 0 0
48 0 my $self = shift;
49 0 my $root = $self->get_root();
50 0 my @descendants = $root->get_descendants( { ordered => 1 } );
51 0 my $my_number = $self->get_attr('clause_number');
52 0 ▶ return grep { ( $_->get_attr('clause_number') || '' ) eq $my_number } @descendants;
Condition0%0/2
$_->get_attr('clause_number') || ''
l!l
00
MC/DC0%0/1
$_->get_attr('clause_number') || ''
$_->get_attr('clause_number')
Truth table0%0/2
A
A= $_->get_attr('clause_number')
Aresult
11
00
53 }
54  
55 # TODO: same purpose as get_clause_root but instead of clause_number uses is_clause_head
56 sub get_clause_head {
57 0 ▶ log_fatal 'Incorrect number of arguments' if @_ != 1;
Subroutine get_clause_head: not called CC=4 SCAR=30.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 1 0 0 0
58 0 my $self = shift;
59 0 my $node = $self;
60 0 ▶ while ( !$node->get_attr('is_clause_head') && $node->get_parent() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $node->get_attr("is_clause_head") and $node->get_parent) 0 0 0
Condition0%0/3
not $node->get_attr("is_clause_head") and $node->get_parent
!ll&&!rl&&r
000
MC/DC0%0/2
not $node->get_attr("is_clause_head") and $node->get_parent
not $node->get_attr("is_clause_head") $node->get_parent
Truth table0%0/3
not(A) and B
A= not $node->get_attr("is_clause_head")B= $node->get_parent
ABresult
0X0
100
111
61 0 $node = $node->get_parent();
62 }
63 0 return $node;
64 }
65  
66 # Alternative API could be: $node->get_descendants({within_clause=>1});
67 sub get_clause_descendants {
68 0 ▶ log_fatal 'Incorrect number of arguments' if @_ != 1;
Subroutine get_clause_descendants: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 1 0 0 0
69 0 my $self = shift;
70  
71 0 my @clause_children = grep { !$_->get_attr('is_clause_head') } $self->get_children();
72 0 return ( @clause_children, map { $_->get_clause_descendants() } @clause_children );
73 }
74  
75 62 1;
76  
77 __END__
78  
79 =encoding utf-8
80  
81 =head1 NAME
82  
83 Treex::Core::Node::InClause
84  
85 =head1 VERSION
86  
87 version 0.08633_1
88  
89 =head1 DESCRIPTION
90  
91 Moose role for nodes in trees where (linguistic) clauses can be recognized
92 based on attributes C<clause_number> and C<is_clause_head>.
93  
94 =head1 ATTRIBUTES
95  
96 =over
97  
98 =item clause_number
99  
100 Ordinal number that is shared by all nodes of a same clause.
101  
102 =item is_clause_head
103  
104 Is this node a head of a finite clause.
105  
106 =back
107  
108 =head1 METHODS
109  
110 =over
111  
112 =item my $clause_head_node = $node->get_clause_root();
113  
114 Returns the head node of a clause.
115 This implementation is based on the attribute C<clause_number>.
116 Note that it may give different results than C<get_clause_head>.
117  
118 =item $clause_head_node = $node->get_clause_head();
119  
120 Returns the head node of a clause.
121 This implementation is based on the attribute C<is_clause_head>.
122 Note that it may give different results than C<get_clause_root>.
123  
124 =item my @nodes = $node->get_clause_descendants();
125  
126 Returns those descendants which are in the same clause as C<$node>.
127 The current implementation is based on the attribute C<is_clause_head>.
128  
129 =item my @nodes = $node->get_clause_nodes();
130  
131 Returns all nodes of the clause (to which the C<$node> belongs).
132 The current implementation is based on the attribute C<clause_number>.
133  
134 =back
135  
136  
137 =head1 AUTHOR
138  
139 Martin Popel <popel@ufal.mff.cuni.cz>
140  
141 =head1 COPYRIGHT AND LICENSE
142  
143 Copyright © 2011 by Institute of Formal and Applied Linguistics, Charles University in Prague
144  
145 This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
« lib/Treex/Core/DocumentReader/Base.pm ↑ Summary lib/Treex/Core/Node/A.pm »