Probably the simplest way to check a word if it exists is to use DictionaryWordQ[]



But it does not recognise British spelling:



So my guess is that DictionaryWordQ[] checks words from WordList[]:

Select[WordList[], StringLength[#] > 3 && StringTake[#, 4] == "colo" &]


No colour. However,



So the word colour is known to Mathematica, but DictionaryWordQ[] does not see it!




Select[WordList[], StringLength[#] > 1 && StringTake[#, 2] == "qt" &]


which gives an impression that DictionaryWordQ[] is looking at a bigger set of words compared to WordData[] (or it is a bug!).


What is the best way to verify if a word exists?

(Version used: 11.1, 10.4 in Linux)

  • $\begingroup$ The "best" way is to look in the OED :) $\endgroup$ – Bob Hanlon Mar 17 '18 at 18:17
  • 1
    $\begingroup$ @BobHanlon But since no language was given by OP, clearly OED loses out: Dictionary[ {All, "Bürgersteig"}] gives {{German, Bürgersteig}}. :) $\endgroup$ – gwr Mar 17 '18 at 18:20
  • 1
    $\begingroup$ @BobHanlon, therefore OED is not the best choice - QED ;) $\endgroup$ – Sumit Mar 18 '18 at 6:26
  • 2
    $\begingroup$ What does it mean for a word to exist? Do the words "mimsy" and "borogoves" exist? $\endgroup$ – mattdm Mar 18 '18 at 16:29
  • 2
    $\begingroup$ @mattdm Play Scrabble, to give a practical example, with a bunch of people and you will soon find out, that citing Lewis Carroll or your local community's mumbo-jumbo may not be enough evidence. :) $\endgroup$ – gwr Mar 18 '18 at 17:30

Using DictionaryLookup seems to be more reliable, while not perfect:

DictionaryLookup[ {All, "word" }, IgnoreCase -> True ]

It seems to be rather comprehensive across different languages:

DictionaryLookup[ {All, "qt"}, IgnoreCase -> True ]

{{"Hungarian", "Qt"}}

Albeit, Mathematica will not find "qt" as abbreviation for Quantity (see for example Merriam Webster.

DictionaryLookup[{All, "colour"}, IgnoreCase -> True]

{{"BritishEnglish", "colour"}}

Also, it seems to be more comprehensive than WordList[]:

DictionaryLookup[{"BritishEnglish", "colo" ~~ __}] // Select[StringLength@# > 3 &]


Length @ %


as opposed to 33 from WordList[], as given by OP.

Alternative to DictionaryWordQ for English Words

Options[englishWordExistsQ] = {
   IgnoreCase -> True
englishWordExistsQ[ word_String, opts : OptionsPattern[englishWordExistsQ] ] := Module[
    optIgnoreCase = OptionValue[IgnoreCase],
  results = Join[
    DictionaryLookup[ {"BritishEnglish", word}, IgnoreCase -> optIgnoreCase],
    DictionaryLookup[ {"English", word }, IgnoreCase -> optIgnoreCase ]
  results =!= {}


englishWordExistsQ @ "colour"


  • 1
    $\begingroup$ DictionaryLookup[{All, "excellent" ~~ ___}] $\endgroup$ – Sumit Mar 18 '18 at 6:33

Since gwr already answered the question, let me offer a few routines to check alternative dictionaries.


Merriam-Webster provides an API for looking words up in their Collegiate® Dictionary. You will need to register to obtain an API key:

$MWAPIKey = (* insert your API key *);

MWLookup::suggest = "Word `1` not found. Returning a list of suggestions instead.";
MWLookup::noword = "Word `1` not found.";

MWLookup[word_String] := Module[{url, raw, check},
  url = "https://www.dictionaryapi.com/api/v1/references/collegiate/xml/";
  raw = Import[url <> URLEncode[ToLowerCase[word]] <> "?key=" <> $MWAPIKey, "XML"];
  check = Cases[raw, XMLElement["entry", {"id" -> s_String}, rest_] :> s, ∞];
  If[check =!= {}, check,
     check = Cases[raw, XMLElement["suggestion", {}, {s_String}] :> s, ∞];
     If[check =!= {}, Message[MWLookup::suggest, word]; check, 
        Message[MWLookup::noword, word]; check]]]

For example,


MWLookup["enfant terrible"]
   {"enfant terrible"}


MWLookup::suggest: Word poiuyt not found. Returning a list of suggestions instead.

   {"payout", "pouty", "pout", "Paiute", "Poitou", "peyote", "uppity", "potty", "poult",
    "piety", "pity", "polit", "polity", "polite", "putty", "pilot", "opiate", "poet",
    "puto", "pollute"}



MWLookup::noword: Word qazwrk not found.



The Oxford Dictionaries also provide an API, which you'll need to register for. Their system is a bit more complicated, since calling their API requires an API ID and an API key:

$OxfordAPIID = (* insert your API ID *);
$OxfordAPIKey = (* insert your API key *);

OxfordLookup::noword = "Word `1` not found.";

OxfordLookup[word_String] := Module[{url, w, raw, check},
      url = "https://od-api.oxforddictionaries.com:443/api/v1/inflections/en/";
      w = StringReplace[URLEncode[ToLowerCase[word]], "+" -> "%20"];
      raw = Import[HTTPRequest[url <> w, <|"Method" -> "GET",
                                           "Headers" -> {"app_id" -> $OxfordAPIID,
                                                         "app_key" -> $OxfordAPIKey}|>],
      check = Quiet[Check[ImportString[raw, "RawJSON"], ImportString[raw, "HTML"],
                          Import::jsonhintposandchar], Import::jsonhintposandchar];
      If[check === "Not Found  \nNo lemmas found matching supplied source_lang and word",
         Message[OxfordLookup::noword, word]; Return[{}, Module]];
         StringReplace[Through[check["results"]["id"]], "_" -> " "]]

For example,


OxfordLookup["enfant terrible"]
   {"enfant terrible"}


MWLookup::noword: Word poiuyt not found.


Oxford also provides an API for searching the Oxford English Dictionary, but the API is still in prototype stage, and still has some functionality (e.g. stemming) missing. Nevertheless, here is how to call the API from Mathematica:

OEDLookup::noword = "Word `1` not found.";
OEDLookup[word_String] := Module[{url, w, raw}, 
   url = "https://oed-api-demo-2445581300291.apicast.io:443/oed/api/v0.0/words/?lemma=";
   w = URLEncode[ToLowerCase[word]];
   raw = Flatten[Import[HTTPRequest[url <> w, <|"Method" -> "GET", 
                        "Headers" -> {"Accept" -> "application/json", 
                        "app_id" -> $OxfordAPIID, "app_key" -> $OxfordAPIKey}|>], 
   If[raw === {}, Message[OEDLookup::noword, word]; {}, Through[raw["lemma"]]]]

For example:

   {"set", "set", "set", "set"}

OEDLookup["to and fro"]
   {"to and fro"}
  • $\begingroup$ Very nice. Can you give an estimate for how long an average lookup takes? $\endgroup$ – Yves Klett Mar 18 '18 at 11:50
  • $\begingroup$ My Internet connection is horribly slow, but I've found that the APIs for both services return in about a second or so. $\endgroup$ – J. M. will be back soon Mar 18 '18 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.