• Stars
    star
    103
  • Rank 333,046 (Top 7 %)
  • Language
    JavaScript
  • License
    GNU General Publi...
  • Created over 5 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

RiTa: generative language tools

license npm version CDNJS

RiTa: tools for generative natural language

RiTa is implemented in Java and JavaScript, with a common API for both, and is free/libre/open-source via the GPL license.

Features in v2.0

  • 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
  • New options for generation via grammars and Markov chains

Note: version 2.0 contains breaking changes -- please check the release notes

Installation

  • For node: npm install rita
  • For browsers: <script src="https://unpkg.com/rita"></script>
  • For developers

Example (node)

let RiTa = require('rita');

// to find rhymes
let rhymes = RiTa.rhymes('sweet');
console.log(rhymes);

// to analyze a sentence
let data = RiTa.analyze("The elephant took a bite!");
console.log(data);

// to load a grammar
let grammar = RiTa.grammar(jsonRules);
console.log(grammar.expand());

API

RiTa RiMarkov RiGrammar
RiTa.addTransform()
RiTa.alliterations()
RiTa.analyze()
RiTa.concordance()
RiTa.conjugate()
RiTa.evaluate()
RiTa.grammar()
RiTa.hasWord()
RiTa.isAbbrev()
RiTa.isAdjective()
RiTa.isAdverb()
RiTa.isAlliteration()
RiTa.isNoun()
RiTa.isPunct()
RiTa.isQuestion()
RiTa.isStopWord()
RiTa.isRhyme()
RiTa.isVerb()
RiTa.kwic()
RiTa.markov()
RiTa.pastPart()
RiTa.phones()
RiTa.pos()
RiTa.posInline()
RiTa.presentPart()
RiTa.pluralize()
RiTa.randomOrdering()
RiTa.randomSeed()
RiTa.randomWord()
RiTa.rhymes()
RiTa.search()
RiTa.sentences()
RiTa.singularize()
RiTa.soundsLike()
RiTa.spellsLike()
RiTa.stem()
RiTa.stresses()
RiTa.syllables()
RiTa.tokenize()
RiTa.untokenize()
addText()
completions()
generate()
probability()
probabilities()
size()
toString()
toJSON()
fromJSON()











addRule()
addRules()
expand()
removeRule()
toJSON()
toString()
fromJSON()













RiScript

RiScript is a writer-focused scripting language integrated with RiTa. It enables simple generative primitives within plain text for dynamic expansion at runtime. RiScript primitives can be used as part of any RiTa grammar or executed directly using RiTa.evaluate(). For more info, see this interactive notebook.




Developing

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 run test

If all goes well, you should see a list of successful tests and find the library built in 'dist'


During development it is faster to run tests directly on the source, rather then the built library:

$ npm run test.src

You can also watch the source code and build automatically on any change:

$ npm run watch.src

Please make contributions via fork-and-pull - thanks!


 

Visual Studio Code

Once you have things running with npm/mocha, 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

 

About

 

Quick Start

A simple sketch

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://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <script src="https://unpkg.com/rita"></script>
  <script>
    window.onload = function() {
      let words = RiTa.tokenize("The elephant took a bite!");
      $('#content').text(words);
    };
  </script>
  <div id="content" width=200 height=200></div>
<html>

With p5.js

Create a new file on your desktop called 'test.html' and download the latest rita.js from here, add 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(50);
    textSize(20);
    noStroke();

    let words = RiTa.tokenize("The elephant took a bite!")
    for (let i=0; i < words.length; i++) {
        text(words[i], 50, 50 + i*20);
    }
  }
  </script>
</html>

With node.js and npm

To install: $ npm install rita

let RiTa = require('rita');
let data = RiTa.analyze("The elephant took a bite!");
console.log(data);

 

Contributors

Code Contributors

This project exists only because of the people who contribute. Thank you!

Financial Contributors

More Repositories

1

AdNauseamV1

*** This is not the current AdNauseam repository: please find the current repo here:
JavaScript
385
star
2

RiTaV1

RiTa: the generative language toolkit
JavaScript
354
star
3

RiTaJSv1

RiTa: the generative language toolkit (in JS)
JavaScript
268
star
4

rita

Website, documentation and examples for RiTa
JavaScript
71
star
5

RiTaJSHistory

RiTaJS: A generative language toolkit for JavaScript
JavaScript
44
star
6

dialogic

Dialogic: generative interactive dialog
JavaScript
27
star
7

ritajs

RiTa for JavaScript
JavaScript
23
star
8

AdNauseam-chrome

A Chrome extension to help defend against surveillance and tracking by ad-networks
JavaScript
19
star
9

ChinaEye

Experience the web as if you were living in China...
JavaScript
9
star
10

rita4j

RiTa for Java
Java
8
star
11

annograms

JavaScript
3
star
12

AdLiPo

Replacing ads with generative language
JavaScript
2
star
13

spectre

SPECTRE
JavaScript
2
star
14

TrackMeNot

Development for TrackMeNot v2 (2022)
2
star
15

RiTranslate

A translation API for RiTa
Java
2
star
16

PerceptualReader

Java
2
star
17

Website

Website
JavaScript
2
star
18

riscript

RiScript: a minor language
JavaScript
2
star
19

GetGen

A Workshop for Processing Community Day @ HK 2019
JavaScript
2
star
20

rws

A micro-workshop on randomness
Processing
2
star
21

AoAServer

Architecture of Association server
Java
1
star
22

GML

Vogel's Generative Movement Language (GML)
Java
1
star
23

AdCollector

JavaScript
1
star
24

ReadersJS

JavaScript
1
star
25

spectre-server

JavaScript
1
star
26

TrackMeNotWeb

Website for TrackMeNot Project
HTML
1
star
27

spectre-mail

spectre-mail
JavaScript
1
star
28

ReadersWeb

Website for The Readers Project
HTML
1
star
29

GlyphFlock

Demo of path-based flocking in p5.js
JavaScript
1
star
30

LongestCommonPhrase

LongestCommonPhrase implementation
Java
1
star
31

Assign7

Assign7
JavaScript
1
star
32

SomeThingWeAre

JavaScript
1
star
33

AdLiPoV2

Updated AdLiPo Dev
JavaScript
1
star
34

ritwit

The RiTwit library for js
JavaScript
1
star
35

RiTaBox2d

JavaScript
1
star
36

AdWatch

AdNauseam automated with Nightwatch
JavaScript
1
star