-
Notifications
You must be signed in to change notification settings - Fork 0
/
Yinglish.pm
executable file
·57 lines (46 loc) · 956 Bytes
/
Yinglish.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env perl -w
use strict;
use warnings;
use Lingua::ZH::Jieba;
use utf8;
binmode STDOUT, "utf8";
package Yinglish;
my $jieba = Lingua::ZH::Jieba->new();
sub _word_convert {
my $w = shift;
my $t = shift;
my $inrando = shift;
my $rand = rand();
if ($rand > $inrando) {
return $w;
}
if ($w =~ m/^(,|\.|,|。)$/) {
return "……";
}
if ($w =~ m/^(!|!)$/) {
return "❤";
}
if (length $w > 1 && $rand > 0.5) {
$w =~ m/^./;
return $& . "……" . $w;
}
else {
if ($t eq "n" && $rand < 0.5) {
$w =~ s/./〇/g;
}
return "……" . $w;
}
}
sub chs2yin {
my $s = shift;
my $inran = shift || 0.5;
my $tags = $jieba->tag($s);
my $res = "";
for my $p (@$tags) {
my $w = shift @$p;
my $t = shift @$p;
$res .= &_word_convert($w, $t, $inran);
}
return $res;
}
1;