Skip to content

Instantly share code, notes, and snippets.

@mattn
Created March 6, 2009 03:37
Show Gist options
  • Save mattn/74741 to your computer and use it in GitHub Desktop.
Save mattn/74741 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use utf8;
use String::Trigram;
my @cmpBase = qw(もまんが もみんが ももんが うみんが);
my $trig = new String::Trigram(cmpBase => \@cmpBase);
my %result;
my $numOfSimStrings = $trig->getSimilarStrings("ももんが", \%result);
print "Found $numOfSimStrings similar strings.\n";
foreach (keys %result) {
print "Similar string $_ has a similarity of ", sprintf ("%02f", ($result{$_} * 100)), "%\n";
}
# Similar string もみんが has a similarity of 33.333333%
# Similar string うみんが has a similarity of 20.000000%
# Similar string ももんが has a similarity of 100.000000%
# Similar string もまんが has a similarity of 33.333333%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment