Skip to content
This repository has been archived by the owner on Jun 8, 2023. It is now read-only.

Commit

Permalink
Added support for Bigrams/Phrases
Browse files Browse the repository at this point in the history
  • Loading branch information
Cody Hoover committed Aug 25, 2014
1 parent e6e0bb6 commit bf41933
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/scripts/wordnik.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# hubot define me <word> - Grabs a dictionary definition of a word.
# hubot pronounce me <word> - Links to a pronunciation of a word.
# hubot spell me <word> - Suggests correct spellings of a possible word.
# hubot bigram me <word> - Grabs the most frequently used bigram phrases containing this word
#
# Notes:
# You'll need an API key from http://developer.wordnik.com/
Expand Down Expand Up @@ -73,6 +74,24 @@ module.exports = (robot) ->
list = wordinfo.suggestions.join(', ')
msg.send "Suggestions for \"#{word}\": #{list}"

# Bigrams
robot.respond /bigram( me)? (.*)/i, (msg) ->
word = msg.match[2]

fetch_wordnik_resource(msg, word, 'phrases', {}) (err, res, body) ->
phrases = JSON.parse(body)

if phrases.length == 0
msg.send "No bigrams for \"#{word}\" found."
else
reply = "Bigrams for \"#{word}\":\n"

phrases = phrases.forEach (phrase) ->
if phrase.gram1 != undefined and phrase.gram2 != undefined
reply += "#{phrase.gram1} #{phrase.gram2}\n"

msg.send reply

fetch_wordnik_resource = (msg, word, resource, query, callback) ->
# FIXME prefix with HUBOT_ for
if process.env.WORDNIK_API_KEY == undefined
Expand Down

0 comments on commit bf41933

Please sign in to comment.