bontaki-engine
Version:
emotions to psychoanalytic metaphor conversion
69 lines (60 loc) • 1.98 kB
JavaScript
module.exports = function (props) {
// private
function randomItem(array) {
return array[Math.floor(Math.random() * array.length)]
}
function randomScripture() {
const books = Object.keys(props.method.bible);
const book = books[randomItem(books)];
const chapters = Object.keys(props.method.bible[book].chapters);
const chapter = chapters[randomItem(chapters)];
const verse = randomItem(chapter);
return props.method.bible[book].chapters[chapter][verse];
}
function serialScriptures() {
var scriptures = [];
for(var books = 0; books < props.method.bible.length; ++books) {
for(var chapters = 0; chapters < props.method.bible[books].chapters.length; ++chapters) {
for(var verses = 0; verses < props.method.bible[books].chapters[chapters].length; ++verses) {
const verse = props.method.bible[books].chapters[chapters][verses];
const address = `${props.method.bible[books].name} ${chapters + 1}:${verses + 1}`
scriptures.push(`${verse} ${address}`)
}
}
}
return scriptures;
}
function writeFile(path, data) {
return new Promise((resolve, reject) => {
props.method.fs.writeFile(path, data, (error, data) => {
if(error) {
reject(error);
}
resolve(data);
});
});
}
// privileged
this.createScriptureData = async function() {
const scriptures_data = [].concat(...serialScriptures().map((verse, i) => {
console.log(i);
const matches = props.method.keywords.map((matching) => {
if(matching.keywords.some(keyword => verse.includes(keyword))) {
return { answer: verse, intent: matching.intent }
}
return false;
});
if(matches.length === 0) {
return false;
}
return matches;
})).filter((d) => {
return d;
});
console.log(scriptures_data);
await writeFile(props.method.path.join(__dirname, "../data/scriptures.data.json"), JSON.stringify(scriptures_data));
}
this.serialScriptures = function() {
return serialScriptures();
}
};