Skip to content

dhowe/rita4j

Repository files navigation

Maven Central npm version

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

Note: Version 2.0 contains breaking changes! Please check the release notes

Installation

<dependency>
  <groupId>org.rednoise</groupId>
  <artifactId>rita</artifactId>
  <version>2.4</version>
</dependency>

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 simple, writer-focused scripting language included in RiTa. It enables several generative primitives within plain text for expansion at runtime. RiScript primitives can be used as part of any RiTa grammar or executed directly using RiTa.evaluate(). For documentation, see this interactive notebook.




Developing

$ git clone https://github.com/dhowe/rita4j.git
$ cd rita4j
$ mvn install      # when done, you should see "BUILD SUCCESS"

The project requires a minimum version of Java 8 and Maven 3.6 to build.

Eclipse

  1. Do steps above under Developing
  2. In eclipse, File->Import->Maven->Existing Maven Projects and select your 'rita4j' folder
  3. Right-click on project, and select 'Run-as' -> 'Maven install' or 'JUnit tests'

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



A Simple Example (Java)

    For online examples in JavaScript, see this page

  1. Create a new Java project in Eclipse (or your IDE of choice)
  2. Download rita.jar and add it to the build path for the project. In eclipse: 'Project' > 'Properties' > 'Java Build Path' > 'Libraries' > 'Add External JARs...'
  3. Create and run a new class, SimpleExample.java, with the following code:
import rita.*;

public class SimpleExample {

  public static void main(String[] args) {

    System.out.println(RiTa.analyze("The elephant took a bite!"));
  }
}

In Processing

To install:

  1. Open Processing and select 'Sketch' menu > 'Import Library...' > 'Add Library...'
  2. Search for 'RiTa' and then install it

Create an example sketch as follows (and/or see the included examples):

import rita.*;
import java.util.*;

void setup() {

  size(600, 200);
  background(50);
  textSize(20);
  noStroke();

  Map data = RiTa.analyze("The elephant took a bite!");

  float y = 15;
  for (Iterator it = data.keySet().iterator(); it.hasNext();) {
    String key = (String) it.next();
    text(key + ": " + data.get(key), 25, y += 26);
  }
}

Contributors

Code Contributors

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

Financial Contributors