Skip to content

Commit

Permalink
Update README, enhance test codes
Browse files Browse the repository at this point in the history
  • Loading branch information
HyunSeung Kim committed Oct 31, 2013
1 parent dcab9db commit 3986340
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 10 deletions.
33 changes: 26 additions & 7 deletions README.md
Expand Up @@ -20,7 +20,6 @@ more

# try this!!
use Template::Reverse;
use Template::Reverse::Converter::TT2;
use Data::Dumper;

my $rev = Template::Reverse->new;
Expand All @@ -30,14 +29,13 @@ more
my $str2 = ['I',' ','am',' ', 'khs' ,' ','and',' ','a',' ','perlmania']; # Use Parse::Lex or Parse::Token::Lite to make it easy.
my $parts = $rev->detect($str1, $str2);

my $tt2 = Template::Reverse::Converter::TT2->new;
my $templates = $tt2->Convert($parts); # equals to ['I am [% value %] and','and [% value %]']



my $str3 = "I am king of the world and a richest man";

# extract!!
# 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;
my $value = $ext->extract($templates->[0], $str3);
Expand All @@ -46,6 +44,27 @@ more
my $value = $ext->extract($templates->[1], $str3);
print Dumper($value); # output : {'value'=>'a richest man'}



# extract with Regexp
my $regexp_conv = Template::Reverse::Converter::Regexp->new;
my $regexp_list = $regexp_conv->Convert($parts); # equals to ['I am [% value %] and ',' and [% value %]']

my $str3 = "I am king of the world and a richest man";

# extract!!
foreach my $regexp (@{$regexp_list}){
if( $str3 =~ /$regexp/ ){
print $1."\n";
}
}

# When you need to get regexp as string.
use re regexp_pattern;
my($pat,$flag) = regexp_pattern( $regexp_list->[0] );
print $pat; # Not to use $flag, set flags in pat like '(?i)...'.

# DESCRIPTION

Template::Reverse detects different parts between pair of similar text as merged texts from same template.
Expand Down
2 changes: 1 addition & 1 deletion dist.ini
Expand Up @@ -3,7 +3,7 @@ author = HyeonSeung Kim <sng2nara@hanmail.net>
license = Perl_5
copyright_holder = HyeonSeung Kim
copyright_year = 2012
version = 0.141
version = 0.142

[@Basic]

Expand Down
4 changes: 4 additions & 0 deletions lib/Template/Reverse.pm
Expand Up @@ -64,6 +64,10 @@ more
}
}
# When you need to get regexp as string.
use re regexp_pattern;
my($pat,$flag) = regexp_pattern( $regexp_list->[0] );
print $pat; # Not to use $flag, set flags in pat like '(?i)...'.
=head1 DESCRIPTION
Expand Down
4 changes: 2 additions & 2 deletions t/09-cowork-extract.t
Expand Up @@ -50,8 +50,8 @@ is $extres->{'value'}, '1200';
$extres = $ext->extract($temp,"가격1300원");
is $extres->{'value'}, '1300';

$str1 = [map{$_,' '}qw"I am perl, and I am smart"];
$str2 = [map{$_,' '}qw"I am khs, and I am a perlmania"];
$str1 = [map{$_,' '}qw(I am perl, and I am smart)];
$str2 = [map{$_,' '}qw(I am khs, and I am a perlmania)];
pop(@{$str1});
pop(@{$str2});
my $str3 = "I am king of the world, and I am a richest man";
Expand Down
5 changes: 5 additions & 0 deletions t/11-cowork-regexp.t
Expand Up @@ -41,8 +41,13 @@ $str1 = [qw"가격 1200 원"];
$str2 = [qw"가격 1300 원"];
$parts = $rev->detect($str1,$str2);
$temps = $regexp->Convert($parts);
print Dumper $temps;
is_deeply( $temps, [qr'가격(.+?)원'] );

use re 'regexp_pattern';
my ($asstr) = regexp_pattern $temps->[0];
is $asstr,'가격(.+?)원';

$temp = $temps->[0];
"가격1200원"=~/$temp/;
$extres = $1;
Expand Down

0 comments on commit 3986340

Please sign in to comment.