Treex/Core/Phrase/Term.pm

filter: Statementstmt 59.6% 34 / 57 Branchbran 30.0% 6 / 20 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 63.6% 7 / 11 Podpod 100% 5 / 5 totaltotal 54.0% 53 / 98 CC 12 SCAR 22.2
CC
12
Cov
51%
as_string
20.0
__ANON__
12.5
project_dependencies
6.0
CRAP 9.2
« Treex/Core/Node.pm ↑ Summary Treex/Core/Config.pm »
1 package Treex::Core::Phrase::Term;
2 3 $Treex::Core::Phrase::Term::VERSION = '2.20151210';
3 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Treex::Core::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Treex::Core::Node;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 extends 'Treex::Core::Phrase';
11  
12  
13  
14 3 has 'node' =>
15 (
16 is => 'ro',
17 isa => 'Treex::Core::Node',
18 required => 1
19 );
20  
21 3 has 'deprel' =>
22 (
23 is => 'rw',
24 isa => 'Str',
25 required => 1
26 );
27  
28  
29  
30 #------------------------------------------------------------------------------
31 # This block will be called before object construction. It will copy the deprel
32 # attribute from the node (unless it has been supplied by the caller
33 # separately). Then it will pass all the attributes to the constructor.
34 #------------------------------------------------------------------------------
35 around BUILDARGS => sub
36 {
37 3 ▶ my $orig = shift;
Subroutine __ANON__: called CC=8 SCAR=25.3
38 3 my $class = shift;
39 # Call the default BUILDARGS in Moose::Object. It will take care of distinguishing between a hash reference and a plain hash.
40 3 my $attr = $class->$orig(@_);
41 3 ▶ if(defined($attr->{node}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attr->{"node"}) 3 0 3
42 {
43 3 my $node = $attr->{node};
44 # Add deprel only if it has not been supplied separately.
45 3 ▶ if(!defined($attr->{deprel}))
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $attr->{"deprel"}) 3 0 3
46 {
47 3 ▶ if(defined($node->deprel()))
Branch: 3 branches
BranchTrueFalseTotal
if (defined $node->deprel) { } 0 3 3
elsif (defined $node->afun) { } 0 3 3
elsif (defined $node->conll_deprel) { } 0 3 3
48 {
49 0 $attr->{deprel} = $node->deprel();
50 }
51 elsif(defined($node->afun()))
52 {
53 0 $attr->{deprel} = $node->afun();
54 }
55 elsif(defined($node->conll_deprel()))
56 {
57 0 $attr->{deprel} = $node->conll_deprel();
58 }
59 else
60 {
61 3 $attr->{deprel} = 'NR';
62 }
63 }
64 # Copy the initial value of is_member from the node to the phrase.
65 3 ▶ if(!defined($attr->{is_member}) && $node->is_member())
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $attr->{"is_member"} and $node->is_member) 0 3 3
Condition33%1/3
not defined $attr->{"is_member"} and $node->is_member
!ll&&!rl&&r
030
MC/DC0%0/2
not defined $attr->{"is_member"} and $node->is_member
not defined $attr->{"is_member"} $node->is_member
Truth table33%1/3
not(A) and B
A= not defined $attr->{"is_member"}B= $node->is_member
ABresult
0X0
100
111
66 {
67 0 $attr->{is_member} = 1;
68 }
69 }
70 3 return $attr;
71 3 };
72  
73  
74  
75 #------------------------------------------------------------------------------
76 # Tells whether this phrase is terminal. We could probably use the Moose's
77 # methods to query the class name but this will be more convenient.
78 #------------------------------------------------------------------------------
79 sub is_terminal
80 {
81 1 ▶ my $self = shift;
Subroutine is_terminal: called CC=1 SCAR=0.0
Pod documented
82 1 return 1;
83 }
84  
85  
86  
87 #------------------------------------------------------------------------------
88 # Returns the list of dependents of the phrase. Terminal phrases return an
89 # empty list by definition.
90 #------------------------------------------------------------------------------
91 sub dependents
92 {
93 0 ▶ my $self = shift;
Subroutine dependents: not called CC=1 SCAR=6.9
Pod documented
94 0 return ();
95 }
96  
97  
98  
99 #------------------------------------------------------------------------------
100 # Returns the list of children of the phrase. Terminal phrases return an empty
101 # list by definition.
102 #------------------------------------------------------------------------------
103 sub children
104 {
105 0 ▶ my $self = shift;
Subroutine children: not called CC=1 SCAR=6.9
Pod documented
106 0 return ();
107 }
108  
109  
110  
111 #------------------------------------------------------------------------------
112 # Projects dependencies between the head and the dependents back to the
113 # underlying dependency structure. There is not much to do in the terminal
114 # phrase as it does not have any dependents. However, we will attach all nodes
115 # to the root, to prevent temporary cycles during the tree construction.
116 #------------------------------------------------------------------------------
117 sub project_dependencies
118 {
119 0 ▶ my $self = shift;
Subroutine project_dependencies: not called CC=2 SCAR=17.9
Pod documented
120 0 my $node = $self->node();
121 0 ▶ unless($node->is_root())
Branch: 1 branch
BranchTrueFalseTotal
unless ($node->is_root) 0 0 0
122 {
123 0 my $root = $node->get_root();
124 0 $node->set_parent($root);
125 }
126 # Reset the is_member flag.
127 # If we are converting to the Prague style, the flag will be set again where needed.
128 0 $node->set_is_member(0);
129 }
130  
131  
132  
133 #------------------------------------------------------------------------------
134 # Returns a textual representation of the phrase and all subphrases. Useful for
135 # debugging.
136 #------------------------------------------------------------------------------
137 sub as_string
138 {
139 0 ▶ my $self = shift;
Subroutine as_string: not called CC=4 SCAR=30.0
Pod documented
140 0 my $node = $self->node();
141 0 my $form = '_';
142 0 ▶ if($node->is_root())
Branch: 2 branches
BranchTrueFalseTotal
if ($node->is_root) { } 0 0 0
elsif (defined $node->form) { } 0 0 0
143 {
144 0 $form = 'ROOT';
145 }
146 elsif(defined($node->form()))
147 {
148 0 $form = $node->form();
149 }
150 0 my $ord = $node->ord();
151 0 ▶ my $deprel = defined($self->deprel()) ? '-'.$self->deprel() : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $self->deprel ? : 0 0 0
152 0 return "[ $form-$ord$deprel ]";
153 }
154  
155  
156  
157 3 __PACKAGE__->meta->make_immutable();
158  
159 3 1;
160  
161  
162  
163 =for Pod::Coverage BUILD
164  
165 =encoding utf-8
166  
167 =head1 NAME
168  
169 Treex::Core::Phrase::Term
170  
171 =head1 VERSION
172  
173 version 2.20151210
174  
175 =head1 SYNOPSIS
176  
177 use Treex::Core::Document;
178 use Treex::Core::Phrase::Term;
179  
180 my $document = new Treex::Core::Document;
181 my $bundle = $document->create_bundle();
182 my $zone = $bundle->create_zone('en');
183 my $root = $zone->create_atree();
184 my $phrase = new Treex::Core::Phrase::Term ('node' => $root);
185  
186 =head1 DESCRIPTION
187  
188 C<Term> is a terminal C<Phrase>. It contains (refers to) one C<Node> and it can
189 be part of nonterminal phrases (C<NTerm>).
190 See L<Treex::Core::Phrase> for more details.
191  
192 =head1 ATTRIBUTES
193  
194 =over
195  
196 =item node
197  
198 Refers to the C<Node> wrapped in this terminal phrase.
199  
200 =item deprel
201  
202 Any label describing the type of the dependency relation between this phrase
203 (its node) and the governing phrase (node of the first ancestor phrase where
204 this one does not act as head). This label is typically taken from the
205 underlying node when the phrase is built, but it may be translated or modified
206 and it is not kept synchronized with the underlying dependency tree during
207 transformations of the phrase structure. Nevertheless it is assumed that once
208 the transformations are done, the final dependency relations will be projected
209 back to the dependency tree.
210  
211 The C<deprel> attribute can also be supplied separately when creating the
212 C<Phrase::Term>. If it is not supplied, it will be copied from the C<Node>
213 to which the C<node> attribute refers.
214  
215 =item dependents
216  
217 Returns the list of dependents of the phrase. Terminal phrases return an
218 empty list by definition.
219  
220 =item children
221  
222 Returns the list of children of the phrase. Terminal phrases return an
223 empty list by definition.
224  
225 =item project_dependencies
226  
227 Projects dependencies between the head and the dependents back to the
228 underlying dependency structure. There is not much to do in the terminal
229 phrase as it does not have any dependents. However, we will attach all nodes
230 to the root, to prevent temporary cycles during the tree construction.
231  
232 =item as_string
233  
234 Returns a textual representation of the phrase and all subphrases. Useful for
235 debugging.
236  
237 =back
238  
239 =head1 AUTHORS
240  
241 Daniel Zeman <zeman@ufal.mff.cuni.cz>
242  
243 =head1 COPYRIGHT AND LICENSE
244  
245 Copyright © 2013, 2015 by Institute of Formal and Applied Linguistics, Charles University in Prague
246 This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
« Treex/Core/Node.pm ↑ Summary Treex/Core/Config.pm »