X-Git-Url: http://git.ieval.ro/?p=text-levenshtein-edlib.git;a=blobdiff_plain;f=lib%2FText%2FLevenshtein%2FEdlib.pm;h=6b38a6c742a892a3f21b7db106c6f38efe5befe8;hp=9274517a6efbdc153c5102f8485c1285a3a33e96;hb=159e7b256c1d89f5b2ba99c9db939bedef8de142;hpb=a99d15a3e2868f2ec62f8a81fcba0ede439c723e diff --git a/lib/Text/Levenshtein/Edlib.pm b/lib/Text/Levenshtein/Edlib.pm index 9274517..6b38a6c 100644 --- a/lib/Text/Levenshtein/Edlib.pm +++ b/lib/Text/Levenshtein/Edlib.pm @@ -24,7 +24,7 @@ my @constants = EDLIB_TASK_PATH/; our %EXPORT_TAGS = - (all => [ @constants, qw/align distance/ ], constants => \@constants); + (all => [ @constants, qw/align distance to_cigar/ ], constants => \@constants); our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); our @EXPORT = ( @{ $EXPORT_TAGS{'constants'} } ); our $VERSION = '0.001'; @@ -67,8 +67,15 @@ sub align { } sub distance { - my ($q, $t, $k) = @_; - align($q, $t, $k)->{editDistance} + my ($q, $t, $k, $mode) = @_; + align($q, $t, $k, $mode, EDLIB_TASK_DISTANCE())->{editDistance} +} + +sub to_cigar { + my ($align, $format) = @_; + $align = pack 'C*', @$align; + $format //= EDLIB_CIGAR_STANDARD(); + edlibAlignmentToCigar($align, $format); } 1; @@ -95,7 +102,9 @@ Text::Levenshtein::Edlib - XS edit distance and optimal alignment path calculati say "Start locations are: @{$align->{startLocations}}"; say "End locations are: @{$align->{endLocations}}"; say "Alignment path is: @{$align->{alignment}}"; - + say "Alignment path (in CIGAR format): ", to_cigar $align->{alignment}; + say "Alignment path (in extended CIGAR format): ", + to_cigar $align->{alignment}, EDLIB_CIGAR_EXTENDED; =head1 DESCRIPTION @@ -111,7 +120,7 @@ This module has two functions: =over -=item B(I<$query>, I<$target>, [I<$max_distance>]) +=item B(I<$query>, I<$target>, [I<$max_distance>, [I<$mode>]]) This is the basic interface to the library. It is compatible with the function of the same name in L. @@ -119,7 +128,8 @@ function of the same name in L. It returns the edit distance between the two given strings. If the third argument is specified, and the edit distance is greater than the value of the third argument, then the function finishes the -computation early and returns undef. +computation early and returns undef. See below for the meaning of the +optional I<$mode> argument. =item B(I<$query>, I<$target>, [I<$max_distance>, [I<$mode>, [I<$task>]]]) @@ -224,7 +234,7 @@ constant, C and C. =head1 SEE ALSO -L +L, L =head1 AUTHOR