Block/W2A/JA/RehangConjunctions.pm

filter: Statementstmt 30.6% 19 / 62 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 55.5% 5 / 9 Podpod 0.0% 0 / 4 totaltotal 22.0% 24 / 109 CC 17 SCAR 36.1
CC
17
Cov
21%
should_switch_with_parent
72.0
switch_with_parent
42.0
fix_subtree
20.0
CRAP 37.0
« Block/W2A/JA/TagMeCab.pm ↑ Summary Block/W2A/JA/RehangParticles.pm »
1 package Treex::Block::W2A::JA::RehangConjunctions;
2 1 $Treex::Block::W2A::JA::RehangConjunctions::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  
10 1 extends 'Treex::Core::Block';
11  
12 # While recursively depth-first-traversing the tree
13 # we sometimes rehang already processed parent node as a child node.
14 # But we don't want to process such nodes again.
15 1 my %is_processed;
16  
17 0 ▶sub process_atree {
Subroutine process_atree: not called CC=2 SCAR=17.9
Pod undocumented
18 0 my ( $self, $a_root ) = @_;
19 0 %is_processed = ();
20  
21 0 my @children = $a_root->get_children();
22 0 ▶ for (my $i = (scalar @children) - 1; $i >= 0; $i--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 0 0 0
23 0 fix_subtree($children[$i]);
24 }
25 0 return 1;
26 }
27  
28 0 ▶sub fix_subtree {
Subroutine fix_subtree: not called CC=4 SCAR=30.0
Pod undocumented
29 0 my ($a_node) = @_;
30  
31 0 ▶ if ( should_switch_with_parent($a_node) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (should_switch_with_parent($a_node)) 0 0 0
32 0 switch_with_parent($a_node);
33 }
34 0 $is_processed{$a_node} = 1;
35
36 0 my @children = $a_node->get_children();
37 # since Japanese is head-final, we prefer to go through children
38 # in a reverse order
39 0 ▶ for (my $i = (scalar @children) - 1; $i >= 0; $i--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 0 0 0
40 0 ▶ next if $is_processed{$children[$i]};
Branch: 1 branch
BranchTrueFalseTotal
if $is_processed{$children[$i]} 0 0 0
41
42 0 fix_subtree($children[$i]);
43 }
44 0 return;
45 }
46  
47 0 ▶sub should_switch_with_parent {
Subroutine should_switch_with_parent: not called CC=8 SCAR=42.8
Pod undocumented
48 0 my ($a_node) = @_;
49 0 my $tag = $a_node->tag;
50 0 my $form = $a_node->form;
51 0 ▶ return 0 if ($tag !~ /^Joshi-SetsuzokuJoshi/ && $tag !~ /^Joshi-Heiritsujoshi/ && $tag !~ /^Setsuzokushi/);
Branch: 1 branch
BranchTrueFalseTotal
unless $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
52  
53 # 接続詞 - Setsuzokushi - conjunction (sentence introduction)
54 # 助詞-接続助詞 - Joshi-SetsuzokuJoshi - particle-conjunctive
55 # 助詞-並立助詞 - Joshi-Heiritsujoshi - particle-coordinate
56  
57 0 my $parent = $a_node->get_parent();
58 0 ▶ return 0 if $parent->is_root();
Branch: 1 branch
BranchTrueFalseTotal
if $parent->is_root 0 0 0
59  
60 # we need to treat "て" particle differently, if its just a part of "continuous" form of a verb (e.g. verb + て + います).
61 0 ▶ if ( $form eq "て" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($form eq "\x{3066}") 0 0 0
62
63 # note that a possible non-independent verb (e.g. います) should be already sibling of "て" particle, thanks to W2A::JA::RehangAuxVerbs
64 0 foreach my $child ($parent->get_children()) {
65 0 ▶ return 0 if $child->tag =~ /HiJiritsu/;
Branch: 1 branch
BranchTrueFalseTotal
if $child->tag =~ /HiJiritsu/ 0 0 0
66 }
67 }
68  
69 0 return 1;
70 }
71  
72 0 ▶sub switch_with_parent {
Subroutine switch_with_parent: not called CC=6 SCAR=37.4
Pod undocumented
73 0 my ($a_node) = @_;
74 0 my $tag = $a_node->tag;
75  
76  
77 0 my $parent = $a_node->get_parent();
78 0 my $granpa = $parent->get_parent();
79 0 $a_node->set_parent($granpa);
80 0 $parent->set_parent($a_node);
81  
82 # for coordination particles, we further change topology:
83 # we want both coordinated nodes to be dependent on the particle
84 0 ▶ if ($tag =~ /-Heiritsujoshi/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag =~ /-Heiritsujoshi/) 0 0 0
85 0 $parent = $a_node->get_parent();
86 0 $granpa = $parent->get_parent();
87 0 $a_node->set_parent($granpa);
88 0 $parent->set_parent($a_node);
89  
90 # we must set IsMember for both coordinated nodes
91 0 foreach my $child ( $a_node->get_children() ) {
92 0 $child->set_is_member(1);
93 }
94  
95 0 $parent = $a_node->get_parent();
96  
97 # in case of multiple coordinations we rehang children of the particle to the higher coordination particle
98 0 ▶ if ($parent->tag && $parent->tag =~ /-Heiritsujoshi/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent->tag and $parent->tag =~ /-Heiritsujoshi/) 0 0 0
Condition0%0/3
$parent->tag and $parent->tag =~ /-Heiritsujoshi/
!ll&&!rl&&r
000
MC/DC0%0/2
$parent->tag and $parent->tag =~ /-Heiritsujoshi/
$parent->tag $parent->tag =~ /-Heiritsujoshi/
Truth table0%0/3
A and B
A= $parent->tagB= $parent->tag =~ /-Heiritsujoshi/
ABresult
0X0
100
111
99 0 foreach my $child ( $a_node->get_children() ) {
100 0 $child->set_parent($parent);
101 }
102 }
103 }
104  
105 0 return;
106 }
107  
108 1 1;
109  
110 __END__
« Block/W2A/JA/TagMeCab.pm ↑ Summary Block/W2A/JA/RehangParticles.pm »