\doxysection{sphinx\+\_\+lm\+\_\+convert.\+c}
\label{sphinx__lm__convert_8c_source}\index{src/sphinx\_lmtools/sphinx\_lm\_convert.c@{src/sphinx\_lmtools/sphinx\_lm\_convert.c}}
\textbf{ Go to the documentation of this file.}
\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)\ 2009\ 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{00041\ \textcolor{preprocessor}{\#include\ <sphinxbase/logmath.h>}}
\DoxyCodeLine{00042\ \textcolor{preprocessor}{\#include\ <sphinxbase/ngram\_model.h>}}
\DoxyCodeLine{00043\ \textcolor{preprocessor}{\#include\ <sphinxbase/cmd\_ln.h>}}
\DoxyCodeLine{00044\ \textcolor{preprocessor}{\#include\ <sphinxbase/ckd\_alloc.h>}}
\DoxyCodeLine{00045\ \textcolor{preprocessor}{\#include\ <sphinxbase/err.h>}}
\DoxyCodeLine{00046\ \textcolor{preprocessor}{\#include\ <sphinxbase/pio.h>}}
\DoxyCodeLine{00047\ \textcolor{preprocessor}{\#include\ <sphinxbase/strfuncs.h>}}
\DoxyCodeLine{00048\ }
\DoxyCodeLine{00049\ \textcolor{preprocessor}{\#include\ <stdio.h>}}
\DoxyCodeLine{00050\ \textcolor{preprocessor}{\#include\ <string.h>}}
\DoxyCodeLine{00051\ \textcolor{preprocessor}{\#include\ <math.h>}}
\DoxyCodeLine{00052\ }
\DoxyCodeLine{00053\ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ arg\_t\ defn[]\ =\ \{}
\DoxyCodeLine{00054\ \ \ \{\ \textcolor{stringliteral}{"{}-\/help"{}},}
\DoxyCodeLine{00055\ \ \ \ \ ARG\_BOOLEAN,}
\DoxyCodeLine{00056\ \ \ \ \ \textcolor{stringliteral}{"{}no"{}},}
\DoxyCodeLine{00057\ \ \ \ \ \textcolor{stringliteral}{"{}Shows\ the\ usage\ of\ the\ tool"{}}\},}
\DoxyCodeLine{00058\ }
\DoxyCodeLine{00059\ \ \ \{\ \textcolor{stringliteral}{"{}-\/logbase"{}},}
\DoxyCodeLine{00060\ \ \ \ \ ARG\_FLOAT64,}
\DoxyCodeLine{00061\ \ \ \ \ \textcolor{stringliteral}{"{}1.0001"{}},}
\DoxyCodeLine{00062\ \ \ \ \ \textcolor{stringliteral}{"{}Base\ in\ which\ all\ log-\/likelihoods\ calculated"{}}\ \},}
\DoxyCodeLine{00063\ }
\DoxyCodeLine{00064\ \ \ \{\ \textcolor{stringliteral}{"{}-\/i"{}},}
\DoxyCodeLine{00065\ \ \ \ \ REQARG\_STRING,}
\DoxyCodeLine{00066\ \ \ \ \ NULL,}
\DoxyCodeLine{00067\ \ \ \ \ \textcolor{stringliteral}{"{}Input\ language\ model\ file\ (required)"{}}\},}
\DoxyCodeLine{00068\ }
\DoxyCodeLine{00069\ \ \ \{\ \textcolor{stringliteral}{"{}-\/o"{}},}
\DoxyCodeLine{00070\ \ \ \ \ REQARG\_STRING,}
\DoxyCodeLine{00071\ \ \ \ \ NULL,}
\DoxyCodeLine{00072\ \ \ \ \ \textcolor{stringliteral}{"{}Output\ language\ model\ file\ (required)"{}}\},}
\DoxyCodeLine{00073\ }
\DoxyCodeLine{00074\ \ \ \{\ \textcolor{stringliteral}{"{}-\/ifmt"{}},}
\DoxyCodeLine{00075\ \ \ \ \ ARG\_STRING,}
\DoxyCodeLine{00076\ \ \ \ \ NULL,}
\DoxyCodeLine{00077\ \ \ \ \ \textcolor{stringliteral}{"{}Input\ language\ model\ format\ (will\ guess\ if\ not\ specified)"{}}\},}
\DoxyCodeLine{00078\ }
\DoxyCodeLine{00079\ \ \ \{\ \textcolor{stringliteral}{"{}-\/ofmt"{}},}
\DoxyCodeLine{00080\ \ \ \ \ ARG\_STRING,}
\DoxyCodeLine{00081\ \ \ \ \ NULL,}
\DoxyCodeLine{00082\ \ \ \ \ \textcolor{stringliteral}{"{}Output\ language\ model\ file\ (will\ guess\ if\ not\ specified)"{}}\},}
\DoxyCodeLine{00083\ }
\DoxyCodeLine{00084\ \ \ \{\ \textcolor{stringliteral}{"{}-\/ienc"{}},}
\DoxyCodeLine{00085\ \ \ \ \ ARG\_STRING,}
\DoxyCodeLine{00086\ \ \ \ \ NULL,}
\DoxyCodeLine{00087\ \ \ \ \ \textcolor{stringliteral}{"{}Input\ language\ model\ text\ encoding\ (no\ conversion\ done\ if\ not\ specified)"{}}\},}
\DoxyCodeLine{00088\ }
\DoxyCodeLine{00089\ \ \ \{\ \textcolor{stringliteral}{"{}-\/oenc"{}},}
\DoxyCodeLine{00090\ \ \ \ \ ARG\_STRING,}
\DoxyCodeLine{00091\ \ \ \ \ \textcolor{stringliteral}{"{}utf8"{}},}
\DoxyCodeLine{00092\ \ \ \ \ \textcolor{stringliteral}{"{}Output\ language\ model\ text\ encoding"{}}\},}
\DoxyCodeLine{00093\ }
\DoxyCodeLine{00094\ \ \ \{\ \textcolor{stringliteral}{"{}-\/case"{}},}
\DoxyCodeLine{00095\ \ \ \ \ ARG\_STRING,}
\DoxyCodeLine{00096\ \ \ \ \ NULL,}
\DoxyCodeLine{00097\ \ \ \ \ \textcolor{stringliteral}{"{}Ether\ 'lower'\ or\ 'upper'\ -\/\ case\ fold\ to\ lower/upper\ case\ (NOT\ UNICODE\ AWARE)"{}}\ \},}
\DoxyCodeLine{00098\ }
\DoxyCodeLine{00099\ \ \ \{\ \textcolor{stringliteral}{"{}-\/mmap"{}},}
\DoxyCodeLine{00100\ \ \ \ \ ARG\_BOOLEAN,}
\DoxyCodeLine{00101\ \ \ \ \ \textcolor{stringliteral}{"{}no"{}},}
\DoxyCodeLine{00102\ \ \ \ \ \textcolor{stringliteral}{"{}Use\ memory-\/mapped\ I/O\ for\ reading\ binary\ LM\ files"{}}\},}
\DoxyCodeLine{00103\ }
\DoxyCodeLine{00104\ \ \ \{\ \textcolor{stringliteral}{"{}-\/debug"{}},}
\DoxyCodeLine{00105\ \ \ \ \ ARG\_INT32,}
\DoxyCodeLine{00106\ \ \ \ \ NULL,}
\DoxyCodeLine{00107\ \ \ \ \ \textcolor{stringliteral}{"{}Verbosity\ level\ for\ debugging\ messages"{}}}
\DoxyCodeLine{00108\ \ \ \},}
\DoxyCodeLine{00109\ }
\DoxyCodeLine{00110\ \ \ \{\ NULL,\ 0,\ NULL,\ NULL\ \}}
\DoxyCodeLine{00111\ \};}
\DoxyCodeLine{00112\ }
\DoxyCodeLine{00113\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00114\ usagemsg(\textcolor{keywordtype}{char}\ *pgm)}
\DoxyCodeLine{00115\ \{}
\DoxyCodeLine{00116\ \ \ \ \ E\_INFO(\textcolor{stringliteral}{"{}Usage:\ \%s\ -\/i\ <input.lm>\ \(\backslash\)\(\backslash\)\(\backslash\)n"{}},\ pgm);}
\DoxyCodeLine{00117\ \ \ \ \ E\_INFOCONT(\textcolor{stringliteral}{"{}\(\backslash\)t[-\/ifmt\ txt]\ [-\/ofmt\ dmp]\(\backslash\)n"{}});}
\DoxyCodeLine{00118\ \ \ \ \ E\_INFOCONT(\textcolor{stringliteral}{"{}\(\backslash\)t-\/o\ <output.lm.DMP>\(\backslash\)n"{}});}
\DoxyCodeLine{00119\ }
\DoxyCodeLine{00120\ \ \ \ \ exit(0);}
\DoxyCodeLine{00121\ \}}
\DoxyCodeLine{00122\ }
\DoxyCodeLine{00123\ }
\DoxyCodeLine{00124\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{00125\ main(\textcolor{keywordtype}{int}\ argc,\ \textcolor{keywordtype}{char}\ *argv[])}
\DoxyCodeLine{00126\ \{}
\DoxyCodeLine{00127\ \ \ \ \ \ \ \ \ cmd\_ln\_t\ *config;}
\DoxyCodeLine{00128\ \ \ \ \ \ \ \ \ ngram\_model\_t\ *lm\ =\ NULL;}
\DoxyCodeLine{00129\ \ \ \ \ \ \ \ \ logmath\_t\ *lmath;}
\DoxyCodeLine{00130\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ itype,\ otype;}
\DoxyCodeLine{00131\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{char}\ \textcolor{keyword}{const}\ *kase;}
\DoxyCodeLine{00132\ }
\DoxyCodeLine{00133\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((config\ =\ cmd\_ln\_parse\_r(NULL,\ defn,\ argc,\ argv,\ TRUE))\ ==\ NULL)}
\DoxyCodeLine{00134\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 1;}
\DoxyCodeLine{00135\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00136\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (cmd\_ln\_boolean\_r(config,\ \textcolor{stringliteral}{"{}-\/help"{}}))\ \{}
\DoxyCodeLine{00137\ \ \ \ \ \ \ \ \ \ \ \ \ usagemsg(argv[0]);}
\DoxyCodeLine{00138\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00139\ }
\DoxyCodeLine{00140\ \ \ \ \ \ \ \ \ err\_set\_debug\_level(cmd\_ln\_int32\_r(config,\ \textcolor{stringliteral}{"{}-\/debug"{}}));}
\DoxyCodeLine{00141\ }
\DoxyCodeLine{00142\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Create\ log\ math\ object.\ */}}
\DoxyCodeLine{00143\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((lmath\ =\ logmath\_init}
\DoxyCodeLine{00144\ \ \ \ \ \ \ \ \ \ \ \ \ \ (cmd\_ln\_float64\_r(config,\ \textcolor{stringliteral}{"{}-\/logbase"{}}),\ 0,\ 0))\ ==\ NULL)\ \{}
\DoxyCodeLine{00145\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ E\_FATAL(\textcolor{stringliteral}{"{}Failed\ to\ initialize\ log\ math\(\backslash\)n"{}});}
\DoxyCodeLine{00146\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00147\ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00148\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (cmd\_ln\_str\_r(config,\ \textcolor{stringliteral}{"{}-\/i"{}})\ ==\ NULL\ ||\ cmd\_ln\_str\_r(config,\ \textcolor{stringliteral}{"{}-\/i"{}})\ ==\ NULL)\ \{}
\DoxyCodeLine{00149\ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR(\textcolor{stringliteral}{"{}Please\ specify\ both\ input\ and\ output\ models\(\backslash\)n"{}});}
\DoxyCodeLine{00150\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ error\_out;}
\DoxyCodeLine{00151\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00152\ \ \ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00153\ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00154\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Load\ the\ input\ language\ model.\ */}}
\DoxyCodeLine{00155\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (cmd\_ln\_str\_r(config,\ \textcolor{stringliteral}{"{}-\/ifmt"{}}))\ \{}
\DoxyCodeLine{00156\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((itype\ =\ ngram\_str\_to\_type(cmd\_ln\_str\_r(config,\ \textcolor{stringliteral}{"{}-\/ifmt"{}})))}
\DoxyCodeLine{00157\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ==\ NGRAM\_INVALID)\ \{}
\DoxyCodeLine{00158\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR(\textcolor{stringliteral}{"{}Invalid\ input\ type\ \%s\(\backslash\)n"{}},\ cmd\_ln\_str\_r(config,\ \textcolor{stringliteral}{"{}-\/ifmt"{}}));}
\DoxyCodeLine{00159\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ error\_out;}
\DoxyCodeLine{00160\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00161\ \ \ \ \ \ \ \ \ \ \ \ \ lm\ =\ ngram\_model\_read(config,\ cmd\_ln\_str\_r(config,\ \textcolor{stringliteral}{"{}-\/i"{}}),}
\DoxyCodeLine{00162\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ itype,\ lmath);}
\DoxyCodeLine{00163\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00164\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00165\ \ \ \ \ \ \ \ \ \ \ \ \ lm\ =\ ngram\_model\_read(config,\ cmd\_ln\_str\_r(config,\ \textcolor{stringliteral}{"{}-\/i"{}}),}
\DoxyCodeLine{00166\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ NGRAM\_AUTO,\ lmath);}
\DoxyCodeLine{00167\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00168\ }
\DoxyCodeLine{00169\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (lm\ ==\ NULL)\ \{}
\DoxyCodeLine{00170\ \ \ \ \ \ \ \ \ \ \ \ \ E\_FATAL(\textcolor{stringliteral}{"{}Failed\ to\ read\ the\ model\ from\ the\ file\ '\%s'"{}},\ cmd\_ln\_str\_r(config,\ \textcolor{stringliteral}{"{}-\/i"{}}));}
\DoxyCodeLine{00171\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00172\ }
\DoxyCodeLine{00173\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Guess\ or\ set\ the\ output\ language\ model\ type.\ */}}
\DoxyCodeLine{00174\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (cmd\_ln\_str\_r(config,\ \textcolor{stringliteral}{"{}-\/ofmt"{}}))\ \{}
\DoxyCodeLine{00175\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((otype\ =\ ngram\_str\_to\_type(cmd\_ln\_str\_r(config,\ \textcolor{stringliteral}{"{}-\/ofmt"{}})))}
\DoxyCodeLine{00176\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ==\ NGRAM\_INVALID)\ \{}
\DoxyCodeLine{00177\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR(\textcolor{stringliteral}{"{}Invalid\ output\ type\ \%s\(\backslash\)n"{}},\ cmd\_ln\_str\_r(config,\ \textcolor{stringliteral}{"{}-\/ofmt"{}}));}
\DoxyCodeLine{00178\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ error\_out;}
\DoxyCodeLine{00179\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00180\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00181\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00182\ \ \ \ \ \ \ \ \ \ \ \ \ otype\ =\ ngram\_file\_name\_to\_type(cmd\_ln\_str\_r(config,\ \textcolor{stringliteral}{"{}-\/o"{}}));}
\DoxyCodeLine{00183\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00184\ }
\DoxyCodeLine{00185\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Recode\ the\ language\ model\ if\ desired.\ */}}
\DoxyCodeLine{00186\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (cmd\_ln\_str\_r(config,\ \textcolor{stringliteral}{"{}-\/ienc"{}}))\ \{}
\DoxyCodeLine{00187\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (ngram\_model\_recode(lm,\ cmd\_ln\_str\_r(config,\ \textcolor{stringliteral}{"{}-\/ienc"{}}),}
\DoxyCodeLine{00188\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ cmd\_ln\_str\_r(config,\ \textcolor{stringliteral}{"{}-\/oenc"{}}))\ !=\ 0)\ \{}
\DoxyCodeLine{00189\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR(\textcolor{stringliteral}{"{}Failed\ to\ recode\ language\ model\ from\ \%s\ to\ \%s\(\backslash\)n"{}},}
\DoxyCodeLine{00190\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ cmd\_ln\_str\_r(config,\ \textcolor{stringliteral}{"{}-\/ienc"{}}),}
\DoxyCodeLine{00191\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ cmd\_ln\_str\_r(config,\ \textcolor{stringliteral}{"{}-\/oenc"{}}));}
\DoxyCodeLine{00192\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ error\_out;}
\DoxyCodeLine{00193\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00194\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00195\ }
\DoxyCodeLine{00196\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Case\ fold\ if\ requested.\ */}}
\DoxyCodeLine{00197\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((kase\ =\ cmd\_ln\_str\_r(config,\ \textcolor{stringliteral}{"{}-\/case"{}})))\ \{}
\DoxyCodeLine{00198\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (0\ ==\ strcmp(kase,\ \textcolor{stringliteral}{"{}lower"{}}))\ \{}
\DoxyCodeLine{00199\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ngram\_model\_casefold(lm,\ NGRAM\_LOWER);}
\DoxyCodeLine{00200\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00201\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (0\ ==\ strcmp(kase,\ \textcolor{stringliteral}{"{}upper"{}}))\ \{}
\DoxyCodeLine{00202\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ngram\_model\_casefold(lm,\ NGRAM\_UPPER);}
\DoxyCodeLine{00203\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00204\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00205\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR(\textcolor{stringliteral}{"{}Unknown\ value\ for\ -\/case:\ \%s\(\backslash\)n"{}},\ kase);}
\DoxyCodeLine{00206\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ error\_out;}
\DoxyCodeLine{00207\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00208\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00209\ }
\DoxyCodeLine{00210\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Write\ the\ output\ language\ model.\ */}}
\DoxyCodeLine{00211\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (ngram\_model\_write(lm,\ cmd\_ln\_str\_r(config,\ \textcolor{stringliteral}{"{}-\/o"{}}),\ otype)\ !=\ 0)\ \{}
\DoxyCodeLine{00212\ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR(\textcolor{stringliteral}{"{}Failed\ to\ write\ language\ model\ in\ format\ \%s\ to\ \%s\(\backslash\)n"{}},}
\DoxyCodeLine{00213\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ngram\_type\_to\_str(otype),\ cmd\_ln\_str\_r(config,\ \textcolor{stringliteral}{"{}-\/o"{}}));}
\DoxyCodeLine{00214\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ error\_out;}
\DoxyCodeLine{00215\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00216\ }
\DoxyCodeLine{00217\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ That's\ all\ folks!\ */}}
\DoxyCodeLine{00218\ \ \ \ \ \ \ \ \ ngram\_model\_free(lm);}
\DoxyCodeLine{00219\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00220\ }
\DoxyCodeLine{00221\ error\_out:}
\DoxyCodeLine{00222\ \ \ \ \ \ \ \ \ ngram\_model\_free(lm);}
\DoxyCodeLine{00223\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 1;}
\DoxyCodeLine{00224\ \}}

\end{DoxyCode}
