From 4fe5c87d0cc692f5d64d618d125451cbda9b340f Mon Sep 17 00:00:00 2001 From: Andrew Benson Date: Wed, 11 Dec 2024 16:16:55 -0800 Subject: [PATCH 1/3] feat: Provide a guess for a parameter name when no matching parameter is found in auto-descriptor If no matching parameter can be found in a class when attempting to build an auto-descriptor, we now provide a guess of which parameter was intended by comparing the given name to the available names using the Levenshtein distance. --- .github/actions/buildMacOS/action.yml | 1 + .../Build/SourceTree/Process/FunctionClass.pm | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/actions/buildMacOS/action.yml b/.github/actions/buildMacOS/action.yml index 5d309d363..f31bf6e49 100644 --- a/.github/actions/buildMacOS/action.yml +++ b/.github/actions/buildMacOS/action.yml @@ -210,6 +210,7 @@ runs: sudo perl -MCPAN -e 'force("install","XML::SAX::ParserFactory")' sudo perl -MCPAN -e 'force("install","XML::Validator::Schema")' sudo perl -MCPAN -e 'force("install","Text::Template")' + sudo perl -MCPAN -e 'force("install","Text::Levenshtein)' sudo perl -MCPAN -e 'force("install","List::Uniq")' sudo perl -MCPAN -e 'force("install","IO::Util")' sudo perl -MCPAN -e 'force("install","Class::Util")' diff --git a/perl/Galacticus/Build/SourceTree/Process/FunctionClass.pm b/perl/Galacticus/Build/SourceTree/Process/FunctionClass.pm index 0ba430ec1..ed404359b 100644 --- a/perl/Galacticus/Build/SourceTree/Process/FunctionClass.pm +++ b/perl/Galacticus/Build/SourceTree/Process/FunctionClass.pm @@ -11,10 +11,13 @@ use XML::Simple; use Sort::Topo; use LaTeX::Encode; use Scalar::Util qw(reftype); +use List::Util; +use List::MoreUtils qw(first_index); use List::ExtraUtils; use List::Uniq ':all'; use File::Changes; use Fortran::Utils; +use Text::Levenshtein; use Text::Template 'fill_in_string'; use Storable qw(dclone); use Galacticus::Build::SourceTree::Process::SourceIntrospection; @@ -414,7 +417,15 @@ sub Process_FunctionClass { } } else { $supported = -1; - push(@failureMessage,"could not find a matching internal variable for parameter [".$name."]"); + my @potentialNames = map {@{$_->{'variableNames'}}} @{$potentialNames->{'parameters'}}; + my @distances = &Text::Levenshtein::distance(lc($name),map {lc($_)} @potentialNames); + my $indexMinimum = first_index {$_ == &List::Util::min(@distances)} @distances; + my $message = "could not find a matching internal variable for parameter [".$name."]"; + unless ( $indexMinimum == -1 ) { + (my $nameGuess = $potentialNames[$indexMinimum]) =~ s/_//; + $message .= " - did you mean [".$nameGuess."]"; + } + push(@failureMessage,$message); } } } else { From 93f9604bb5ef3a6cea2abb10341da60c8d29ca34 Mon Sep 17 00:00:00 2001 From: Andrew Benson Date: Wed, 11 Dec 2024 18:58:19 -0800 Subject: [PATCH 2/3] fix: Avoid processing of empty lists of potential parameter names --- .../Build/SourceTree/Process/FunctionClass.pm | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/perl/Galacticus/Build/SourceTree/Process/FunctionClass.pm b/perl/Galacticus/Build/SourceTree/Process/FunctionClass.pm index ed404359b..955a0ac5a 100644 --- a/perl/Galacticus/Build/SourceTree/Process/FunctionClass.pm +++ b/perl/Galacticus/Build/SourceTree/Process/FunctionClass.pm @@ -417,13 +417,15 @@ sub Process_FunctionClass { } } else { $supported = -1; - my @potentialNames = map {@{$_->{'variableNames'}}} @{$potentialNames->{'parameters'}}; - my @distances = &Text::Levenshtein::distance(lc($name),map {lc($_)} @potentialNames); - my $indexMinimum = first_index {$_ == &List::Util::min(@distances)} @distances; my $message = "could not find a matching internal variable for parameter [".$name."]"; - unless ( $indexMinimum == -1 ) { - (my $nameGuess = $potentialNames[$indexMinimum]) =~ s/_//; - $message .= " - did you mean [".$nameGuess."]"; + my @potentialNames = map {@{$_->{'variableNames'}}} @{$potentialNames->{'parameters'}}; + if ( scalar(@potentialNames) > 0 ) { + my @distances = &Text::Levenshtein::distance(lc($name),map {lc($_)} @potentialNames); + my $indexMinimum = first_index {$_ == &List::Util::min(@distances)} @distances; + unless ( $indexMinimum == -1 ) { + (my $nameGuess = $potentialNames[$indexMinimum]) =~ s/_//; + $message .= " - did you mean [".$nameGuess."]"; + } } push(@failureMessage,$message); } From 4b55b464328b6783a4bafd70197240966b4ff690 Mon Sep 17 00:00:00 2001 From: Andrew Benson Date: Thu, 12 Dec 2024 07:03:12 -0800 Subject: [PATCH 3/3] fix: Add missing quote character --- .github/actions/buildMacOS/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/buildMacOS/action.yml b/.github/actions/buildMacOS/action.yml index f31bf6e49..f5b17a12b 100644 --- a/.github/actions/buildMacOS/action.yml +++ b/.github/actions/buildMacOS/action.yml @@ -210,7 +210,7 @@ runs: sudo perl -MCPAN -e 'force("install","XML::SAX::ParserFactory")' sudo perl -MCPAN -e 'force("install","XML::Validator::Schema")' sudo perl -MCPAN -e 'force("install","Text::Template")' - sudo perl -MCPAN -e 'force("install","Text::Levenshtein)' + sudo perl -MCPAN -e 'force("install","Text::Levenshtein")' sudo perl -MCPAN -e 'force("install","List::Uniq")' sudo perl -MCPAN -e 'force("install","IO::Util")' sudo perl -MCPAN -e 'force("install","Class::Util")'