Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. # try this!!
  2. use Template::Reverse;
  3. use Data::Dumper;
  4. use utf8;
  5. binmode(STDOUT,':utf8');
  6. my $rev = Template::Reverse->new;
  7.  
  8. # generating patterns automatically!!
  9. my $str1 = [split(/(\s)/,"안녕하세 저는 김현승 입니다.")];
  10. my $str2 = [split(/(\s)/,"반갑습니다 저는 박연건 입니다.")];
  11. my $parts = $rev->detect($str1, $str2);
  12. my $str3 = "심심합니다 저는 조건희 입니다.";
  13.  
  14. print "$str3\n";
  15. # extract with TT2
  16. use Template::Reverse::Converter::TT2;
  17. my $tt2 = Template::Reverse::Converter::TT2->new;
  18. my $templates = $tt2->Convert($parts); # equals to ['I am [% value %] and ',' and [% value %]']
  19.  
  20. use Template::Extract;
  21. my $ext = Template::Extract->new;
  22. foreach my $part (@{$templates}){
  23. print "$part => ";
  24. my $value = $ext->extract($part, $str3);
  25. print $value->{value}."\n"; # output : {'value'=>'king of the world'}
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement