name: LanguageModelJSGF
synopsis:

>     g++ [flags ...] file ... -l /isip/tools/lib/$ISIP_BINARY/lib_mmedia.a

>     #include <LanguageModelJSGF.h>

>     boolean read(Sof& sof, long tag, const String& cname = CLASS_NAME);
>     HierarchicalDigraph& getHDigraph();

quick start:

>     Sof sof;
>     sof.open("lm_jsgf_obj.sof", File::READ_ONLY);

>     LanguageModelJSGF lmjsgf;
>     lmjsgf.read(sof, 0);

>     HierarchicalDigraph hg;
>     hg.assign(lmjsgf.getHDigraph());

description:
The LanguageModelJSGF class is used to parse JSGF format grammars and convert them into ISIP's HierarchicalDigraph (IHD) format so they will be compatible with all ISIP tools. It also performs the reverse conversion. The JSGFParser class is used to parse all JSGF format content.
dependencies:

- Console
- DiGraph
- Filename
- LanguageModelBase
- Pair
- Sdb
- Short
- Sof
- Triple
- Ulong
- JSGFParser
- JSGFToken

public constants:

- define the class name:

      static const String LanguageModelJSGF::CLASS_NAME = L"LanguageModelJSGF";

- other important constants:

      static const SearchSymbol LanguageModelJSGF::START_SYMBOL = L"S";

      static const SearchSymbol LanguageModelJSGF::TERM_SYMBOL = L"T";

      static const long LanguageModelJSGF::DEF_LEVEL = -1;

- i/o related constants:

      static const String LanguageModelJSGF::DEF_PARAM = L"";

      static const String LanguageModelJSGF::PARAM_GRAMMARS = L"grammars";

      static const String LanguageModelJSGF::TOP_GRAMMAR_NAME = L"sentence";

- jsgf comments:

      static const String LanguageModelJSGF::COMMENT_GRAMMAR_NAME = L"// Define the grammar name";

      static const String LanguageModelJSGF::COMMENT_TERM_SYMBOL = L"// Define the ISIP graph terminal symbol";

      static const String LanguageModelJSGF::COMMENT_START_SYMBOL = L"// Define the ISIP graph start symbol";

      static const String LanguageModelJSGF::COMMENT_RESERVED_GRAMMAR = L"// Define the ISIP reserved grammar name";

      static const String LanguageModelJSGF::COMMENT_SYMBOLS = L"// Define the symbols";

      static const String LanguageModelJSGF::COMMENT_RULES = L"// Define the rules";

      static const String LanguageModelJSGF::COMMENT_CONTEXT_RULE = L"// Define the context rule";

- other jsgf standard syntax constants:

      static const String LanguageModelJSGF::PARAM_JSGF_START_SYMBOL(L"ISIP_JSGF_1_0_START");

      static const String LanguageModelJSGF::PARAM_JSGF_TERM_SYMBOL(L"ISIP_JSGF_1_0_TERM");

      static const String LanguageModelJSGF::START_SYMBOL_REFERENCE(L"ISIP_JSGF_START");

      static const String LanguageModelJSGF::TERM_SYMBOL_REFERENCE(L"ISIP_JSGF_TERM");

      static const String LanguageModelJSGF::OPERATOR_OPENPARENS(L"(");

      static const String LanguageModelJSGF::OPERATOR_CLOSEPARENS(L")");

      static const String LanguageModelJSGF::OPERATOR_OPENANGLEBRACKET(L"<");

      static const String LanguageModelJSGF::OPERATOR_CLOSEANGLEBRACKET(L">");

      static const String LanguageModelJSGF::OPERATOR_FWDSLASH(L"/");

      static const String LanguageModelJSGF::OPERATOR_EQUALS(L"=");

      static const String LanguageModelJSGF::OPERATOR_ALTERNATION(L"|");

      static const String LanguageModelJSGF::OPERATOR_SEMICOLON(L";");

- open/close operator constants:

      static const long LanguageModelJSGF::OPERATOR_OPEN_POS = 0;

      static const long LanguageModelJSGF::OPERATOR_CLOSE_POS = 1;

- other i/o constants:

      static const String LanguageModelJSGF::KEYWORD_PUBLIC(L"public");

      static const String LanguageModelJSGF::KEYWORD_GRAMMAR(L"grammar");

      static const String LanguageModelJSGF::GRAMMAR_DEF_BASE(L"network.grammar.");

      static const String LanguageModelJSGF::PARAM_UNDERSCORE(L"_");

      static const String LanguageModelJSGF::PARAM_JSGF_VERSION(L"#JSGF V1.0;");

      static const String LanguageModelJSGF::CONTEXT_LABEL_PREFIX(L"G_");

      static const String LanguageModelJSGF::RULE_NAME_BASE(L"extension");

