Skip to content
ExpandingDev edited this page Sep 12, 2015 · 2 revisions

JSGFGen Wiki

A Java library for programmically creating JSGF grammars.

JSGF stands for:
JavaSpeech
Grammar
Format

Specifications: http://www.w3.org/TR/jsgf/

Usage

First make sure to include the latest release .jar in your buildpath.

JSGF Gen uses the Grammar class as the main container for holding a grammar's rules. Create a Grammar object to start:

Grammar g = new Grammar();

The Grammar class is made to hold Rule objects. To create a Rule object:

Rule myRule = new Rule("greet", new Token("hello world"));

The first argument of the Rule constructor is a String containing the rule name. The following arguments is any class implementing the Expansion interface. A rule expansion is defined [here] (http://www.w3.org/TR/jsgf/#20480). A full list of classes implementing the Expansion interface can be found .
After creating your rule(s), add it/them to the Grammar object:

g.addRule(myRule);

Once you have added all of your rules to the grammar, retrieve the textual representation of the grammar using:

String text = g.compileGrammar();

The compileGrammar method returns a String containing the JSGF Grammar.

Clone this wiki locally