| 1 | package Serge::Engine::Plugin::Transform::endpunc; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use parent Serge::Engine::Plugin::Base::Transform; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | sub name { | ||||||||||||||||||||||||||||
| 8 | 0 | ▶ | return 'End punctuation plugin'; | ||||||||||||||||||||||||||
|
Subroutine
name: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 9 | } | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | sub filter_key { | ||||||||||||||||||||||||||||
| 12 | 0 | ▶ | my ($self, $s) = @_; | ||||||||||||||||||||||||||
|
Subroutine
filter_key: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | 0 | $s =~ s/[^\w\d\]\)\>]+$//; # remove all trailing non-character symbols | |||||||||||||||||||||||||||
| 14 | 0 | return $s; | |||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | sub transform { | ||||||||||||||||||||||||||||
| 18 | 0 | ▶ | my ($self, $s, $target, $lang) = @_; | ||||||||||||||||||||||||||
|
Subroutine
transform: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 0 | my $sourcepunc = ''; | |||||||||||||||||||||||||||
| 21 | 0 | ▶ | if ($s =~ m/([^\w\d\]\)\>]+)$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 0 | $sourcepunc = $1; | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | my $targetpunc = ''; | |||||||||||||||||||||||||||
| 26 | 0 | ▶ | if ($target =~ m/([^\w\d\]\)\>]+)$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 0 | $targetpunc = $1; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | if ($sourcepunc eq $targetpunc && $targetpunc eq '') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$sourcepunc eq $targetpunc and $targetpunc eq ""
MC/DC0%0/2
$sourcepunc eq $targetpunc and $targetpunc eq ""
$sourcepunc eq $targetpunc
$targetpunc eq ""
Truth table0%0/3
A and B
A= $sourcepunc eq $targetpuncB= $targetpunc eq ""
| |||||||||||||||||||||||||||||
| 31 | # try to get rid of the trailing tags and whitespace to get the actual punctuation | ||||||||||||||||||||||||||||
| 32 | 0 | my $filtered_target = $target; | |||||||||||||||||||||||||||
| 33 | 0 | $filtered_target =~ s/\s*<[^<>]+>\s*$//s; | |||||||||||||||||||||||||||
| 34 | 0 | ▶ | if ($filtered_target ne $target) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 0 | return $self->transform($s, $filtered_target, $lang); | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | if ($sourcepunc ne $targetpunc) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | # In Japanese, replace certain punctuation symbols | ||||||||||||||||||||||||||||
| 41 | 0 | ▶ | if ($lang =~ m/^(ja|ja-.*)$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 0 | $targetpunc = _adjust_japanese_punctuation($targetpunc); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | $s =~ s/[^\w\d\]\)\>]*$/$targetpunc/e; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | return $s; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | sub _adjust_japanese_punctuation { | ||||||||||||||||||||||||||||
| 52 | 0 | ▶ | my $s = shift; | ||||||||||||||||||||||||||
|
Subroutine
_adjust_japanese_punctuation: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 53 | 0 | $s =~ s/\.{3}/â¦/g; | |||||||||||||||||||||||||||
| 54 | 0 | $s =~ tr/.?!/ãï¼ï¼/; | |||||||||||||||||||||||||||
| 55 | 0 | return $s; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 1 | 1; | |||||||||||||||||||||||||||