RiTa is implemented in JavaScript and Java, with a common API for both, and is free/libre/open-source.
- Smart lexicon search for words matching part-of-speech, syllable, stress and rhyme patterns
- Fast, heuristic algorithms for inflection, conjugation, stemming, tokenization, and more
- Letter-to-sound engine for feature analysis of arbitrary words (with/without lexicon)
- Integration of the RiScript scripting language, designed for writers, now built with the blazing fast Chevrotain parser
- New options for generation via grammars and Markov chains
- Published in ESM, CommonJS and as an IIFE
Note: version 3.0 contains breaking changes -- please check the release notes
- For esm:
import { RiTa } from "https://esm.sh/rita";
- For node:
$ npm install rita
let { RiTa } = require('rita');
- For browsers:
<script src="https://unpkg.com/rita"></script>
- For p5.js:
<script src="https://unpkg.com/rita"></script>
- For developers
import { RiTa } from "https://esm.sh/rita";
// to analyze a sentence
let data = RiTa.analyze("The elephant took a bite!");
console.log(data);
// to load a grammar
let grammar = RiTa.grammar(rulesObjectOrJSON);
console.log(grammar.expand());
RiScript (the minor language that powers RiTa) was designed specifically for writers working with code. RiScript primitives (choices, symbols, gates, transforms, etc) can be used as part of any RiTa grammar or executed directly using RiTa.evaluate. For more info, see this interactive notebook on observable.
To install/build the library and run tests (with npm/mocha and node v14.x):
$ git clone https://github.com/dhowe/ritajs.git
$ cd ritajs
$ npm install
$ npm run build
$ npm test
If all goes well, you should see a list of successful tests and find the library built in 'dist'
Please make contributions via fork-and-pull - thanks!
Once you have things running with npm/mocha/tsup, you might also try VSCode.
Some of the following extensions may also be useful:
- hbenl.vscode-mocha-test-adapter
- hbenl.vscode-test-explorer
- ms-vscode.test-adapter-converter
Here you can see the tests in the VSCode Testing view
![vscode-tests](https://private-user-images.githubusercontent.com/737638/283873092-103665fb-3dc8-448b-9ed3-d706be6797fc.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ2NTU1ODYsIm5iZiI6MTcyNDY1NTI4NiwicGF0aCI6Ii83Mzc2MzgvMjgzODczMDkyLTEwMzY2NWZiLTNkYzgtNDQ4Yi05ZWQzLWQ3MDZiZTY3OTdmYy5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwODI2JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDgyNlQwNjU0NDZaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1kZjBiMjBiZGU0ZjdkNWU5OTQ0YTMxZjBhOGVlYTgyYzcwOGQ2YWMxMmI0OTc1NGQ0ODk2MWRlYWE4YzY3NWI4JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.4ZvOOuXj4pq2O-AOQjyPBN1tM7nA1bUsvVbTZeWF_fs)
- Author: Daniel C. Howe
- Web Site: https://rednoise.org/rita
- Github Repo: https://github.com/dhowe/rita
- Issues: https://github.com/dhowe/rita/issues
- Reference: https://rednoise.org/rita/reference
- RiScript: https://github.com/dhowe/riscript
Create a new file on your desktop called 'test.html' with the following lines, save and drag it into a browser:
<html>
<script src="https://unpkg.com/rita"></script>
<script>
window.onload = function() {
let words = RiTa.tokenize("The elephant took a bite!");
document.getElementById("content").innerHTML = words;
};
</script>
<div id="content" width=200 height=200></div>
<html>
Create a new file on your desktop called 'test.html' with the following lines, save and drag it into a browser:
<html>
<body>
<div id="content" width=200 height=200></div>
<script type="module">
import { RiTa } from "https://esm.sh/rita";
let words = RiTa.tokenize("The elephant took a bite!");
document.getElementById("content").innerHTML = words;
</script>
</body>
<html>
With p5.js
Create a new file on your desktop called 'test.html' with the following lines, save and drag it into a browser:
<html>
<script src="https://unpkg.com/p5"></script>
<script src="https://unpkg.com/rita"></script>
<script>
function setup() {
createCanvas(200,200);
background(245);
textAlign(CENTER);
textSize(20);
let words = RiTa.tokenize("The elephant took a bite!")
for (let i=0; i < words.length; i++) {
text(words[i], 100, 50 + i*20);
}
}
</script>
</html>
If you already have a sketch, simply add <script src="https://unpkg.com/rita"></script>
to your index.html to include RiTa.
To install: $ npm install rita
let RiTa = require('rita');
let data = RiTa.analyze("The elephant took a bite!");
console.log(data);
This project exists only because of the people who contribute. Thank you!