From 15ffdb3644b2510084ae93cb1425fbeaaad0d863 Mon Sep 17 00:00:00 2001 From: su-fang Date: Fri, 23 Sep 2022 16:38:39 +0800 Subject: [PATCH] Import Upstream version 0.03 --- Changes | 13 +++++++++ LevenshteinXS.pm | 75 +++++++++++++++++++++++++++++++++++++++++++++++ LevenshteinXS.xs | 76 ++++++++++++++++++++++++++++++++++++++++++++++++ MANIFEST | 8 +++++ META.yml | 11 +++++++ Makefile.PL | 12 ++++++++ README | 54 ++++++++++++++++++++++++++++++++++ test.pl | 16 ++++++++++ 8 files changed, 265 insertions(+) create mode 100644 Changes create mode 100644 LevenshteinXS.pm create mode 100644 LevenshteinXS.xs create mode 100644 MANIFEST create mode 100644 META.yml create mode 100644 Makefile.PL create mode 100644 README create mode 100644 test.pl diff --git a/Changes b/Changes new file mode 100644 index 0000000..ba3fe18 --- /dev/null +++ b/Changes @@ -0,0 +1,13 @@ +Revision history for Perl extension Text::LevenshteinXS. + +0.03 Tue Jun 29 14:42:00 2004 + - move variable declaration to fix SGI compile error. + +0.02 Sat Mar 06 10:54:00 2004 + - short circuits added for special cases to increase + speed. + +0.01 Wed Mar 26 10:23:49 2003 + - original version; created by h2xs 1.21 with options + -n Text::LevenshteinXS + diff --git a/LevenshteinXS.pm b/LevenshteinXS.pm new file mode 100644 index 0000000..9ee31e5 --- /dev/null +++ b/LevenshteinXS.pm @@ -0,0 +1,75 @@ +package Text::LevenshteinXS; + +use strict; +use warnings; +use Carp; + +require Exporter; +require DynaLoader; +use AutoLoader; + +our @ISA = qw(Exporter DynaLoader); + +our %EXPORT_TAGS = ( 'all' => [ qw( + +) ] ); + +our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); + +our @EXPORT = qw( +distance +); +our $VERSION = '0.03'; + +bootstrap Text::LevenshteinXS $VERSION; + +1; +__END__ + +=head1 NAME + +Text::LevenshteinXS - An XS implementation of the Levenshtein edit distance + +=head1 SYNOPSIS + + use Text::LevenshteinXS qw(distance); + + print distance("foo","four"); + # prints "2" + + print distance("foo","bar"); + # prints "3" + + +=head1 DESCRIPTION + +This module implements the Levenshtein edit distance in a XS way. + +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: + + +=head1 CREDITS + +All the credits go to Vladimir Levenshtein the author of the algorithm and to +Lorenzo Seidenari who made the C implementation + + +=head1 SEE ALSO + +Text::Levenshtein , Text::WagnerFischer , Text::Brew , String::Approx + + +=head1 AUTHOR + +Copyright 2003 Dree Mistrut > +Modifications Copyright 2004 Josh Goldberg > + +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 diff --git a/LevenshteinXS.xs b/LevenshteinXS.xs new file mode 100644 index 0000000..4df9cb0 --- /dev/null +++ b/LevenshteinXS.xs @@ -0,0 +1,76 @@ +#include "EXTERN.h" +#include "perl.h" +#include "XSUB.h" + +/****************************************************/ +/* Levenshtein Distance Algorithm */ +/* C Implementation by Lorenzo Seidenari */ +/* http://www.merriampark.com/ldc.htm */ +/* modified by dree */ +/****************************************************/ + +#include +#include + +int levenshtein_distance(char *s,char*t); +int minimum(int a,int b,int c); + +int levenshtein_distance(char *s,char*t) + +/*Compute levenshtein distance between s and t*/ +{ + //Step 1 + int k,i,j,n,m,cost,*d,distance; + if (strcmp(s,t) == 0) {return 0;} + n=strlen(s); + m=strlen(t); + if(n==0) {return m;} + if(m==0) {return n;} + + d=malloc((sizeof(int))*(m+1)*(n+1)); + m++; + n++; + //Step 2 + for(k=0;k 'Text::LevenshteinXS', + 'VERSION_FROM' => 'LevenshteinXS.pm', + 'PREREQ_PM' => { Test }, + ($] >= 5.005 ? () : ( + ABSTRACT_FROM => 'LevenshteinXS.pm', + AUTHOR => 'Dree Mistrut and Josh Goldberg ' + )), +); diff --git a/README b/README new file mode 100644 index 0000000..13cadb2 --- /dev/null +++ b/README @@ -0,0 +1,54 @@ + +Text::LevenshteinXS is an XS implementation of the Levenshtein edit distance in Perl. +A good point to start is: + +See also Text::Levenshtein on CPAN for a pure Perl version of this module. + + +PREREQUISITES + +This suite requires Perl 5; I tested it only under Perl 5.6. + +Text::LevenshteinXS requires the Test module. + +A C compiler. + + +INSTALLATION + +You install Text::LevenshteinXS by running these commands in the *nix environment: + + perl Makefile.PL + make + make test (optional) + make install + +To install Text::LevenshteinXS in the Win32 environment, use nmake instead of make. +nmake is available for free (in a self extracting executable): + +After download and inflate, put nmake.exe and nmake.err in c:\windows\command . +You need also a C compiler (e.g. Visual C++). + + +DOCUMENTATION + +POD format documentation is included in LevenshteinXS.pm. +POD is readable with the command: + + perldoc Text::LevenshteinXS + + +AVAILABILITY + +The latest version of Text::LevenshteinXS is available from the +CPAN + + +COPYRIGHT + +Copyright 2003 Dree Mistrut + +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. + diff --git a/test.pl b/test.pl new file mode 100644 index 0000000..5dab34e --- /dev/null +++ b/test.pl @@ -0,0 +1,16 @@ +use Test; +BEGIN { plan tests => 6 }; + +use Text::LevenshteinXS qw(distance); + +ok(1); +if (distance("foo","four") == 2) {ok(1)} else {ok(0)} +if (distance("foo","foo") == 0) {ok(1)} else {ok(0)} +if (distance("foo","") == 3) {ok(1)} else {ok(0)} +if (distance("four","foo") == 2) {ok(1)} else {ok(0)} +if (distance("foo","bar") == 3) {ok(1)} else {ok(0)} + + + + +