-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8027de7
Showing
7 changed files
with
324 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
node_modules | ||
|
||
lib-cov | ||
*.seed | ||
*.log | ||
*.csv | ||
*.dat | ||
*.out | ||
*.pid | ||
*.gz | ||
|
||
pids | ||
logs | ||
results | ||
|
||
npm-debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2013 Darius Kazemi | ||
|
||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Bad 80's freestyle battle raps: on demand! | ||
|
||
First install its dependencies: | ||
|
||
$ npm install | ||
|
||
Then run it: | ||
|
||
$ node rapbot.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
key: 'd4711e36506fe047f12970c6fdc0b43f6e4fef2e855e03d5c' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* indefinite-article.js v1.0.0, 12-18-2011 | ||
* | ||
* @author: Rodrigo Neri (@rigoneri) | ||
* Modified by Darius Kazemi to work with Require. | ||
* | ||
* (The MIT License) | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
( function ( root ){ | ||
|
||
var article = function(phrase) { | ||
|
||
// Getting the first word | ||
var match = /\w+/.exec(phrase); | ||
if (match) | ||
var word = match[0]; | ||
else | ||
return "an"; | ||
|
||
var l_word = word.toLowerCase(); | ||
// Specific start of words that should be preceeded by 'an' | ||
var alt_cases = ["honest", "hour", "hono"]; | ||
for (var i in alt_cases) { | ||
if (l_word.indexOf(alt_cases[i]) == 0) | ||
return "an"; | ||
} | ||
|
||
// Single letter word which should be preceeded by 'an' | ||
if (l_word.length == 1) { | ||
if ("aedhilmnorsx".indexOf(l_word) >= 0) | ||
return "an"; | ||
else | ||
return "a"; | ||
} | ||
|
||
// Capital words which should likely be preceeded by 'an' | ||
if (word.match(/(?!FJO|[HLMNS]Y.|RY[EO]|SQU|(F[LR]?|[HL]|MN?|N|RH?|S[CHKLMNPTVW]?|X(YL)?)[AEIOU])[FHLMNRSX][A-Z]/)) { | ||
return "an"; | ||
} | ||
|
||
// Special cases where a word that begins with a vowel should be preceeded by 'a' | ||
regexes = [/^e[uw]/, /^onc?e\b/, /^uni([^nmd]|mo)/, /^u[bcfhjkqrst][aeiou]/] | ||
for (var i in regexes) { | ||
if (l_word.match(regexes[i])) | ||
return "a" | ||
} | ||
|
||
// Special capital words (UK, UN) | ||
if (word.match(/^U[NK][AIEO]/)) { | ||
return "a"; | ||
} | ||
else if (word == word.toUpperCase()) { | ||
if ("aedhilmnorsx".indexOf(l_word[0]) >= 0) | ||
return "an"; | ||
else | ||
return "a"; | ||
} | ||
|
||
// Basic method of words that begin with a vowel being preceeded by 'an' | ||
if ("aeiou".indexOf(l_word[0]) >= 0) | ||
return "an"; | ||
|
||
// Instances where y follwed by specific letters is preceeded by 'an' | ||
if (l_word.match(/^y(b[lor]|cl[ea]|fere|gg|p[ios]|rou|tt)/)) | ||
return "an"; | ||
|
||
return "a"; | ||
} | ||
|
||
module.exports = article; | ||
})( this ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "rapbot", | ||
"description": "You like bad 80's freestyle battle rapping? Let's automate that shit.", | ||
"version": "0.1.0", | ||
"homepage": "https://github.com/dariusk/rapbot", | ||
"author": { | ||
"name": "Darius Kazemi", | ||
"email": "darius.kazemi@gmail.com", | ||
"url": "http://tinysubversions.com" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/dariusk/rapbot" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/dariusk/rapbot/issues" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "https://github.com/dariusk/rapbot/blob/master/LICENSE-MIT" | ||
} | ||
], | ||
"dependencies": { | ||
"wordnik-bb": ">=0.1.0", | ||
"inflection": "1.2.5", | ||
"express": "3.0.x", | ||
"underscore.deferred": "0.4.x" | ||
}, | ||
"engines": { | ||
"node": ">=0.8.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
var APIKEY = require('./config.js').key; | ||
var _ = require('underscore.deferred'); | ||
var I = require('inflection'); | ||
var request = require('request'); | ||
var article = require('./indefinite'); | ||
var Wordnik = require('wordnik-bb').init(APIKEY); | ||
|
||
var express = require('express'), | ||
app = express(); | ||
app.use(express.logger()); | ||
app.listen(3000); | ||
console.log('Express server started on port 3000'); | ||
|
||
function getCoupletPromise() { | ||
|
||
var coupletDeferred = _.Deferred(); | ||
var coupletPromise = coupletDeferred.promise(); | ||
|
||
var url = "http://api.wordnik.com//v4/words.json/randomWord?includePartOfSpeech=noun&excludePartOfSpeech=proper-noun,proper-noun-plural,proper-noun-posessive,suffix,family-name,idiom,affix&minCorpusCount=5000&api_key=" + APIKEY; | ||
var rwDeferred = _.Deferred(); | ||
var randomWordPromise = rwDeferred.promise(); | ||
request({ | ||
url : url | ||
}, function(error, response, body) { | ||
if (!error && response.statusCode === 200) { | ||
//console.log(JSON.parse(body).word); | ||
//console.log(I.singularize(JSON.parse(body).word)); | ||
var word = new Wordnik.Word({word: I.singularize(JSON.parse(body).word), params:{ | ||
relationshipTypes: 'rhyme', | ||
limitPerRelationshipType: 100, | ||
hasDictionaryDef: true | ||
}}); | ||
word.getWord() | ||
.then( function() { | ||
rwDeferred.resolve(word); | ||
}); | ||
|
||
} | ||
else { | ||
rwDeferred.reject(error); | ||
} | ||
}); | ||
|
||
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 a = article(word.id) + " "; | ||
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 | ||
]; | ||
var first = 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); | ||
( function(first) { | ||
|
||
posPromise.done(function(pos) { | ||
var result = "oops!"; | ||
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 " | ||
]; | ||
result = pre[Math.floor(Math.random()*pre.length)] + word2; | ||
} | ||
else if (pos === 'noun' || pos === 'proper-noun') { | ||
var a = article(word.id) + " "; | ||
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, | ||
"Try to step to me and I'mma wreck your ", | ||
"Wherever I go, people give me some " | ||
]; | ||
result = pre[Math.floor(Math.random()*pre.length)] + I.singularize(word2); | ||
} | ||
else if (pos === 'verb-transitive') { | ||
result = "My rhyme profile makes the ladies " + word2; | ||
} | ||
else if (pos === 'interjection') { | ||
result = "*skratch solo* ... (" + word2[0] + "-" + word2[0] + "-" + word2 + "!)"; | ||
} | ||
else { | ||
result = pos; | ||
//coupletDeferred.resolve(result); | ||
coupletDeferred.resolve(""); | ||
} | ||
coupletDeferred.resolve(first + "\n<br>" + result + "\n<br>"); | ||
}); | ||
})(first); | ||
} | ||
else { | ||
//coupletDeferred.resolve("Sorry. We couldn't find anything that rhymes with " + word.id + "!"); | ||
coupletDeferred.resolve(""); | ||
} | ||
}); | ||
}); | ||
return coupletDeferred.promise(); | ||
} | ||
|
||
app.get('/' , function(req, res){ | ||
|
||
var cypher = ""; | ||
|
||
var stuffToDo = []; | ||
for (var i=0;i<12;i++) { | ||
var cp = getCoupletPromise(); | ||
cp.done(function(couplet) { | ||
if(couplet !== "") { | ||
cypher += (couplet); | ||
} | ||
}); | ||
stuffToDo.push(cp); | ||
} | ||
|
||
_.when(stuffToDo).done( function() { | ||
console.log(cypher); | ||
console.log('*drops the mic*'); | ||
cypher += "<br>*drops the mic*"; | ||
res.send('<!doctype html><html><head><title>Freestyle 80s Battle Rap Generator</title><style type="text/css"></style></head><body style="font-family:sans-serif;width:600px;"><h1>Freestyle 80s Battle Rap Generator</h1><p>'+cypher+'</p><script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(["_setAccount", "UA-37844294-1"]); _gaq.push(["_trackPageview"]); (function() { var ga = document.createElement("script"); ga.type = "text/javascript"; ga.async = true; ga.src = ("https:" == document.location.protocol ? "https://ssl" : "http://www") + ".google-analytics.com/ga.js"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(ga, s); })(); </script></body></html>'); | ||
|
||
}); | ||
|
||
}); | ||
|
||
|
||
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(); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|