Skip to content

Instantly share code, notes, and snippets.

@andrew-t
Last active February 8, 2019 16:07
Show Gist options
  • Save andrew-t/233644d2216515fa81c51265cd1daf2b to your computer and use it in GitHub Desktop.
Save andrew-t/233644d2216515fa81c51265cd1daf2b to your computer and use it in GitHub Desktop.
generates euphemisms for a notable online berksquad
// cmudict file at http://svn.code.sf.net/p/cmusphinx/code/trunk/cmudict/cmudict-0.7b
// for more info see http://www.speech.cs.cmu.edu/cgi-bin/cmudict
const dict = require('fs')
.readFileSync(__dirname + '/cmudict', 'utf8')
.split('\n')
.filter(x => x && x[0] != ';')
.map(x => {
const [ word, parts ] = x.split(' ');
return {
word: word.replace(/\(\d+\)$/, ''),
parts: parts.split(' ')
};
});
const g = dict.filter(x => x.parts[0] === 'G'),
g1 = g.filter(x => stressPattern(x) == '1'),
g2 = g.filter(x => stressPattern(x) == '10');
for (let i = 0; i < 50; ++i)
console.log(c(g2) + c(g1));
function stressPattern(x) {
return x.parts.join('').replace(/[^\d]/g, '')
.replace(/1-9/g, '1');
}
function c(arr) {
const x = arr[~~(Math.random() * arr.length)].word;
return x.substr(0, 1).toUpperCase()
+ x.substr(1).toLowerCase();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment