| 1 | package Treex::Block::W2A::JA::FixInterpunction; | ||||||||||||||||||||||||||||
| 2 | 1 | $Treex::Block::W2A::JA::FixInterpunction::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 | # we change "。", "?" and "!" to ".", "?" and "!" | ||||||||||||||||||||||||||||
| 12 | # we also rehang them to the root | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 0 | ▶ | sub process_atree { | ||||||||||||||||||||||||||
|
Subroutine
process_atree: not called CC=12 SCAR=50.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 15 | 0 | my ( $self, $a_root ) = @_; | |||||||||||||||||||||||||||
| 16 | 0 | foreach my $a_node ( $a_root->get_descendants() ) { | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | next if ( $a_node->form !~ /[。?!]/ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | # we do not want Interpunction nodes to have children, so we rehang | ||||||||||||||||||||||||||||
| 21 | # them to the previous parent | ||||||||||||||||||||||||||||
| 22 | 0 | my $parent = $a_node->get_parent(); | |||||||||||||||||||||||||||
| 23 | 0 | my @children = $a_node->get_children(); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | # set new parent for the children (since japanese is head final, | ||||||||||||||||||||||||||||
| 26 | # it should be the last child) | ||||||||||||||||||||||||||||
| 27 | 0 | my $new_parent; | |||||||||||||||||||||||||||
| 28 | 0 | ▶ | if (@children) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 0 | $new_parent = pop @children; | |||||||||||||||||||||||||||
| 30 | 0 | ▶ | $new_parent->set_parent($parent) if ($new_parent); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # rehang the rest of the children | ||||||||||||||||||||||||||||
| 34 | 0 | foreach my $child (@children) { | |||||||||||||||||||||||||||
| 35 | 0 | $child->set_parent($new_parent); | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | if ( $a_node->form eq "。" and $a_node->tag =~ /^Kigō/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$a_node->form eq "\x{3002}" and $a_node->tag =~ /^Kig\x{14d}/
MC/DC0%0/2
$a_node->form eq "\x{3002}" and $a_node->tag =~ /^Kig\x{14d}/
$a_node->form eq "\x{3002}"
$a_node->tag =~ /^Kig\x{14d}/
Truth table0%0/3
A and B
A= $a_node->form eq "\x{3002}"B= $a_node->tag =~ /^Kig\x{14d}/
| |||||||||||||||||||||||||||||
| 40 | 0 | $a_node->set_form("."); | |||||||||||||||||||||||||||
| 41 | 0 | $a_node->set_lemma("."); | |||||||||||||||||||||||||||
| 42 | 0 | $a_node->set_parent($a_root); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if ( $a_node->form eq "?" and $a_node->tag =~ /^Kigō/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$a_node->form eq "\x{ff1f}" and $a_node->tag =~ /^Kig\x{14d}/
MC/DC0%0/2
$a_node->form eq "\x{ff1f}" and $a_node->tag =~ /^Kig\x{14d}/
$a_node->form eq "\x{ff1f}"
$a_node->tag =~ /^Kig\x{14d}/
Truth table0%0/3
A and B
A= $a_node->form eq "\x{ff1f}"B= $a_node->tag =~ /^Kig\x{14d}/
| |||||||||||||||||||||||||||||
| 45 | 0 | $a_node->set_form("?"); | |||||||||||||||||||||||||||
| 46 | 0 | $a_node->set_lemma("?"); | |||||||||||||||||||||||||||
| 47 | 0 | $a_node->set_parent($a_root); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | 0 | ▶ | if ( $a_node->form eq "!" and $a_node->tag =~ /^Kigō/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$a_node->form eq "\x{ff01}" and $a_node->tag =~ /^Kig\x{14d}/
MC/DC0%0/2
$a_node->form eq "\x{ff01}" and $a_node->tag =~ /^Kig\x{14d}/
$a_node->form eq "\x{ff01}"
$a_node->tag =~ /^Kig\x{14d}/
Truth table0%0/3
A and B
A= $a_node->form eq "\x{ff01}"B= $a_node->tag =~ /^Kig\x{14d}/
| |||||||||||||||||||||||||||||
| 50 | 0 | $a_node->set_form("!"); | |||||||||||||||||||||||||||
| 51 | 0 | $a_node->set_lemma("!"); | |||||||||||||||||||||||||||
| 52 | 0 | $a_node->set_parent($a_root); | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | 0 | return 1; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 1 | 1; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | __END__ | ||||||||||||||||||||||||||||