blib/lib/PMLTQ/Relation/TreexFileIterator.pm

filter: Statementstmt 41.8% 31 / 74 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 24 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 64.2% 9 / 14 Podpod 0.0% 0 / 3 totaltotal 27.5% 40 / 145 CC 20 SCAR 38.1
CC
20
Cov
27%
next
90.0
_next_file
72.0
_extract_trees
20.0
CRAP 45.1
« blib/lib/PMLTQ/Command/init.pm ↑ Summary blib/lib/PMLTQ/Command/webtreebank.pm »
1 package PMLTQ::Relation::TreexFileIterator;
2 13 our $AUTHORITY = 'cpan:MATY';
3 13 $PMLTQ::Relation::TreexFileIterator::VERSION = '1.5.0';
4 # ABSTRACT: Same as L<PMLTQ::Relation::FileIterator> but for Treex files
5  
6 13 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 13 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 13 ▶use base qw(PMLTQ::Relation::CurrentFileIterator);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 13 ▶use constant TREES=>PMLTQ::Relation::CurrentFileIterator::FIRST_FREE;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 13 ▶use constant TREEX_DOC=>PMLTQ::Relation::CurrentFileIterator::FIRST_FREE+1;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 13 ▶use PMLTQ::Loader 'load_class';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 13 ▶use English qw(-no_match_vars); # Load this because otherwise Treex::Core ends up with error on Perl 5.14
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 13 our $PROGRESS; ### newly added
19 13 our $STOP; ### newly added
20  
21 sub new {
22 0 ▶ my ($class,$conditions,$schema_root_name)=@_;
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
23  
24 0 ▶ croak 'Please install Treex::Core if you want to use PML-TQ with treex files' unless load_class('Treex::Core::Document');
Branch: 1 branch
BranchTrueFalseTotal
unless load_class("Treex::Core::Document") 0 0 0
25  
26 0 my $self = CurrentFileIterator->new($conditions, $schema_root_name);
27 0 $self->[TREES] = [];
28 0 return bless $self, $class; # rebless
29 }
30  
31 sub tree {
32 0 ▶ my ($self, $n)=@_;
Subroutine tree: not called CC=1 SCAR=6.9
Pod undocumented
33 0 return $self->[TREES]->[$n];
34 }
35  
36 sub _next_file {
37 0 ▶ my ($self)=@_;
Subroutine _next_file: not called CC=8 SCAR=42.8
38 0 my $f;
39 0 my $schema_name = $self->[PMLTQ::Relation::CurrentFileIterator::SCHEMA_ROOT_NAME];
40 0 ▶ while (@{$self->[PMLTQ::Relation::CurrentFileIterator::FILE_QUEUE]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->[5];}) 0 0 0
41 0 $f = shift @{$self->[PMLTQ::Relation::CurrentFileIterator::FILE_QUEUE]};
42 0 ▶ if ($f) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f) 0 0 0
43 0 push @{$self->[PMLTQ::Relation::CurrentFileIterator::FILE_QUEUE]}, TredMacro::GetSecondaryFiles($f);
44 0 ▶ if (!defined($schema_name) or $schema_name eq PML::SchemaName($f)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $schema_name or $schema_name eq PML::SchemaName($f)) 0 0 0
Condition0%0/3
not defined $schema_name or $schema_name eq PML::SchemaName($f)
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $schema_name or $schema_name eq PML::SchemaName($f)
not defined $schema_name $schema_name eq PML::SchemaName($f)
Truth table0%0/3
not(A) or B
A= not defined $schema_nameB= $schema_name eq PML::SchemaName($f)
ABresult
1X1
011
000
45 0 $self->[PMLTQ::Relation::CurrentFileIterator::FILE]=$f;
46 0 $self->[TREEX_DOC] = Treex::Core::Document->new({pmldoc => $f}); # This will rebless the file document as Treex::Core::Document
47 0 $self->[PMLTQ::Relation::CurrentFileIterator::TREE_NO]=0;
48 0 $self->_extract_trees;
49 0 my $n = $self->[PMLTQ::Relation::CurrentFileIterator::NODE] = $self->tree(0);
50 0 ▶ return ($n && $self->[PMLTQ::Relation::CurrentFileIterator::CONDITIONS]->($n,$f)) ? $n : ($n && $self->next)
Branch: 1 branch
BranchTrueFalseTotal
$n && $self->[0]->($n, $f) ? : 0 0 0
Condition0%0/6
$n and $self->[0]->($n, $f)
!ll&&!rl&&r
000
$n and $self->next
!ll&&!rl&&r
000
MC/DC0%0/2
$n and $self->[0]->($n, $f)
$n $self->[0]->($n, $f)
MC/DC0%0/2
$n and $self->next
$n $self->next
Truth table0%0/3
A and B
A= $nB= $self->[0]->($n, $f)
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $nB= $self->next
ABresult
0X0
100
111
51 }
52 }
53 }
54 0 return;
55 }
56  
57 # Don't use any treex specific methods, nodes might not be reblessed
58 sub _extract_trees {
59 0 ▶ my ($self)=@_;
Subroutine _extract_trees: not called CC=4 SCAR=30.0
60 0 my $doc = $self->[TREEX_DOC];
61 # lets assume it's a treex doc
62 0 $self->[TREES] = [];
63 0 foreach my $bundle ($doc->get_bundles) {
64 0 ▶ last unless defined $bundle->{zones};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bundle->{"zones"} 0 0 0
65 0 foreach my $zone ($bundle->get_all_zones) {
66 0 push @{$self->[TREES]}, $zone->get_all_trees;
67 }
68 }
69 }
70  
71 sub next {
72 0 ▶ my ($self)=@_;
Subroutine next: not called CC=9 SCAR=45.0
Pod undocumented
73 0 my $conditions=$self->[PMLTQ::Relation::CurrentFileIterator::CONDITIONS];
74 0 my $n=$self->[PMLTQ::Relation::CurrentFileIterator::NODE];
75 0 my $f=$self->[PMLTQ::Relation::CurrentFileIterator::FILE];
76 0 ▶ while ($n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n) 0 0 0
77 # Treex has following hacked but we want to have classic following
78 $n = Treex::PML::Node::following($n) ||
79 0 ▶ (($PROGRESS ? $PROGRESS->() : 1) && $STOP && do { $n = undef; last }) ||
Branch: 1 branch
BranchTrueFalseTotal
$PMLTQ::Relation::TreexFileIterator::PROGRESS ? : 0 0 0
Condition0%0/15
Treex::PML::Node::following($n) || ($PMLTQ::Relation::TreexFileIterator::PROGRESS ? &$PMLTQ::Relation::TreexFileIterator::PROGRESS() : 1) && $PMLTQ::Relation::TreexFileIterator::STOP && do { $n = undef; last } || $self->tree(++$self->[3]) || $self->_next_file
l!l&&r!l&&!r
000
Treex::PML::Node::following($n) or $PMLTQ::Relation::TreexFileIterator::PROGRESS ? &$PMLTQ::Relation::TreexFileIterator::PROGRESS() : 1 and $PMLTQ::Relation::TreexFileIterator::STOP and do { $n = undef; last } or $self->tree(++$self->[3])
l!l&&r!l&&!r
000
Treex::PML::Node::following($n) or $PMLTQ::Relation::TreexFileIterator::PROGRESS ? &$PMLTQ::Relation::TreexFileIterator::PROGRESS() : 1 and $PMLTQ::Relation::TreexFileIterator::STOP and do { $n = undef; last }
l!l&&r!l&&!r
000
$PMLTQ::Relation::TreexFileIterator::PROGRESS ? &$PMLTQ::Relation::TreexFileIterator::PROGRESS() : 1 and $PMLTQ::Relation::TreexFileIterator::STOP and do { $n = undef; last }
!ll&&!rl&&r
000
$PMLTQ::Relation::TreexFileIterator::PROGRESS ? &$PMLTQ::Relation::TreexFileIterator::PROGRESS() : 1 and $PMLTQ::Relation::TreexFileIterator::STOP
!ll&&!rl&&r
000
MC/DC0%0/6
Treex::PML::Node::following($n) || ($PMLTQ::Relation::TreexFileIterator::PROGRESS ? &$PMLTQ::Relation::TreexFileIterator::PROGRESS() : 1) && $PMLTQ::Relation::TreexFileIterator::STOP && do { $n = undef; last } || $self->tree(++$self->[3]) || $self->_next_file
Treex::PML::Node::following($n) $PMLTQ::Relation::TreexFileIterator::PROGRESS ? &$PMLTQ::Relation::TreexFileIterator::PROGRESS() : 1 $PMLTQ::Relation::TreexFileIterator::STOP do { $n = undef; last } $self->tree(++$self->[3]) $self->_next_file
Truth table0%0/11
A or B and C and D or E || F
A= Treex::PML::Node::following($n)B= $PMLTQ::Relation::TreexFileIterator::PROGRESS ? &$PMLTQ::Relation::TreexFileIterator::PROGRESS() : 1C= $PMLTQ::Relation::TreexFileIterator::STOPD= do { $n = undef; last }E= $self->tree(++$self->[3])F= $self->_next_file
ABCDEFresult
1XXXXX1
0111XX1
00XX1X1
010X1X1
01101X1
00XX011
010X011
0110011
00XX000
010X000
0110000
80 $self->tree(++$self->[PMLTQ::Relation::CurrentFileIterator::TREE_NO]) || $self->_next_file();
81  
82 0 ▶ last if $conditions->($n,$f);
Branch: 1 branch
BranchTrueFalseTotal
if &$conditions($n, $f) 0 0 0
83 }
84 0 return $self->[PMLTQ::Relation::CurrentFileIterator::NODE]=$n;
85 }
86  
87 13 1; # End of PMLTQ::Relation::TreexFileIterator
88  
89 __END__
« blib/lib/PMLTQ/Command/init.pm ↑ Summary blib/lib/PMLTQ/Command/webtreebank.pm »