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