Block/W2A/JA/RehangParticles.pm

filter: Statementstmt 40.4% 19 / 47 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 55.5% 5 / 9 Podpod 0.0% 0 / 4 totaltotal 29.6% 24 / 81 CC 11 SCAR 32.5
CC
11
Cov
29%
should_switch_with_parent
56.0
fix_subtree
20.0
process_atree
6.0
CRAP 25.8
« Block/W2A/JA/RehangConjunctions.pm ↑ Summary Block/W2A/JA/RehangCopulas.pm »
1 package Treex::Block::W2A::JA::RehangParticles;
2 1 $Treex::Block::W2A::JA::RehangParticles::VERSION = '0.13095';
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  
6 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Treex::Core::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 extends 'Treex::Core::Block';
10  
11 # While recursively depth-first-traversing the tree
12 # we sometimes rehang already processed parent node as a child node.
13 # But we don't want to process such nodes again.
14 1 my %is_processed;
15  
16 0 ▶sub process_atree {
Subroutine process_atree: not called CC=2 SCAR=17.9
Pod undocumented
17 0 my ( $self, $a_root ) = @_;
18 0 %is_processed = ();
19 0 foreach my $child ( $a_root->get_children() ) {
20 0 fix_subtree($child);
21 }
22 0 return 1;
23 }
24  
25 0 ▶sub fix_subtree {
Subroutine fix_subtree: not called CC=4 SCAR=30.0
Pod undocumented
26 0 my ($a_node) = @_;
27  
28 0 ▶ if ( should_switch_with_parent($a_node) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (should_switch_with_parent($a_node)) 0 0 0
29 0 switch_with_parent($a_node);
30 }
31 0 $is_processed{$a_node} = 1;
32
33 0 foreach my $child ( $a_node->get_children() ) {
34 0 ▶ next if $is_processed{$child};
Branch: 1 branch
BranchTrueFalseTotal
if $is_processed{$child} 0 0 0
35 0 fix_subtree($child);
36 }
37  
38 0 return;
39 }
40  
41 0 ▶sub should_switch_with_parent {
Subroutine should_switch_with_parent: not called CC=7 SCAR=40.3
Pod undocumented
42 0 my ($a_node) = @_;
43 0 my $tag = $a_node->tag;
44 0 ▶ return 0 if $tag !~ /^Joshi/;
Branch: 1 branch
BranchTrueFalseTotal
unless $tag =~ /^Joshi/ 0 0 0
45  
46 # conjunctions are handled in other block
47 0 ▶ return 0 if ($tag =~ /^Joshi-SetsuzokuJoshi/ || $tag =~ /^Joshi-Heiritsujoshi/ || $tag =~ /^Setsuzokushi/);
Branch: 1 branch
BranchTrueFalseTotal
if $tag =~ /^Joshi-SetsuzokuJoshi/ or $tag =~ /^Joshi-Heiritsujoshi/ or $tag =~ /^Setsuzokushi/ 0 0 0
Condition0%0/6
$tag =~ /^Joshi-SetsuzokuJoshi/ or $tag =~ /^Joshi-Heiritsujoshi/ or $tag =~ /^Setsuzokushi/
l!l&&r!l&&!r
000
$tag =~ /^Joshi-SetsuzokuJoshi/ or $tag =~ /^Joshi-Heiritsujoshi/
l!l&&r!l&&!r
000
MC/DC0%0/3
$tag =~ /^Joshi-SetsuzokuJoshi/ or $tag =~ /^Joshi-Heiritsujoshi/ or $tag =~ /^Setsuzokushi/
$tag =~ /^Joshi-SetsuzokuJoshi/ $tag =~ /^Joshi-Heiritsujoshi/ $tag =~ /^Setsuzokushi/
Truth table0%0/4
A or B or C
A= $tag =~ /^Joshi-SetsuzokuJoshi/B= $tag =~ /^Joshi-Heiritsujoshi/C= $tag =~ /^Setsuzokushi/
ABCresult
1XX1
01X1
0011
0000
48  
49 # we probably do not want to move adverbial particles
50 0 ▶ return 0 if $tag =~ /FukuJoshi/;
Branch: 1 branch
BranchTrueFalseTotal
if $tag =~ /FukuJoshi/ 0 0 0
51  
52 0 my $parent = $a_node->get_parent();
53 0 ▶ return 0 if $parent->is_root();
Branch: 1 branch
BranchTrueFalseTotal
if $parent->is_root 0 0 0
54  
55 0 return 1;
56 }
57  
58 0 ▶sub switch_with_parent {
Subroutine switch_with_parent: not called CC=1 SCAR=6.9
Pod undocumented
59 0 my ($a_node) = @_;
60 0 my $form = $a_node->form;
61 0 my $parent = $a_node->get_parent();
62 0 my $granpa = $parent->get_parent();
63 0 $a_node->set_parent($granpa);
64 0 $parent->set_parent($a_node);
65  
66 0 return;
67 }
68  
69 1 1;
70  
71 __END__
« Block/W2A/JA/RehangConjunctions.pm ↑ Summary Block/W2A/JA/RehangCopulas.pm »