in reply to Text::Fuzzy recursive fuzzy_index

Sorry monks, now I understand what is meant by "closest" match found (I interpreted it as "first"). In this way it can find only one match... and the function is no use to me. I need to get the offset of a fuzzy match, but need also to be able to set the max. distance (similarity)...

Replies are listed 'Best First'.
Re^2: Text::Fuzzy recursive fuzzy_index
by swl (Prior) on Sep 22, 2018 at 23:03 UTC

    Text::Fuzzy has a maximum distance setting. set_max_distance of Text::Fuzzy.

    It seems not to have a function that will return matched strings with their distances, but you could iterate over the data yourself using the distance method. See code below for an example.

    I think the nearest method in list context will return the list of strings with the shortest distance, so will not be all those within the maximum distance. Both those would be useful to have - maybe submit a feature request?

    # code not tested my $max_distance = 4; my $some_label = 'blortbertblart'; my %targets_hash = (...); my $distance_finder = Text::Fuzzy->new( $some_label, trans => 1); $distance_finder->set_max_distance ($max_distance); my %poss_matches; foreach my $target (keys %targets_hash) { my $distance = $distance_finder->distance( $target_label ); next if !defined $distance; $poss_matches{$distance} //= []; push @{$poss_matches{$distance}}, $target; } # do stuff with @poss_matches