| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | next if $is_processed{$children[$i]}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/6
$tag =~ /^Joshi-SetsuzokuJoshi/ or $tag =~ /^Joshi-Heiritsujoshi/ or $tag =~ /^Setsuzokushi/
$tag =~ /^Joshi-SetsuzokuJoshi/ or $tag =~ /^Joshi-Heiritsujoshi/
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/
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$parent->tag and $parent->tag =~ /-Heiritsujoshi/
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/
| |||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||