Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Freestyle rap generator.

  • Loading branch information...
commit 7e0f67d8c210e7ad42ffcf348afd0a5342b3f2c2 1 parent f11ff1a
@dariusk authored
Showing with 79 additions and 2 deletions.
  1. +2 −2 lib/wordnik-bb.js
  2. +77 −0 rhymes.js
View
4 lib/wordnik-bb.js
@@ -160,7 +160,7 @@ exports.init = function(APIKEY) {
var params = this.get("params");
var queryString = "";
for (var i in params) {
- if (params.hasOwnProperty(i)) {
+ if (params.hasOwnProperty(i) && i !== "wordParams") {
queryString += "&"+i+"="+params[i];
}
}
@@ -188,7 +188,7 @@ exports.init = function(APIKEY) {
random.getRandomWord()
.then( function(random) {
- var word = new Word({word: random.word});
+ var word = new Word({word: random.word, params: self.options.wordParams});
deferred.resolve(word);
});
View
77 rhymes.js
@@ -0,0 +1,77 @@
+var APIKEY = 'd4711e36506fe047f12970c6fdc0b43f6e4fef2e855e03d5c';
+var Wordnik = require('./lib/wordnik-bb.js').init(APIKEY);
+var $ = require('jquery');
+
+// Here's an example of using the getRandomWordModel function, which behind the scenes generates a random word and then creates a Wordnik.Word model based on it.
+var randomWordPromise = Wordnik.getRandomWordModel({
+ includePartOfSpeech: "noun",
+ excludePartOfSpeech: "proper-noun,proper-noun-plural,proper-noun-posessive,suffix,family-name,idiom,affix",
+ minCorpusCount: 5000,
+ wordParams: {
+ relationshipTypes: 'rhyme',
+ limitPerRelationshipType: 100,
+ hasDictionaryDef: true
+ }
+ }
+);
+
+randomWordPromise.done(function(word) {
+ //console.log("The model for our random word: ", word);
+ // We could also get more info about the random word, in this case, relatedWords that rhyme:
+ word.getRelatedWords()
+ .then( function() {
+ if (word.get("relatedWords").length > 0) {
+ var opens = [
+ "I'm the illest MC to ever rock the ",
+ "When I'm on the mic you realize you're just a ",
+ "My rhymes bring the power like a raging ",
+ "If you can't handle this then you're nothing but a "
+ ];
+ console.log(opens[Math.floor(Math.random()*opens.length)] + word.id);
+ var word2 = word.get("relatedWords")[0].words[Math.floor(Math.random()*word.get("relatedWords")[0].words.length)];
+ var posPromise = getPartOfSpeech(word2);
+ posPromise.done(function(pos) {
+ if (pos === 'adjective') {
+ var pre = [
+ "You can try and battle me, but you're too ",
+ "I make the MCs in the place wish that they were ",
+ "My rhymes blow your mind and you think it's ",
+ "My sweet-ass rhymes make your woman feel "
+ ];
+ console.log( pre[Math.floor(Math.random()*pre.length)] + word2);
+ }
+ else if (pos === 'noun' || pos === 'proper-noun') {
+ var pre = [
+ "Every other MC is a sucker ",
+ "There's nobody like me 'cause I'm the greatest ",
+ "You hear my freestyle and you drop your ",
+ "My flow and my style both blow away the ",
+ "My posse's got my back and my homies got my ",
+ "Sweeter than molasses, and stronger than a "
+ ];
+ console.log( pre[Math.floor(Math.random()*pre.length)] + word2);
+ }
+ else if (pos === 'verb-transitive') {
+ console.log("My rhyme profile makes the ladies " + word2);
+ }
+ else {
+ console.log(pos);
+ }
+ });
+ }
+ else {
+ console.log("Sorry. We couldn't find anything that rhymes with " + word.id + "!");
+ }
+ });
+});
+
+function getPartOfSpeech(wordId) {
+ // accepts a word string
+ var word = new Wordnik.Word({word: wordId, params:{includeSuggestions:true}});
+ var deferred = $.Deferred();
+ word.getDefinitions()
+ .then( function(word) {
+ deferred.resolve(word.get("definitions")[0].partOfSpeech);
+ });
+ return deferred.promise();
+}

0 comments on commit 7e0f67d

Please sign in to comment.
Something went wrong with that request. Please try again.