Public
Edited
May 22, 2021
3 stars
Insert cell
Insert cell
Insert cell
Insert cell
replace = function (para) {
let words = RiTa.tokenize(para); // split into words
let indices = RiTa.randomOrdering(words.length); // shuffle indices

for (let i = 0; i < indices.length; i++) {
let idx = indices[i];
let word = words[idx].toLowerCase();
if (word.length < 3) continue; // len >= 3

// find related words
let pos = RiTa.tagger.allTags(word)[0];
let rhymes = RiTa.rhymes(word, { pos });
let sounds = RiTa.soundsLike(word, { pos });
let spells = RiTa.spellsLike(word, { pos });
let similars = [...rhymes, ...sounds, ...spells];

// only keep words with 2 or more similars
if (similars.length < 2) {
console.log("No sims for " + word);
continue;
}

// pick a random similar
let next = RiTa.random(similars);
if (next.includes(word) || word.includes(next)) {
continue; // skip substrings
}

if (/[A-Z]/.test(words[idx][0])) {
next = RiTa.capitalize(next); // keep capitals
}

console.log("replace(" + idx + "): " + word + " -> " + next, +new Date());
words[idx] = next; // do replacement
break;
}

return RiTa.untokenize(words);
}
Insert cell
Insert cell
Insert cell
Insert cell
RiTa.VERSION

Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more