A StringToken Parser which gives Google Search style “Did you mean:” Suggestions

后端 未结 8 1039
-上瘾入骨i
-上瘾入骨i 2020-12-28 11:17

Seeking a method to:

Take whitespace separated tokens in a String; return a suggested Word


ie:
Google Search can take \"fon

8条回答
  •  悲&欢浪女
    2020-12-28 11:23

    First off:

    • Java
    • C++
    • C#

    Use the one of your choice. I suspect it runs the query against a spell-checking engine with a word limit of exactly one, it then does nothing if the entire query is valid, otherwise it replaces each word with that word's best match. In other words, the following algorithm (an empty return string means that the query had no problems):

    startup()
    {
       set the spelling engines word suggestion limit to 1
    }
    
    option 1()
    {
       int currentPosition = engine.NextWord(start the search at word 0, querystring);
    
       if(currentPosition == -1)
          return empty string; // Query is a-ok.
    
       while(currentPosition != -1)
       {
           queryString = engine.ReplaceWord(engine.CurrentWord, queryString, the suggestion with index 0);
           currentPosition = engine.NextWord(currentPosition, querystring);
       }
    
       return queryString;
    }
    

提交回复
热议问题