| 1 | package Treex::Tool::Parser::MSTperl::Node; | ||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||
| 3 | 10 | $Treex::Tool::Parser::MSTperl::Node::VERSION = '0.11949'; | |||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 10 | has config => ( | |||||||||||||||||||||||||||
| 9 | isa => 'Treex::Tool::Parser::MSTperl::Config', | ||||||||||||||||||||||||||||
| 10 | is => 'ro', | ||||||||||||||||||||||||||||
| 11 | required => '1', | ||||||||||||||||||||||||||||
| 12 | ); | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 10 | has fields => ( | |||||||||||||||||||||||||||
| 15 | isa => 'ArrayRef[Str]', | ||||||||||||||||||||||||||||
| 16 | is => 'rw', | ||||||||||||||||||||||||||||
| 17 | required => '1', | ||||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 10 | has ord => ( | |||||||||||||||||||||||||||
| 21 | isa => 'Int', | ||||||||||||||||||||||||||||
| 22 | is => 'rw', | ||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 10 | has parent => ( | |||||||||||||||||||||||||||
| 26 | isa => 'Maybe[Treex::Tool::Parser::MSTperl::Node]', | ||||||||||||||||||||||||||||
| 27 | is => 'rw', | ||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 10 | has parentOrd => ( | |||||||||||||||||||||||||||
| 31 | isa => 'Int', | ||||||||||||||||||||||||||||
| 32 | is => 'rw', | ||||||||||||||||||||||||||||
| 33 | default => 0, | ||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | has children => ( | ||||||||||||||||||||||||||||
| 37 | isa => 'ArrayRef[Treex::Tool::Parser::MSTperl::Edge]', | ||||||||||||||||||||||||||||
| 38 | is => 'rw', | ||||||||||||||||||||||||||||
| 39 | 645 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | 10 | ); | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 10 | has label => ( | |||||||||||||||||||||||||||
| 43 | isa => 'Str', | ||||||||||||||||||||||||||||
| 44 | is => 'rw', | ||||||||||||||||||||||||||||
| 45 | default => '_', | ||||||||||||||||||||||||||||
| 46 | trigger => \&_label_set, | ||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | # label updated => need to update features of children | ||||||||||||||||||||||||||||
| 50 | # which contain LABEL | ||||||||||||||||||||||||||||
| 51 | # (i.e. FeaturesControl->feature_parent on config->label_field_index) | ||||||||||||||||||||||||||||
| 52 | # probably obsolete, now handled by dynamic features notion | ||||||||||||||||||||||||||||
| 53 | 370 | ▶ | sub _label_set { | ||||||||||||||||||||||||||
|
Subroutine
_label_set: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 370 | my ($self) = @_; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # my ( $self, $parent_label ) = @_; | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 370 | my $ALGORITHM = $self->config->labeller_algorithm; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 370 | ▶ | if ( $ALGORITHM < 20 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 370 | ▶ | if ( $self->_fully_built ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | # TODO: not necessary to update ALL of the features! | ||||||||||||||||||||||||||||
| 65 | 231 | foreach my $child_edge ( @{ $self->children } ) { | |||||||||||||||||||||||||||
| 66 | 197 | my $edge_features = $self->config-> | |||||||||||||||||||||||||||
| 67 | labelledFeaturesControl->get_all_features($child_edge); | ||||||||||||||||||||||||||||
| 68 | 197 | $child_edge->features($edge_features); | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # else only just building -> no updating yet! | ||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 370 | return; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 10 | has _fully_built => ( | |||||||||||||||||||||||||||
| 79 | isa => 'Bool', | ||||||||||||||||||||||||||||
| 80 | is => 'rw', | ||||||||||||||||||||||||||||
| 81 | default => '0', | ||||||||||||||||||||||||||||
| 82 | ); | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 645 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 85 | 645 | my ($self) = @_; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | # handle parentOrd | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 645 | my $parentOrdIndex = $self->config->parent_ord_field_index; | |||||||||||||||||||||||||||
| 90 | 645 | my $parentOrd = $self->fields->[$parentOrdIndex]; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | # if parent is set (i.e. not filled with dummy value) | ||||||||||||||||||||||||||||
| 93 | 645 | ▶ | if ( defined $parentOrd && $parentOrd != -2 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $parentOrd and $parentOrd != -2
MC/DC50%1/2
defined $parentOrd and $parentOrd != -2
defined $parentOrd
$parentOrd != -2
Truth table66%2/3
A and B
A= defined $parentOrdB= $parentOrd != -2
| |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | # set the parentOrd field | ||||||||||||||||||||||||||||
| 96 | 140 | $self->parentOrd($parentOrd); | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | # fill with dummy value as this must not be used | ||||||||||||||||||||||||||||
| 101 | # (use node->parentOrd instead) | ||||||||||||||||||||||||||||
| 102 | 645 | $self->fields->[$parentOrdIndex] = -2; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | # handle label | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 645 | my $labelIndex = $self->config->label_field_index; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | # if label is used | ||||||||||||||||||||||||||||
| 109 | 645 | ▶ | if ( defined $labelIndex ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 645 | my $label = $self->fields->[$labelIndex]; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | # if label is set (i.e. not filled with dummy value) | ||||||||||||||||||||||||||||
| 113 | 645 | ▶ | if ( defined $label && $label ne '_' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $label and $label ne "_"
MC/DC50%1/2
defined $label and $label ne "_"
defined $label
$label ne "_"
Truth table66%2/3
A and B
A= defined $labelB= $label ne "_"
| |||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | # set the label field | ||||||||||||||||||||||||||||
| 116 | 140 | $self->label($label); | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | # fill with dummy value as this must not be used | ||||||||||||||||||||||||||||
| 121 | # (use node->label instead) | ||||||||||||||||||||||||||||
| 122 | 645 | $self->fields->[$labelIndex] = '_'; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | # my $debug = join ',', @{$self->fields}; | ||||||||||||||||||||||||||||
| 126 | # warn "$debug\n"; | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 645 | $self->_fully_built(1); | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 645 | return; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 231 | ▶ | sub copy_nonparsed { | ||||||||||||||||||||||||||
|
Subroutine
copy_nonparsed: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 134 | 231 | my ($self) = @_; | |||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 231 | my $copy = Treex::Tool::Parser::MSTperl::Node->new( | |||||||||||||||||||||||||||
| 137 | fields => $self->fields, | ||||||||||||||||||||||||||||
| 138 | config => $self->config, | ||||||||||||||||||||||||||||
| 139 | ); | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 231 | return $copy; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 231 | ▶ | sub copy_nonlabelled { | ||||||||||||||||||||||||||
|
Subroutine
copy_nonlabelled: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 145 | 231 | my ($self) = @_; | |||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 231 | my $copy = Treex::Tool::Parser::MSTperl::Node->new( | |||||||||||||||||||||||||||
| 148 | fields => $self->fields, | ||||||||||||||||||||||||||||
| 149 | config => $self->config, | ||||||||||||||||||||||||||||
| 150 | parentOrd => $self->parentOrd, | ||||||||||||||||||||||||||||
| 151 | ); | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 231 | return $copy; | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 10 | 1; | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | __END__ | ||||||||||||||||||||||||||||