mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-25 13:29:29 +01:00
Replace Text::Levenshtein with Text::Levenshtein::XS
Text::Levenshtein::XS is much, much, much, much faster and more efficient. Existing PBot users: Please run `cpanm Text::Levenshtein::XS` to install this module.
This commit is contained in:
parent
731d795c03
commit
d1bb30ef94
2
cpanfile
2
cpanfile
@ -48,7 +48,7 @@ requires 'Socket';
|
|||||||
requires 'Storable';
|
requires 'Storable';
|
||||||
requires 'Symbol';
|
requires 'Symbol';
|
||||||
requires 'Text::CSV';
|
requires 'Text::CSV';
|
||||||
requires 'Text::Levenshtein';
|
requires 'Text::Levenshtein::XS';
|
||||||
requires 'Text::ParseWords';
|
requires 'Text::ParseWords';
|
||||||
requires 'Time::Duration';
|
requires 'Time::Duration';
|
||||||
requires 'Time::HiRes';
|
requires 'Time::HiRes';
|
||||||
|
@ -1093,6 +1093,7 @@ sub cmd_factfind {
|
|||||||
$arguments =~ s/\s+/ /g;
|
$arguments =~ s/\s+/ /g;
|
||||||
|
|
||||||
$arguments = substr($arguments, 0, 30);
|
$arguments = substr($arguments, 0, 30);
|
||||||
|
|
||||||
my $argtype = undef;
|
my $argtype = undef;
|
||||||
|
|
||||||
$argtype = "owned by $owner" if defined $owner and $owner ne '.*';
|
$argtype = "owned by $owner" if defined $owner and $owner ne '.*';
|
||||||
@ -1117,6 +1118,10 @@ sub cmd_factfind {
|
|||||||
|
|
||||||
if (not defined $argtype) { return $usage; }
|
if (not defined $argtype) { return $usage; }
|
||||||
|
|
||||||
|
if ($channel eq 'global') {
|
||||||
|
$channel = '\.\*';
|
||||||
|
}
|
||||||
|
|
||||||
my ($text, $last_trigger, $last_chan, $i);
|
my ($text, $last_trigger, $last_chan, $i);
|
||||||
$last_chan = "";
|
$last_chan = "";
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
@ -115,7 +115,7 @@ sub interpreter {
|
|||||||
|
|
||||||
# otherwise keyword hasn't been found, display similiar matches for all channels
|
# otherwise keyword hasn't been found, display similiar matches for all channels
|
||||||
else {
|
else {
|
||||||
my $namespace = $strictnamespace ? $context->{from} : '.*';
|
my $namespace = $context->{from};
|
||||||
$namespace = '.*' if $namespace !~ /^#/;
|
$namespace = '.*' if $namespace !~ /^#/;
|
||||||
|
|
||||||
my $namespace_regex = $namespace;
|
my $namespace_regex = $namespace;
|
||||||
|
@ -19,7 +19,7 @@ package PBot::Core::Storage::DualIndexHashObject;
|
|||||||
|
|
||||||
use PBot::Imports;
|
use PBot::Imports;
|
||||||
|
|
||||||
use Text::Levenshtein qw(fastdistance);
|
use Text::Levenshtein::XS qw(distance);
|
||||||
use JSON;
|
use JSON;
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
@ -153,7 +153,9 @@ sub levenshtein_matches {
|
|||||||
|
|
||||||
if (not $secondary_index) {
|
if (not $secondary_index) {
|
||||||
foreach my $index (sort keys %{$self->{hash}}) {
|
foreach my $index (sort keys %{$self->{hash}}) {
|
||||||
my $distance_result = fastdistance($primary_index, $index);
|
my $distance_result = distance($primary_index, $index, 20);
|
||||||
|
next if not defined $distance_result;
|
||||||
|
|
||||||
my $length = (length $primary_index > length $index) ? length $primary_index : length $index;
|
my $length = (length $primary_index > length $index) ? length $primary_index : length $index;
|
||||||
|
|
||||||
if ($distance_result / $length < $distance) {
|
if ($distance_result / $length < $distance) {
|
||||||
@ -180,7 +182,9 @@ sub levenshtein_matches {
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach my $index2 (sort keys %{$self->{hash}->{$index1}}) {
|
foreach my $index2 (sort keys %{$self->{hash}->{$index1}}) {
|
||||||
my $distance_result = fastdistance($secondary_index, $index2);
|
my $distance_result = distance($secondary_index, $index2, 20);
|
||||||
|
next if not defined $distance_result;
|
||||||
|
|
||||||
my $length = (length $secondary_index > length $index2) ? length $secondary_index : length $index2;
|
my $length = (length $secondary_index > length $index2) ? length $secondary_index : length $index2;
|
||||||
|
|
||||||
if ($distance_result / $length < $distance) {
|
if ($distance_result / $length < $distance) {
|
||||||
|
@ -24,7 +24,7 @@ use PBot::Core::Utils::SQLiteLogger;
|
|||||||
use PBot::Core::Utils::SQLiteLoggerLayer;
|
use PBot::Core::Utils::SQLiteLoggerLayer;
|
||||||
|
|
||||||
use DBI;
|
use DBI;
|
||||||
use Text::Levenshtein qw(fastdistance);
|
use Text::Levenshtein::XS qw(distance);
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my ($class, %args) = @_;
|
my ($class, %args) = @_;
|
||||||
@ -238,7 +238,8 @@ sub levenshtein_matches {
|
|||||||
my $length_a = length $index1;
|
my $length_a = length $index1;
|
||||||
|
|
||||||
foreach my $index (sort $self->get_keys) {
|
foreach my $index (sort $self->get_keys) {
|
||||||
my $distance_result = fastdistance($index1, $index);
|
my $distance_result = distance($index1, $index, 20);
|
||||||
|
next if not defined $distance_result;
|
||||||
|
|
||||||
my $length_b = length $index;
|
my $length_b = length $index;
|
||||||
|
|
||||||
@ -274,7 +275,8 @@ sub levenshtein_matches {
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach my $i2 (sort $self->get_keys($i1)) {
|
foreach my $i2 (sort $self->get_keys($i1)) {
|
||||||
my $distance_result = fastdistance($index2, $i2);
|
my $distance_result = distance($index2, $i2, 20);
|
||||||
|
next if not defined $distance_result;
|
||||||
|
|
||||||
my $length_b = length $i2;
|
my $length_b = length $i2;
|
||||||
|
|
||||||
@ -304,6 +306,9 @@ sub levenshtein_matches {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$output =~ s/(.*), /$1 or /;
|
$output =~ s/(.*), /$1 or /;
|
||||||
|
|
||||||
|
$output = 'none' if not length $output;
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ package PBot::Core::Storage::HashObject;
|
|||||||
|
|
||||||
use PBot::Imports;
|
use PBot::Imports;
|
||||||
|
|
||||||
use Text::Levenshtein qw(fastdistance);
|
use Text::Levenshtein::XS qw(distance);
|
||||||
use JSON;
|
use JSON;
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
@ -143,7 +143,8 @@ sub levenshtein_matches {
|
|||||||
my @matches;
|
my @matches;
|
||||||
|
|
||||||
foreach my $index (sort keys %{$self->{hash}}) {
|
foreach my $index (sort keys %{$self->{hash}}) {
|
||||||
my $distance = fastdistance($keyword, $index);
|
my $distance = distance($keyword, $index, 20);
|
||||||
|
next if not defined $distance;
|
||||||
|
|
||||||
my $length_a = length $keyword;
|
my $length_a = length $keyword;
|
||||||
my $length_b = length $index;
|
my $length_b = length $index;
|
||||||
|
@ -25,8 +25,8 @@ use PBot::Imports;
|
|||||||
# These are set by the /misc/update_version script
|
# These are set by the /misc/update_version script
|
||||||
use constant {
|
use constant {
|
||||||
BUILD_NAME => "PBot",
|
BUILD_NAME => "PBot",
|
||||||
BUILD_REVISION => 4370,
|
BUILD_REVISION => 4371,
|
||||||
BUILD_DATE => "2021-08-26",
|
BUILD_DATE => "2021-08-27",
|
||||||
};
|
};
|
||||||
|
|
||||||
sub initialize {}
|
sub initialize {}
|
||||||
|
11
updates/4371_SEE_COMMIT_MESSAGE_FOR_DETAILS.pl
Executable file
11
updates/4371_SEE_COMMIT_MESSAGE_FOR_DETAILS.pl
Executable file
@ -0,0 +1,11 @@
|
|||||||
|
#!/usr/bin/env perl
|
||||||
|
|
||||||
|
# Recent updates require a bot restart
|
||||||
|
#
|
||||||
|
# Replaced Text::Levenshtein with the much, much faster Text::Levenshtein::XS.
|
||||||
|
#
|
||||||
|
# If you do not have Text::Levenshtein::XS installed, you must install it:
|
||||||
|
#
|
||||||
|
# cpanm Text::Levenshtein::XS
|
||||||
|
|
||||||
|
exit 0;
|
Loading…
Reference in New Issue
Block a user