Block/W2A/JA/RehangCopulas.pm

filter: Statementstmt 38.0% 19 / 50 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 28.5% 24 / 84 CC 12 SCAR 32.2
CC
12
Cov
28%
should_switch_with_parent
56.0
fix_subtree
20.0
process_atree
6.0
CRAP 25.1
« Block/W2A/JA/RehangParticles.pm ↑ Summary Block/W2A/JA/RehangAuxVerbs.pm »
1 package Treex::Block::W2A::JA::RehangCopulas;
2 1 $Treex::Block::W2A::JA::RehangCopulas::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 # We rehang copula (lemmas "だ" and "です"), which are marked as auxiliary verbs but are often dependent on non-verb token (noun, adjective...). In this case they function as a predicate in a sentence (often translated as "to be"), so we want to change the dependecy.
13  
14 # TODO: take care of "では" stem form of a copula
15  
16 # While recursively depth-first-traversing the tree
17 # we sometimes rehang already processed parent node as a child node.
18 # But we don't want to process such nodes again.
19 1 my %is_processed;
20  
21 0 ▶sub process_atree {
Subroutine process_atree: not called CC=2 SCAR=17.9
Pod undocumented
22 0 my ( $self, $a_root ) = @_;
23 0 %is_processed = ();
24 0 foreach my $child ( $a_root->get_children() ) {
25 0 fix_subtree($child);
26 }
27 0 return 1;
28 }
29  
30 0 ▶sub fix_subtree {
Subroutine fix_subtree: not called CC=4 SCAR=30.0
Pod undocumented
31 0 my ($a_node) = @_;
32 0 my $lemma = $a_node->lemma;
33  
34 0 ▶ if ( should_switch_with_parent($a_node) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (should_switch_with_parent($a_node)) 0 0 0
35 0 switch_with_parent($a_node);
36 }
37 0 $is_processed{$a_node} = 1;
38
39 0 foreach my $child ( $a_node->get_children() ) {
40 0 ▶ next if $is_processed{$child};
Branch: 1 branch
BranchTrueFalseTotal
if $is_processed{$child} 0 0 0
41 0 fix_subtree($child);
42 }
43 0 return;
44 }
45  
46 0 ▶sub should_switch_with_parent {
Subroutine should_switch_with_parent: not called CC=7 SCAR=40.3
Pod undocumented
47 0 my ($a_node) = @_;
48 0 my $tag = $a_node->tag;
49 0 my $lemma = $a_node->lemma;
50 0 ▶ return 0 if $tag !~ /^Jodōshi/;
Branch: 1 branch
BranchTrueFalseTotal
unless $tag =~ /^Jod\x{14d}shi/ 0 0 0
51
52 0 ▶ return 0 if ( $lemma ne "です" && $lemma ne "だ" && $lemma ) ;
Branch: 1 branch
BranchTrueFalseTotal
if $lemma ne "\x{3067}\x{3059}" and $lemma ne "\x{3060}" and $lemma 0 0 0
Condition0%0/6
$lemma ne "\x{3067}\x{3059}" and $lemma ne "\x{3060}" and $lemma
!ll&&!rl&&r
000
$lemma ne "\x{3067}\x{3059}" and $lemma ne "\x{3060}"
!ll&&!rl&&r
000
MC/DC0%0/3
$lemma ne "\x{3067}\x{3059}" and $lemma ne "\x{3060}" and $lemma
$lemma ne "\x{3067}\x{3059}" $lemma ne "\x{3060}" $lemma
Truth table0%0/4
A and B and C
A= $lemma ne "\x{3067}\x{3059}"B= $lemma ne "\x{3060}"C= $lemma
ABCresult
0XX0
10X0
1100
1111
53  
54 0 my $parent = $a_node->get_parent();
55 0 ▶ return 0 if $parent->is_root();
Branch: 1 branch
BranchTrueFalseTotal
if $parent->is_root 0 0 0
56  
57 # we only switch copula, if their parent is a non-verb (otherwise they really are just auxiliary verbs, e.g formal past negation ありません "でし" た).
58 0 ▶ return 0 if $parent->tag() =~ /^Dōshi/;
Branch: 1 branch
BranchTrueFalseTotal
if $parent->tag =~ /^D\x{14d}shi/ 0 0 0
59  
60 0 return 1;
61 }
62  
63 0 ▶sub switch_with_parent {
Subroutine switch_with_parent: not called CC=2 SCAR=17.9
Pod undocumented
64 0 my ($a_node) = @_;
65 0 my $parent = $a_node->get_parent();
66 0 my $granpa = $parent->get_parent();
67 0 $a_node->set_parent($granpa);
68 0 $parent->set_parent($a_node);
69  
70 0 foreach my $child ( $parent->get_children() ) {
71 0 $child->set_parent($a_node);
72 }
73 0 return;
74 }
75  
76 1 1;
77  
78 __END__
« Block/W2A/JA/RehangParticles.pm ↑ Summary Block/W2A/JA/RehangAuxVerbs.pm »