Skip to content

Instantly share code, notes, and snippets.

@sng2c
Created June 23, 2017 10:01
Show Gist options
  • Save sng2c/a52b813a724d20653670dbc81820c561 to your computer and use it in GitHub Desktop.
Save sng2c/a52b813a724d20653670dbc81820c561 to your computer and use it in GitHub Desktop.
# 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