Hello Sosi,

In addition to Text::Fuzzy, you should look at Algorithm::Diff. Here’s some proof-of-concept code:

#! perl use strict; use warnings; use Algorithm::Diff qw( LCS ); use Data::Dump; use constant MIN_MATCH => 0.5; my @source = ( 'John Ronald Reuel Tolkien', 'John Ronald S Tolkien', 'Trent Reznor', 'Barack Hussein Obama II', 'Barack Hussein II', ); my @search = ( 'John Ronald Reuel T', 'Trent Reznor', 'Barack Hussein II', 'Barack Hussein Obama II', 'No match here', ); my %searches = map { $_ => [] } @search; for my $s (@search) { my @search_chars = split //, $s; my @matches; for my $source (@source) { my @source_chars = split //, $source; my @diff_chars = LCS(\@search_chars, \@source_chars); my $diff = join '', @diff_chars; if (!@{ $searches{$s} } || length $diff > length $searches{$s}->[0]) { $searches{$s}->[0] = $diff; $searches{$s}->[1] = $source; } } } for my $key (keys %searches) { my $len_key = length $key; my $len_match = length $searches{$key}->[0]; delete $searches{$key} if ($len_match / $len_key) < MIN_MATCH; } dd \%searches;

Output:

23:19 >perl 1044_SoPW.pl { "Barack Hussein II" => ["Barack Hussein II", "Barack Hussein O +bama II"], "Barack Hussein Obama II" => ["Barack Hussein Obama II", "Barack Hus +sein Obama II"], "John Ronald Reuel T" => ["John Ronald Reuel T", "John Ronald Re +uel Tolkien"], "Trent Reznor" => ["Trent Reznor", "Trent Reznor"], } 23:19 >

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re: Searching for best match by Athanasius
in thread Searching for best match by Sosi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.