\doxysection{ngram\+\_\+model\+\_\+internal.\+h}
\label{ngram__model__internal_8h_source}\index{src/libsphinxbase/lm/ngram\_model\_internal.h@{src/libsphinxbase/lm/ngram\_model\_internal.h}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{comment}{/*\ -\/*-\/\ c-\/basic-\/offset:\ 4;\ indent-\/tabs-\/mode:\ nil\ -\/*-\/\ */}}
\DoxyCodeLine{00002\ \textcolor{comment}{/*\ ====================================================================}}
\DoxyCodeLine{00003\ \textcolor{comment}{\ *\ Copyright\ (c)\ 1999-\/2007\ Carnegie\ Mellon\ University.\ \ All\ rights}}
\DoxyCodeLine{00004\ \textcolor{comment}{\ *\ reserved.}}
\DoxyCodeLine{00005\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00006\ \textcolor{comment}{\ *\ Redistribution\ and\ use\ in\ source\ and\ binary\ forms,\ with\ or\ without}}
\DoxyCodeLine{00007\ \textcolor{comment}{\ *\ modification,\ are\ permitted\ provided\ that\ the\ following\ conditions}}
\DoxyCodeLine{00008\ \textcolor{comment}{\ *\ are\ met:}}
\DoxyCodeLine{00009\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00010\ \textcolor{comment}{\ *\ 1.\ Redistributions\ of\ source\ code\ must\ retain\ the\ above\ copyright}}
\DoxyCodeLine{00011\ \textcolor{comment}{\ *\ \ \ \ notice,\ this\ list\ of\ conditions\ and\ the\ following\ disclaimer.\ }}
\DoxyCodeLine{00012\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00013\ \textcolor{comment}{\ *\ 2.\ Redistributions\ in\ binary\ form\ must\ reproduce\ the\ above\ copyright}}
\DoxyCodeLine{00014\ \textcolor{comment}{\ *\ \ \ \ notice,\ this\ list\ of\ conditions\ and\ the\ following\ disclaimer\ in}}
\DoxyCodeLine{00015\ \textcolor{comment}{\ *\ \ \ \ the\ documentation\ and/or\ other\ materials\ provided\ with\ the}}
\DoxyCodeLine{00016\ \textcolor{comment}{\ *\ \ \ \ distribution.}}
\DoxyCodeLine{00017\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00018\ \textcolor{comment}{\ *\ This\ work\ was\ supported\ in\ part\ by\ funding\ from\ the\ Defense\ Advanced\ }}
\DoxyCodeLine{00019\ \textcolor{comment}{\ *\ Research\ Projects\ Agency\ and\ the\ National\ Science\ Foundation\ of\ the\ }}
\DoxyCodeLine{00020\ \textcolor{comment}{\ *\ United\ States\ of\ America,\ and\ the\ CMU\ Sphinx\ Speech\ Consortium.}}
\DoxyCodeLine{00021\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00022\ \textcolor{comment}{\ *\ THIS\ SOFTWARE\ IS\ PROVIDED\ BY\ CARNEGIE\ MELLON\ UNIVERSITY\ \`{}\`{}AS\ IS''\ AND\ }}
\DoxyCodeLine{00023\ \textcolor{comment}{\ *\ ANY\ EXPRESSED\ OR\ IMPLIED\ WARRANTIES,\ INCLUDING,\ BUT\ NOT\ LIMITED\ TO,\ }}
\DoxyCodeLine{00024\ \textcolor{comment}{\ *\ THE\ IMPLIED\ WARRANTIES\ OF\ MERCHANTABILITY\ AND\ FITNESS\ FOR\ A\ PARTICULAR}}
\DoxyCodeLine{00025\ \textcolor{comment}{\ *\ PURPOSE\ ARE\ DISCLAIMED.\ \ IN\ NO\ EVENT\ SHALL\ CARNEGIE\ MELLON\ UNIVERSITY}}
\DoxyCodeLine{00026\ \textcolor{comment}{\ *\ NOR\ ITS\ EMPLOYEES\ BE\ LIABLE\ FOR\ ANY\ DIRECT,\ INDIRECT,\ INCIDENTAL,}}
\DoxyCodeLine{00027\ \textcolor{comment}{\ *\ SPECIAL,\ EXEMPLARY,\ OR\ CONSEQUENTIAL\ DAMAGES\ (INCLUDING,\ BUT\ NOT\ }}
\DoxyCodeLine{00028\ \textcolor{comment}{\ *\ LIMITED\ TO,\ PROCUREMENT\ OF\ SUBSTITUTE\ GOODS\ OR\ SERVICES;\ LOSS\ OF\ USE,\ }}
\DoxyCodeLine{00029\ \textcolor{comment}{\ *\ DATA,\ OR\ PROFITS;\ OR\ BUSINESS\ INTERRUPTION)\ HOWEVER\ CAUSED\ AND\ ON\ ANY\ }}
\DoxyCodeLine{00030\ \textcolor{comment}{\ *\ THEORY\ OF\ LIABILITY,\ WHETHER\ IN\ CONTRACT,\ STRICT\ LIABILITY,\ OR\ TORT\ }}
\DoxyCodeLine{00031\ \textcolor{comment}{\ *\ (INCLUDING\ NEGLIGENCE\ OR\ OTHERWISE)\ ARISING\ IN\ ANY\ WAY\ OUT\ OF\ THE\ USE\ }}
\DoxyCodeLine{00032\ \textcolor{comment}{\ *\ OF\ THIS\ SOFTWARE,\ EVEN\ IF\ ADVISED\ OF\ THE\ POSSIBILITY\ OF\ SUCH\ DAMAGE.}}
\DoxyCodeLine{00033\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00034\ \textcolor{comment}{\ *\ ====================================================================}}
\DoxyCodeLine{00035\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00036\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00037\ \textcolor{comment}{/*}}
\DoxyCodeLine{00038\ \textcolor{comment}{\ *\ \(\backslash\)file\ ngram\_model\_internal.h\ Internal\ structures\ for\ N-\/Gram\ models}}
\DoxyCodeLine{00039\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00040\ \textcolor{comment}{\ *\ Author:\ David\ Huggins-\/Daines\ <dhuggins@cs.cmu.edu>}}
\DoxyCodeLine{00041\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00042\ }
\DoxyCodeLine{00043\ \textcolor{preprocessor}{\#ifndef\ \_\_NGRAM\_MODEL\_INTERNAL\_H\_\_}}
\DoxyCodeLine{00044\ \textcolor{preprocessor}{\#define\ \_\_NGRAM\_MODEL\_INTERNAL\_H\_\_}}
\DoxyCodeLine{00045\ }
\DoxyCodeLine{00046\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/ngram\_model.h"{}}}
\DoxyCodeLine{00047\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/hash\_table.h"{}}}
\DoxyCodeLine{00048\ }
\DoxyCodeLine{00055\ \textcolor{keyword}{struct\ }ngram\_model\_s\ \{}
\DoxyCodeLine{00056\ \ \ \ \ \textcolor{keywordtype}{int}\ refcount;\ \ \ \ \ \ \ }
\DoxyCodeLine{00057\ \ \ \ \ int32\ *n\_counts;\ \ \ \ }
\DoxyCodeLine{00058\ \ \ \ \ int32\ n\_1g\_alloc;\ \ \ }
\DoxyCodeLine{00059\ \ \ \ \ int32\ n\_words;\ \ \ \ \ \ }
\DoxyCodeLine{00061\ \ \ \ \ uint8\ n;\ \ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00062\ \ \ \ \ uint8\ n\_classes;\ \ \ \ }
\DoxyCodeLine{00063\ \ \ \ \ uint8\ writable;\ \ \ \ \ }
\DoxyCodeLine{00064\ \ \ \ \ uint8\ flags;\ \ \ \ \ \ \ \ }
\DoxyCodeLine{00066\ \ \ \ \ logmath\_t\ *lmath;\ \ \ }
\DoxyCodeLine{00067\ \ \ \ \ float32\ lw;\ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00068\ \ \ \ \ int32\ log\_wip;\ \ \ \ \ \ }
\DoxyCodeLine{00069\ \ \ \ \ int32\ log\_uw;\ \ \ \ \ \ \ }
\DoxyCodeLine{00070\ \ \ \ \ int32\ log\_uniform;\ \ }
\DoxyCodeLine{00071\ \ \ \ \ int32\ log\_uniform\_weight;\ }
\DoxyCodeLine{00072\ \ \ \ \ int32\ log\_zero;\ \ \ \ \ }
\DoxyCodeLine{00073\ \ \ \ \ \textcolor{keywordtype}{char}\ **word\_str;\ \ \ \ }
\DoxyCodeLine{00074\ \ \ \ \ hash\_table\_t\ *wid;\ \ }
\DoxyCodeLine{00075\ \ \ \ \ int32\ *tmp\_wids;\ \ \ \ }
\DoxyCodeLine{00076\ \ \ \ \ \textcolor{keyword}{struct\ }ngram\_class\_s\ **classes;\ }
\DoxyCodeLine{00077\ \ \ \ \ \textcolor{keyword}{struct\ }ngram\_funcs\_s\ *funcs;\ \ \ }
\DoxyCodeLine{00078\ \};}
\DoxyCodeLine{00079\ }
\DoxyCodeLine{00083\ \textcolor{keyword}{struct\ }ngram\_class\_s\ \{}
\DoxyCodeLine{00084\ \ \ \ \ int32\ tag\_wid;\ \ }
\DoxyCodeLine{00085\ \ \ \ \ int32\ start\_wid;\ }
\DoxyCodeLine{00086\ \ \ \ \ int32\ n\_words;\ \ \ }
\DoxyCodeLine{00087\ \ \ \ \ int32\ *prob1;\ \ \ \ }
\DoxyCodeLine{00091\ \ \ \ \ \textcolor{keyword}{struct\ }ngram\_hash\_s\ \{}
\DoxyCodeLine{00092\ \ \ \ \ \ \ \ \ int32\ wid;\ \ \ \ }
\DoxyCodeLine{00093\ \ \ \ \ \ \ \ \ int32\ prob1;\ \ }
\DoxyCodeLine{00094\ \ \ \ \ \ \ \ \ int32\ next;\ \ \ }
\DoxyCodeLine{00095\ \ \ \ \ \}\ *nword\_hash;}
\DoxyCodeLine{00096\ \ \ \ \ int32\ n\_hash;\ \ \ \ \ \ \ }
\DoxyCodeLine{00097\ \ \ \ \ int32\ n\_hash\_inuse;\ }
\DoxyCodeLine{00098\ \};}
\DoxyCodeLine{00099\ }
\DoxyCodeLine{00100\ \textcolor{preprocessor}{\#define\ NGRAM\_HASH\_SIZE\ 128}}
\DoxyCodeLine{00101\ }
\DoxyCodeLine{00102\ \textcolor{preprocessor}{\#define\ NGRAM\_BASEWID(wid)\ ((wid)\&0xffffff)}}
\DoxyCodeLine{00103\ \textcolor{preprocessor}{\#define\ NGRAM\_CLASSID(wid)\ (((wid)>>24)\ \&\ 0x7f)}}
\DoxyCodeLine{00104\ \textcolor{preprocessor}{\#define\ NGRAM\_CLASSWID(wid,classid)\ (((classid)<<24)\ |\ 0x80000000\ |\ (wid))}}
\DoxyCodeLine{00105\ \textcolor{preprocessor}{\#define\ NGRAM\_IS\_CLASSWID(wid)\ ((wid)\&0x80000000)}}
\DoxyCodeLine{00106\ }
\DoxyCodeLine{00107\ \textcolor{preprocessor}{\#define\ UG\_ALLOC\_STEP\ 10}}
\DoxyCodeLine{00108\ }
\DoxyCodeLine{00110\ \textcolor{keyword}{typedef}\ \textcolor{keyword}{struct\ }ngram\_funcs\_s\ \{}
\DoxyCodeLine{00114\ \ \ \ \ void\ (*free)(ngram\_model\_t\ *model);}
\DoxyCodeLine{00118\ \ \ \ \ int\ (*apply\_weights)(ngram\_model\_t\ *model,}
\DoxyCodeLine{00119\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ float32\ lw,}
\DoxyCodeLine{00120\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ float32\ wip,}
\DoxyCodeLine{00121\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ float32\ uw);}
\DoxyCodeLine{00125\ \ \ \ \ int32\ (*score)(ngram\_model\_t\ *model,}
\DoxyCodeLine{00126\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ wid,}
\DoxyCodeLine{00127\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ *history,}
\DoxyCodeLine{00128\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ n\_hist,}
\DoxyCodeLine{00129\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ *n\_used);}
\DoxyCodeLine{00134\ \ \ \ \ int32\ (*raw\_score)(ngram\_model\_t\ *model,}
\DoxyCodeLine{00135\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ wid,}
\DoxyCodeLine{00136\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ *history,}
\DoxyCodeLine{00137\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ n\_hist,}
\DoxyCodeLine{00138\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ *n\_used);}
\DoxyCodeLine{00150\ \ \ \ \ int32\ (*add\_ug)(ngram\_model\_t\ *model,}
\DoxyCodeLine{00151\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ wid,\ int32\ lweight);}
\DoxyCodeLine{00155\ \ \ \ \ void\ (*flush)(ngram\_model\_t\ *model);}
\DoxyCodeLine{00156\ }
\DoxyCodeLine{00160\ \ \ \ \ ngram\_iter\_t\ *\ (*iter)(ngram\_model\_t\ *model,\ int32\ wid,\ int32\ *history,\ int32\ n\_hist);}
\DoxyCodeLine{00161\ }
\DoxyCodeLine{00165\ \ \ \ \ ngram\_iter\_t\ *\ (*mgrams)(ngram\_model\_t\ *model,\ int32\ m);}
\DoxyCodeLine{00166\ }
\DoxyCodeLine{00170\ \ \ \ \ ngram\_iter\_t\ *\ (*successors)(ngram\_iter\_t\ *itor);}
\DoxyCodeLine{00171\ }
\DoxyCodeLine{00175\ \ \ \ \ int32\ \textcolor{keyword}{const}\ *\ (*iter\_get)(ngram\_iter\_t\ *itor,}
\DoxyCodeLine{00176\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ *out\_score,}
\DoxyCodeLine{00177\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ *out\_bowt);}
\DoxyCodeLine{00178\ }
\DoxyCodeLine{00182\ \ \ \ \ ngram\_iter\_t\ *\ (*iter\_next)(ngram\_iter\_t\ *itor);}
\DoxyCodeLine{00183\ }
\DoxyCodeLine{00187\ \ \ \ \ void\ (*iter\_free)(ngram\_iter\_t\ *itor);}
\DoxyCodeLine{00188\ \}\ ngram\_funcs\_t;}
\DoxyCodeLine{00189\ }
\DoxyCodeLine{00193\ \textcolor{keyword}{struct\ }ngram\_iter\_s\ \{}
\DoxyCodeLine{00194\ \ \ \ \ ngram\_model\_t\ *model;}
\DoxyCodeLine{00195\ \ \ \ \ int32\ *wids;\ \ \ \ \ \ }
\DoxyCodeLine{00196\ \ \ \ \ int16\ m;\ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00197\ \ \ \ \ int16\ successor;\ \ }
\DoxyCodeLine{00198\ \};}
\DoxyCodeLine{00199\ }
\DoxyCodeLine{00203\ \textcolor{keyword}{typedef}\ \textcolor{keyword}{struct\ }classdef\_s\ \{}
\DoxyCodeLine{00204\ \ \ \ \ \textcolor{keywordtype}{char}\ **words;}
\DoxyCodeLine{00205\ \ \ \ \ float32\ *weights;}
\DoxyCodeLine{00206\ \ \ \ \ int32\ n\_words;}
\DoxyCodeLine{00207\ \}\ classdef\_t;}
\DoxyCodeLine{00208\ }
\DoxyCodeLine{00212\ int32}
\DoxyCodeLine{00213\ ngram\_model\_init(ngram\_model\_t\ *model,}
\DoxyCodeLine{00214\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ngram\_funcs\_t\ *funcs,}
\DoxyCodeLine{00215\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ logmath\_t\ *lmath,}
\DoxyCodeLine{00216\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ n,\ int32\ n\_unigram);}
\DoxyCodeLine{00217\ }
\DoxyCodeLine{00221\ ngram\_model\_t\ *ngram\_model\_arpa\_read(cmd\_ln\_t\ *config,}
\DoxyCodeLine{00222\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *file\_name,}
\DoxyCodeLine{00223\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ logmath\_t\ *lmath);}
\DoxyCodeLine{00227\ ngram\_model\_t\ *ngram\_model\_dmp\_read(cmd\_ln\_t\ *config,}
\DoxyCodeLine{00228\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *file\_name,}
\DoxyCodeLine{00229\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ logmath\_t\ *lmath);}
\DoxyCodeLine{00233\ ngram\_model\_t\ *ngram\_model\_dmp32\_read(cmd\_ln\_t\ *config,}
\DoxyCodeLine{00234\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *file\_name,}
\DoxyCodeLine{00235\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ logmath\_t\ *lmath);}
\DoxyCodeLine{00236\ }
\DoxyCodeLine{00240\ \textcolor{keywordtype}{int}\ ngram\_model\_arpa\_write(ngram\_model\_t\ *model,}
\DoxyCodeLine{00241\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *file\_name);}
\DoxyCodeLine{00245\ \textcolor{keywordtype}{int}\ ngram\_model\_dmp\_write(ngram\_model\_t\ *model,}
\DoxyCodeLine{00246\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *file\_name);}
\DoxyCodeLine{00247\ }
\DoxyCodeLine{00251\ int32\ read\_classdef\_file(hash\_table\_t\ *classes,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *classdef\_file);}
\DoxyCodeLine{00252\ }
\DoxyCodeLine{00256\ \textcolor{keywordtype}{void}\ classdef\_free(classdef\_t\ *classdef);}
\DoxyCodeLine{00257\ }
\DoxyCodeLine{00261\ ngram\_class\_t\ *ngram\_class\_new(ngram\_model\_t\ *model,\ int32\ tag\_wid,}
\DoxyCodeLine{00262\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ start\_wid,\ glist\_t\ classwords);}
\DoxyCodeLine{00263\ }
\DoxyCodeLine{00267\ \textcolor{keywordtype}{void}\ ngram\_class\_free(ngram\_class\_t\ *lmclass);}
\DoxyCodeLine{00268\ }
\DoxyCodeLine{00274\ int32\ ngram\_class\_prob(ngram\_class\_t\ *lmclass,\ int32\ wid);}
\DoxyCodeLine{00275\ }
\DoxyCodeLine{00279\ \textcolor{keywordtype}{void}\ ngram\_iter\_init(ngram\_iter\_t\ *itor,\ ngram\_model\_t\ *model,}
\DoxyCodeLine{00280\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ m,\ \textcolor{keywordtype}{int}\ successor);}
\DoxyCodeLine{00281\ }
\DoxyCodeLine{00282\ \textcolor{preprocessor}{\#endif\ }\textcolor{comment}{/*\ \_\_NGRAM\_MODEL\_INTERNAL\_H\_\_\ */}\textcolor{preprocessor}{}}

\end{DoxyCode}
