Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@beaugunderson
Created August 9, 2016 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beaugunderson/5d657657918236f9ff03695b4e77e1f6 to your computer and use it in GitHub Desktop.
Save beaugunderson/5d657657918236f9ff03695b4e77e1f6 to your computer and use it in GitHub Desktop.
var Rhyme = require('rhyme-plus').Rhyme;
var sentenceTools = require('sentence-tools');
var Twit = require('twit');
var _ = require('lodash');
var T = new Twit(botUtilities.getTwitterAuthFromEnv());
var rhyme = new Rhyme();
function syllables(line) {
return _.sum(sentenceTools.words(line).map(function (word) {
return rhyme.syllables(word) || 1000;
}));
}
function syllableMap(line) {
return sentenceTools.words(line).map(function (word) {
return rhyme.syllables(word);
});
}
rhyme.load(function () {
var stream = T.stream('statuses/sample', {language: 'en'});
stream.on('tweet', function (tweet) {
var s = syllables(tweet.text);
var m = syllableMap(tweet.text);
if (s === 7 &&
(_.isEqual(m, [1, 1, 1, 1, 1, 1, 1]) ||
_.isEqual(m, [1, 2, 1, 1, 1, 1]) ||
_.isEqual(m, [1, 1, 2, 1, 1, 1]) ||
_.isEqual(m, [1, 3, 1, 1, 1]) ||
_.isEqual(m, [1, 1, 1, 1, 1, 2]) ||
_.isEqual(m, [1, 2, 1, 1, 2]) ||
_.isEqual(m, [1, 1, 2, 1, 2]) ||
_.isEqual(m, [1, 3, 1, 2]))) {
console.log(s, '-', tweet.text);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment