\doxysection{lm3g\+\_\+templates.\+c}
\label{lm3g__templates_8c_source}\index{src/libsphinxbase/lm/lm3g\_templates.c@{src/libsphinxbase/lm/lm3g\_templates.c}}

\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\_templates.c\ Core\ Sphinx\ 3-\/gram\ code\ used\ in}}
\DoxyCodeLine{00039\ \textcolor{comment}{\ *\ DMP/DMP32/ARPA\ (for\ now)\ model\ code.}}
\DoxyCodeLine{00040\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00041\ }
\DoxyCodeLine{00042\ \textcolor{preprocessor}{\#include\ <assert.h>}}
\DoxyCodeLine{00043\ }
\DoxyCodeLine{00044\ \textcolor{comment}{/*\ Locate\ a\ specific\ bigram\ within\ a\ bigram\ list\ */}}
\DoxyCodeLine{00045\ \textcolor{preprocessor}{\#define\ BINARY\_SEARCH\_THRESH\ \ \ \ 16}}
\DoxyCodeLine{00046\ \textcolor{keyword}{static}\ int32}
\DoxyCodeLine{00047\ find\_bg(bigram\_t\ *\ bg,\ int32\ n,\ int32\ w)}
\DoxyCodeLine{00048\ \{}
\DoxyCodeLine{00049\ \ \ \ \ int32\ i,\ b,\ e;}
\DoxyCodeLine{00050\ }
\DoxyCodeLine{00051\ \ \ \ \ \textcolor{comment}{/*\ Binary\ search\ until\ segment\ size\ <\ threshold\ */}}
\DoxyCodeLine{00052\ \ \ \ \ b\ =\ 0;}
\DoxyCodeLine{00053\ \ \ \ \ e\ =\ n;}
\DoxyCodeLine{00054\ \ \ \ \ \textcolor{keywordflow}{while}\ (e\ -\/\ b\ >\ BINARY\_SEARCH\_THRESH)\ \{}
\DoxyCodeLine{00055\ \ \ \ \ \ \ \ \ i\ =\ (b\ +\ e)\ >>\ 1;}
\DoxyCodeLine{00056\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (bg[i].wid\ <\ w)}
\DoxyCodeLine{00057\ \ \ \ \ \ \ \ \ \ \ \ \ b\ =\ i\ +\ 1;}
\DoxyCodeLine{00058\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (bg[i].wid\ >\ w)}
\DoxyCodeLine{00059\ \ \ \ \ \ \ \ \ \ \ \ \ e\ =\ i;}
\DoxyCodeLine{00060\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}}
\DoxyCodeLine{00061\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ i;}
\DoxyCodeLine{00062\ \ \ \ \ \}}
\DoxyCodeLine{00063\ }
\DoxyCodeLine{00064\ \ \ \ \ \textcolor{comment}{/*\ Linear\ search\ within\ narrowed\ segment\ */}}
\DoxyCodeLine{00065\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ b;\ (i\ <\ e)\ \&\&\ (bg[i].wid\ !=\ w);\ i++);}
\DoxyCodeLine{00066\ \ \ \ \ \textcolor{keywordflow}{return}\ ((i\ <\ e)\ ?\ i\ :\ -\/1);}
\DoxyCodeLine{00067\ \}}
\DoxyCodeLine{00068\ }
\DoxyCodeLine{00069\ \textcolor{keyword}{static}\ int32}
\DoxyCodeLine{00070\ lm3g\_bg\_score(NGRAM\_MODEL\_TYPE\ *model,}
\DoxyCodeLine{00071\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ lw1,\ int32\ lw2,\ int32\ *n\_used)}
\DoxyCodeLine{00072\ \{}
\DoxyCodeLine{00073\ \ \ \ \ int32\ i,\ n,\ b,\ score;}
\DoxyCodeLine{00074\ \ \ \ \ bigram\_t\ *bg;}
\DoxyCodeLine{00075\ }
\DoxyCodeLine{00076\ \ \ \ \ \textcolor{keywordflow}{if}\ (lw1\ <\ 0\ ||\ model-\/>base.n\ <\ 2)\ \{}
\DoxyCodeLine{00077\ \ \ \ \ \ \ \ \ *n\_used\ =\ 1;}
\DoxyCodeLine{00078\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ model-\/>lm3g.unigrams[lw2].prob1.l;}
\DoxyCodeLine{00079\ \ \ \ \ \}}
\DoxyCodeLine{00080\ }
\DoxyCodeLine{00081\ \ \ \ \ b\ =\ FIRST\_BG(model,\ lw1);}
\DoxyCodeLine{00082\ \ \ \ \ n\ =\ FIRST\_BG(model,\ lw1\ +\ 1)\ -\/\ b;}
\DoxyCodeLine{00083\ \ \ \ \ bg\ =\ model-\/>lm3g.bigrams\ +\ b;}
\DoxyCodeLine{00084\ }
\DoxyCodeLine{00085\ \ \ \ \ \textcolor{keywordflow}{if}\ ((i\ =\ find\_bg(bg,\ n,\ lw2))\ >=\ 0)\ \{}
\DoxyCodeLine{00086\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Access\ mode\ =\ bigram\ */}}
\DoxyCodeLine{00087\ \ \ \ \ \ \ \ \ *n\_used\ =\ 2;}
\DoxyCodeLine{00088\ \ \ \ \ \ \ \ \ score\ =\ model-\/>lm3g.prob2[bg[i].prob2].l;}
\DoxyCodeLine{00089\ \ \ \ \ \}}
\DoxyCodeLine{00090\ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00091\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Access\ mode\ =\ unigram\ */}}
\DoxyCodeLine{00092\ \ \ \ \ \ \ \ \ *n\_used\ =\ 1;}
\DoxyCodeLine{00093\ \ \ \ \ \ \ \ \ score\ =\ model-\/>lm3g.unigrams[lw1].bo\_wt1.l\ +\ model-\/>lm3g.unigrams[lw2].prob1.l;}
\DoxyCodeLine{00094\ \ \ \ \ \}}
\DoxyCodeLine{00095\ }
\DoxyCodeLine{00096\ \ \ \ \ \textcolor{keywordflow}{return}\ (score);}
\DoxyCodeLine{00097\ \}}
\DoxyCodeLine{00098\ }
\DoxyCodeLine{00099\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00100\ load\_tginfo(NGRAM\_MODEL\_TYPE\ *model,\ int32\ lw1,\ int32\ lw2)}
\DoxyCodeLine{00101\ \{}
\DoxyCodeLine{00102\ \ \ \ \ int32\ i,\ n,\ b,\ t;}
\DoxyCodeLine{00103\ \ \ \ \ bigram\_t\ *bg;}
\DoxyCodeLine{00104\ \ \ \ \ tginfo\_t\ *tginfo;}
\DoxyCodeLine{00105\ }
\DoxyCodeLine{00106\ \ \ \ \ \textcolor{comment}{/*\ First\ allocate\ space\ for\ tg\ information\ for\ bg\ lw1,lw2\ */}}
\DoxyCodeLine{00107\ \ \ \ \ tginfo\ =\ (tginfo\_t\ *)\ listelem\_malloc(model-\/>lm3g.le);}
\DoxyCodeLine{00108\ \ \ \ \ tginfo-\/>w1\ =\ lw1;}
\DoxyCodeLine{00109\ \ \ \ \ tginfo-\/>tg\ =\ NULL;}
\DoxyCodeLine{00110\ \ \ \ \ tginfo-\/>next\ =\ model-\/>lm3g.tginfo[lw2];}
\DoxyCodeLine{00111\ \ \ \ \ model-\/>lm3g.tginfo[lw2]\ =\ tginfo;}
\DoxyCodeLine{00112\ }
\DoxyCodeLine{00113\ \ \ \ \ \textcolor{comment}{/*\ Locate\ bigram\ lw1,lw2\ */}}
\DoxyCodeLine{00114\ \ \ \ \ b\ =\ model-\/>lm3g.unigrams[lw1].bigrams;}
\DoxyCodeLine{00115\ \ \ \ \ n\ =\ model-\/>lm3g.unigrams[lw1\ +\ 1].bigrams\ -\/\ b;}
\DoxyCodeLine{00116\ \ \ \ \ bg\ =\ model-\/>lm3g.bigrams\ +\ b;}
\DoxyCodeLine{00117\ }
\DoxyCodeLine{00118\ \ \ \ \ \textcolor{keywordflow}{if}\ ((n\ >\ 0)\ \&\&\ ((i\ =\ find\_bg(bg,\ n,\ lw2))\ >=\ 0))\ \{}
\DoxyCodeLine{00119\ \ \ \ \ \ \ \ \ tginfo-\/>bowt\ =\ model-\/>lm3g.bo\_wt2[bg[i].bo\_wt2].l;}
\DoxyCodeLine{00120\ }
\DoxyCodeLine{00121\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Find\ t\ =\ Absolute\ first\ trigram\ index\ for\ bigram\ lw1,lw2\ */}}
\DoxyCodeLine{00122\ \ \ \ \ \ \ \ \ b\ +=\ i;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ b\ =\ Absolute\ index\ of\ bigram\ lw1,lw2\ on\ disk\ */}}
\DoxyCodeLine{00123\ \ \ \ \ \ \ \ \ t\ =\ FIRST\_TG(model,\ b);}
\DoxyCodeLine{00124\ }
\DoxyCodeLine{00125\ \ \ \ \ \ \ \ \ tginfo-\/>tg\ =\ model-\/>lm3g.trigrams\ +\ t;}
\DoxyCodeLine{00126\ }
\DoxyCodeLine{00127\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Find\ \#tg\ for\ bigram\ w1,w2\ */}}
\DoxyCodeLine{00128\ \ \ \ \ \ \ \ \ tginfo-\/>n\_tg\ =\ FIRST\_TG(model,\ b\ +\ 1)\ -\/\ t;}
\DoxyCodeLine{00129\ \ \ \ \ \}}
\DoxyCodeLine{00130\ \ \ \ \ \textcolor{keywordflow}{else}\ \{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ No\ bigram\ w1,w2\ */}}
\DoxyCodeLine{00131\ \ \ \ \ \ \ \ \ tginfo-\/>bowt\ =\ 0;}
\DoxyCodeLine{00132\ \ \ \ \ \ \ \ \ tginfo-\/>n\_tg\ =\ 0;}
\DoxyCodeLine{00133\ \ \ \ \ \}}
\DoxyCodeLine{00134\ \}}
\DoxyCodeLine{00135\ }
\DoxyCodeLine{00136\ \textcolor{comment}{/*\ Similar\ to\ find\_bg\ */}}
\DoxyCodeLine{00137\ \textcolor{keyword}{static}\ int32}
\DoxyCodeLine{00138\ find\_tg(trigram\_t\ *\ tg,\ int32\ n,\ int32\ w)}
\DoxyCodeLine{00139\ \{}
\DoxyCodeLine{00140\ \ \ \ \ int32\ i,\ b,\ e;}
\DoxyCodeLine{00141\ }
\DoxyCodeLine{00142\ \ \ \ \ b\ =\ 0;}
\DoxyCodeLine{00143\ \ \ \ \ e\ =\ n;}
\DoxyCodeLine{00144\ \ \ \ \ \textcolor{keywordflow}{while}\ (e\ -\/\ b\ >\ BINARY\_SEARCH\_THRESH)\ \{}
\DoxyCodeLine{00145\ \ \ \ \ \ \ \ \ i\ =\ (b\ +\ e)\ >>\ 1;}
\DoxyCodeLine{00146\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (tg[i].wid\ <\ w)}
\DoxyCodeLine{00147\ \ \ \ \ \ \ \ \ \ \ \ \ b\ =\ i\ +\ 1;}
\DoxyCodeLine{00148\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (tg[i].wid\ >\ w)}
\DoxyCodeLine{00149\ \ \ \ \ \ \ \ \ \ \ \ \ e\ =\ i;}
\DoxyCodeLine{00150\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}}
\DoxyCodeLine{00151\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ i;}
\DoxyCodeLine{00152\ \ \ \ \ \}}
\DoxyCodeLine{00153\ }
\DoxyCodeLine{00154\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ b;\ (i\ <\ e)\ \&\&\ (tg[i].wid\ !=\ w);\ i++);}
\DoxyCodeLine{00155\ \ \ \ \ \textcolor{keywordflow}{return}\ ((i\ <\ e)\ ?\ i\ :\ -\/1);}
\DoxyCodeLine{00156\ \}}
\DoxyCodeLine{00157\ }
\DoxyCodeLine{00158\ \textcolor{keyword}{static}\ int32}
\DoxyCodeLine{00159\ lm3g\_tg\_score(NGRAM\_MODEL\_TYPE\ *model,\ int32\ lw1,}
\DoxyCodeLine{00160\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ lw2,\ int32\ lw3,\ int32\ *n\_used)}
\DoxyCodeLine{00161\ \{}
\DoxyCodeLine{00162\ \ \ \ \ ngram\_model\_t\ *base\ =\ \&model-\/>base;}
\DoxyCodeLine{00163\ \ \ \ \ int32\ i,\ n,\ score;}
\DoxyCodeLine{00164\ \ \ \ \ trigram\_t\ *tg;}
\DoxyCodeLine{00165\ \ \ \ \ tginfo\_t\ *tginfo,\ *prev\_tginfo;}
\DoxyCodeLine{00166\ }
\DoxyCodeLine{00167\ \ \ \ \ \textcolor{keywordflow}{if}\ ((base-\/>n\ <\ 3)\ ||\ (lw1\ <\ 0)\ ||\ (lw2\ <\ 0))}
\DoxyCodeLine{00168\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ (lm3g\_bg\_score(model,\ lw2,\ lw3,\ n\_used));}
\DoxyCodeLine{00169\ }
\DoxyCodeLine{00170\ \ \ \ \ prev\_tginfo\ =\ NULL;}
\DoxyCodeLine{00171\ \ \ \ \ \textcolor{keywordflow}{for}\ (tginfo\ =\ model-\/>lm3g.tginfo[lw2];\ tginfo;\ tginfo\ =\ tginfo-\/>next)\ \{}
\DoxyCodeLine{00172\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (tginfo-\/>w1\ ==\ lw1)}
\DoxyCodeLine{00173\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00174\ \ \ \ \ \ \ \ \ prev\_tginfo\ =\ tginfo;}
\DoxyCodeLine{00175\ \ \ \ \ \}}
\DoxyCodeLine{00176\ }
\DoxyCodeLine{00177\ \ \ \ \ \textcolor{keywordflow}{if}\ (!tginfo)\ \{}
\DoxyCodeLine{00178\ \ \ \ \ \ \ \ \ load\_tginfo(model,\ lw1,\ lw2);}
\DoxyCodeLine{00179\ \ \ \ \ \ \ \ \ tginfo\ =\ model-\/>lm3g.tginfo[lw2];}
\DoxyCodeLine{00180\ \ \ \ \ \}}
\DoxyCodeLine{00181\ \ \ \ \ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (prev\_tginfo)\ \{}
\DoxyCodeLine{00182\ \ \ \ \ \ \ \ \ prev\_tginfo-\/>next\ =\ tginfo-\/>next;}
\DoxyCodeLine{00183\ \ \ \ \ \ \ \ \ tginfo-\/>next\ =\ model-\/>lm3g.tginfo[lw2];}
\DoxyCodeLine{00184\ \ \ \ \ \ \ \ \ model-\/>lm3g.tginfo[lw2]\ =\ tginfo;}
\DoxyCodeLine{00185\ \ \ \ \ \}}
\DoxyCodeLine{00186\ }
\DoxyCodeLine{00187\ \ \ \ \ tginfo-\/>used\ =\ 1;}
\DoxyCodeLine{00188\ }
\DoxyCodeLine{00189\ \ \ \ \ \textcolor{comment}{/*\ Trigrams\ for\ w1,w2\ now\ pointed\ to\ by\ tginfo\ */}}
\DoxyCodeLine{00190\ \ \ \ \ n\ =\ tginfo-\/>n\_tg;}
\DoxyCodeLine{00191\ \ \ \ \ tg\ =\ tginfo-\/>tg;}
\DoxyCodeLine{00192\ \ \ \ \ \textcolor{keywordflow}{if}\ ((i\ =\ find\_tg(tg,\ n,\ lw3))\ >=\ 0)\ \{}
\DoxyCodeLine{00193\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Access\ mode\ =\ trigram\ */}}
\DoxyCodeLine{00194\ \ \ \ \ \ \ \ \ *n\_used\ =\ 3;}
\DoxyCodeLine{00195\ \ \ \ \ \ \ \ \ score\ =\ model-\/>lm3g.prob3[tg[i].prob3].l;}
\DoxyCodeLine{00196\ \ \ \ \ \}}
\DoxyCodeLine{00197\ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00198\ \ \ \ \ \ \ \ \ score\ =\ tginfo-\/>bowt\ +\ lm3g\_bg\_score(model,\ lw2,\ lw3,\ n\_used);}
\DoxyCodeLine{00199\ \ \ \ \ \}}
\DoxyCodeLine{00200\ }
\DoxyCodeLine{00201\ \ \ \ \ \textcolor{keywordflow}{return}\ (score);}
\DoxyCodeLine{00202\ \}}
\DoxyCodeLine{00203\ }
\DoxyCodeLine{00204\ \textcolor{keyword}{static}\ int32}
\DoxyCodeLine{00205\ lm3g\_template\_score(ngram\_model\_t\ *base,\ int32\ wid,}
\DoxyCodeLine{00206\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ *history,\ int32\ n\_hist,}
\DoxyCodeLine{00207\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ *n\_used)}
\DoxyCodeLine{00208\ \{}
\DoxyCodeLine{00209\ \ \ \ \ NGRAM\_MODEL\_TYPE\ *model\ =\ (NGRAM\_MODEL\_TYPE\ *)base;}
\DoxyCodeLine{00210\ \ \ \ \ \textcolor{keywordflow}{switch}\ (n\_hist)\ \{}
\DoxyCodeLine{00211\ \ \ \ \ \textcolor{keywordflow}{case}\ 0:}
\DoxyCodeLine{00212\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Access\ mode:\ unigram\ */}}
\DoxyCodeLine{00213\ \ \ \ \ \ \ \ \ *n\_used\ =\ 1;}
\DoxyCodeLine{00214\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ model-\/>lm3g.unigrams[wid].prob1.l;}
\DoxyCodeLine{00215\ \ \ \ \ \textcolor{keywordflow}{case}\ 1:}
\DoxyCodeLine{00216\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ lm3g\_bg\_score(model,\ history[0],\ wid,\ n\_used);}
\DoxyCodeLine{00217\ \ \ \ \ \textcolor{keywordflow}{case}\ 2:}
\DoxyCodeLine{00218\ \ \ \ \ \textcolor{keywordflow}{default}:}
\DoxyCodeLine{00219\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Anything\ greater\ than\ 2\ is\ the\ same\ as\ a\ trigram\ for\ now.\ */}}
\DoxyCodeLine{00220\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ lm3g\_tg\_score(model,\ history[1],\ history[0],\ wid,\ n\_used);}
\DoxyCodeLine{00221\ \ \ \ \ \}}
\DoxyCodeLine{00222\ \}}
\DoxyCodeLine{00223\ }
\DoxyCodeLine{00224\ \textcolor{keyword}{static}\ int32}
\DoxyCodeLine{00225\ lm3g\_template\_raw\_score(ngram\_model\_t\ *base,\ int32\ wid,}
\DoxyCodeLine{00226\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ *history,\ int32\ n\_hist,}
\DoxyCodeLine{00227\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ *n\_used)}
\DoxyCodeLine{00228\ \{}
\DoxyCodeLine{00229\ \ \ \ \ NGRAM\_MODEL\_TYPE\ *model\ =\ (NGRAM\_MODEL\_TYPE\ *)base;}
\DoxyCodeLine{00230\ \ \ \ \ int32\ score;}
\DoxyCodeLine{00231\ }
\DoxyCodeLine{00232\ \ \ \ \ \textcolor{keywordflow}{switch}\ (n\_hist)\ \{}
\DoxyCodeLine{00233\ \ \ \ \ \textcolor{keywordflow}{case}\ 0:}
\DoxyCodeLine{00234\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Access\ mode:\ unigram\ */}}
\DoxyCodeLine{00235\ \ \ \ \ \ \ \ \ *n\_used\ =\ 1;}
\DoxyCodeLine{00236\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Undo\ insertion\ penalty.\ */}}
\DoxyCodeLine{00237\ \ \ \ \ \ \ \ \ score\ =\ model-\/>lm3g.unigrams[wid].prob1.l\ -\/\ base-\/>log\_wip;}
\DoxyCodeLine{00238\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Undo\ language\ weight.\ */}}
\DoxyCodeLine{00239\ \ \ \ \ \ \ \ \ score\ =\ (int32)(score\ /\ base-\/>lw);}
\DoxyCodeLine{00240\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Undo\ unigram\ interpolation\ */}}
\DoxyCodeLine{00241\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (strcmp(base-\/>word\_str[wid],\ \textcolor{stringliteral}{"{}<s>"{}})\ !=\ 0)\ \{\ \textcolor{comment}{/*\ FIXME:\ configurable\ start\_sym\ */}}
\DoxyCodeLine{00242\ \ \ \ \ \ \ \ \ \ \ \ \ score\ =\ logmath\_log(base-\/>lmath,}
\DoxyCodeLine{00243\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ logmath\_exp(base-\/>lmath,\ score)}
\DoxyCodeLine{00244\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ -\/\ logmath\_exp(base-\/>lmath,\ }
\DoxyCodeLine{00245\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ base-\/>log\_uniform\ +\ base-\/>log\_uniform\_weight));}
\DoxyCodeLine{00246\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00247\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ score;}
\DoxyCodeLine{00248\ \ \ \ \ \textcolor{keywordflow}{case}\ 1:}
\DoxyCodeLine{00249\ \ \ \ \ \ \ \ \ score\ =\ lm3g\_bg\_score(model,\ history[0],\ wid,\ n\_used);}
\DoxyCodeLine{00250\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00251\ \ \ \ \ \textcolor{keywordflow}{case}\ 2:}
\DoxyCodeLine{00252\ \ \ \ \ \textcolor{keywordflow}{default}:}
\DoxyCodeLine{00253\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Anything\ greater\ than\ 2\ is\ the\ same\ as\ a\ trigram\ for\ now.\ */}}
\DoxyCodeLine{00254\ \ \ \ \ \ \ \ \ score\ =\ lm3g\_tg\_score(model,\ history[1],\ history[0],\ wid,\ n\_used);}
\DoxyCodeLine{00255\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00256\ \ \ \ \ \}}
\DoxyCodeLine{00257\ \ \ \ \ \textcolor{comment}{/*\ FIXME\ (maybe):\ This\ doesn't\ undo\ unigram\ weighting\ in\ backoff\ cases.\ */}}
\DoxyCodeLine{00258\ \ \ \ \ \textcolor{keywordflow}{return}\ (int32)((score\ -\/\ base-\/>log\_wip)\ /\ base-\/>lw);}
\DoxyCodeLine{00259\ \}}
\DoxyCodeLine{00260\ }
\DoxyCodeLine{00261\ \textcolor{keyword}{static}\ int32}
\DoxyCodeLine{00262\ lm3g\_template\_add\_ug(ngram\_model\_t\ *base,}
\DoxyCodeLine{00263\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ wid,\ int32\ lweight)}
\DoxyCodeLine{00264\ \{}
\DoxyCodeLine{00265\ \ \ \ \ NGRAM\_MODEL\_TYPE\ *model\ =\ (NGRAM\_MODEL\_TYPE\ *)base;}
\DoxyCodeLine{00266\ \ \ \ \ \textcolor{keywordflow}{return}\ lm3g\_add\_ug(base,\ \&model-\/>lm3g,\ wid,\ lweight);}
\DoxyCodeLine{00267\ \}}
\DoxyCodeLine{00268\ }
\DoxyCodeLine{00269\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00270\ lm3g\_template\_flush(ngram\_model\_t\ *base)}
\DoxyCodeLine{00271\ \{}
\DoxyCodeLine{00272\ \ \ \ \ NGRAM\_MODEL\_TYPE\ *model\ =\ (NGRAM\_MODEL\_TYPE\ *)base;}
\DoxyCodeLine{00273\ \ \ \ \ lm3g\_tginfo\_reset(base,\ \&model-\/>lm3g);}
\DoxyCodeLine{00274\ \}}
\DoxyCodeLine{00275\ }
\DoxyCodeLine{00276\ \textcolor{keyword}{typedef}\ \textcolor{keyword}{struct\ }lm3g\_iter\_s\ \{}
\DoxyCodeLine{00277\ \ \ \ \ ngram\_iter\_t\ base;}
\DoxyCodeLine{00278\ \ \ \ \ unigram\_t\ *ug;}
\DoxyCodeLine{00279\ \ \ \ \ bigram\_t\ *bg;}
\DoxyCodeLine{00280\ \ \ \ \ trigram\_t\ *tg;}
\DoxyCodeLine{00281\ \}\ lm3g\_iter\_t;}
\DoxyCodeLine{00282\ }
\DoxyCodeLine{00283\ \textcolor{keyword}{static}\ ngram\_iter\_t\ *}
\DoxyCodeLine{00284\ lm3g\_template\_iter(ngram\_model\_t\ *base,\ int32\ wid,}
\DoxyCodeLine{00285\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ *history,\ int32\ n\_hist)}
\DoxyCodeLine{00286\ \{}
\DoxyCodeLine{00287\ \ \ \ \ NGRAM\_MODEL\_TYPE\ *model\ =\ (NGRAM\_MODEL\_TYPE\ *)base;}
\DoxyCodeLine{00288\ \ \ \ \ lm3g\_iter\_t\ *itor\ =\ ckd\_calloc(1,\ \textcolor{keyword}{sizeof}(*itor));}
\DoxyCodeLine{00289\ }
\DoxyCodeLine{00290\ \ \ \ \ ngram\_iter\_init((ngram\_iter\_t\ *)itor,\ base,\ n\_hist,\ FALSE);}
\DoxyCodeLine{00291\ }
\DoxyCodeLine{00292\ \ \ \ \ \textcolor{keywordflow}{if}\ (n\_hist\ ==\ 0)\ \{}
\DoxyCodeLine{00293\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Unigram\ is\ the\ easiest.\ */}}
\DoxyCodeLine{00294\ \ \ \ \ \ \ \ \ itor-\/>ug\ =\ model-\/>lm3g.unigrams\ +\ wid;}
\DoxyCodeLine{00295\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ (ngram\_iter\_t\ *)itor;}
\DoxyCodeLine{00296\ \ \ \ \ \}}
\DoxyCodeLine{00297\ \ \ \ \ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (n\_hist\ ==\ 1)\ \{}
\DoxyCodeLine{00298\ \ \ \ \ \ \ \ \ int32\ i,\ n,\ b;}
\DoxyCodeLine{00299\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Find\ the\ bigram,\ as\ in\ bg\_score\ above\ (duplicate\ code...)\ */}}
\DoxyCodeLine{00300\ \ \ \ \ \ \ \ \ itor-\/>ug\ =\ model-\/>lm3g.unigrams\ +\ history[0];}
\DoxyCodeLine{00301\ \ \ \ \ \ \ \ \ b\ =\ FIRST\_BG(model,\ history[0]);}
\DoxyCodeLine{00302\ \ \ \ \ \ \ \ \ n\ =\ FIRST\_BG(model,\ history[0]\ +\ 1)\ -\/\ b;}
\DoxyCodeLine{00303\ \ \ \ \ \ \ \ \ itor-\/>bg\ =\ model-\/>lm3g.bigrams\ +\ b;}
\DoxyCodeLine{00304\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ If\ no\ such\ bigram\ exists\ then\ fail.\ */}}
\DoxyCodeLine{00305\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((i\ =\ find\_bg(itor-\/>bg,\ n,\ wid))\ <\ 0)\ \{}
\DoxyCodeLine{00306\ \ \ \ \ \ \ \ \ \ \ \ \ ngram\_iter\_free((ngram\_iter\_t\ *)itor);}
\DoxyCodeLine{00307\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00308\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00309\ \ \ \ \ \ \ \ \ itor-\/>bg\ +=\ i;}
\DoxyCodeLine{00310\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ (ngram\_iter\_t\ *)itor;}
\DoxyCodeLine{00311\ \ \ \ \ \}}
\DoxyCodeLine{00312\ \ \ \ \ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (n\_hist\ ==\ 2)\ \{}
\DoxyCodeLine{00313\ \ \ \ \ \ \ \ \ int32\ i,\ n;}
\DoxyCodeLine{00314\ \ \ \ \ \ \ \ \ tginfo\_t\ *tginfo,\ *prev\_tginfo;}
\DoxyCodeLine{00315\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Find\ the\ trigram,\ as\ in\ tg\_score\ above\ (duplicate\ code...)\ */}}
\DoxyCodeLine{00316\ \ \ \ \ \ \ \ \ itor-\/>ug\ =\ model-\/>lm3g.unigrams\ +\ history[1];}
\DoxyCodeLine{00317\ \ \ \ \ \ \ \ \ prev\_tginfo\ =\ NULL;}
\DoxyCodeLine{00318\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (tginfo\ =\ model-\/>lm3g.tginfo[history[0]];}
\DoxyCodeLine{00319\ \ \ \ \ \ \ \ \ \ \ \ \ \ tginfo;\ tginfo\ =\ tginfo-\/>next)\ \{}
\DoxyCodeLine{00320\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (tginfo-\/>w1\ ==\ history[1])}
\DoxyCodeLine{00321\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00322\ \ \ \ \ \ \ \ \ \ \ \ \ prev\_tginfo\ =\ tginfo;}
\DoxyCodeLine{00323\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00324\ }
\DoxyCodeLine{00325\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (!tginfo)\ \{}
\DoxyCodeLine{00326\ \ \ \ \ \ \ \ \ \ \ \ \ load\_tginfo(model,\ history[1],\ history[0]);}
\DoxyCodeLine{00327\ \ \ \ \ \ \ \ \ \ \ \ \ tginfo\ =\ model-\/>lm3g.tginfo[history[0]];}
\DoxyCodeLine{00328\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00329\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (prev\_tginfo)\ \{}
\DoxyCodeLine{00330\ \ \ \ \ \ \ \ \ \ \ \ \ prev\_tginfo-\/>next\ =\ tginfo-\/>next;}
\DoxyCodeLine{00331\ \ \ \ \ \ \ \ \ \ \ \ \ tginfo-\/>next\ =\ model-\/>lm3g.tginfo[history[0]];}
\DoxyCodeLine{00332\ \ \ \ \ \ \ \ \ \ \ \ \ model-\/>lm3g.tginfo[history[0]]\ =\ tginfo;}
\DoxyCodeLine{00333\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00334\ }
\DoxyCodeLine{00335\ \ \ \ \ \ \ \ \ tginfo-\/>used\ =\ 1;}
\DoxyCodeLine{00336\ }
\DoxyCodeLine{00337\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Trigrams\ for\ w1,w2\ now\ pointed\ to\ by\ tginfo\ */}}
\DoxyCodeLine{00338\ \ \ \ \ \ \ \ \ n\ =\ tginfo-\/>n\_tg;}
\DoxyCodeLine{00339\ \ \ \ \ \ \ \ \ itor-\/>tg\ =\ tginfo-\/>tg;}
\DoxyCodeLine{00340\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((i\ =\ find\_tg(itor-\/>tg,\ n,\ wid))\ >=\ 0)\ \{}
\DoxyCodeLine{00341\ \ \ \ \ \ \ \ \ \ \ \ \ itor-\/>tg\ +=\ i;}
\DoxyCodeLine{00342\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Now\ advance\ the\ bigram\ pointer\ accordingly.\ \ FIXME:}}
\DoxyCodeLine{00343\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ \ \ *\ Note\ that\ we\ actually\ already\ found\ the\ relevant\ bigram}}
\DoxyCodeLine{00344\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ \ \ *\ in\ load\_tginfo.\ */}}
\DoxyCodeLine{00345\ \ \ \ \ \ \ \ \ \ \ \ \ itor-\/>bg\ =\ model-\/>lm3g.bigrams;}
\DoxyCodeLine{00346\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{while}\ (FIRST\_TG(model,\ (itor-\/>bg\ -\/\ model-\/>lm3g.bigrams\ +\ 1))}
\DoxyCodeLine{00347\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ <=\ (itor-\/>tg\ -\/\ model-\/>lm3g.trigrams))}
\DoxyCodeLine{00348\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ++itor-\/>bg;}
\DoxyCodeLine{00349\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ (ngram\_iter\_t\ *)itor;}
\DoxyCodeLine{00350\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00351\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00352\ \ \ \ \ \ \ \ \ \ \ \ \ ngram\_iter\_free((ngram\_iter\_t\ *)itor);}
\DoxyCodeLine{00353\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ (ngram\_iter\_t\ *)NULL;}
\DoxyCodeLine{00354\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00355\ \ \ \ \ \}}
\DoxyCodeLine{00356\ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00357\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Should\ not\ happen.\ */}}
\DoxyCodeLine{00358\ \ \ \ \ \ \ \ \ assert(n\_hist\ ==\ 0);\ \textcolor{comment}{/*\ Guaranteed\ to\ fail.\ */}}
\DoxyCodeLine{00359\ \ \ \ \ \ \ \ \ ngram\_iter\_free((ngram\_iter\_t\ *)itor);}
\DoxyCodeLine{00360\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00361\ \ \ \ \ \}}
\DoxyCodeLine{00362\ \}}
\DoxyCodeLine{00363\ }
\DoxyCodeLine{00364\ \textcolor{keyword}{static}\ ngram\_iter\_t\ *}
\DoxyCodeLine{00365\ lm3g\_template\_mgrams(ngram\_model\_t\ *base,\ \textcolor{keywordtype}{int}\ m)}
\DoxyCodeLine{00366\ \{}
\DoxyCodeLine{00367\ \ \ \ \ NGRAM\_MODEL\_TYPE\ *model\ =\ (NGRAM\_MODEL\_TYPE\ *)base;}
\DoxyCodeLine{00368\ \ \ \ \ lm3g\_iter\_t\ *itor\ =\ ckd\_calloc(1,\ \textcolor{keyword}{sizeof}(*itor));}
\DoxyCodeLine{00369\ \ \ \ \ ngram\_iter\_init((ngram\_iter\_t\ *)itor,\ base,\ m,\ FALSE);}
\DoxyCodeLine{00370\ }
\DoxyCodeLine{00371\ \ \ \ \ itor-\/>ug\ =\ model-\/>lm3g.unigrams;}
\DoxyCodeLine{00372\ \ \ \ \ itor-\/>bg\ =\ model-\/>lm3g.bigrams;}
\DoxyCodeLine{00373\ \ \ \ \ itor-\/>tg\ =\ model-\/>lm3g.trigrams;}
\DoxyCodeLine{00374\ }
\DoxyCodeLine{00375\ \ \ \ \ \textcolor{comment}{/*\ Advance\ bigram\ pointer\ to\ match\ first\ trigram.\ */}}
\DoxyCodeLine{00376\ \ \ \ \ \textcolor{keywordflow}{if}\ (m\ >\ 1\ \&\&\ base-\/>n\_counts[1]\ >\ 1)\ \ \{}
\DoxyCodeLine{00377\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{while}\ (FIRST\_TG(model,\ (itor-\/>bg\ -\/\ model-\/>lm3g.bigrams\ +\ 1))}
\DoxyCodeLine{00378\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ <=\ (itor-\/>tg\ -\/\ model-\/>lm3g.trigrams))}
\DoxyCodeLine{00379\ \ \ \ \ \ \ \ \ \ \ \ \ ++itor-\/>bg;}
\DoxyCodeLine{00380\ \ \ \ \ \}}
\DoxyCodeLine{00381\ }
\DoxyCodeLine{00382\ \ \ \ \ \textcolor{comment}{/*\ Advance\ unigram\ pointer\ to\ match\ first\ bigram.\ */}}
\DoxyCodeLine{00383\ \ \ \ \ \textcolor{keywordflow}{if}\ (m\ >\ 0\ \&\&\ base-\/>n\_counts[0]\ >\ 1)\ \{}
\DoxyCodeLine{00384\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{while}\ (itor-\/>ug[1].bigrams\ <=\ (itor-\/>bg\ -\/\ model-\/>lm3g.bigrams))}
\DoxyCodeLine{00385\ \ \ \ \ \ \ \ \ \ \ \ \ ++itor-\/>ug;}
\DoxyCodeLine{00386\ \ \ \ \ \}}
\DoxyCodeLine{00387\ }
\DoxyCodeLine{00388\ \ \ \ \ \textcolor{keywordflow}{return}\ (ngram\_iter\_t\ *)itor;}
\DoxyCodeLine{00389\ \}}
\DoxyCodeLine{00390\ }
\DoxyCodeLine{00391\ \textcolor{keyword}{static}\ ngram\_iter\_t\ *}
\DoxyCodeLine{00392\ lm3g\_template\_successors(ngram\_iter\_t\ *bitor)}
\DoxyCodeLine{00393\ \{}
\DoxyCodeLine{00394\ \ \ \ \ NGRAM\_MODEL\_TYPE\ *model\ =\ (NGRAM\_MODEL\_TYPE\ *)bitor-\/>model;}
\DoxyCodeLine{00395\ \ \ \ \ lm3g\_iter\_t\ *from\ =\ (lm3g\_iter\_t\ *)bitor;}
\DoxyCodeLine{00396\ \ \ \ \ lm3g\_iter\_t\ *itor\ =\ ckd\_calloc(1,\ \textcolor{keyword}{sizeof}(*itor));}
\DoxyCodeLine{00397\ }
\DoxyCodeLine{00398\ \ \ \ \ itor-\/>ug\ =\ from-\/>ug;}
\DoxyCodeLine{00399\ \ \ \ \ \textcolor{keywordflow}{switch}\ (bitor-\/>m)\ \{}
\DoxyCodeLine{00400\ \ \ \ \ \textcolor{keywordflow}{case}\ 0:}
\DoxyCodeLine{00401\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Next\ itor\ bigrams\ is\ the\ same\ as\ this\ itor\ bigram\ or}}
\DoxyCodeLine{00402\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ itor\ bigrams\ is\ more\ than\ total\ count.\ This\ means\ no\ successors\ */}}
\DoxyCodeLine{00403\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (((itor-\/>ug\ +\ 1)\ -\/\ model-\/>lm3g.unigrams\ <\ bitor-\/>model-\/>n\_counts[0]\ \&\&}
\DoxyCodeLine{00404\ \ \ \ \ \ \ \ \ \ \ \ \ itor-\/>ug-\/>bigrams\ ==\ (itor-\/>ug\ +\ 1)-\/>bigrams)\ ||\ }
\DoxyCodeLine{00405\ \ \ \ \ \ \ \ \ \ \ \ \ itor-\/>ug-\/>bigrams\ ==\ bitor-\/>model-\/>n\_counts[1])}
\DoxyCodeLine{00406\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ done;}
\DoxyCodeLine{00407\ \ \ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00408\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Start\ iterating\ from\ first\ bigram\ successor\ of\ from-\/>ug.\ */}}
\DoxyCodeLine{00409\ \ \ \ \ \ \ \ \ itor-\/>bg\ =\ model-\/>lm3g.bigrams\ +\ itor-\/>ug-\/>bigrams;}
\DoxyCodeLine{00410\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00411\ \ \ \ \ \textcolor{keywordflow}{case}\ 1:}
\DoxyCodeLine{00412\ \ \ \ \ \ \ \ \ itor-\/>bg\ =\ from-\/>bg;}
\DoxyCodeLine{00413\ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00414\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ This\ indicates\ no\ successors\ */}}
\DoxyCodeLine{00415\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (((itor-\/>bg\ +\ 1)\ -\/\ model-\/>lm3g.bigrams\ <\ bitor-\/>model-\/>n\_counts[1]\ \&\&}
\DoxyCodeLine{00416\ \ \ \ \ \ \ \ \ \ \ \ \ FIRST\_TG\ (model,\ itor-\/>bg\ -\/\ model-\/>lm3g.bigrams)\ ==\ }
\DoxyCodeLine{00417\ \ \ \ \ \ \ \ \ \ \ \ \ FIRST\_TG\ (model,\ (itor-\/>bg\ +\ 1)\ -\/\ model-\/>lm3g.bigrams))\ ||}
\DoxyCodeLine{00418\ \ \ \ \ \ \ \ \ \ \ \ \ FIRST\_TG\ (model,\ itor-\/>bg\ -\/\ model-\/>lm3g.bigrams)\ ==\ bitor-\/>model-\/>n\_counts[2])}
\DoxyCodeLine{00419\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ done;}
\DoxyCodeLine{00420\ \ \ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00421\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Start\ iterating\ from\ first\ trigram\ successor\ of\ from-\/>bg.\ */}}
\DoxyCodeLine{00422\ \ \ \ \ \ \ \ \ itor-\/>tg\ =\ (model-\/>lm3g.trigrams\ }
\DoxyCodeLine{00423\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ +\ FIRST\_TG(model,\ (itor-\/>bg\ -\/\ model-\/>lm3g.bigrams)));}
\DoxyCodeLine{00424\ \textcolor{preprocessor}{\#if\ 0}}
\DoxyCodeLine{00425\ \ \ \ \ \ \ \ \ printf(\textcolor{stringliteral}{"{}\%s\ \%s\ =>\ \%d\ (\%s)\(\backslash\)n"{}},}
\DoxyCodeLine{00426\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ model-\/>base.word\_str[itor-\/>ug\ -\/\ model-\/>lm3g.unigrams],}
\DoxyCodeLine{00427\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ model-\/>base.word\_str[itor-\/>bg-\/>wid],}
\DoxyCodeLine{00428\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ FIRST\_TG(model,\ (itor-\/>bg\ -\/\ model-\/>lm3g.bigrams)),}
\DoxyCodeLine{00429\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ model-\/>base.word\_str[itor-\/>tg-\/>wid]);}
\DoxyCodeLine{00430\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00431\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00432\ \ \ \ \ \textcolor{keywordflow}{case}\ 2:}
\DoxyCodeLine{00433\ \ \ \ \ \textcolor{keywordflow}{default}:}
\DoxyCodeLine{00434\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ All\ invalid!\ */}}
\DoxyCodeLine{00435\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ done;}
\DoxyCodeLine{00436\ \ \ \ \ \}}
\DoxyCodeLine{00437\ }
\DoxyCodeLine{00438\ \ \ \ \ ngram\_iter\_init((ngram\_iter\_t\ *)itor,\ bitor-\/>model,\ bitor-\/>m\ +\ 1,\ TRUE);}
\DoxyCodeLine{00439\ \ \ \ \ \textcolor{keywordflow}{return}\ (ngram\_iter\_t\ *)itor;}
\DoxyCodeLine{00440\ \ \ \ \ done:}
\DoxyCodeLine{00441\ \ \ \ \ \ \ \ \ ckd\_free(itor);}
\DoxyCodeLine{00442\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00443\ \}}
\DoxyCodeLine{00444\ }
\DoxyCodeLine{00445\ \textcolor{keyword}{static}\ int32\ \textcolor{keyword}{const}\ *}
\DoxyCodeLine{00446\ lm3g\_template\_iter\_get(ngram\_iter\_t\ *base,}
\DoxyCodeLine{00447\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ *out\_score,\ int32\ *out\_bowt)}
\DoxyCodeLine{00448\ \{}
\DoxyCodeLine{00449\ \ \ \ \ NGRAM\_MODEL\_TYPE\ *model\ =\ (NGRAM\_MODEL\_TYPE\ *)base-\/>model;}
\DoxyCodeLine{00450\ \ \ \ \ lm3g\_iter\_t\ *itor\ =\ (lm3g\_iter\_t\ *)base;}
\DoxyCodeLine{00451\ }
\DoxyCodeLine{00452\ \ \ \ \ base-\/>wids[0]\ =\ itor-\/>ug\ -\/\ model-\/>lm3g.unigrams;}
\DoxyCodeLine{00453\ \ \ \ \ \textcolor{keywordflow}{if}\ (itor-\/>bg)\ base-\/>wids[1]\ =\ itor-\/>bg-\/>wid;}
\DoxyCodeLine{00454\ \ \ \ \ \textcolor{keywordflow}{if}\ (itor-\/>tg)\ base-\/>wids[2]\ =\ itor-\/>tg-\/>wid;}
\DoxyCodeLine{00455\ \textcolor{preprocessor}{\#if\ 0}}
\DoxyCodeLine{00456\ \ \ \ \ printf(\textcolor{stringliteral}{"{}itor\_get:\ \%d\ \%d\ \%d\(\backslash\)n"{}},\ base-\/>wids[0],\ base-\/>wids[1],\ base-\/>wids[2]);}
\DoxyCodeLine{00457\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00458\ }
\DoxyCodeLine{00459\ \ \ \ \ \textcolor{keywordflow}{switch}\ (base-\/>m)\ \{}
\DoxyCodeLine{00460\ \ \ \ \ \textcolor{keywordflow}{case}\ 0:}
\DoxyCodeLine{00461\ \ \ \ \ \ \ \ \ *out\_score\ =\ itor-\/>ug-\/>prob1.l;}
\DoxyCodeLine{00462\ \ \ \ \ \ \ \ \ *out\_bowt\ =\ itor-\/>ug-\/>bo\_wt1.l;}
\DoxyCodeLine{00463\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00464\ \ \ \ \ \textcolor{keywordflow}{case}\ 1:}
\DoxyCodeLine{00465\ \ \ \ \ \ \ \ \ *out\_score\ =\ model-\/>lm3g.prob2[itor-\/>bg-\/>prob2].l;}
\DoxyCodeLine{00466\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (model-\/>lm3g.bo\_wt2)}
\DoxyCodeLine{00467\ \ \ \ \ \ \ \ \ \ \ \ \ *out\_bowt\ =\ model-\/>lm3g.bo\_wt2[itor-\/>bg-\/>bo\_wt2].l;}
\DoxyCodeLine{00468\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}}
\DoxyCodeLine{00469\ \ \ \ \ \ \ \ \ \ \ \ \ *out\_bowt\ =\ 0;}
\DoxyCodeLine{00470\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00471\ \ \ \ \ \textcolor{keywordflow}{case}\ 2:}
\DoxyCodeLine{00472\ \ \ \ \ \ \ \ \ *out\_score\ =\ model-\/>lm3g.prob3[itor-\/>tg-\/>prob3].l;}
\DoxyCodeLine{00473\ \ \ \ \ \ \ \ \ *out\_bowt\ =\ 0;}
\DoxyCodeLine{00474\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00475\ \ \ \ \ \textcolor{keywordflow}{default}:\ \textcolor{comment}{/*\ Should\ not\ happen.\ */}}
\DoxyCodeLine{00476\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00477\ \ \ \ \ \}}
\DoxyCodeLine{00478\ \ \ \ \ \textcolor{keywordflow}{return}\ base-\/>wids;}
\DoxyCodeLine{00479\ \}}
\DoxyCodeLine{00480\ }
\DoxyCodeLine{00481\ \textcolor{keyword}{static}\ ngram\_iter\_t\ *}
\DoxyCodeLine{00482\ lm3g\_template\_iter\_next(ngram\_iter\_t\ *base)}
\DoxyCodeLine{00483\ \{}
\DoxyCodeLine{00484\ \ \ \ \ NGRAM\_MODEL\_TYPE\ *model\ =\ (NGRAM\_MODEL\_TYPE\ *)base-\/>model;}
\DoxyCodeLine{00485\ \ \ \ \ lm3g\_iter\_t\ *itor\ =\ (lm3g\_iter\_t\ *)base;}
\DoxyCodeLine{00486\ }
\DoxyCodeLine{00487\ \ \ \ \ \textcolor{keywordflow}{switch}\ (base-\/>m)\ \{}
\DoxyCodeLine{00488\ \ \ \ \ \textcolor{keywordflow}{case}\ 0:}
\DoxyCodeLine{00489\ \ \ \ \ \ \ \ \ ++itor-\/>ug;}
\DoxyCodeLine{00490\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Check\ for\ end\ condition.\ */}}
\DoxyCodeLine{00491\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (itor-\/>ug\ -\/\ model-\/>lm3g.unigrams\ >=\ base-\/>model-\/>n\_counts[0])}
\DoxyCodeLine{00492\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ done;}
\DoxyCodeLine{00493\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00494\ \ \ \ \ \textcolor{keywordflow}{case}\ 1:}
\DoxyCodeLine{00495\ \ \ \ \ \ \ \ \ ++itor-\/>bg;}
\DoxyCodeLine{00496\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Check\ for\ end\ condition.\ */}}
\DoxyCodeLine{00497\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (itor-\/>bg\ -\/\ model-\/>lm3g.bigrams\ >=\ base-\/>model-\/>n\_counts[1])}
\DoxyCodeLine{00498\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ done;}
\DoxyCodeLine{00499\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Advance\ unigram\ pointer\ if\ necessary\ in\ order\ to\ get\ one}}
\DoxyCodeLine{00500\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ *\ that\ points\ to\ this\ bigram.\ */}}
\DoxyCodeLine{00501\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{while}\ (itor-\/>bg\ -\/\ model-\/>lm3g.bigrams\ >=\ itor-\/>ug[1].bigrams)\ \{}
\DoxyCodeLine{00502\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Stop\ if\ this\ is\ a\ successor\ iterator,\ since\ we\ don't}}
\DoxyCodeLine{00503\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ \ \ *\ want\ a\ new\ unigram.\ */}}
\DoxyCodeLine{00504\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (base-\/>successor)}
\DoxyCodeLine{00505\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ done;}
\DoxyCodeLine{00506\ \ \ \ \ \ \ \ \ \ \ \ \ ++itor-\/>ug;}
\DoxyCodeLine{00507\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (itor-\/>ug\ ==\ model-\/>lm3g.unigrams\ +\ base-\/>model-\/>n\_counts[0])\ \{}
\DoxyCodeLine{00508\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR(\textcolor{stringliteral}{"{}Bigram\ \%d\ has\ no\ valid\ unigram\ parent\(\backslash\)n"{}},}
\DoxyCodeLine{00509\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ itor-\/>bg\ -\/\ model-\/>lm3g.bigrams);}
\DoxyCodeLine{00510\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ done;}
\DoxyCodeLine{00511\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00512\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00513\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00514\ \ \ \ \ \textcolor{keywordflow}{case}\ 2:}
\DoxyCodeLine{00515\ \ \ \ \ \ \ \ \ ++itor-\/>tg;}
\DoxyCodeLine{00516\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Check\ for\ end\ condition.\ */}}
\DoxyCodeLine{00517\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (itor-\/>tg\ -\/\ model-\/>lm3g.trigrams\ >=\ base-\/>model-\/>n\_counts[2])}
\DoxyCodeLine{00518\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ done;}
\DoxyCodeLine{00519\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Advance\ bigram\ pointer\ if\ necessary.\ */}}
\DoxyCodeLine{00520\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{while}\ (itor-\/>tg\ -\/\ model-\/>lm3g.trigrams\ >=}
\DoxyCodeLine{00521\ \ \ \ \ \ \ \ \ \ \ \ \ FIRST\_TG(model,\ (itor-\/>bg\ -\/\ model-\/>lm3g.bigrams\ +\ 1)))\ \{}
\DoxyCodeLine{00522\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (base-\/>successor)}
\DoxyCodeLine{00523\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ done;}
\DoxyCodeLine{00524\ \ \ \ \ \ \ \ \ \ \ \ \ ++itor-\/>bg;}
\DoxyCodeLine{00525\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (itor-\/>bg\ ==\ model-\/>lm3g.bigrams\ +\ base-\/>model-\/>n\_counts[1])\ \{}
\DoxyCodeLine{00526\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR(\textcolor{stringliteral}{"{}Trigram\ \%d\ has\ no\ valid\ bigram\ parent\(\backslash\)n"{}},}
\DoxyCodeLine{00527\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ itor-\/>tg\ -\/\ model-\/>lm3g.trigrams);}
\DoxyCodeLine{00528\ }
\DoxyCodeLine{00529\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ done;}
\DoxyCodeLine{00530\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00531\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00532\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Advance\ unigram\ pointer\ if\ necessary.\ */}}
\DoxyCodeLine{00533\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{while}\ (itor-\/>bg\ -\/\ model-\/>lm3g.bigrams\ >=\ itor-\/>ug[1].bigrams)\ \{}
\DoxyCodeLine{00534\ \ \ \ \ \ \ \ \ \ \ \ \ ++itor-\/>ug;}
\DoxyCodeLine{00535\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (itor-\/>ug\ ==\ model-\/>lm3g.unigrams\ +\ base-\/>model-\/>n\_counts[0])\ \{}
\DoxyCodeLine{00536\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR(\textcolor{stringliteral}{"{}Trigram\ \%d\ has\ no\ valid\ unigram\ parent\(\backslash\)n"{}},}
\DoxyCodeLine{00537\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ itor-\/>tg\ -\/\ model-\/>lm3g.trigrams);}
\DoxyCodeLine{00538\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ done;}
\DoxyCodeLine{00539\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00540\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00541\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00542\ \ \ \ \ \textcolor{keywordflow}{default}:\ \textcolor{comment}{/*\ Should\ not\ happen.\ */}}
\DoxyCodeLine{00543\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ done;}
\DoxyCodeLine{00544\ \ \ \ \ \}}
\DoxyCodeLine{00545\ }
\DoxyCodeLine{00546\ \ \ \ \ \textcolor{keywordflow}{return}\ (ngram\_iter\_t\ *)itor;}
\DoxyCodeLine{00547\ done:}
\DoxyCodeLine{00548\ \ \ \ \ ngram\_iter\_free(base);}
\DoxyCodeLine{00549\ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00550\ \}}
\DoxyCodeLine{00551\ }
\DoxyCodeLine{00552\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00553\ lm3g\_template\_iter\_free(ngram\_iter\_t\ *base)}
\DoxyCodeLine{00554\ \{}
\DoxyCodeLine{00555\ \ \ \ \ ckd\_free(base);}
\DoxyCodeLine{00556\ \}}

\end{DoxyCode}
