Make suggestions for misspelled queries

Python has a library "from difflib import get_close_matches" that will return a weighted list of words that in some way match the word entered. This is useful to suggest to the user the correct spelling for a query. Is there some way to do this through the API? I had thought of extracting a word list but realized that the size of the list would be prohibitive.

Tagged:

Best Answer

Answers

  • Could I use the "Search" Endpoint for this? When can I find a example of "Search"?

  • SimoneSimone Administrator admin

    Hi @JackHomeyer, interesting point that you raised. Let me contact a colleague who knows more about getting data from the API, so you can get a useful answer. :)

  • AmosDuveenAmosDuveen Member, Administrator, Moderator admin
    edited August 2017

    Hi @JackHomeyer,

    Yes. If you go to the 'search' endpoint of our documentation page, it shows you the allowable filters, including 'q' (the serach string) and lets you place a call (using the 'try it out' button) to see what the results look like.

    As an example, I used the deliberately ambiguous 'runing' ('rune' is not commonly used as a verb, and it could also be a likely misspelling of 'running' or 'ruining'). You can see for yourself that it throws up all sorts of suggestions ( I only included the first 6 of 198, for brevity).


    `{
    "results": [
    {
    "id": "runnable",
    "matchString": "runing",
    "region": "gb",
    "matchType": "headword",
    "word": "runnable"
    },
    {
    "id": "runnability",
    "matchString": "runing",
    "region": "gb",
    "matchType": "headword",
    "word": "runnability"
    },
    {
    "id": "runically",
    "matchString": "runing",
    "region": "gb",
    "matchType": "headword",
    "word": "runically"
    },
    {
    "id": "runed",
    "matchString": "runing",
    "region": "gb",
    "matchType": "headword",
    "word": "runed"
    },
    {
    "id": "run",
    "matchString": "runing",
    "region": "gb",
    "matchType": "headword",
    "word": "run"
    },
    {
    "id": "poker_run",
    "matchString": "runing",
    "region": "gb",
    "matchType": "headword",
    "word": "poker run"
    },

    ...

    ],
    "metadata": {
    "sourceLanguage": "en",
    "limit": 5000,
    "total": 198,
    "provider": "Oxford University Press",
    "offset": 0
    }
    }`

Sign In or Register to comment.