pax_global_header00006660000000000000000000000064142273071550014520gustar00rootroot0000000000000052 comment=da24136b081b2eb9e891a39f927898d6044625c3 libtext-levenshtein-perl-0.15/000077500000000000000000000000001422730715500164025ustar00rootroot00000000000000libtext-levenshtein-perl-0.15/Changes000066400000000000000000000062371422730715500177050ustar00rootroot00000000000000Revision history for Perl module Text::Levenshtein 0.15 2022-04-16 NEILB - Looking at gaps in test coverage revealed some clumsily written logic. Refactoring it not only made the code better, but improved coverage. 0.14 2021-03-24 NEILB - Added String::KeyboardDistance to SEE ALSO - Added Text::Levenshtein::BV to SEE ALSO - Added Text::Levenshtein::Edlib to SEE ALSO - Added Text::Levenshtein::Flexible to SEE ALSO 0.13 2015-08-11 NEILB - Added Text::Dice to SEE ALSO. - Added [MetaJSON] to dist.ini, so META.json will be included in the release tarball. 0.12 2014-10-26 NEILB - Require Unicode::Collate 1.04 or higher. Tests on early Perls were failing, most often down to Unicode::Collate 0.52, on Perl 5.8.9. 0.11 2014-10-26 NEILB - The first implementation of the ignore_diacritics option was very inefficient. It's now at least an order of magnitude faster, if calling it multiple times. 0.10 2014-10-24 NEILB - Added { ignore_diacritics => 1 } option, which can be passed as the last argument to the distance() and fastdistance() subs. OALDERS++ for the suggestion in RT#97883. 0.09 2014-04-26 NEILB - Added Text::Levenshtein::TestUtils in t/lib/ to make it easy to write tests (for different languages). - Added Swedish tests in t/20-swedish.t - thanks to Graham Bowers. - Moved Russian tests (from MMCLERIC) to t/21-russian.t. - Added separate Japanese tests in t/22-japanese.t Thanks to Robert Fraser. - Added Greek tests in t/23-greek.t - thanks to Wikipedia. 0.08 2014-04-23 NEILB - Copy and pasting text from a web page ended up with a UTF-8 dash, instead of the hyphen character I assumed was there. RT#94962 - Added Japanese hiragana test - Added some Russian test cases -- thanks to Vyacheslav Matyukhin - Another test for UTF-8, in Japanese, from Ben Bullock. 0.07 2014-04-23 NEILB - Completely rewrote module, based on the "iterative with two matrix rows" version on the Wikipedia page. Added three new testsuites. - Use List::Util::min() - Drop the '&' before 'fastdistance' in the doc. RT#42535 - Moved module to lib/Text/Levenshtein.pm - Moved test.pl to t/01-original.t and changed it to be a proper testsuite - Removed META.yml so metadata files will be generated - Specified min perl version as 5.6.0 - Added a bunch of similar modules to the SEE ALSO section - Added an explicit COPYRIGHT AND LICENSE section in pod - Added github repo to pod (and to the metadata) - Reformatted Changes as per CPAN::Changes::Spec 0.06_01 2008-05-14 JGOLDBERG - Bugfixes, especially 26134 0.05 2004-07-01 JGOLDBERG - Rename distfile for consistency 0.04: 2004-03-06 JGOLDBERG - Added several modifications to increase speed - Added fastdistance routine when array form can be sacrificed for increased speed 0.03 2002-07-28 DREE - Changed docs to point to Text::WagnerFischer (Thanks to S. Rodighiero and D. Frankowski to point me this) - Better initialization of the matrix 0.02 2002-05-29 DREE - Added array support 0.01 2002-05-20 DREE - No changes -- initial release libtext-levenshtein-perl-0.15/LICENSE000066400000000000000000000436551422730715500174240ustar00rootroot00000000000000This software is copyright (c) 2002 by Dree Mistrut. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2002 by Dree Mistrut. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2002 by Dree Mistrut. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End libtext-levenshtein-perl-0.15/MANIFEST000066400000000000000000000005711422730715500175360ustar00rootroot00000000000000# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.017. Changes LICENSE MANIFEST META.json META.yml Makefile.PL README dist.ini lib/Text/Levenshtein.pm t/01-original.t t/02-more-basic-tests.t t/03-word-lists.t t/04-invalid-inputs.t t/20-swedish.t t/21-russian.t t/22-japanese.t t/23-greek.t t/24-ignore-diacritics.t t/lib/Text/Levenshtein/TestUtils.pm libtext-levenshtein-perl-0.15/META.json000066400000000000000000000033001422730715500200170ustar00rootroot00000000000000{ "abstract" : "calculate the Levenshtein edit distance between two strings", "author" : [ "Dree Mistrut ", "Josh Goldberg ", "Neil Bowers " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 6.017, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Text-Levenshtein", "no_index" : { "package" : [ "Text::Levenshtein::TestUtils" ] }, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Carp" : "0", "Exporter" : "0", "List::Util" : "0", "Unicode::Collate" : "1.04", "perl" : "5.006", "strict" : "0", "warnings" : "0" } }, "test" : { "requires" : { "Test::More" : "0.88", "lib" : "0", "open" : "0", "parent" : "0", "utf8" : "0" } } }, "release_status" : "stable", "resources" : { "homepage" : "https://github.com/neilbowers/Text-Levenshtein", "repository" : { "type" : "git", "url" : "https://github.com/neilbowers/Text-Levenshtein.git", "web" : "https://github.com/neilbowers/Text-Levenshtein" } }, "version" : "0.15", "x_generated_by_perl" : "v5.28.2", "x_serialization_backend" : "Cpanel::JSON::XS version 4.27", "x_spdx_expression" : "Artistic-1.0-Perl OR GPL-1.0-or-later" } libtext-levenshtein-perl-0.15/META.yml000066400000000000000000000020071422730715500176520ustar00rootroot00000000000000--- abstract: 'calculate the Levenshtein edit distance between two strings' author: - 'Dree Mistrut ' - 'Josh Goldberg ' - 'Neil Bowers ' build_requires: Test::More: '0.88' lib: '0' open: '0' parent: '0' utf8: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 generated_by: 'Dist::Zilla version 6.017, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Text-Levenshtein no_index: package: - Text::Levenshtein::TestUtils requires: Carp: '0' Exporter: '0' List::Util: '0' Unicode::Collate: '1.04' perl: '5.006' strict: '0' warnings: '0' resources: homepage: https://github.com/neilbowers/Text-Levenshtein repository: https://github.com/neilbowers/Text-Levenshtein.git version: '0.15' x_generated_by_perl: v5.28.2 x_serialization_backend: 'YAML::Tiny version 1.73' x_spdx_expression: 'Artistic-1.0-Perl OR GPL-1.0-or-later' libtext-levenshtein-perl-0.15/Makefile.PL000066400000000000000000000027161422730715500203620ustar00rootroot00000000000000# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.017. use strict; use warnings; use 5.006; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "calculate the Levenshtein edit distance between two strings", "AUTHOR" => "Dree Mistrut , Josh Goldberg , Neil Bowers ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "Text-Levenshtein", "LICENSE" => "perl", "MIN_PERL_VERSION" => "5.006", "NAME" => "Text::Levenshtein", "PREREQ_PM" => { "Carp" => 0, "Exporter" => 0, "List::Util" => 0, "Unicode::Collate" => "1.04", "strict" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "Test::More" => "0.88", "lib" => 0, "open" => 0, "parent" => 0, "utf8" => 0 }, "VERSION" => "0.15", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Carp" => 0, "Exporter" => 0, "List::Util" => 0, "Test::More" => "0.88", "Unicode::Collate" => "1.04", "lib" => 0, "open" => 0, "parent" => 0, "strict" => 0, "utf8" => 0, "warnings" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); libtext-levenshtein-perl-0.15/README000066400000000000000000000032231422730715500172620ustar00rootroot00000000000000 Text::Levenshtein is an implementation of the Levenshtein edit distance in Perl. If you're not familiar with this algorithm, a good place to start is the wikipedia page: http://en.wikipedia.org/wiki/Levenshtein_distance The SEE ALSO section in the documentation for this module lists other modules on CPAN that calculate edit distances for two strings. PREREQUISITES This suite requires Perl 5.6 or later, and only uses core 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): After download and inflate, put nmake.exe and nmake.err in c:\windows\command . DOCUMENTATION POD format documentation is included in Levenshtein.pm. You can read the documentation online: https://metacpan.org/pod/Text::Levenshtein Or read it on your terminal, using the perldoc command: perldoc Text::Levenshtein AVAILABILITY The latest version of Text::Levenshtein is available from CPAN http://search.cpan.org/ https://metacpan.org/pod/Text::Levenshtein COPYRIGHT Copyright 2002 Dree Mistrut Copyright (C) 2004-2014 Josh Goldberg. Copyright (C) 2014- Neil Bowers. 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. This module is now maintained by Neil Bowers libtext-levenshtein-perl-0.15/dist.ini000066400000000000000000000007121422730715500200460ustar00rootroot00000000000000name = Text-Levenshtein author = Dree Mistrut author = Josh Goldberg author = Neil Bowers license = Perl_5 copyright_holder = Dree Mistrut copyright_year = 2002 version = 0.15 [@Filter] -bundle = @Basic -remove = Readme [PkgVersion] [AutoPrereqs] [MetaJSON] [Prereqs] Unicode::Collate = 1.04 [MetaNoIndex] package = Text::Levenshtein::TestUtils [GithubMeta] [Git::Tag] tag_message= [Git::Push] libtext-levenshtein-perl-0.15/lib/000077500000000000000000000000001422730715500171505ustar00rootroot00000000000000libtext-levenshtein-perl-0.15/lib/Text/000077500000000000000000000000001422730715500200745ustar00rootroot00000000000000libtext-levenshtein-perl-0.15/lib/Text/Levenshtein.pm000066400000000000000000000172751422730715500227320ustar00rootroot00000000000000package Text::Levenshtein; $Text::Levenshtein::VERSION = '0.15'; use 5.006; use strict; use warnings; use Exporter; use Carp; use List::Util (); our @ISA = qw(Exporter); our @EXPORT = (); our @EXPORT_OK = qw(distance fastdistance); our %EXPORT_TAGS = (); sub distance { my $opt = pop(@_) if @_ > 0 && ref($_[-1]) eq 'HASH'; croak "distance() takes 2 or more arguments" if @_ < 2; my ($s,@t)=@_; my @results; $opt = {} if not defined $opt; foreach my $t (@t) { push(@results, fastdistance($s, $t, $opt)); } return wantarray ? @results : $results[0]; } my $eq_with_diacritics = sub { my ($x, $y) = @_; return $x eq $y; }; my $eq_without_diacritics; # This is the "Iterative with two matrix rows" version # from the wikipedia page # http://en.wikipedia.org/wiki/Levenshtein_distance#Computing_Levenshtein_distance sub fastdistance { my $opt = pop(@_) if @_ > 0 && ref($_[-1]) eq 'HASH'; croak "fastdistance() takes 2 or 3 arguments" unless @_ == 2; my ($s, $t) = @_; my (@v0, @v1); my ($i, $j); my $eq; $opt = {} if not defined $opt; if ($opt->{ignore_diacritics}) { if (not defined $eq_without_diacritics) { require Unicode::Collate; my $collator = Unicode::Collate->new(normalization => undef, level => 1); $eq_without_diacritics = sub { return $collator->eq(@_); }; } $eq = $eq_without_diacritics; } else { $eq = $eq_with_diacritics; } my $s_length = defined($s) ? length($s) : 0; my $t_length = defined($t) ? length($t) : 0; return $s_length if $t_length == 0; return $t_length if $s_length == 0; return 0 if $s eq $t; for ($i = 0; $i < $t_length + 1; $i++) { $v0[$i] = $i; } for ($i = 0; $i < $s_length; $i++) { $v1[0] = $i + 1; for ($j = 0; $j < $t_length; $j++) { # my $cost = substr($s, $i, 1) eq substr($t, $j, 1) ? 0 : 1; my $cost = $eq->(substr($s, $i, 1), substr($t, $j, 1)) ? 0 : 1; $v1[$j + 1] = List::Util::min( $v1[$j] + 1, $v0[$j + 1] + 1, $v0[$j] + $cost, ); } for ($j = 0; $j < $t_length + 1; $j++) { $v0[$j] = $v1[$j]; } } return $v1[ $t_length]; } 1; __END__ =encoding UTF8 =head1 NAME Text::Levenshtein - calculate the Levenshtein edit distance between two strings =head1 SYNOPSIS use Text::Levenshtein qw(distance); print distance("foo","four"); # prints "2" my @words = qw/ four foo bar /; my @distances = distance("foo",@words); print "@distances"; # prints "2 0 3" =head1 DESCRIPTION This module implements the Levenshtein edit distance, which measures the difference between two strings, in terms of the I. 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. To learn more about the Levenshtein metric, have a look at the L. =head2 distance() The simplest usage will take two strings and return the edit distance: $distance = distance('brown', 'green'); # returns 3, as 'r' and 'n' don't change Instead of a single second string, you can pass a list of strings. Each string will be compared to the first string passed, and a list of the edit distances returned: @words = qw/ green trainee brains /; @distances = distances('brown', @words); # returns (3, 5, 3) =head2 fastdistance() Previous versions of this module provided an alternative implementation, in the function C. This function is still provided, for backwards compatibility, but they now run the same function to calculate the edit distance. Unlike C, C only takes two strings, and returns the edit distance between them. =head1 ignore_diacritics Both the C and C functions can take a hashref with optional arguments, as the final argument. At the moment the only option is C. If this is true, then any diacritics are ignored when calculating edit distance. For example, "cafe" and "café" normally have an edit distance of 1, but when diacritics are ignored, the distance will be 0: use Text::Levenshtein 0.11 qw/ distance /; $distance = distance($word1, $word2, {ignore_diacritics => 1}); If you turn on this option, then L will be loaded, and used when comparing characters in the words. Early version of C didn't support this version, so you should require version 0.11 or later, as above. =head1 SEE ALSO There are many different modules on CPAN for calculating the edit distance between two strings. Here's just a selection. L and L are both versions of the Levenshtein algorithm that require a C compiler, but will be a lot faster than this module. L is another C implementation, but offers some twists: you can specify a maximum distance that you're interested in, which makes it faster; you can also give different costs to insertion, deletion, and substitution. Hasn't been updated since 2014. L is a Perl wrapper around a C++ library that provides the Levenshtein edit distance and optimal alignment path for a pair of strings. It doesn't support UTF-8 strings, though. L implements the Levenshtein algorithm using bit vectors, and claims to be faster than this implementation. I haven't benchmarked them. The Damerau-Levenshtein edit distance is like the Levenshtein distance, but in addition to insertion, deletion and substitution, it also considers the transposition of two adjacent characters to be a single edit. The module L defaults to using a pure perl implementation, but if you've installed L then it will be a lot quicker. L is an implementation of the Wagner-Fischer edit distance, which is similar to the Levenshtein, but applies different weights to each edit type. L is an implementation of the Brew edit distance, which is another algorithm based on edit weights. L provides a number of operations for partial or fuzzy matching of text based on edit distance. L is a pure perl implementation of the same interface. L takes two strings and returns a value between 0 (meaning entirely different) and 1 (meaning identical). Apparently based on edit distance. L calculates L for two strings. This formula was originally developed to measure the similarity of two different populations in ecological research. L and L calculate the "keyboard distance" between two strings. =head1 REPOSITORY L =head1 AUTHOR Dree Mistrut originally wrote this module and released it to CPAN in 2002. Josh Goldberg then took over maintenance and released versions between 2004 and 2008. Neil Bowers (NEILB on CPAN) is now maintaining this module. Version 0.07 was a complete rewrite, based on one of the algorithms on the wikipedia page. =head1 COPYRIGHT AND LICENSE This software is copyright (C) 2002-2004 Dree Mistrut. Copyright (C) 2004-2014 Josh Goldberg. Copyright (C) 2014- Neil Bowers. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut libtext-levenshtein-perl-0.15/t/000077500000000000000000000000001422730715500166455ustar00rootroot00000000000000libtext-levenshtein-perl-0.15/t/01-original.t000066400000000000000000000023261422730715500210570ustar00rootroot00000000000000#!perl # # 01-original.t - this is the original testsuite that was included # use 5.006; use strict; use warnings; use Test::More 0.88 tests => 13; use Text::Levenshtein qw(distance fastdistance); is_deeply(distance("foo","four"),2,"Correct distance foo four"); is_deeply(distance("foo","foo"),0,"Correct distance foo foo"); is_deeply(distance("cow","cat"),2,"Correct distance cow cat"); is_deeply(distance("cat","moocow"),5,"Correct distance cat moocow"); is_deeply(distance("cat","cowmoo"),5,"Correct distance cat cowmoo"); is_deeply(distance("sebastian","sebastien"),1,"Correct distance sebastian sebastien"); is_deeply(distance("more","cowbell"),5,"Correct distance more cowbell"); my @foo = distance("foo","four","foo","bar"); my @bar = (2,0,3); is_deeply(\@foo,\@bar,"Array test: Correct distances foo four foo bar"); is_deeply(fastdistance("foo","boo"),1,"Fast test: Correct distance foo boo"); is_deeply(fastdistance("foo",""),3,"Fast test: Correct distance 'foo' and ''"); is_deeply(fastdistance("foo",undef),3,"Fast test: Correct distance 'foo' and undef"); is_deeply(fastdistance("","foo"),3,"Fast test: Correct distance '' and 'foo'"); is_deeply(fastdistance(undef,"foo"),3,"Fast test: Correct distance undef and 'foo'"); libtext-levenshtein-perl-0.15/t/02-more-basic-tests.t000066400000000000000000000010251422730715500224300ustar00rootroot00000000000000#!perl use strict; use warnings; use utf8; use lib 't/lib'; use Text::Levenshtein::TestUtils qw/ run_data_tests /; run_data_tests(); __DATA__ # Identical words chocolate chocolate 0 -- # Both empty strings 0 -- # One empty string chocolate 9 -- # Identical words, one space character 0 -- # Completely different words pink blue 4 -- # Second word is the first, with a prefix fly butterfly 6 -- # Second word is the first, with a suffix blue bluebottle 6 -- # The only difference is an accent on one letter cafe café 1 -- libtext-levenshtein-perl-0.15/t/03-word-lists.t000066400000000000000000000006411422730715500213620ustar00rootroot00000000000000#!perl use strict; use warnings; use Test::More 0.88; use Text::Levenshtein qw/ distance /; my @TESTS = ( ['pink', ['pink', 'pine', 'pork', ''], [0, 1, 2, 4]], ['', [' ', '', '42', 'marvin'], [1, 0, 2, 6]], ); plan tests => int(@TESTS); foreach my $test (@TESTS) { my ($word, $listref, $resultref) = @$test; my @results = distance($word, @$listref); is_deeply(\@results, $resultref); } libtext-levenshtein-perl-0.15/t/04-invalid-inputs.t000066400000000000000000000015301422730715500222200ustar00rootroot00000000000000#! perl use strict; use warnings; use Test::More 0.88 tests => 5; use Text::Levenshtein qw/ distance fastdistance /; my $distance; eval { $distance = distance() }; ok($@ && $@ =~ m!takes 2 or more arguments!, "passing no arguments to distance() should croak"); eval { $distance = distance('pink') }; ok($@ && $@ =~ m!takes 2 or more arguments!, "passing one argument to distance() should croak"); eval { $distance = fastdistance() }; ok($@ && $@ =~ m!takes 2 or 3 arguments!, "passing no arguments to fastdistance() should croak"); eval { $distance = fastdistance('pink') }; ok($@ && $@ =~ m!takes 2 or 3 arguments!, "passing one argument to fastdistance() should croak"); eval { $distance = fastdistance('pink', 'blue', 'brown') }; ok($@ && $@ =~ m!takes 2 or 3 arguments!, "passing three argument to fastdistance() should croak"); libtext-levenshtein-perl-0.15/t/20-swedish.t000066400000000000000000000007001422730715500207140ustar00rootroot00000000000000#!perl use strict; use warnings; use utf8; use lib 't/lib'; use Text::Levenshtein::TestUtils qw/ run_data_tests /; run_data_tests(); __DATA__ läsa lösa 1 -- lösa låsa 1 -- fästa festa 1 -- fästa fastna 2 -- fasta fresta 2 -- fästing fästning 1 -- råda röda 1 -- röda röta 1 -- röda rida 1 -- tråna trana 1 -- tråna träna 1 -- trana träna 1 -- möta mata 1 -- möta mäta 1 -- mata matta 1 -- mata mätta 2 -- mäta mätta 1 -- libtext-levenshtein-perl-0.15/t/21-russian.t000066400000000000000000000005301422730715500207340ustar00rootroot00000000000000#!perl use strict; use warnings; use utf8; use lib 't/lib'; use Text::Levenshtein::TestUtils qw/ run_data_tests /; run_data_tests(); __DATA__ решение решето 3 -- статуя статус 1 -- дверь двор 2 -- смысл мысль 2 -- кость кисть 1 -- распределение определение 3 -- libtext-levenshtein-perl-0.15/t/22-japanese.t000066400000000000000000000007741422730715500210510ustar00rootroot00000000000000#!perl use strict; use warnings; use utf8; use lib 't/lib'; use Text::Levenshtein::TestUtils qw/ run_data_tests /; run_data_tests(); __DATA__ カタナ カタカナ 1 -- あいうえお あいうお 1 -- しか あしか 1 -- はし はしご 1 -- 事務 事務所 1 -- じむ じむしょ 2 -- 事務機 事務局 1 -- じむき じむきょく 2 -- 勉強 勉強家 1 -- べんきょう べんきょうか 1 -- ヘン アヘン 1 -- ヘン ペン 1 -- あやまり あやまち 1 -- 謝り 誤り 1 -- libtext-levenshtein-perl-0.15/t/23-greek.t000066400000000000000000000007341422730715500203550ustar00rootroot00000000000000#!perl # # Greek UTF-8 examples # use strict; use warnings; use utf8; use lib 't/lib'; use Text::Levenshtein::TestUtils qw/ run_data_tests /; run_data_tests(); __DATA__ ἀγαθός ἀγάπη 4 -- ἀγορά ἀγκών 3 -- ἄγχω ἄγω 1 -- ἀθήρα ἀθλητής 5 -- αἴγαγρος αἴγαγρος 0 -- ἄλληλον ἄλλος 3 -- βάθος βαθύς 2 -- δέκα δέλτα 2 -- ἕτερος ἔτυμος 3 -- κακός καλός 1 -- libtext-levenshtein-perl-0.15/t/24-ignore-diacritics.t000066400000000000000000000003521422730715500226540ustar00rootroot00000000000000#!perl use strict; use warnings; use utf8; use lib 't/lib'; use Text::Levenshtein::TestUtils qw/ run_data_tests /; run_data_tests({ ignore_diacritics => 1 }); __DATA__ låsa läsa 0 -- mån man 0 -- mått mätt 0 -- café cafe -- libtext-levenshtein-perl-0.15/t/lib/000077500000000000000000000000001422730715500174135ustar00rootroot00000000000000libtext-levenshtein-perl-0.15/t/lib/Text/000077500000000000000000000000001422730715500203375ustar00rootroot00000000000000libtext-levenshtein-perl-0.15/t/lib/Text/Levenshtein/000077500000000000000000000000001422730715500226235ustar00rootroot00000000000000libtext-levenshtein-perl-0.15/t/lib/Text/Levenshtein/TestUtils.pm000066400000000000000000000036631422730715500251310ustar00rootroot00000000000000package Text::Levenshtein::TestUtils; use strict; use warnings; # This line is needed before we use Test::More, to suppress warnings # about "Wide character in print" from Test::Builder use open ':std', ':encoding(utf8)'; use Test::More 0.88; use Text::Levenshtein qw/ distance fastdistance /; use parent 'Exporter'; use Carp; our @EXPORT_OK = qw/ run_data_tests /; sub run_data_tests { my $opt = {}; my $package = (caller(0))[0]; my $distance; my $fh; my @extra; @extra = @_; $fh = do { no strict 'refs'; \*{"${package}::DATA"}; }; my @tests = parse_tests($fh); plan tests => 4 * @tests; foreach my $test (@tests) { $distance = distance($test->{word1}, $test->{word2}, @extra); ok($distance == $test->{distance}, "$test->{title} (distance)"); $distance = distance($test->{word2}, $test->{word1}, @extra); ok($distance == $test->{distance}, "$test->{title} (reverse distance)"); $distance = fastdistance($test->{word1}, $test->{word2}, @extra); ok($distance == $test->{distance}, "$test->{title} (fastdistance)"); $distance = fastdistance($test->{word2}, $test->{word1}, @extra); ok($distance == $test->{distance}, "$test->{title} (reverse fastdistance)"); } } sub parse_tests { my $fh = shift; my @tests; my @fields; local $_; while (<$fh>) { next if /^--/; # test case divider next if /^#/; # comment chomp; push(@fields, $_); if (@fields == 3) { my ($word1, $word2, $expected_distance) = @fields; push(@tests, { title => "$word1 vs $word2", word1 => $word1, word2 => $word2, distance => $expected_distance, }); @fields = (); } } return @tests; } 1;