Skip to content

Commit

Permalink
Merge pull request #756 from galacticusorg/featGuessParameterName
Browse files Browse the repository at this point in the history
Provide a guess for a parameter name when no matching parameter is found in auto-descriptor
  • Loading branch information
abensonca authored Dec 13, 2024
2 parents 8557bc3 + 4b55b46 commit 9b7a315
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/actions/buildMacOS/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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")'
Expand Down
15 changes: 14 additions & 1 deletion perl/Galacticus/Build/SourceTree/Process/FunctionClass.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -414,7 +417,17 @@ sub Process_FunctionClass {
}
} else {
$supported = -1;
push(@failureMessage,"could not find a matching internal variable for parameter [".$name."]");
my $message = "could not find a matching internal variable for parameter [".$name."]";
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);
}
}
} else {
Expand Down

0 comments on commit 9b7a315

Please sign in to comment.