Treex/Core/Phrase/Builder.pm

filter: Statementstmt 67.3% 33 / 49 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 10 / 12 Podpod 100% 2 / 2 totaltotal 69.2% 45 / 65 CC 3 SCAR 12.3
CC
3
Cov
65%
build
12.0
detect_special_constructions
2.0
BEGIN
1.0
CRAP 3.4
« Treex/Core/TredView/AnnotationCommand.pm ↑ Summary Treex/Tool/Probe.pm »
1 package Treex::Core::Phrase::Builder;
2 1 $Treex::Core::Phrase::Builder::VERSION = '2.20151210';
3 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use List::MoreUtils qw(any);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Treex::Core::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Treex::Core::Node;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Treex::Core::Phrase::Term;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Treex::Core::Phrase::NTerm;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Treex::Core::Phrase::PP;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Treex::Core::Phrase::Coordination;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16  
17 #------------------------------------------------------------------------------
18 # Wraps a node (and its subtree, if any) in a phrase.
19 #------------------------------------------------------------------------------
20 sub build
21 {
22 0 ▶ my $self = shift;
Subroutine build: not called CC=3 SCAR=24.8
Pod documented
23 0 my $node = shift; # Treex::Core::Node
24 0 my @nchildren = $node->children();
25 0 my $phrase = new Treex::Core::Phrase::Term('node' => $node);
26 0 ▶ if(@nchildren)
Branch: 1 branch
BranchTrueFalseTotal
if (@nchildren) 0 0 0
27 {
28 # Move the is_member flag to the parent phrase.
29 0 my $member = $phrase->is_member();
30 0 $phrase->set_is_member(0);
31 # Create a new nonterminal phrase and make the current terminal phrase its head child.
32 0 $phrase = new Treex::Core::Phrase::NTerm('head' => $phrase, 'is_member' => $member);
33 0 foreach my $nchild (@nchildren)
34 {
35 0 my $pchild = $self->build($nchild);
36 0 $pchild->set_parent($phrase);
37 }
38 }
39 # Now look at the new phrase whether it corresponds to any special construction.
40 # This may include tree transformations and even construction of a new nonterminal of a special
41 # class (we will get the new phrase as the result and the old one will be discarded).
42 # We can only inspect and modify the current phrase and its children.
43 # Nevertheless, we still have to include terminal phrases because we may have to change their deprels.
44 0 $phrase = $self->detect_special_constructions($phrase);
45 0 return $phrase;
46 }
47  
48  
49  
50 #------------------------------------------------------------------------------
51 # Examines a nonterminal phrase and tries to recognize certain special phrase
52 # types. This part will be different for different builders. It depends both on
53 # the expected input style and the desired output style. This method is always
54 # called after a new nonterminal phrase is built. It can be defined as empty if
55 # the builder does not do anything special.
56 #------------------------------------------------------------------------------
57 sub detect_special_constructions
58 {
59 0 ▶ my $self = shift;
Subroutine detect_special_constructions: not called CC=1 SCAR=6.9
Pod documented
60 0 my $phrase = shift; # Treex::Core::Phrase
61 # Do the treebank-specific manipulations here.
62 # Return the resulting phrase. It may be different from the input phrase.
63 0 return $phrase;
64 }
65  
66  
67  
68 1 __PACKAGE__->meta->make_immutable();
69  
70 1 1;
71  
72  
73  
74 =for Pod::Coverage BUILD
75  
76 =encoding utf-8
77  
78 =head1 NAME
79  
80 Treex::Core::Phrase::Builder
81  
82 =head1 VERSION
83  
84 version 2.20151210
85  
86 =head1 DESCRIPTION
87  
88 A C<Builder> provides methods to construct a phrase structure tree around
89 a dependency tree. It takes a C<Node> and returns a C<Phrase>.
90  
91 The tree of phrases is constructed bottom-up and after every new nonterminal
92 phrase is created, the method C<detect_special_constructions()> is called.
93 It is empty by default but derived classes may use it to implement detection
94 of special phrase types in particular annotation styles, such as the Prague-style
95 coordination. See C<Treex::Tool::PhraseBuilder> for an example.
96  
97 =head1 METHODS
98  
99 =over
100  
101 =item build
102  
103 Wraps a node (and its subtree, if any) in a phrase.
104  
105 =item detect_special_constructions
106  
107 Takes a phrase and returns either the same phrase, or a new phrase that should
108 replace it.
109  
110 Examines a nonterminal phrase and tries to recognize certain special phrase
111 types. This part will be different for different builders. It depends both on
112 the expected input style and the desired output style. This method is always
113 called after a new nonterminal phrase is built. It can be defined as empty if
114 the builder does not do anything special.
115  
116 =back
117  
118 =head1 AUTHORS
119  
120 Daniel Zeman <zeman@ufal.mff.cuni.cz>
121  
122 =head1 COPYRIGHT AND LICENSE
123  
124 Copyright © 2015 by Institute of Formal and Applied Linguistics, Charles University in Prague
125 This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
« Treex/Core/TredView/AnnotationCommand.pm ↑ Summary Treex/Tool/Probe.pm »