Skip to content

Commit

Permalink
SuggestedSpellings extended and renamed to HELP_SEARCH_ALTERNATIVES
Browse files Browse the repository at this point in the history
Now it also 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.
  • Loading branch information
Alexander Konovalov committed Feb 16, 2017
1 parent c5272cb commit 43aa919
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 41 deletions.
85 changes: 53 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,53 @@ 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 pattersn 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 := [];

for topic in topics do
if Length(topic) > 3 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 +248,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 +940,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
17 changes: 17 additions & 0 deletions tst/teststandard/helptools.tst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This test check various auxiliary functions used by the help system.
#
# For the test that systematically checks each mahual 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" ]
gap> STOP_TEST( "helptools.tst" );

0 comments on commit 43aa919

Please sign in to comment.