Created
June 23, 2017 10:01
-
-
Save sng2c/a52b813a724d20653670dbc81820c561 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# try this!! | |
use Template::Reverse; | |
use Data::Dumper; | |
use utf8; | |
binmode(STDOUT,':utf8'); | |
my $rev = Template::Reverse->new; | |
# generating patterns automatically!! | |
my $str1 = [split(/(\s)/,"안녕하세 저는 김현승 입니다.")]; | |
my $str2 = [split(/(\s)/,"반갑습니다 저는 박연건 입니다.")]; | |
my $parts = $rev->detect($str1, $str2); | |
my $str3 = "심심합니다 저는 조건희 입니다."; | |
print "$str3\n"; | |
# extract with TT2 | |
use Template::Reverse::Converter::TT2; | |
my $tt2 = Template::Reverse::Converter::TT2->new; | |
my $templates = $tt2->Convert($parts); # equals to ['I am [% value %] and ',' and [% value %]'] | |
use Template::Extract; | |
my $ext = Template::Extract->new; | |
foreach my $part (@{$templates}){ | |
print "$part => "; | |
my $value = $ext->extract($part, $str3); | |
print $value->{value}."\n"; # output : {'value'=>'king of the world'} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment