<?php $isip_window_title = "ISIP Homepage"; ?>
<?php include("/data/isip/www/templates/documentation/header/header.html"); ?>

<!--#set var="isip_page_title" value="NGramModel" -->
<?php include("/data/isip/www/templates/documentation/body/index_class.html"); ?>
<?php include("/data/isip/www/templates/documentation/body/bar.html"); ?>

<a name="name">
<b>
name:
<a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/NGramModel.h">NGramModel</a>
</b>

<br><br>

<a name="synopsis">
<b>synopsis:</b>

<blockquote>
<pre>
g++ [flags ...] file ... -l /isip/tools/lib/$ISIP_BINARY/lib_stat.a

#include &lt;NGramModel.h&gt;

~NGramModel();
NGramModel();
NGramModel(const NGramModel& copy_sym);

boolean load(Sof& sof, const long& tag, const Vector<String>& symbol_table,
             const String& name = CLASS_NAME);
boolean getScore(const VectorLong& index_a, float& score_a);
boolean setOrder(long order);

</pre>
</blockquote>

<a name="quick_start">
<b>quick start:</b>

<blockquote>
<pre>
#include &lt;NGramModel.h&gt;

// configure ngram object and load a trigram file
//
NGramModel ngrm;
ngrm.setOrder(3);
ngrm.load(sof, 1, symbol_table);
sof.close();

// test getScore
//
String symb1(L"ONE"), symb2(L"TWO"), symb3(L"FOUR");
VectorLong index(2);

// get a bigram (ONE TWO) probability
//
index(0) = *symbol_hash.get(symb1);
index(1) = *symbol_hash.get(symb2);

float score = ngrm.getScore(index);

</pre>
</blockquote>

<a name="description"> 
<b>description:</b>
<br><br>

NGramModel is a class that manages N-gram probabilities, such as
bigram, trigram, etc. This class can be used to load an input N-gram
file, such as NIST_ARPA grammar file, and then store it to HashTable
for lookup.
<br><br>

<a name="dependencies">
<b>dependencies:</b>
<br><br>

<ul>
  <li> <a href="../../dstr/HashTable/index.html">HashTable</a>
  <li> <a href="../../mmedia/NGramNode/NGramNode.h">NGramNode</a>
  <li> <a href="../../mmedia/NGramParser/NGramParser.h">NGramParser</a>
</ul>

<a name="constants">
<b>public constants:</b>
<br><br>

<ul>
  <li> define the class name:

       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/ngrm_00.cc&constant=CLASS_NAME">static const String CLASS_NAME = L"NGramModel";</a></pre>

  <li> define i/o related constants:

       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/ngrm_00.cc&constant=PARAM_ORDER">static const String NGramModel::PARAM_ORDER = L"order";</a></pre>
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/ngrm_00.cc&constant=PARAM_KEYS">static const String NGramModel::PARAM_KEYS = L"keys";</a></pre>
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/ngrm_00.cc&constant=PARAM_VALUES">static const String NGramModel::PARAM_VALUES = L"values";</a></pre>
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/ngrm_00.cc&constant=PARAM_GRAM_HASH">static const String NGramModel::PARAM_GRAM_HASH = L"gram_hash_table";</a></pre>
       
  <li> define the default value(s) of the class data:
       
       <pre>static const String DEF_PARAM = L"";</pre>
       <pre>static const Long DEF_ORDER = 0;</pre>
       <pre>static const Float DEF_ORDER = 0.0;</pre>

  <li> define default arguments to methods:
       
       <pre>static const ulong DEF_REF_INCR = (ulong)1;</pre>
       <pre>static const ulong DEF_REF_DECR = (ulong)1;</pre>

</ul>
	 
<a name="error">       
<b>error codes:</b>
<br><br>

<ul>
  <li> error code indicating a general error:
       
       <pre><a href="/perl/ifc_document.pl?err=00060600">static const long ERR = 00060600;</a></pre>
       
</ul>

<a name="protected">
<b>protected data:</b>
<br><br>

<ul>
  <li> define the order of Ngram:

       <pre>Long order_d;
  
  <li> define a hash table containing Ngrams:
       
       <pre>HashTable<Long, NGramNode> gram_hash_d;</pre>
       
  <li> define a vector which mapping search symbols:

       <pre>SiVector<String> symbol_table_d;</pre>

  <li> debug level:
       
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/ngrm_00.cc&static=debug_level_d">static Integral::DEBUG debug_level_d;</a></pre>
       
  <li> memory manager:
       
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/ngrm_00.cc&static=mgr_d">static MemoryManager mgr_d;</a></pre>
       
