-2

I am trying to make a program for a Discord bot that takes a single parameter that the user gives it, checks to make sure the parameter is valid and usable, then sends it to the Merriam Webster API, takes the JSON it gets back and displays the short definition to the end user.

The only part I need an answer for right now is how would I check to make sure that the argument the user gives me is actually a valid word, or is that even possible? I know how to check to make sure the argument the user supplies is actually a bunch of letters with args[0].split("").every(isNaN), but not how to verify it is a word before sending it off. I believe the api handles it well either way, instead it will just return search results that it thinks might be what the user was trying to search for, except this will make the code more complicated, because I will have to make sure the definition was actually included in the response.

Searched all over, all I got was how to see if a string contained a certain word or phrase. I am using https://dictionaryapi.com.

  • didn't downvote but happy to give feedback. Firstly, definition of a "valid word" is very vague. In what language, in what context? Do medical terms count? Secondly, the question seems "recursive". Obviously the only way of doing this is matching against a dictionary so you would be looking up a dictionary before looking up a dictionary. Which is weird & inefficient to say the least. Last but not least, the question lacks research on response processing. Acting based on response structure is very common practice & is indeed less complicated & more structured than validating a word is a "word" – sinanspd Dec 02 '19 at 01:54
  • thank you, I'm pretty sure my answer, which I got partly from you, is to send it in without validating to make sure it's an English word (and I believe the service I'm using has two different APIs for words and medical terms) and process whether it's valid or not from the information I get back – PolyversialMind Dec 02 '19 at 02:01
  • No problem. I would highly recommend sticking to only 1 API. In a perfect world and good API design, Merriam should have been returning an error but it looks like they might not be doing that. Think about it, other options are you will either maintain a local dictionary and have to update whenever a new word is introduced or use a second API. Now your program has to rely on 2 APIs being up and functioning at all times, which is double the risk. One source leads to better, more reliable, more organized design. Happy coding – sinanspd Dec 02 '19 at 02:05

1 Answers1

0

You need a dictionary to match against and then send it.

How to check whether given string is a word

Tony
  • 77
  • 3
  • 12
  • slight issue, that's java, and I don't know Java. I am using dictionaryapi.com, but I don't know how I would validate a word with that. i would probably send it in, and it would return without a definition, telling me it's not a word – PolyversialMind Dec 02 '19 at 01:56