\doxysection{lm3g\+\_\+model.\+h}
\label{lm3g__model_8h_source}\index{src/libsphinxbase/lm/lm3g\_model.h@{src/libsphinxbase/lm/lm3g\_model.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\ lm3g\_model.h\ Core\ Sphinx\ 3-\/gram\ code\ used\ in}}
\DoxyCodeLine{00039\ \textcolor{comment}{\ *\ DMP/DMP32/ARPA\ (for\ now)\ model\ code.}}
\DoxyCodeLine{00040\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00041\ \textcolor{comment}{\ *\ Author:\ A\ cast\ of\ thousands,\ probably.}}
\DoxyCodeLine{00042\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00043\ }
\DoxyCodeLine{00044\ \textcolor{preprocessor}{\#ifndef\ \_\_NGRAM\_MODEL\_LM3G\_H\_\_}}
\DoxyCodeLine{00045\ \textcolor{preprocessor}{\#define\ \_\_NGRAM\_MODEL\_LM3G\_H\_\_}}
\DoxyCodeLine{00046\ }
\DoxyCodeLine{00047\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/listelem\_alloc.h"{}}}
\DoxyCodeLine{00048\ }
\DoxyCodeLine{00049\ \textcolor{preprocessor}{\#include\ "{}ngram\_model\_internal.h"{}}}
\DoxyCodeLine{00050\ }
\DoxyCodeLine{00054\ \textcolor{keyword}{typedef}\ \textcolor{keyword}{union\ }\{}
\DoxyCodeLine{00055\ \ \ \ \ float32\ f;}
\DoxyCodeLine{00056\ \ \ \ \ int32\ l;}
\DoxyCodeLine{00057\ \}\ lmprob\_t;}
\DoxyCodeLine{00058\ }
\DoxyCodeLine{00068\ \textcolor{keyword}{typedef}\ \textcolor{keyword}{struct\ }sorted\_entry\_s\ \{}
\DoxyCodeLine{00069\ \ \ \ \ lmprob\_t\ val;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00070\ \ \ \ \ uint32\ lower;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00073\ \ \ \ \ uint32\ higher;\ \ \ \ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00076\ \}\ sorted\_entry\_t;}
\DoxyCodeLine{00077\ }
\DoxyCodeLine{00082\ \textcolor{keyword}{typedef}\ \textcolor{keyword}{struct\ }\{}
\DoxyCodeLine{00083\ \ \ \ \ sorted\_entry\_t\ *list;}
\DoxyCodeLine{00084\ \ \ \ \ int32\ free;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00085\ \ \ \ \ int32\ size;}
\DoxyCodeLine{00086\ \}\ sorted\_list\_t;}
\DoxyCodeLine{00087\ }
\DoxyCodeLine{00091\ \textcolor{keyword}{typedef}\ \textcolor{keyword}{struct\ }unigram\_s\ \{}
\DoxyCodeLine{00092\ \ \ \ \ lmprob\_t\ prob1;\ \ \ \ \ }
\DoxyCodeLine{00093\ \ \ \ \ lmprob\_t\ bo\_wt1;\ \ \ \ }
\DoxyCodeLine{00094\ \ \ \ \ int32\ bigrams;\ \ \ \ \ \ \ }
\DoxyCodeLine{00095\ \}\ unigram\_t;}
\DoxyCodeLine{00096\ }
\DoxyCodeLine{00100\ \textcolor{keyword}{typedef}\ \textcolor{keyword}{struct\ }bigram\_s\ bigram\_t;}
\DoxyCodeLine{00104\ \textcolor{keyword}{typedef}\ \textcolor{keyword}{struct\ }trigram\_s\ trigram\_t;}
\DoxyCodeLine{00105\ }
\DoxyCodeLine{00106\ }
\DoxyCodeLine{00107\ \textcolor{comment}{/*}}
\DoxyCodeLine{00108\ \textcolor{comment}{\ *\ To\ conserve\ space,\ bigram\ info\ is\ kept\ in\ many\ tables.\ \ Since\ the\ number}}
\DoxyCodeLine{00109\ \textcolor{comment}{\ *\ of\ distinct\ values\ <<\ \#bigrams,\ these\ table\ indices\ can\ be\ 16-\/bit\ values.}}
\DoxyCodeLine{00110\ \textcolor{comment}{\ *\ prob2\ and\ bo\_wt2\ are\ such\ indices,\ but\ keeping\ trigram\ index\ is\ less\ easy.}}
\DoxyCodeLine{00111\ \textcolor{comment}{\ *\ It\ is\ supposed\ to\ be\ the\ index\ of\ the\ first\ trigram\ entry\ for\ each\ bigram.}}
\DoxyCodeLine{00112\ \textcolor{comment}{\ *\ But\ such\ an\ index\ cannot\ be\ represented\ in\ 16-\/bits,\ hence\ the\ following}}
\DoxyCodeLine{00113\ \textcolor{comment}{\ *\ segmentation\ scheme:\ Partition\ bigrams\ into\ segments\ of\ BG\_SEG\_SZ}}
\DoxyCodeLine{00114\ \textcolor{comment}{\ *\ consecutive\ entries,\ such\ that\ \#trigrams\ in\ each\ segment\ <=\ 2**16\ (the}}
\DoxyCodeLine{00115\ \textcolor{comment}{\ *\ corresponding\ trigram\ segment).\ \ The\ bigram\_t.trigrams\ value\ is\ then\ a}}
\DoxyCodeLine{00116\ \textcolor{comment}{\ *\ 16-\/bit\ relative\ index\ within\ the\ trigram\ segment.\ \ A\ separate\ table-\/-\/}}
\DoxyCodeLine{00117\ \textcolor{comment}{\ *\ lm\_t.tseg\_base-\/-\/has\ the\ index\ of\ the\ 1st\ trigram\ for\ each\ bigram\ segment.}}
\DoxyCodeLine{00118\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00119\ \textcolor{preprocessor}{\#define\ BG\_SEG\_SZ\ \ \ \ \ \ \ 512\ \ \ \ \ }\textcolor{comment}{/*\ chosen\ so\ that\ \#trigram/segment\ <=\ 2**16\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00120\ \textcolor{preprocessor}{\#define\ LOG\_BG\_SEG\_SZ\ \ \ 9}}
\DoxyCodeLine{00121\ }
\DoxyCodeLine{00129\ \textcolor{keyword}{typedef}\ \textcolor{keyword}{struct\ }tginfo\_s\ \{}
\DoxyCodeLine{00130\ \ \ \ \ int32\ w1;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00132\ \ \ \ \ int32\ n\_tg;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00133\ \ \ \ \ int32\ bowt;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00134\ \ \ \ \ int32\ used;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00135\ \ \ \ \ trigram\_t\ *tg;\ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00136\ \ \ \ \ \textcolor{keyword}{struct\ }tginfo\_s\ *next;\ \ \ \ \ \ }
\DoxyCodeLine{00137\ \}\ tginfo\_t;}
\DoxyCodeLine{00138\ }
\DoxyCodeLine{00142\ \textcolor{keyword}{typedef}\ \textcolor{keyword}{struct\ }lm3g\_model\_s\ \{}
\DoxyCodeLine{00143\ \ \ \ \ unigram\_t\ *unigrams;}
\DoxyCodeLine{00144\ \ \ \ \ bigram\_t\ *bigrams;}
\DoxyCodeLine{00145\ \ \ \ \ trigram\_t\ *trigrams;}
\DoxyCodeLine{00146\ \ \ \ \ lmprob\_t\ *prob2;\ \ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00147\ \ \ \ \ int32\ n\_prob2;\ \ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00148\ \ \ \ \ lmprob\_t\ *bo\_wt2;\ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00149\ \ \ \ \ int32\ n\_bo\_wt2;\ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00150\ \ \ \ \ lmprob\_t\ *prob3;\ \ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00151\ \ \ \ \ int32\ n\_prob3;\ \ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00152\ \ \ \ \ int32\ *tseg\_base;\ \ \ \ }
\DoxyCodeLine{00154\ \ \ \ \ tginfo\_t\ **tginfo;\ \ \ }
\DoxyCodeLine{00156\ \ \ \ \ listelem\_alloc\_t\ *le;\ }
\DoxyCodeLine{00157\ \}\ lm3g\_model\_t;}
\DoxyCodeLine{00158\ }
\DoxyCodeLine{00159\ \textcolor{keywordtype}{void}\ lm3g\_tginfo\_free(ngram\_model\_t\ *base,\ lm3g\_model\_t\ *lm3g);}
\DoxyCodeLine{00160\ \textcolor{keywordtype}{void}\ lm3g\_tginfo\_reset(ngram\_model\_t\ *base,\ lm3g\_model\_t\ *lm3g);}
\DoxyCodeLine{00161\ \textcolor{keywordtype}{void}\ lm3g\_apply\_weights(ngram\_model\_t\ *base,}
\DoxyCodeLine{00162\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ lm3g\_model\_t\ *lm3g,}
\DoxyCodeLine{00163\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ float32\ lw,\ float32\ wip,\ float32\ uw);}
\DoxyCodeLine{00164\ int32\ lm3g\_add\_ug(ngram\_model\_t\ *base,}
\DoxyCodeLine{00165\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ lm3g\_model\_t\ *lm3g,\ int32\ wid,\ int32\ lweight);}
\DoxyCodeLine{00166\ }
\DoxyCodeLine{00167\ }
\DoxyCodeLine{00172\ \textcolor{keywordtype}{void}\ init\_sorted\_list(sorted\_list\_t\ *l);}
\DoxyCodeLine{00173\ \textcolor{keywordtype}{void}\ free\_sorted\_list(sorted\_list\_t\ *l);}
\DoxyCodeLine{00174\ lmprob\_t\ *vals\_in\_sorted\_list(sorted\_list\_t\ *l);}
\DoxyCodeLine{00175\ int32\ sorted\_id(sorted\_list\_t\ *\ l,\ int32\ *val);}
\DoxyCodeLine{00176\ }
\DoxyCodeLine{00177\ \textcolor{preprocessor}{\#endif\ }\textcolor{comment}{/*\ \_\_NGRAM\_MODEL\_LM3G\_H\_\_\ */}\textcolor{preprocessor}{}}

\end{DoxyCode}