</ul>

<a name="public">
<b>required public methods:</b>
<br><br>

<ul>
  <li> static methods:  

       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/NGramModel.h&method=name">static const String& name();</a></pre>
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/ngrm_02.cc&method=diagnose">static boolean diagnose(Integral::DEBUG debug_level);</a></pre>

  <li> debug methods:

       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/NGramModel.h&method=setDebug">static boolean setDebug(Integral::DEBUG debug_level);</a></pre>
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/ngrm_01.cc&method=debug">boolean debug(const unichar* message) const;</a></pre>

  <li> destructor/constructor(s):
       
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/NGramModel.h&method=destructor">~NGramModel();</a></pre>
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/NGramModel.h&method=default+constructor">NGramModel(Long order = DEF_ORDER);</a></pre>

  <li> assign methods:
       
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/NGramModel.h&method=assign">boolean assign(const NGramModel& copy_arg);</a></pre>

  <li> operator= methods:
       
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/NGramModel.h&method=operator%3D&instance=0">Histogram& operator= (const NGramModel& arg);</a></pre>

  <li> i/o methods:
       
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/ngrm_04.cc&method=sofSize">long sofSize() const;</a></pre>
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/ngrm_03.cc&method=read">boolean read(Sof& sof, long tag, const String& name = CLASS_NAME);</a></pre>
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/ngrm_04.cc&method=write">boolean write(Sof& sof, long tag, const String& name = CLASS_NAME) const;</a></pre>
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/ngrm_03.cc&method=readData">boolean readData(Sof& sof, const String& pname = DEF_PARAM, long size = SofParser::FULL_OBJECT, boolean param = true, boolean nested = false);</a></pre>       
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/ngrm_04.cc&method=writeData">boolean writeData(Sof& sof, const String& pname = DEF_PARAM) const;</a></pre>

  <li> equality methods:
       
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/ngrm_00.cc&method=eq&instance=0">boolean eq(const NGramModel& arg) const;</a></pre>

  <li> memory management methods:

       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/NGramModel.h&method=new">static void* operator new(size_t size);</a></pre>
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/NGramModel.h&method=new[]">static void* operator new[](size_t size);</a></pre>
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/NGramModel.h&method=delete">static void operator delete(void* ptr);</a></pre>
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/NGramModel.h&method=delete[]">static void operator delete[](void* ptr);</a></pre>  
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/NGramModel.h&method=setGrowSize">static boolean setGrowSize(long grow_size);</a></pre>
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/ngrm_00.cc&method=clear">boolean clear(Integral::CMODE ctype = Integral::DEF_CMODE);</a></pre>
       
</ul>

<a name="specific">
<b>class-specific public methods:</b>
<br><br>

<ul>
  <li> NGramModel set/get methods:
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/NGramModel.h&method=setOrder">boolean setOrder(long order);</a></pre>
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/NGramModel.h&method=getOrder">long getOrder() const;</a></pre>
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/NGramModel.h&method=getGramHash">HashTable&lt;Long, NGramNode&gt; getGramHash();</a></pre>
       
  <li> load/store methods:

       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/ngrm_05.cc&method=load">boolean load(Sof& sof, const long& tag, const Vector<String>& symbol_table, const String& name = CLASS_NAME);</a></pre>
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/ngrm_05.cc&method=store">boolean store(Sof& sof, const long& tag, const String& name = CLASS_NAME) const;</a></pre>

  <li> Ngram related methods:
	    
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/ngrm_05.cc&method=getScore">float getScore(const VectorLong& symbol_indices);</a></pre>
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/stat/NGramModel/ngrm_06.cc&method=getScore">boolean getScore(const VectorLong& index_a, float& score_a);</a></pre>

</ul>

<a name="private">
<b>private methods:</b>
<br><br>

<ul>
  <li> none
</ul>

<a name="examples">
<b>examples:</b>
<br><br>

<ul>
  <li> none
</ul>

<a name="notes">
<b>notes:</b>
<br><br>

<ul>
  <li> none
</ul>

<!--#include virtual="/hse/ies/templates/documentation/footer/footer.html" -->
