r29812 - in /branches/upstream/libtext-levenshtein-perl: ./ current/ current/Changes current/Levenshtein.pm current/MANIFEST current/META.yml current/Makefile.PL current/README current/test.pl
ryan52-guest at users.alioth.debian.org
ryan52-guest at users.alioth.debian.org
Mon Jan 19 05:57:04 UTC 2009
Author: ryan52-guest
Date: Mon Jan 19 05:56:57 2009
New Revision: 29812
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=29812
Log:
[svn-inject] Installing original source of libtext-levenshtein-perl
Added:
branches/upstream/libtext-levenshtein-perl/
branches/upstream/libtext-levenshtein-perl/current/
branches/upstream/libtext-levenshtein-perl/current/Changes
branches/upstream/libtext-levenshtein-perl/current/Levenshtein.pm
branches/upstream/libtext-levenshtein-perl/current/MANIFEST
branches/upstream/libtext-levenshtein-perl/current/META.yml
branches/upstream/libtext-levenshtein-perl/current/Makefile.PL
branches/upstream/libtext-levenshtein-perl/current/README
branches/upstream/libtext-levenshtein-perl/current/test.pl
Added: branches/upstream/libtext-levenshtein-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtext-levenshtein-perl/current/Changes?rev=29812&op=file
==============================================================================
--- branches/upstream/libtext-levenshtein-perl/current/Changes (added)
+++ branches/upstream/libtext-levenshtein-perl/current/Changes Mon Jan 19 05:56:57 2009
@@ -1,0 +1,29 @@
+Change file for Text::Levenshtein
+Dree Mistrut <dree at friul.it>
+Josh Goldberg <josh at 3io.com>
+
+Version 0.05: 2004/06/29
+ Rename distfile for consistency
+
+Version 0.04: 2004/03/06
+
+ Added several modifications to increase speed
+ Added fastdistance routine when array form can be sacrificed
+ for increased speed
+
+Version 0.03 : 2002/07/28
+
+ Changed docs to point to Text::WagnerFischer
+ (Thanks to S. Rodighiero and D. Frankowski to point me this)
+ Better initialization of the matrix
+
+
+Version 0.02 : 2002/05/21
+
+ Added array support
+
+
+Version 0.01 : 2002/05/20
+
+ No changes -- initial release
+
Added: branches/upstream/libtext-levenshtein-perl/current/Levenshtein.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtext-levenshtein-perl/current/Levenshtein.pm?rev=29812&op=file
==============================================================================
--- branches/upstream/libtext-levenshtein-perl/current/Levenshtein.pm (added)
+++ branches/upstream/libtext-levenshtein-perl/current/Levenshtein.pm Mon Jan 19 05:56:57 2009
@@ -1,0 +1,151 @@
+package Text::Levenshtein;
+
+use strict;
+use Exporter;
+use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
+
+$VERSION = '0.04';
+ at ISA = qw(Exporter);
+ at EXPORT = ();
+ at EXPORT_OK = qw(&distance &fastdistance);
+%EXPORT_TAGS = ();
+
+
+sub _min
+{
+ return $_[0] < $_[1]
+ ? $_[0] < $_[2] ? $_[0] : $_[2]
+ : $_[1] < $_[2] ? $_[1] : $_[2];
+}
+
+
+sub distance
+{
+ my ($s, at t)=@_;
+
+ my $n=length($s);
+ my @result;
+
+ foreach my $t (@t) {
+ if ($s eq $t) {
+ push @result, 0;
+ next;
+ }
+ my @d;
+ my $cost=0;
+
+ my $m=length($t);
+ push @result,$m and next unless $n;
+ push @result,$n and next unless $m;
+
+ $d[0][0]=0;
+ foreach my $i (1 .. $n) {
+ if ($i != $n && substr($s,$i) eq substr($t,$i)) {
+ push @result,$i;next;
+ }
+ $d[$i][0]=$i;
+ }
+ foreach my $j (1 .. $m) {
+ if ($j != $m && substr($s,$j) eq substr($t,$j)) {
+ push @result,$j;next;
+ }
+ $d[0][$j]=$j;
+ }
+
+ for my $i (1 .. $n) {
+ my $s_i=substr($s,$i-1,1);
+ for my $j (1 .. $m) {
+ $d[$i][$j]=&_min($d[$i-1][$j]+1,
+ $d[$i][$j-1]+1,
+ $d[$i-1][$j-1]+($s_i eq substr($t,$j-1,1) ? 0 : 1) )
+ }
+ }
+
+ push @result,$d[$n][$m];
+ }
+
+ if (wantarray) {return @result} else {return $result[0]}
+}
+
+sub fastdistance
+{
+ my $word1 = shift;
+ my $word2 = shift;
+
+ return 0 if $word1 eq $word2;
+ my @d;
+
+ my $len1 = length $word1;
+ my $len2 = length $word2;
+
+ $d[0][0] = 0;
+ for (1 .. $len1) {
+ $d[$_][0] = $_;
+ return $_ if $_!=$len1 && substr($word1,$_) eq substr($word2,$_);
+ }
+ for (1 .. $len2) {
+ $d[0][$_] = $_;
+ return $_ if $_!=$len2 && substr($word1,$_) eq substr($word2,$_);
+ }
+
+ for my $i (1 .. $len1) {
+ my $w1 = substr($word1,$i-1,1);
+ for (1 .. $len2) {
+ $d[$i][$_] = _min($d[$i-1][$_]+1, $d[$i][$_-1]+1, $d[$i-1][$_-1]+($w1 eq substr($word2,$_-1,1) ? 0 : 1));
+ }
+ }
+ return $d[$len1][$len2];
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Text::Levenshtein - An implementation of the Levenshtein edit distance
+
+=head1 SYNOPSIS
+
+ use Text::Levenshtein qw(distance);
+
+ print distance("foo","four");
+ # prints "2"
+
+ print fastdistance("foo","four");
+ # prints "2" faster
+
+ my @words=("four","foo","bar");
+ my @distances=distance("foo", at words);
+
+ print "@distances";
+ # prints "2 0 3"
+
+
+=head1 DESCRIPTION
+
+This module implements the Levenshtein edit distance.
+The Levenshtein edit distance is a measure of the degree of proximity between two strings.
+This distance is the number of substitutions, deletions or insertions ("edits")
+needed to transform one string into the other one (and vice versa).
+When two strings have distance 0, they are the same.
+A good point to start is: <http://www.merriampark.com/ld.htm>
+
+&fastdistance can be called with two scalars and is faster in most cases.
+
+See also Text::LevenshteinXS on CPAN if you do not require a perl-only implementation. It
+is extremely faster in nearly all cases.
+
+See also Text::WagnerFischer on CPAN for a configurable edit distance, i.e. for
+configurable costs (weights) for the edits.
+
+
+=head1 AUTHOR
+
+Copyright 2002 Dree Mistrut <F<dree at friul.it>>
+
+This package is free software and is provided "as is" without express
+or implied warranty. You can redistribute it and/or modify it under
+the same terms as Perl itself.
+
+=cut
Added: branches/upstream/libtext-levenshtein-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtext-levenshtein-perl/current/MANIFEST?rev=29812&op=file
==============================================================================
--- branches/upstream/libtext-levenshtein-perl/current/MANIFEST (added)
+++ branches/upstream/libtext-levenshtein-perl/current/MANIFEST Mon Jan 19 05:56:57 2009
@@ -1,0 +1,7 @@
+Changes
+Makefile.PL
+README
+Levenshtein.pm
+test.pl
+MANIFEST
+META.yml Module meta-data (added by MakeMaker)
Added: branches/upstream/libtext-levenshtein-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtext-levenshtein-perl/current/META.yml?rev=29812&op=file
==============================================================================
--- branches/upstream/libtext-levenshtein-perl/current/META.yml (added)
+++ branches/upstream/libtext-levenshtein-perl/current/META.yml Mon Jan 19 05:56:57 2009
@@ -1,0 +1,11 @@
+# http://module-build.sourceforge.net/META-spec.html
+#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
+name: Text-Levenshtein
+version: 0.05
+version_from:
+installdirs: site
+requires:
+ Test::More: 0
+
+distribution_type: module
+generated_by: ExtUtils::MakeMaker version 6.17
Added: branches/upstream/libtext-levenshtein-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtext-levenshtein-perl/current/Makefile.PL?rev=29812&op=file
==============================================================================
--- branches/upstream/libtext-levenshtein-perl/current/Makefile.PL (added)
+++ branches/upstream/libtext-levenshtein-perl/current/Makefile.PL Mon Jan 19 05:56:57 2009
@@ -1,0 +1,9 @@
+use ExtUtils::MakeMaker;
+# See lib/ExtUtils/MakeMaker.pm for details of how to influence
+# the contents of the Makefile that is written.
+WriteMakefile(
+ NAME => 'Text::Levenshtein',
+ VERSION => '0.05',
+ LINKTYPE => '$(INST_PM)',
+ PREREQ_PM => {'Test::More' => 0}
+ );
Added: branches/upstream/libtext-levenshtein-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtext-levenshtein-perl/current/README?rev=29812&op=file
==============================================================================
--- branches/upstream/libtext-levenshtein-perl/current/README (added)
+++ branches/upstream/libtext-levenshtein-perl/current/README Mon Jan 19 05:56:57 2009
@@ -1,0 +1,51 @@
+
+Text::Levenshtein is an implementation of the Levenshtein edit distance in Perl.
+A good point to start is: <http://www.merriampark.com/ld.htm>
+
+See also Text::WagnerFischer on CPAN for a configurable edit distance.
+
+
+PREREQUISITES
+
+This suite requires Perl 5; I tested it only under Perl 5.6.
+
+Text::Levenshtein does not use any nonstandard modules.
+
+
+INSTALLATION
+
+You install Text::Levenshtein by running these commands in the *nix environment:
+
+ perl Makefile.PL
+ make
+ make test (optional)
+ make install
+
+To install Text::Levenshtein in the Win32 environment, use nmake instead of make.
+nmake is available for free (in a self extracting executable):
+<http://download.microsoft.com/download/vc15/Patch/1.52/W95/EN-US/Nmake15.exe>
+After download and inflate, put nmake.exe and nmake.err in c:\windows\command .
+
+
+DOCUMENTATION
+
+POD format documentation is included in Levenshtein.pm.
+POD is readable with the command:
+
+ perldoc Text::Levenshtein
+
+
+AVAILABILITY
+
+The latest version of Text::Levenshtein is available from the
+CPAN <http://search.cpan.org/>
+
+
+COPYRIGHT
+
+Copyright 2002 Dree Mistrut <dree at friul.it>
+
+This package is free software and is provided "as is" without express
+or implied warranty. You can redistribute it and/or modify it under
+the same terms as Perl itself.
+
Added: branches/upstream/libtext-levenshtein-perl/current/test.pl
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtext-levenshtein-perl/current/test.pl?rev=29812&op=file
==============================================================================
--- branches/upstream/libtext-levenshtein-perl/current/test.pl (added)
+++ branches/upstream/libtext-levenshtein-perl/current/test.pl Mon Jan 19 05:56:57 2009
@@ -1,0 +1,11 @@
+use strict;
+use Test::More qw (no_plan);
+use lib 'blib/lib';
+use Text::Levenshtein qw(distance fastdistance);
+
+is_deeply(distance("foo","four"),2,"Correct distance");
+is_deeply(distance("foo","foo"),0,"Correct distance");
+my @foo = distance("foo","four","foo","bar");
+my @bar = (2,0,3);
+is_deeply(\@foo,\@bar,"Array test: Correct distances");
+is_deeply(fastdistance("foo","boo"),1,"Fast test: Correct distance");
More information about the Pkg-perl-cvs-commits
mailing list