| 1 | package Treex::Block::Read::AlignedSentences; | ||||||||||
| 2 | 2 | $Treex::Block::Read::AlignedSentences::VERSION = '2.20151102'; | |||||||||
| 3 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use Treex::Core::Common; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | extends 'Treex::Block::Read::BaseAlignedTextReader'; | |||||||||
| 8 | |||||||||||
| 9 | 2 | ▶ | sub next_document { | ||||||||
|
Subroutine
next_document: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||
| 10 | 2 | my ($self) = @_; | |||||||||
| 11 | |||||||||||
| 12 | 2 | my $texts_ref = $self->next_document_texts(); | |||||||||
| 13 | |||||||||||
| 14 | 2 | ▶ | return if !defined $texts_ref; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 15 | |||||||||||
| 16 | my %sentences = | ||||||||||
| 17 | 2 | map { $_ => [ split /\n/, $texts_ref->{$_} ] } keys %{$texts_ref}; | |||||||||
| 18 | |||||||||||
| 19 | 2 | my $n = 0; | |||||||||
| 20 | 2 | for my $zone_label ( keys %sentences ) { | |||||||||
| 21 | 4 | ▶ | if ( !$n ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 2 | $n = @{ $sentences{$zone_label} }; | |||||||||
| 23 | } | ||||||||||
| 24 | log_fatal "Different number of lines in aligned documents" | ||||||||||
| 25 | 4 | ▶ | if $n != @{ $sentences{$zone_label} }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | 1 | my $doc = $self->new_document(); | |||||||||
| 29 | 1 | for my $i ( 0 .. $n - 1 ) { | |||||||||
| 30 | 2 | my $bundle = $doc->create_bundle(); | |||||||||
| 31 | 2 | for my $zone_label ( keys %sentences ) { | |||||||||
| 32 | 4 | my ( $lang, $selector ) = ( $zone_label, $self->selector ); | |||||||||
| 33 | 4 | ▶ | if ( $zone_label =~ /_/ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 2 | ( $lang, $selector ) = split /_/, $zone_label; | |||||||||
| 35 | } | ||||||||||
| 36 | 4 | my $zone = $bundle->create_zone( $lang, $selector ); | |||||||||
| 37 | 4 | $zone->set_sentence( $sentences{$zone_label}[$i] ); | |||||||||
| 38 | } | ||||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | 1 | return $doc; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 2 | 1; | |||||||||
| 45 | |||||||||||
| 46 | __END__ | ||||||||||