Treex/Block/Util/FixInvalidIDs.pm

filter: Statementstmt 33.3% 10 / 30 Branchbran 0.0% 0 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 2 / 3 Podpod 100% 1 / 1 totaltotal 24.0% 13 / 54 CC 13 SCAR 50.6
CC
13
Cov
20%
process_zone
182.0
BEGIN
1.0
BEGIN
1.0
CRAP 157.9
« Treex/Core/Resource.pm ↑ Summary Treex/Block/Util/Find.pm »
1 package Treex::Block::Util::FixInvalidIDs;
2 1 $Treex::Block::Util::FixInvalidIDs::VERSION = '2.20151210';
3 1 ▶use Treex::Core::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 extends 'Treex::Core::Block';
6  
7 1 has action => (
8 is=>'ro',
9 default=>'warn',
10 );
11  
12 sub process_zone {
13 0 ▶ my ( $self, $zone ) = @_;
Subroutine process_zone: not called CC=13 SCAR=52.0
Pod documented
14 0 my $doc = $zone->get_document();
15  
16 0 foreach my $tnode ($zone->get_ttree()->get_descendants()){
17 0 my $lex_rf = $tnode->get_attr('a/lex.rf');
18 0 ▶ if (!defined $lex_rf) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $lex_rf) { } 0 0 0
elsif (not $doc->id_is_indexed($lex_rf)) { } 0 0 0
19 0 ▶ log_warn "Missing id in a/lex.rf of " . $tnode->get_address if $self->action eq 'warn';
Branch: 1 branch
BranchTrueFalseTotal
if $self->action eq "warn" 0 0 0
20 }
21 elsif (!$doc->id_is_indexed($lex_rf)){
22 0 $tnode->set_lex_anode(undef);
23 0 ▶ log_warn "Missing node with id $lex_rf in a/lex.rf of " . $tnode->get_address if $self->action eq 'warn';
Branch: 1 branch
BranchTrueFalseTotal
if $self->action eq "warn" 0 0 0
24 }
25 0 my $aux_rfs = $tnode->get_attr('a/aux.rf');
26 0 ▶ if ($aux_rfs){
Branch: 1 branch
BranchTrueFalseTotal
if ($aux_rfs) 0 0 0
27 0 ▶ my @filtered = grep {defined $_ && $doc->id_is_indexed($_)} @$aux_rfs;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and $doc->id_is_indexed($_) 0 0 0
28 0 ▶ if (@filtered != @$aux_rfs){
Branch: 1 branch
BranchTrueFalseTotal
if (@filtered != @$aux_rfs) 0 0 0
29 0 $tnode->set_attr('a/aux.rf', \@filtered);
30  
31 0 ▶ if ($self->action eq 'warn') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->action eq "warn") 0 0 0
32 0 foreach my $aux_rf (@$aux_rfs){
33 0 ▶ if (!defined $aux_rf) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $aux_rf) { } 0 0 0
elsif (not $doc->id_is_indexed($aux_rf)) { } 0 0 0
34 0 log_warn "Missing id in a/aux.rf of " . $tnode->get_address;
35 } elsif (!$doc->id_is_indexed($aux_rf)){
36 0 log_warn "Missing node with id $aux_rf in a/aux.rf of " . $tnode->get_address;
37 }
38 }
39 }
40 }
41 }
42 }
43  
44 0 return;
45 }
46  
47 1 1;
48  
49 __END__
50  
51 =encoding utf-8
52  
53 =head1 NAME
54  
55 Treex::Block::Util::FixInvalidIDs
56  
57 =head1 VERSION
58  
59 version 2.20151210
60  
61 =head1 DESCRIPTION
62  
63 If there is a *.rf attribute with id which is not present in the document,
64 delete this id. The current implementation checks only a/lex.rf and a/aux.rf.
65  
66 Such situation should never happen, but if we have invalid data on the input,
67 this block may be handy.
68  
69 =head1 AUTHOR
70  
71 Martin Popel <popel@ufal.mff.cuni.cz>
72  
73 =head1 COPYRIGHT AND LICENSE
74  
75 Copyright © 2015 by Institute of Formal and Applied Linguistics, Charles University in Prague
76 This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
« Treex/Core/Resource.pm ↑ Summary Treex/Block/Util/Find.pm »