quick start:g++ [flags ...] file ... -l /isip/tools/lib/$ISIP_BINARY/lib_mmedia.a #include <JSGFParser.h> JSGFParser(); boolean setExpression(String& expression_a, long line_a); boolean parseExpression(const String& graph_start_a, const String& graph_term_a); DiGraph<String> getGraph(); Vector<String> getSymbolList(); String getGrammarName();
description:JSGFParser jp; String start(L"S"); String term(L"T"); String expression(L"public <rule> = /0/ A /0/ B /0/ C;"); jp.setExpression(expression, 0); jp.parseExpression(start, term);
static const String CLASS_NAME = L"JSGFParser";
static const long DEF_MAX_EXPRESSIONS = 500;
static const long DEF_LINE_NUMBER = 0;
static const String DEF_GRAPH_START = L"";
static const String DEF_GRAPH_TERM = L"";
static const String DEF_GRAMMAR_NAME = L"";
static const long ERR = 50100;
String expression_d[500];
long line_d;
Queue<JSGFToken> queue_d[500];
Queue<JSGFToken> final_d;
DiGraph<String> graph_d;
String grammar_name_d;
Vector<String> symbol_list_d;
String graph_start_d;
String graph_term_d;
static MemoryManager mgr_d;
static const String& name();
static boolean diagnose(Integral::DEBUG level_a);
boolean debug(const unichar* msg_a) const;
~JSGFParser();
JSGFParser();
boolean assign(const JSGFParser& arg_a);
JSGFParser& operator=(const JSGFParser& arg_a);
boolean eq(const JSGFParser& arg_a) const;
boolean read(Sof& sof, long tag, const String& cname = CLASS_NAME);
boolean write(Sof& sof, long tag, const String& cname = CLASS_NAME) const;
static void* operator new(size_t size);
static void* operator new[](size_t size);
static void operator delete(void* ptr);
static void operator delete[](void* ptr);
static boolean setGrowSize(long grow_size);
boolean clear(Integral::CMODE ctype_a);
boolean parseExpression(const String& graph_start_a, const String& graph_term_a);
boolean setExpression(String& expression_a, long line_a);
DiGraph<String> getGraph();
Vector<String> getSymbolList();
String getGrammarName();
boolean tokenize(const String& expression_a, Queue<JSGFToken>& queue_a);
boolean splitRuleLine(const String& arg_a, Queue<JSGFToken>& queue_a);
boolean drawGraph();
boolean replace(Queue<JSGFToken> queue_a, long public_index_a);
JSGFToken searchStart(Queue<JSGFToken>& arg_a, Queue<JSGFToken>& head_a);
boolean searchEnd(GraphVertex<String>* current_a, GraphVertex<String>* destination_a, float weight_a);
// isip include files
//
#include <JSGFParser.h>
// declare an JSGFParser
//
JSGFParser jp;
// define symbols for the ISIP DiGraph default starting and ending vertices
//
String start(L"S");
String term(L"T");
// declare a simple JSGF grammar
//
String exp(L"public <rule> = <ISIP_JSGF_1_0_START> /0/ boy ( /0.2/ run | /0.8/ walk ) /0/ <ISIP_JSGF_1_0_TERM>;");
// set expression
//
jp.setExpression(exp, 0));
// parse expression
//
jp.parseExpression(start, term));
// get symbol list of the graph converted from the JSGF grammar
//
Vector<String> symbol_list = jp.getSymbolList();
// get the graph converted from the JSGF grammar
//
DiGraph<String> graph = jp.getGraph();
// open file to store the symbol list and the graph
//
String tmp_filename(L"example_output.sof");
Sof sof;
if(!sof.open(tmp_filename, File::WRITE_ONLY)) {
return Error::handle(tmp_filename, L"open", Error::TEST, __FILE__, __LINE__);
}
// write the symbol list to the file
//
symbol_list.write(sof, 0);
// write the graph to the file
//
graph.write(sof, 0);
// close the file
//
sof.close();
---------------------------------------------------------------------------
This is the output SOF file that contains the symbol list and graph, where
a vector of the symbols is listed under the tag @ Vector<String> 0 @ and
the vertices and arcs of the graph under the tag @ DiGraph<String> 0 @:
@ Sof v1.0 @
@ Vector<String> 0 @
values = {
"boy"
}, {
"run"
}, {
"walk"
};
@ DiGraph<String> 0 @
weighted = true;
vertices =
{0, {"boy"}},
{1, {"run"}},
{2, {"walk"}};
arcs =
{S, 0, 0, true},
{0, 2, 0.8, true},
{0, 1, 0.2, true},
{1, T, 0, true},
{2, T, 0, true};
grammar network.grammar.sentence;
<rulename> = one two three;
this is a test
<rule> = <expansion1> <expansion2>;
<sentence> = this is a test;
<color> = red | green | blue;
<color> = /0.2/ red | /0.5/ green | /0.3/ blue;
<action> = please ( open | close) the door;
<action> = run+ without stop;
<action> = repeat <action>;
// this is a comment
#JSGF V1.0;
#JSGF V1.0;
// Define the grammar name
grammar network.grammar.sentence;
// Define the rules
public <sentence> = <ISIP_JSGF_1_0_START> /0/ SILENCE <extension> /0/ SILENCE /0/ <ISIP_JSGF_1_0_TERM>;
<extension> = /0/ ONE | /0/ TWO | /0/ THREE | /0/ FOUR | /0/ FIVE | /0/ SIX | /0/ SEVEN | /0/ EIGHT | /0/ NINE | /0/ OH | /0/ ZERO;
#JSGF V1.0;
// Define the grammar name
grammar network.grammar.one;
// Define the rules
public <one> = <ISIP_JSGF_1_0_START> /0/ <A> /0/ <B> /0/ <C> /0/ <D> /0/ <E> /0/ <ISIP_JSGF_1_0_TERM>;
<A> = /0/ S_1+;
<B> = /0/ S_2+;
<C> = /0/ S_3+;
<D> = /0/ S_4+;
<E> = /0/ S_5+;
<ISIP_JSGF_1_0_START>
<ISIP_JSGF_1_0_TERM>