Block/Read/CoNLLX.pm

filter: Statementstmt 32.2% 20 / 62 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 5 / 6 Podpod 100% 1 / 1 totaltotal 30.5% 26 / 85 CC 12 SCAR 47.0
CC
12
Cov
26%
next_document
156.0
BEGIN
1.0
BEGIN
1.0
CRAP 110.4
« Block/W2A/Tag.pm ↑ Summary Tool/Segment/RuleBased.pm »
1 package Treex::Block::Read::CoNLLX;
2 1 $Treex::Block::Read::CoNLLX::VERSION = '2.20151102';
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Treex::Core::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use File::Slurp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 extends 'Treex::Block::Read::BaseCoNLLReader';
9  
10 1 has feat_is_iset => ( is => 'rw', isa => 'Bool', default => 0 );
11  
12 1 has deprel_is_afun => ( is => 'rw', isa => 'Bool', default => 0 );
13  
14 0 ▶sub next_document {
Subroutine next_document: not called CC=12 SCAR=50.5
Pod documented
15 0 my ($self) = @_;
16 0 my $text = $self->next_document_text();
17 0 ▶ return if !defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 0 0
18  
19 0 my $document = $self->new_document();
20 0 foreach my $tree ( split /\n\s*\n/, $text ) {
21 0 my @tokens = split( /\n/, $tree );
22 # Skip empty sentences (if any sentence is empty at all,
23 # typically it is the first or the last one because of superfluous empty lines).
24 0 ▶ next unless(@tokens);
Branch: 1 branch
BranchTrueFalseTotal
unless @tokens 0 0 0
25 0 my $bundle = $document->create_bundle();
26 0 my $zone = $bundle->create_zone( $self->language, $self->selector );
27 0 my $aroot = $zone->create_atree();
28 0 ▶ if ( $self->deprel_is_afun ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->deprel_is_afun) 0 0 0
29 0 $aroot->set_afun('AuxS');
30 }
31 0 my @parents = (0);
32 0 my @nodes = ($aroot);
33 0 my $sentence;
34 0 foreach my $token (@tokens) {
35 0 ▶ next if $token =~ /^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $token =~ /^\s*$/ 0 0 0
36 0 my ( $id, $form, $lemma, $cpos, $pos, $feat, $head, $deprel ) = split( /\t/, $token );
37 0 my $newnode = $aroot->create_child();
38 0 $newnode->shift_after_subtree($aroot);
39 0 $newnode->set_form($form);
40 0 $newnode->set_lemma($lemma);
41 0 $newnode->set_tag($pos);
42 0 $newnode->set_conll_cpos($cpos);
43 0 $newnode->set_conll_pos($pos);
44 0 $newnode->set_conll_feat($feat);
45 0 ▶ if ( $self->feat_is_iset ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->feat_is_iset) 0 0 0
46 0 $newnode->set_iset_conll_feat($feat);
47 }
48 0 $newnode->set_conll_deprel($deprel);
49 0 ▶ if ( $self->deprel_is_afun ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->deprel_is_afun) 0 0 0
50 0 ▶ if ( $deprel =~ /_M$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($deprel =~ /_M$/) 0 0 0
51 0 $newnode->set_is_member(1);
52 0 $deprel =~ s/_M$//;
53 }
54 0 $newnode->set_afun($deprel);
55 }
56 0 ▶ $sentence .= "$form " if(defined($form));
Branch: 1 branch
BranchTrueFalseTotal
if defined $form 0 0 0
57 0 push @nodes, $newnode;
58 0 push @parents, $head;
59 }
60 0 foreach my $i ( 1 .. $#nodes ) {
61 0 $nodes[$i]->set_parent( $nodes[ $parents[$i] ] );
62 }
63 0 $sentence =~ s/\s+$//;
64 0 $zone->set_sentence($sentence);
65 }
66  
67 0 return $document;
68 }
69  
70 1 1;
71  
72 __END__
« Block/W2A/Tag.pm ↑ Summary Tool/Segment/RuleBased.pm »