1

This might end up being a very general question, but hopefully it will be useful to others as well.

I want to be able to request a word that is x number of syllables with a stress on x.[y] syllable. I've found plenty of APIs that return both of these such as Wordnik, but I'm not sure how to approach the search aspect. The URL to get the syllables is

GET /word.json/{word}/hyphenation

but I won't know the word ahead of time to make this request. They also have this:

GET /words.json/randomWords

which returns a list random words.

Is there a way to achieve what I want with this API without asking for random words over and over and checking if they meet my needs? That just seems like it would be really slow and push me over my usage limits.

Do I need to build my own data structure with the words and syllables to query locally?

jemtan990
  • 443
  • 1
  • 6
  • 22
  • Sadly, Wordnik doesn't offer this data right now, but something similar is on our roadmap. I don't have a release date, but if you join our API Announcements list (http://wordnik.us2.list-manage1.com/subscribe?u=1c9b004e359a58df355705423&id=e142268969) you'll be the first to hear. (Also, please feel free to send feature requests!) – esperluette Aug 03 '16 at 21:29
  • Wow! I didn't anticipate someone from Wordnik running into this. I'm subscribed to the announcements list and look forward to hearing about new stuff! – jemtan990 Aug 04 '16 at 12:43

1 Answers1

3

I doubt you'll find this kind of specialized query on any of the big dictionary APIs. You'll need to download an English dictionary and create your own data structure to do this kind of thing.

The Moby Project has a hyphenated dictionary with about 185,000 words in it. There are many other dictionary projects available. A good place to start looking is http://www.dicts.info/dictionaries.php.

Once you've downloaded the dictionary, you'll need to preprocess it to build your data structure. You should be able to construct a dictionary or hash map that is indexed by (syllables, emphasis), and whose data member is a list of words. So you'd have an entry like (4, 2) (4-syllable word with emphasis on the 2nd syllable), and a list of all such words.

To query it, then, you'd just pack the query into a structure and look up that key in the hash map. Then pick a random word from the resulting list.

Jim Mischel
  • 131,090
  • 20
  • 188
  • 351
  • This is the answer I expected but wasn't hoping for. I was trying to find a shortcut, but I guess I'll do the brute work. Thanks for the resources! – jemtan990 Aug 03 '16 at 18:26