cthulhusay is awake
This commit is contained in:
commit
bc30849709
4 changed files with 243 additions and 0 deletions
59
.gitignore
vendored
Normal file
59
.gitignore
vendored
Normal file
|
@ -0,0 +1,59 @@
|
|||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Typescript v1 declaration files
|
||||
typings/
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
|
46
README.md
Normal file
46
README.md
Normal file
|
@ -0,0 +1,46 @@
|
|||
# Cthulhusay
|
||||
|
||||
Cthulhusay is the one and only cthulhu-fhtagn-ator (not true, but who cares): an extremely sophisticated software to generate curses and/or cake recipes in R'lyehian (also known as Cthuvian).
|
||||
|
||||
Forget about cowsay: it's time to talk like a Great Old. Also, don't forget to walk like a R'lyehian.
|
||||
|
||||
Words were taken from https://www.yog-sothoth.com/wiki/index.php/R'lyehian
|
||||
|
||||
## Eeerrr... Ok, I guess, but why?
|
||||
|
||||
But for the glory of Cthulhu, of course!
|
||||
|
||||
## Is there... I don't know, any documentation maybe?
|
||||
|
||||
Seriously?
|
||||
|
||||
Ok, ok...
|
||||
|
||||
npm install
|
||||
npm run cthulhusay
|
||||
|
||||
|
||||
## I see. What now?
|
||||
|
||||
Kn'a nilgh'ri mg r'luhog ep nww mg f'nww uaaahhor bug.
|
||||
|
||||
Which can be translated more or less like "let's add some bugs together to this code": add some feature and do a pull request.
|
||||
|
||||
## I'm not sure that JavaScript is truly a R'lyehian language...
|
||||
|
||||
You may be right. Here it is the Python version: https://github.com/alberanid/cthulhusay
|
||||
|
||||
## License and copyright
|
||||
|
||||
Copyright 2017 Davide Alberani <da@erlug.linux.it>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
105
cthulhusay.js
Normal file
105
cthulhusay.js
Normal file
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
|
||||
R'lyehian language generator. The one and only cthulhu-fhtagn-ator.
|
||||
|
||||
Copyright 2017 Davide Alberani <da@erlug.linux.it>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
// Summoned from https://www.yog-sothoth.com/wiki/index.php/R'lyehian
|
||||
var WORDS = ["'ai", "'bthnk", "'fhalma", 'ah', 'athg', 'bug', "ch'", 'chtenff', 'ebumna', 'ee', 'ehye', 'ep', 'fhtagn',
|
||||
"fm'latgh", 'ftaghu', 'geb', 'gnaiih', "gof'nn", 'goka', 'gotha', "grah'n", "hafh'drn", 'hai', 'hlirgh',
|
||||
'hrii', 'hupadgh', 'ilyaa', "k'yarnak", 'kadishtu', "kn'a", "li'hee", 'llll', 'lloig', "lw'nafh", "mnahn'",
|
||||
"n'gha", "n'ghft", 'nglui', "nilgh'ri", 'nog', 'nw', 'ooboshu', "orr'e", 'phlegeth', "r'luh", 'ron', "s'uhn",
|
||||
"sgn'wahl", 'shagg', 'shogg', 'shtunggli', 'shugg', "sll'ha", "stell'bsna", "syha'h", 'tharanak', 'throd',
|
||||
'uaaah', "uh'e", 'uln', 'vulgtlagln', 'vulgtm', "wgah'n", "y'hah", 'ya', 'zhro'];
|
||||
|
||||
// I'm confident that we'll find other conjunctions
|
||||
var CONJUNCTIONS = ['mg'];
|
||||
|
||||
var PREFIXES = ['c', "f'", "h'", 'na', 'nafl', 'ng', 'nnn', "ph'", 'y'];
|
||||
|
||||
var SUFFIXES = ['agl', 'nyth', 'og', 'or', 'oth', 'yar'];
|
||||
|
||||
var SENTENCE_ENDS = ['!', '?', '.', '.', '.'];
|
||||
var PUNCTUATIONS = SENTENCE_ENDS.concat([',', ';']);
|
||||
|
||||
var _ = require('lodash');
|
||||
|
||||
|
||||
function sampleMany(seq, freq) {
|
||||
seq = seq || [];
|
||||
freq = freq || 1;
|
||||
var selection = [];
|
||||
var howMany = Math.round(freq * seq.length);
|
||||
_.times(howMany, function() { selection.push(_.sample(seq)); });
|
||||
return selection;
|
||||
}
|
||||
|
||||
|
||||
/** Cthulhu says hi! **/
|
||||
function cthulhu_say(opts) {
|
||||
opts = opts || {};
|
||||
var o = {
|
||||
words: 10,
|
||||
conjuncionsFreq: 0.2,
|
||||
prefixesFreq: 0.25,
|
||||
suffixesFreq: 0.25,
|
||||
pluralsFreq: 0.3,
|
||||
punctuationsFreq: 0.1
|
||||
}
|
||||
_.merge(o, opts);
|
||||
var _range = _.range(o.words);
|
||||
|
||||
var sentence = [];
|
||||
_.times(o.words, function() { sentence.push(_.sample(WORDS)); });
|
||||
_.each(sampleMany(_range, o.pluralsFreq), function(val, idx) {
|
||||
sentence[val] = sentence[val] + sentence[val][sentence[val].length-1];
|
||||
});
|
||||
_.each(sampleMany(_range, o.prefixesFreq), function(val, idx) {
|
||||
sentence[val] = _.sample(PREFIXES) + sentence[val];
|
||||
});
|
||||
_.each(sampleMany(_range, o.suffixesFreq), function(val, idx) {
|
||||
sentence[val] = _.sample(SUFFIXES) + sentence[val];
|
||||
});
|
||||
_.each(sampleMany(_.range(1, o.words-1), o.conjuncionsFreq), function(val, idx) {
|
||||
sentence[val] = _.sample(CONJUNCTIONS);
|
||||
});
|
||||
_.each(sampleMany(_.range(1, o.words-1), o.punctuationsFreq), function(val, idx) {
|
||||
var punctuation = _.sample(PUNCTUATIONS);
|
||||
if (_.includes(PUNCTUATIONS, sentence[val][sentence[val].length-1]) || _.includes(CONJUNCTIONS, _.lowerCase(sentence[val]))) {
|
||||
return;
|
||||
}
|
||||
sentence[val] = sentence[val] + punctuation;
|
||||
if (_.includes(SENTENCE_ENDS, punctuation)) {
|
||||
sentence[val+1] = _.capitalize(sentence[val+1]);
|
||||
}
|
||||
});
|
||||
|
||||
var sentenceText = _.join(sentence, ' ');
|
||||
if (sentenceText) {
|
||||
sentenceText = _.upperFirst(sentenceText);
|
||||
if (o.punctuationsFreq) {
|
||||
sentenceText = sentenceText + _.sample(SENTENCE_ENDS);
|
||||
}
|
||||
}
|
||||
return sentenceText;
|
||||
}
|
||||
|
||||
|
||||
module.exports.cthulhu_say = cthulhu_say;
|
||||
|
||||
|
||||
if (require.main === module) {
|
||||
console.log(cthulhu_say());
|
||||
}
|
33
package.json
Normal file
33
package.json
Normal file
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
"name": "cthulhusay.js",
|
||||
"version": "1.0.0",
|
||||
"description": "the one and only cthulhu-fhtagn-ator",
|
||||
"main": "cthulhusay.js",
|
||||
"scripts": {
|
||||
"cthulhusay": "NODE_ENV=production node cthulhusay.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/alberanid/cthulhusay.js.git"
|
||||
},
|
||||
"keywords": [
|
||||
"cthulhu",
|
||||
"r-lyehian",
|
||||
"cthuvian",
|
||||
"sentence-generator",
|
||||
"phrase",
|
||||
"generator",
|
||||
"words",
|
||||
"great-old",
|
||||
"language"
|
||||
],
|
||||
"author": "Davide Alberani <da@erlug.linux.it>",
|
||||
"license": "Apache-2.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/alberanid/cthulhusay.js/issues"
|
||||
},
|
||||
"homepage": "https://github.com/alberanid/cthulhusay.js#readme",
|
||||
"dependencies": {
|
||||
"lodash": "^4.17.4"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue