| 1 | package Treex::Core::BundleZone; | ||||||||||||||||||||||||||||
| 2 | 35 | $Treex::Core::BundleZone::VERSION = '2.20151210'; | |||||||||||||||||||||||||||
| 3 | 35 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 35 | ▶ | use Treex::Core::Common; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 35 | ▶ | use MooseX::NonMoose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 35 | ▶ | use Treex::Core::Node::A; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 35 | ▶ | use Treex::Core::Node::T; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 35 | ▶ | use Treex::Core::Node::N; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 35 | ▶ | use Treex::Core::Node::P; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 35 | extends 'Treex::Core::Zone'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | sub _set_bundle { | ||||||||||||||||||||||||||||
| 15 | 48 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_set_bundle: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 48 | my ($bundle) = pos_validated_list( | |||||||||||||||||||||||||||
| 17 | \@_, | ||||||||||||||||||||||||||||
| 18 | { isa => 'Treex::Core::Bundle' }, | ||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||
| 20 | 48 | $self->set_attr( '_bundle', $bundle ); | |||||||||||||||||||||||||||
| 21 | 48 | weaken $self->{'_bundle'}; | |||||||||||||||||||||||||||
| 22 | 48 | return; | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | sub get_bundle { | ||||||||||||||||||||||||||||
| 26 | 1236 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
get_bundle: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | 1236 | return $self->get_attr('_bundle'); | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | sub get_document { | ||||||||||||||||||||||||||||
| 31 | 42 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
get_document: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 32 | 42 | return $self->get_bundle->get_document; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | sub create_atree { | ||||||||||||||||||||||||||||
| 36 | 9 | ▶ | my ($self,$params_rf) = @_; | ||||||||||||||||||||||||||
|
Subroutine
create_atree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 37 | 9 | return $self->create_tree('a',$params_rf); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | sub create_ttree { | ||||||||||||||||||||||||||||
| 41 | 10 | ▶ | my ($self,$params_rf) = @_; | ||||||||||||||||||||||||||
|
Subroutine
create_ttree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 10 | return $self->create_tree('t',$params_rf); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | sub create_ntree { | ||||||||||||||||||||||||||||
| 46 | 4 | ▶ | my ($self,$params_rf) = @_; | ||||||||||||||||||||||||||
|
Subroutine
create_ntree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 47 | 4 | return $self->create_tree('n',$params_rf); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | sub create_ptree { | ||||||||||||||||||||||||||||
| 51 | 6 | ▶ | my ($self,$params_rf) = @_; | ||||||||||||||||||||||||||
|
Subroutine
create_ptree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | 6 | return $self->create_tree('p',$params_rf); | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | sub create_tree { | ||||||||||||||||||||||||||||
| 56 | 78 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
create_tree: called CC=9 SCAR=22.2
Pod
documented
| |||||||||||||||||||||||||||||
| 57 | 78 | my ($layer,$params_rf) = pos_validated_list( | |||||||||||||||||||||||||||
| 58 | \@_, | ||||||||||||||||||||||||||||
| 59 | { isa => 'Treex::Type::Layer' }, | ||||||||||||||||||||||||||||
| 60 | { isa => 'Ref' }, | ||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||
| 62 | 78 | $layer = lc $layer; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 78 | ▶ | if ($self->has_tree($layer)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 12 | ▶ | if (defined $params_rf and $params_rf->{overwrite}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $params_rf and $params_rf->{"overwrite"}
MC/DC0%0/2
defined $params_rf and $params_rf->{"overwrite"}
defined $params_rf
$params_rf->{"overwrite"}
Truth table33%1/3
A and B
A= defined $params_rfB= $params_rf->{"overwrite"}
| |||||||||||||||||||||||||||||
| 66 | 12 | $self->remove_tree($layer); | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | else { | ||||||||||||||||||||||||||||
| 69 | 0 | log_fatal("Zone already contains tree at $layer layer"); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | #my $class = "Treex::Core::Node::" . uc($layer); | ||||||||||||||||||||||||||||
| 74 | #my $tree_root = eval { $class->new( { _called_from_core_ => 1 } ) } or log_fatal $!; #layer subclasses not available yet | ||||||||||||||||||||||||||||
| 75 | 78 | my $opts = { _called_from_core_ => 1 }; | |||||||||||||||||||||||||||
| 76 | 78 | ▶ | my $tree_root = $layer eq 'a' ? Treex::Core::Node::A->new($opts) | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 77 | : $layer eq 't' ? Treex::Core::Node::T->new($opts) | ||||||||||||||||||||||||||||
| 78 | : $layer eq 'n' ? Treex::Core::Node::N->new($opts) | ||||||||||||||||||||||||||||
| 79 | : $layer eq 'p' ? Treex::Core::Node::P->new($opts) | ||||||||||||||||||||||||||||
| 80 | : log_fatal "Cannot create tree for unknown layer $layer"; | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 78 | my $bundle = $self->get_bundle; | |||||||||||||||||||||||||||
| 83 | 78 | $tree_root->_set_zone($self); | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 78 | my $new_tree_name = $layer . "_tree"; | |||||||||||||||||||||||||||
| 86 | 78 | $self->{trees}->{$new_tree_name} = $tree_root; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 78 | my $new_id = "$new_tree_name-" . $self->get_label . "-" . $bundle->get_id . "-root"; | |||||||||||||||||||||||||||
| 89 | 78 | $tree_root->set_id($new_id); | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | # pml-typing | ||||||||||||||||||||||||||||
| 92 | #$tree_root->set_type_by_name( $self->get_document->metaData('schema'), lc($layer) . '-root.type' ); | ||||||||||||||||||||||||||||
| 93 | # $tree_root->set_type_by_name( $self->get_document->metaData('schema'), $tree_root->get_pml_type_name() ); | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 78 | $tree_root->fix_pml_type(); | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | # vyresit usporadavaci atribut! | ||||||||||||||||||||||||||||
| 98 | # TODO: if $tree_root->does('Treex::Core::Role::OrderedTree') | ||||||||||||||||||||||||||||
| 99 | 78 | my $ordering_attribute = $tree_root->get_ordering_member_name; | |||||||||||||||||||||||||||
| 100 | 78 | ▶ | if ( defined $ordering_attribute ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 52 | $tree_root->set_attr( $ordering_attribute, 0 ); | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 78 | return $tree_root; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | sub remove_tree { | ||||||||||||||||||||||||||||
| 108 | 42 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
remove_tree: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 109 | 42 | my ($layer) = pos_validated_list( | |||||||||||||||||||||||||||
| 110 | \@_, | ||||||||||||||||||||||||||||
| 111 | { isa => 'Treex::Type::Layer' }, | ||||||||||||||||||||||||||||
| 112 | ); | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | # remove all nodes ($tree_root->remove does not work, in order to not be used by users) | ||||||||||||||||||||||||||||
| 115 | 42 | my $tree_root = $self->get_tree($layer); | |||||||||||||||||||||||||||
| 116 | 42 | foreach my $child ( $tree_root->get_children() ) { | |||||||||||||||||||||||||||
| 117 | 13 | $child->remove(); | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | 42 | ▶ | if ( $tree_root->id ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 42 | $self->get_document->index_node_by_id( $tree_root->id, undef ); | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | 42 | delete $self->{trees}{ lc($layer) . '_tree' }; | |||||||||||||||||||||||||||
| 123 | 42 | return; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | sub get_tree { | ||||||||||||||||||||||||||||
| 127 | 108 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
get_tree: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 128 | 108 | my ($layer) = pos_validated_list( | |||||||||||||||||||||||||||
| 129 | \@_, | ||||||||||||||||||||||||||||
| 130 | { isa => 'Treex::Type::Layer' }, | ||||||||||||||||||||||||||||
| 131 | ); | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 108 | my $tree_name = lc($layer) . "_tree"; | |||||||||||||||||||||||||||
| 134 | 108 | my $tree = $self->{trees}->{$tree_name}; | |||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 108 | ▶ | if ( not defined $tree ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | 0 | log_fatal( "No $tree_name available in bundle ".$self->get_bundle->get_attr('id')." in zone " . $self->get_label() ); | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | 108 | return $tree; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | sub get_atree { | ||||||||||||||||||||||||||||
| 143 | 9 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
get_atree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 144 | 9 | return $self->get_tree('a'); | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | sub get_ttree { | ||||||||||||||||||||||||||||
| 148 | 9 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
get_ttree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 149 | 9 | return $self->get_tree('t'); | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | sub get_ntree { | ||||||||||||||||||||||||||||
| 153 | 7 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
get_ntree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 154 | 7 | return $self->get_tree('n'); | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | sub get_ptree { | ||||||||||||||||||||||||||||
| 158 | 6 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
get_ptree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 159 | 6 | return $self->get_tree('p'); | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | sub has_tree { | ||||||||||||||||||||||||||||
| 163 | 130 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
has_tree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 164 | 130 | my ($layer) = pos_validated_list( | |||||||||||||||||||||||||||
| 165 | \@_, | ||||||||||||||||||||||||||||
| 166 | { isa => 'Treex::Type::Layer' }, | ||||||||||||||||||||||||||||
| 167 | ); | ||||||||||||||||||||||||||||
| 168 | 130 | my $tree_name = lc($layer) . "_tree"; | |||||||||||||||||||||||||||
| 169 | 130 | return defined $self->{trees}->{$tree_name}; | |||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | sub has_atree { | ||||||||||||||||||||||||||||
| 173 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
has_atree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 174 | 3 | return $self->has_tree('a'); | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | sub has_ttree { | ||||||||||||||||||||||||||||
| 178 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
has_ttree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 179 | 3 | return $self->has_tree('t'); | |||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | sub has_ntree { | ||||||||||||||||||||||||||||
| 183 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
has_ntree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 184 | 3 | return $self->has_tree('n'); | |||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | sub has_ptree { | ||||||||||||||||||||||||||||
| 188 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
has_ptree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 189 | 3 | return $self->has_tree('p'); | |||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | sub get_all_trees { | ||||||||||||||||||||||||||||
| 193 | 459 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
get_all_trees: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 1836 | return grep {defined} | |||||||||||||||||||||||||||
| 196 | 459 | map { $self->{trees}->{ $_ . "_tree" }; } qw(a t n p); | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | sub sentence { | ||||||||||||||||||||||||||||
| 200 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
sentence: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 201 | 0 | return $self->get_attr('sentence'); | |||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | sub set_sentence { | ||||||||||||||||||||||||||||
| 205 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
set_sentence: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 206 | 0 | my ($text) = pos_validated_list( | |||||||||||||||||||||||||||
| 207 | \@_, | ||||||||||||||||||||||||||||
| 208 | { isa => 'Str' }, | ||||||||||||||||||||||||||||
| 209 | ); | ||||||||||||||||||||||||||||
| 210 | 0 | return $self->set_attr( 'sentence', $text ); | |||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | sub copy { | ||||||||||||||||||||||||||||
| 214 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
copy: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 215 | 0 | my $selector1 = shift; | |||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | # Get the bundle the zone is in. | ||||||||||||||||||||||||||||
| 218 | 0 | my $bundle = $self->get_bundle(); | |||||||||||||||||||||||||||
| 219 | 0 | my $zone1 = $bundle->get_or_create_zone( $self->language(), $selector1 ); | |||||||||||||||||||||||||||
| 220 | ### TO DO: copy other trees, too (currently only copies a-tree and p-tree) | ||||||||||||||||||||||||||||
| 221 | 0 | ▶ | if($self->has_atree()) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 222 | { | ||||||||||||||||||||||||||||
| 223 | 0 | my $aroot0 = $self->get_atree(); | |||||||||||||||||||||||||||
| 224 | 0 | my $aroot1 = $zone1->create_atree(); | |||||||||||||||||||||||||||
| 225 | 0 | $aroot0->copy_atree($aroot1); | |||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | 0 | ▶ | if($self->has_ptree()) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 228 | { | ||||||||||||||||||||||||||||
| 229 | 0 | my $proot0 = $self->get_ptree(); | |||||||||||||||||||||||||||
| 230 | 0 | my $proot1 = $zone1->create_ptree(); | |||||||||||||||||||||||||||
| 231 | 0 | $proot0->copy_ptree($proot1); | |||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||
| 233 | 0 | return $zone1; | |||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | 35 | 1; | |||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | __END__ | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | =for Pod::Coverage set_sentence | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | =encoding utf-8 | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | =head1 NAME | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | Treex::Core::BundleZone - contains a sentence and its linguistic representations | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | =head1 VERSION | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | version 2.20151210 | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | use Treex::Core; | ||||||||||||||||||||||||||||
| 255 | my $doc = Treex::Core->new; | ||||||||||||||||||||||||||||
| 256 | my $bundle = $doc->create_bundle(); | ||||||||||||||||||||||||||||
| 257 | my $zone = $bundle->create_zone('en','reference'); | ||||||||||||||||||||||||||||
| 258 | $zone->set_sentence('John loves Mary.'); | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | Document zones allow Treex documents to contain more texts, | ||||||||||||||||||||||||||||
| 264 | typically parallel texts (translations), or corresponding | ||||||||||||||||||||||||||||
| 265 | texts from different sources (text to be translated, reference | ||||||||||||||||||||||||||||
| 266 | translation, test translation). | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | C<Treex::Core::BundleZone> instances have the following attributes: | ||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | =over 4 | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | =item language | ||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | =item selector | ||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | =item sentence | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | =back | ||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | The attributes can be accessed using semi-affordance accessors: getters have | ||||||||||||||||||||||||||||
| 283 | the same names as attributes, while setters start with C<set_>. For example, | ||||||||||||||||||||||||||||
| 284 | the attribute C<sentence> has a getter C<sentence()> and a setter | ||||||||||||||||||||||||||||
| 285 | C<set_sentence($sentence)> | ||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | =head1 METHODS | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | =head2 Construction | ||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | C<Treex::Core::BundleZone> instances should not be created by the constructor, | ||||||||||||||||||||||||||||
| 293 | but should be created exclusively by calling one of the following methods | ||||||||||||||||||||||||||||
| 294 | of the embedding L<Treex::Core::Bundle> instance: | ||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | =over 4 | ||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | =item create_zone | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | =item get_or_create_zone | ||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | =back | ||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | =head2 Access to trees | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | There are four types of linguistic trees distinguished in Treex, each of them represented | ||||||||||||||||||||||||||||
| 308 | by one letter: I<a> - analytical treex, I<t> - tectogrammatical trees, I<p> - phrase-structure trees, | ||||||||||||||||||||||||||||
| 309 | I<n> - named entity trees. You can create trees by following methods: | ||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | =over 4 | ||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | =item $zone->create_tree($layer); | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | =item $zone->create_atree(); | ||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | =item $zone->create_ttree(); | ||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | =item $zone->create_ptree(); | ||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | =item $zone->create_ntree(); | ||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | =back | ||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | You can access trees by | ||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | =over 4 | ||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | =item $zone->get_tree($layer); | ||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | =item $zone->get_atree(); | ||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | =item $zone->get_ttree(); | ||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | =item $zone->get_ptree(); | ||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | =item $zone->get_ntree(); | ||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | =item $zone->get_all_trees(); | ||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | =back | ||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | Presence of a tree of a certain type can be detected by | ||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||
| 347 | =over 4 | ||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | =item $zone->has_tree($layer); | ||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | =item $zone->has_atree(); | ||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | =item $zone->has_ttree(); | ||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | =item $zone->has_ptree(); | ||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | =item $zone->has_ntree(); | ||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | =back | ||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | You can remove trees by | ||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | =over 4 | ||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | =item $zone->remove_tree($layer); | ||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | =back | ||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||
| 371 | =head2 Access to embedding objects | ||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | =over 4 | ||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||
| 375 | =item $bundle = $zone->get_bundle(); | ||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||
| 377 | returns the L<Treex::Core::Bundle> instance which the zone belongs to | ||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||
| 379 | =item $doc = $zone->get_document(); | ||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||
| 381 | returns the L<Treex::Core::Document> instance which the zone belongs to | ||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||
| 383 | =back | ||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | =head2 Other | ||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | =over 4 | ||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | =item $zone1 = $zone0->copy($selector1); | ||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | creates a copy of the zone (currently copies only the a-tree) under the same language and a new selector | ||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | =back | ||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | Zdeněk Žabokrtský <zabokrtsky@ufal.mff.cuni.cz> | ||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | Martin Popel <popel@ufal.mff.cuni.cz> | ||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||
| 402 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||
| 404 | Copyright © 2011 by Institute of Formal and Applied Linguistics, Charles University in Prague | ||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||