error codes:

- error code indicating LanguageModelJSGF class general error:

      static const long ERR = 100102;

protected data:

- hierarchical digraph to store symbol table and symbol types

      HierarchicalDigraph hg_d;

- abnf rule model object

      RuleModel abnf_model_d;

- vector to store grammars

      Vector< Vector < Vector<JSGFToken> > > grammars_d;

- memory manager

      static MemoryManager mgr_d;

- isip standard jsgf start symbol

      SearchSymbol start_symbol_d;

- isip standard jsgf term symbol

      SearchSymbol

required public methods:

- static methods:

      static const String& name();

      static boolean diagnose(Integral::DEBUG debug_level);

- debug methods:

      boolean debug(const unichar* msg) const;

- destructor:

      ~LanguageModelJSGF();

- constructor:

      LanguageModelJSGF();

- assign methods:

      boolean assign(const LanguageModelJSGF& arg);

      boolean assign(const LanguageModelBase& arg);

- i/o methods:

      boolean read(Sof& sof, long tag, const String& cname = CLASS_NAME);

      boolean readData(Sof& sof, const String& pname = DEF_PARAM, long size = SofParser::FULL_OBJECT, boolean param = true, boolean nested = false);

      boolean write(Sof& sof, long tag, const String& cname = CLASS_NAME) const;

      boolean writeData(Sof& sof, const String& pname = DEF_PARAM) const;

      long sofSize() const;

- equality methods:

      boolean eq(const LanguageModelJSGF& arg) const;

      boolean eq(const LanguageModelBase& arg) const;

- clear methods:

      boolean clear(Integral::CMODE ctype);

other methods:

- other methods:

      const String& className() const;

      RuleModel getRuleModel();

      RuleModel getABNFRuleModel();

      boolean setRuleModel(const RuleModel& rm_a);

      boolean setABNFRuleModel(const RuleModel& rm_a);

      Vector< Vector < Vector<JSGFToken> > >getJSGFGrammars();

      boolean setJSGFGrammars(Vector< Vector < Vector<JSGFToken> > > grammars_a);

class-specific private methods:

- grammar write methods:

      boolean writeGrammars(Sof& sof, long level, HierarchicalDigraph& h_digraph) const;

      boolean writeSymbolType(Sof& sof, long level, const String& pname, Vector symbol_list) const;

      boolean writeContextMapping(Sof& sof, long level, HierarchicalDigraph& h_digraph) const;

- grammar read methods:

      boolean readSymbolType(Sof& sof, long level, const String& pname, Vector& symbol_list_a, SofParser& parser);

      boolean readGrammars(Sof& sof, const String& pname, long level, boolean use_context, Vector* symbol_table, SofParser& parser);

      boolean readJSGF(Sof& sof, String grammar, Vector& sub_symbol_list, DiGraph& sub_graph, String& sub_graph_name);

      boolean readContextMapping(Sof& sof, const String& pname, long level, SofParser&parser);

- conversion methods:

      boolean alignGraphs(Vector<Vector<JSGFToken> >& token_vector, Vector<SearchSymbol>& symbol_table, Vector<String>& graph_name_list);

      boolean convertGraph(DiGraph<String>& symbol_graph, DiGraph<SearchNode>& node_graph, long& num_symbols, long level);

      ProductionRuleSet convertJSGFtoABNF(Vector grammar);

      Vector<JSGFToken> convertBNFtoJSGF(ProductionRuleSet rules);

      ProductionRule findRule(String ruleref, ProductionRuleSet rules);

      boolean convertTokensToString(Vector token_grammar, String& string_grammar) const;

examples:

- This example shows how to use a LanguageModelJSGF object to read a LanguageModelJSGF object from a file, and retrieve the parsed grammars in HierarchicalDigraph form.

      // declare an sof object to parse the file
      //
      Sof sof;

      // open the file for reading
      //
      sof.open("lm_jsgf_obj.sof", File::READ_ONLY);

      // declare a LMJSGF object to read the grammars
      //
      LanguageModelJSGF lmjsgf;

      // read the grammars
      //
      lmjsgf.read(sof, 0);

      // declare an HierarchicalDigraph object to store the grammars in DiGraph form
      //
      HierarchicalDigraph hg;

      // retrieve the grammars from the LMJSGF object, and store them in the HD object
      //
      hg.assign(lmjsgf.getHDigraph());