Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SuggestedSpellings extended and renamed to HELP_SEARCH_ALTERNATIVES #1144

Merged
merged 1 commit into from
Feb 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 58 additions & 32 deletions lib/helpbase.gi
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ end);
## - Modification of these rules (or using the patterns where one of
## spelling variants is the trailing substring of another) may require
## changing algorithms used in `FindMultiSpelledHelpEntries' and
## `SuggestedSpellings'.
## `HELP_SEARCH_ALTERNATIVES'.

BindGlobal( "TRANSATL",
[ [ "atalogue", "atalog" ],
Expand All @@ -106,16 +106,16 @@ BindGlobal( "TRANSATL",

#############################################################################
##
## SuggestedSpellings
## HELP_SEARCH_ALTERNATIVES
##
## This function is used by HELP_GET_MATCHES to check if the search topic
## might have different spellings, lookign for patterns from `TRANSATL'.
## might have different spellings, looking for patterns from `TRANSATL'.
##
## It returns a list of suggested spellings of a string, for example:
##
## gap> SuggestedSpellings("TriangulizeMat");
## gap> HELP_SEARCH_ALTERNATIVES("TriangulizeMat");
## [ "TrianguliseMat", "TriangulizeMat" ]
## gap> SuggestedSpellings("CentralizerSolvableGroup");
## gap> HELP_SEARCH_ALTERNATIVES("CentralizerSolvableGroup");
## [ "CentraliserSolubleGroup", "CentraliserSolvableGroup",
## "CentralizerSolubleGroup", "CentralizerSolvableGroup" ]
##
Expand All @@ -132,9 +132,13 @@ BindGlobal( "TRANSATL",
## about a dozen of entries which contains two occurrences of some patterns,
## and none with three or more of them.
##
BindGlobal( "SuggestedSpellings", function( topic )
## In addition, it ensures that the search for system setters and testers
## such as e.g. ?SetIsMapping and ?HasIsMapping will return corresponding
## attributes and properties. e.g. IsMapping.
##
BindGlobal( "HELP_SEARCH_ALTERNATIVES", function( topic )
local positions, patterns, pattern, where, what, variant, pos,
newwhere, newwhat, i, chop, begin, topics;
newwhere, newwhat, i, chop, begin, topics, shorttopic, r;

positions:=[];
patterns:=[];
Expand Down Expand Up @@ -186,36 +190,58 @@ for pattern in TRANSATL do
fi;
od;

if Length(positions) = 0 then # no matches - return immeditely
return [ topic ];
fi;
if Length(positions) > 0 then # matches found
# sort data about matches accordingly to their positions in `topic'.
SortParallel( positions, patterns );

# Now chop the string 'topic' into a list of lists, each of them either
# a list of all variants from the respective spelling pattern or just
# a one-element list with the "glueing" string between two patterns or
# a pattern and the beginning or end of the string.

chop:=[];
begin:=1;
for i in [1..Length(positions)] do
Add( chop, [ topic{[begin..patterns[i].start-1 ]} ] );
Add( chop, patterns[i].pattern );
begin := Minimum( patterns[i].finish+1, Length(topic) );
od;

# sort data about matches accordingly to their positions in `topic'.
SortParallel( positions, patterns );
if begin < Length( topic ) then
Add( chop, [ topic{[begin..Length(topic)]} ] );
fi;

# Now chop the string 'topic' into a list of lists, each of them either
# a list of all variants from the respective spelling pattern or just
# a one-element list with the "glueing" string between two pattersn or
# a pattern and the beginning or end of the string.
# Take the cartesian product of 'chop' and form spelling suggestions
# as concatenations of its elements.

chop:=[];
begin:=1;
for i in [1..Length(positions)] do
Add( chop, [ topic{[begin..patterns[i].start-1 ]} ] );
Add( chop, patterns[i].pattern );
begin := Minimum( patterns[i].finish+1, Length(topic) );
od;
topics := List( Cartesian(chop), Concatenation );

else # no matches

topics := [ topic ];

if begin < Length( topic ) then
Add( chop, [ topic{[begin..Length(topic)]} ] );
fi;

# Take the cartesian product of 'chop' and form spelling suggestions
# as concatenations of its elements.
r := [];

# This ensures that e.g. `?HasIsMapping` will show `IsMapping` even if only the
# latter is documented. It is guaranteed that the help system will send search
# terms in lowercase. The requirement of the search term to have the length at
# least 5 and do not have a space after "has" or "set" is essential: it prevents
# "set stabiliser", "hash", "sets", "SetX" etc. to be handled in the same way.
for topic in topics do
if Length(topic) > 4 and topic{[1..3]} in [ "has" , "set" ] and topic[4]<>' ' then
shorttopic := topic{[4..Length(topic)]};
Append( r, [ shorttopic,
Concatenation( "has", shorttopic),
Concatenation( "set", shorttopic) ] );
else
Add(r, topic );
fi;
od;

topics := List( Cartesian(chop), Concatenation );
Sort( topics );
return( topics );
Sort( r );
return( r );

end);

Expand All @@ -227,7 +253,7 @@ end);
##
## This utility may be used in checks of the help system by GAP developers.
##
## `HELP_GET_MATCHES' uses `SuggestedSpellings' to look for other possible
## `HELP_GET_MATCHES' uses `HELP_SEARCH_ALTERNATIVES' to look for other possible
## spellings, e.g. Normaliser/Normalizer, Center/Centre, Solvable/Soluble,
## Analyse/Analyze, Factorisation/Factorization etc.
##
Expand Down Expand Up @@ -919,7 +945,7 @@ InstallGlobalFunction(HELP_GET_MATCHES, function( books, topic, frombegin )
if topic = "size" then # "size" is a notable exception (lowercase is guaranteed)
topics:=[ topic ];
else
topics:=SuggestedSpellings( topic );
topics:=HELP_SEARCH_ALTERNATIVES( topic );
fi;

# <exact> and <match> contain the topics matching
Expand Down
9 changes: 0 additions & 9 deletions tst/testextra/helpsys.tst
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
## This produces the text version of each help section which can be reached
## from GAPs help system.
##
## Exclude from testinstall.g: why?
##

gap> START_TEST("helpsys.tst");
gap> SetUserPreference("Browse", "SelectHelpMatches", false); # needed only for compatibility with the Browse package
Expand All @@ -25,15 +23,8 @@ gap> for i in [1..Length(HELP_LAST.TOPICS)] do HELP(String(i)); od;
gap> PAGER_EXTERNAL:=savepager;;
gap> MakeReadOnlyGlobal("PAGER_EXTERNAL");
gap> SetUserPreference("Pager",savepagerprefs);
gap> ForAll(FindMultiSpelledHelpEntries(), i ->
> Length( Set( List( SuggestedSpellings( i[3] ),
> j -> SuggestedSpellings(j) ) ) ) = 1 );
true
gap> Length(SuggestedSpellings("AnalyseMetacatalogOfCataloguesOfColourizationLabelingsOfCentreBySolvableNormalisersInNormalizerCentralizersInCentre"));
4096
gap> STOP_TEST( "helpsys.tst", 6647170000);


#############################################################################
##
#E
Expand Down
19 changes: 19 additions & 0 deletions tst/teststandard/helptools.tst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This test checks various auxiliary functions used by the help system.
#
# For the test that systematically checks each manual section, see
# tst/testextra/helpsys.tst
#
gap> START_TEST("helptools.tst");
gap> ForAll(FindMultiSpelledHelpEntries(), i ->
> Length( Set( List( HELP_SEARCH_ALTERNATIVES( i[3] ),
> j -> HELP_SEARCH_ALTERNATIVES(j) ) ) ) = 1 );
true
gap> Length(HELP_SEARCH_ALTERNATIVES("AnalyseMetacatalogOfCataloguesOfColourizationLabelingsOfCentreBySolvableNormalisersInNormalizerCentralizersInCentre"));
4096
gap> HELP_SEARCH_ALTERNATIVES("hasismapping");
[ "hasismapping", "ismapping", "setismapping" ]
gap> HELP_SEARCH_ALTERNATIVES("setismapping");
[ "hasismapping", "ismapping", "setismapping" ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps also include HELP_SEARCH_ALTERNATIVES("ismapping") ?

gap> HELP_SEARCH_ALTERNATIVES("ismapping");
[ "ismapping" ]
gap> STOP_TEST( "helptools.tst" );