Block/Read/AlignedSentences.pm

filter: Statementstmt 100% 38 / 38 Branchbran 87.5% 7 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 98.0% 51 / 52 CC 8 SCAR 17.3
CC
8
Cov
98%
next_document
8.0
BEGIN
1.0
BEGIN
1.0
CRAP 5.7
« Tool/Tagger/MorphoDiTa.pm ↑ Summary Block/W2A/SegmentOnNewlines.pm »
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
BranchTrueFalseTotal
unless defined $texts_ref 0 2 2
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
BranchTrueFalseTotal
unless ($n) 2 2 4
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
BranchTrueFalseTotal
if $n != @{$sentences{$zone_label};} 1 3 4
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
BranchTrueFalseTotal
if ($zone_label =~ /_/) 2 2 4
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__
« Tool/Tagger/MorphoDiTa.pm ↑ Summary Block/W2A/SegmentOnNewlines.pm »