sdr 0.7

net.cscott.sdr.calls.grm
Class Grm

java.lang.Object
  extended by net.cscott.sdr.calls.grm.Grm
Direct Known Subclasses:
Grm.Alt, Grm.Concat, Grm.Mult, Grm.Nonterminal, Grm.Terminal

public abstract class Grm
extends Object

This class contains inner classes creating an AST for the 'natural language' grammar of square dance calls and concepts. This AST is transformed into a Java Speech grammar for the Sphinx speech recognition engine, which then generates text strings. The AST is also transformed into an ANTLR v3 grammar parsing those text strings, which creates Apply trees. The raw rules from the call file need to be processed to remove left recursion and to disambiguate using precedence levels. These processed rules are written out as the AllGrm class, accessed via the grammar(Program) method, and used to drive the CompletionEngine.

Version:
$Id: Grm.java,v 1.3 2006-10-22 15:46:06 cananian Exp $
Author:
C. Scott Ananian

Nested Class Summary
static class Grm.Alt
          Alternation: a|b.
static class Grm.Concat
          Concatanation: a b.
static class Grm.Mult
          Multiplicity marker: a*, a+, or a?.
static class Grm.Nonterminal
          A nonterminal reference to an external rule.
static class Grm.Terminal
          A grammar terminal: a string literal to match.
 
Constructor Summary
Grm()
           
 
Method Summary
abstract
<T> T
accept(GrmVisitor<T> v)
           
protected abstract  Grm buildIntern()
           
 boolean equals(Object o)
           
protected abstract  String getName()
           
protected abstract  List<Grm> getOperands()
           
static Map<String,Grm> grammar(Program p)
          Return a natural language grammar for the given square dance program.
 int hashCode()
           
 Grm intern()
           
static Grm mkGrm(String... terminals)
          Make a Grm which will recognize the given sequence of terminal symbols.
static Grm parse(String rule)
          Parse a string representing a Grm.
abstract  int precedence()
           
 String repr()
          Return a Java phrase to reconstruct this Grm.
protected abstract  void repr(StringBuilder sb)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Grm

public Grm()
Method Detail

precedence

public abstract int precedence()

accept

public abstract <T> T accept(GrmVisitor<T> v)

toString

public final String toString()
Overrides:
toString in class Object

repr

public final String repr()
Return a Java phrase to reconstruct this Grm.


repr

protected abstract void repr(StringBuilder sb)

getName

protected abstract String getName()

getOperands

protected abstract List<Grm> getOperands()

buildIntern

protected abstract Grm buildIntern()

intern

public Grm intern()

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object o)
Overrides:
equals in class Object

mkGrm

public static Grm mkGrm(String... terminals)
Make a Grm which will recognize the given sequence of terminal symbols.


grammar

public static Map<String,Grm> grammar(Program p)
Return a natural language grammar for the given square dance program. The grammar is expressed as a map from nonterminal names to Grms. The start production is a nonterminal named 'start'. This grammar is generated by the EmitJava class, invoked from BuildGrammars.


parse

public static Grm parse(String rule)
Parse a string representing a Grm. Parameter references must be numerical.

Throws:
IllegalArgumentException - if the rule is malformed.
Tests:
Successful parse:
js> Grm.parse("foo bar|bat? baz")
foo bar|bat? baz
Unsuccessful parse:
js> try {
  >   Grm.parse("[abc]")
  > } catch (e) { print (e.javaException) }
java.lang.IllegalArgumentException: bad grammar rule: [abc]

sdr 0.7

Copyright © 2006-2009 C. Scott Ananian