Sophie

Sophie

distrib > Fedora > 14 > x86_64 > by-pkgid > 56b1fde4ed0e5f3d153fe0391e13cdf1 > files > 31

pocketsphinx-devel-0.7-1.fc14.x86_64.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>PocketSphinx: src/libpocketsphinx/dict.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript">
$(document).ready(initResizable);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.7.3 -->
<div id="top">
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">PocketSphinx&#160;<span id="projectnumber">0.6</span></div>
  </td>
 </tr>
 </tbody>
</table>
</div>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('dict_8c.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<h1>src/libpocketsphinx/dict.c</h1>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */</span>
<a name="l00002"></a>00002 <span class="comment">/* ====================================================================</span>
<a name="l00003"></a>00003 <span class="comment"> * Copyright (c) 1999-2004 Carnegie Mellon University.  All rights</span>
<a name="l00004"></a>00004 <span class="comment"> * reserved.</span>
<a name="l00005"></a>00005 <span class="comment"> *</span>
<a name="l00006"></a>00006 <span class="comment"> * Redistribution and use in source and binary forms, with or without</span>
<a name="l00007"></a>00007 <span class="comment"> * modification, are permitted provided that the following conditions</span>
<a name="l00008"></a>00008 <span class="comment"> * are met:</span>
<a name="l00009"></a>00009 <span class="comment"> *</span>
<a name="l00010"></a>00010 <span class="comment"> * 1. Redistributions of source code must retain the above copyright</span>
<a name="l00011"></a>00011 <span class="comment"> *    notice, this list of conditions and the following disclaimer. </span>
<a name="l00012"></a>00012 <span class="comment"> *</span>
<a name="l00013"></a>00013 <span class="comment"> * 2. Redistributions in binary form must reproduce the above copyright</span>
<a name="l00014"></a>00014 <span class="comment"> *    notice, this list of conditions and the following disclaimer in</span>
<a name="l00015"></a>00015 <span class="comment"> *    the documentation and/or other materials provided with the</span>
<a name="l00016"></a>00016 <span class="comment"> *    distribution.</span>
<a name="l00017"></a>00017 <span class="comment"> *</span>
<a name="l00018"></a>00018 <span class="comment"> * This work was supported in part by funding from the Defense Advanced </span>
<a name="l00019"></a>00019 <span class="comment"> * Research Projects Agency and the National Science Foundation of the </span>
<a name="l00020"></a>00020 <span class="comment"> * United States of America, and the CMU Sphinx Speech Consortium.</span>
<a name="l00021"></a>00021 <span class="comment"> *</span>
<a name="l00022"></a>00022 <span class="comment"> * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS&#39;&#39; AND </span>
<a name="l00023"></a>00023 <span class="comment"> * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, </span>
<a name="l00024"></a>00024 <span class="comment"> * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR</span>
<a name="l00025"></a>00025 <span class="comment"> * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY</span>
<a name="l00026"></a>00026 <span class="comment"> * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,</span>
<a name="l00027"></a>00027 <span class="comment"> * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT </span>
<a name="l00028"></a>00028 <span class="comment"> * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, </span>
<a name="l00029"></a>00029 <span class="comment"> * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY </span>
<a name="l00030"></a>00030 <span class="comment"> * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT </span>
<a name="l00031"></a>00031 <span class="comment"> * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE </span>
<a name="l00032"></a>00032 <span class="comment"> * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>
<a name="l00033"></a>00033 <span class="comment"> *</span>
<a name="l00034"></a>00034 <span class="comment"> * ====================================================================</span>
<a name="l00035"></a>00035 <span class="comment"> *</span>
<a name="l00036"></a>00036 <span class="comment"> */</span>
<a name="l00037"></a>00037 
<a name="l00038"></a>00038 <span class="comment">/* System headers. */</span>
<a name="l00039"></a>00039 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00040"></a>00040 
<a name="l00041"></a>00041 <span class="comment">/* SphinxBase headers. */</span>
<a name="l00042"></a>00042 <span class="preprocessor">#include &lt;sphinxbase/pio.h&gt;</span>
<a name="l00043"></a>00043 <span class="preprocessor">#include &lt;sphinxbase/strfuncs.h&gt;</span>
<a name="l00044"></a>00044 
<a name="l00045"></a>00045 <span class="comment">/* Local headers. */</span>
<a name="l00046"></a>00046 <span class="preprocessor">#include &quot;<a class="code" href="dict_8h.html" title="Operations on dictionary.">dict.h</a>&quot;</span>
<a name="l00047"></a>00047 
<a name="l00048"></a>00048 
<a name="l00049"></a>00049 <span class="preprocessor">#define DELIM   &quot; \t\n&quot;         </span><span class="comment">/* Set of field separator characters */</span>
<a name="l00050"></a>00050 <span class="preprocessor">#define DEFAULT_NUM_PHONE       (MAX_S3CIPID+1)</span>
<a name="l00051"></a>00051 <span class="preprocessor"></span>
<a name="l00052"></a>00052 <span class="preprocessor">#if WIN32</span>
<a name="l00053"></a>00053 <span class="preprocessor"></span><span class="preprocessor">#define snprintf sprintf_s</span>
<a name="l00054"></a>00054 <span class="preprocessor"></span><span class="preprocessor">#endif </span>
<a name="l00055"></a>00055 <span class="preprocessor"></span>
<a name="l00056"></a>00056 <span class="keyword">extern</span> <span class="keyword">const</span> <span class="keywordtype">char</span> *<span class="keyword">const</span> cmu6_lts_phone_table[];
<a name="l00057"></a>00057 
<a name="l00058"></a>00058 <span class="keyword">static</span> <a class="code" href="s3types_8h.html#ae5f70241ce62a79747f0611029a6409d" title="Size definitions for more semantially meaningful units.">s3cipid_t</a>
<a name="l00059"></a>00059 dict_ciphone_id(<a class="code" href="structdict__t.html" title="a structure for a dictionary.">dict_t</a> * d, <span class="keyword">const</span> <span class="keywordtype">char</span> *str)
<a name="l00060"></a>00060 {
<a name="l00061"></a>00061     <span class="keywordflow">if</span> (d-&gt;nocase)
<a name="l00062"></a>00062         <span class="keywordflow">return</span> bin_mdef_ciphone_id_nocase(d-&gt;<a class="code" href="structdict__t.html#a3a01eb5a3ebda5652d434be26e0cfdd2" title="Model definition used for phone IDs; NULL if none used.">mdef</a>, str);
<a name="l00063"></a>00063     <span class="keywordflow">else</span>
<a name="l00064"></a>00064         <span class="keywordflow">return</span> bin_mdef_ciphone_id(d-&gt;<a class="code" href="structdict__t.html#a3a01eb5a3ebda5652d434be26e0cfdd2" title="Model definition used for phone IDs; NULL if none used.">mdef</a>, str);
<a name="l00065"></a>00065 }
<a name="l00066"></a>00066 
<a name="l00067"></a>00067 
<a name="l00068"></a>00068 <span class="keyword">const</span> <span class="keywordtype">char</span> *
<a name="l00069"></a><a class="code" href="dict_8h.html#a8587d077f5303554df0e26a181bfb0bf">00069</a> dict_ciphone_str(<a class="code" href="structdict__t.html" title="a structure for a dictionary.">dict_t</a> * d, s3wid_t wid, int32 pos)
<a name="l00070"></a>00070 {
<a name="l00071"></a>00071     assert(d != NULL);
<a name="l00072"></a>00072     assert((wid &gt;= 0) &amp;&amp; (wid &lt; d-&gt;n_word));
<a name="l00073"></a>00073     assert((pos &gt;= 0) &amp;&amp; (pos &lt; d-&gt;word[wid].pronlen));
<a name="l00074"></a>00074 
<a name="l00075"></a>00075     <span class="keywordflow">return</span> bin_mdef_ciphone_str(d-&gt;<a class="code" href="structdict__t.html#a3a01eb5a3ebda5652d434be26e0cfdd2" title="Model definition used for phone IDs; NULL if none used.">mdef</a>, d-&gt;<a class="code" href="structdict__t.html#a9e6636bbe45936a03381fea430addd31" title="Array of entries in dictionary.">word</a>[wid].<a class="code" href="structdictword__t.html#acf5836b5a681485868e9090ad67366d5" title="Pronunciation.">ciphone</a>[pos]);
<a name="l00076"></a>00076 }
<a name="l00077"></a>00077 
<a name="l00078"></a>00078 
<a name="l00079"></a>00079 s3wid_t
<a name="l00080"></a><a class="code" href="dict_8h.html#a24888ac8e24259e553c43c4655b38432">00080</a> dict_add_word(<a class="code" href="structdict__t.html" title="a structure for a dictionary.">dict_t</a> * d, <span class="keywordtype">char</span> <span class="keyword">const</span> *word, <a class="code" href="s3types_8h.html#ae5f70241ce62a79747f0611029a6409d" title="Size definitions for more semantially meaningful units.">s3cipid_t</a> <span class="keyword">const</span> * p, int32 np)
<a name="l00081"></a>00081 {
<a name="l00082"></a>00082     int32 len;
<a name="l00083"></a>00083     <a class="code" href="structdictword__t.html" title="a structure for one dictionary word.">dictword_t</a> *wordp;
<a name="l00084"></a>00084     s3wid_t newwid;
<a name="l00085"></a>00085     <span class="keywordtype">char</span> *wword;
<a name="l00086"></a>00086 
<a name="l00087"></a>00087     <span class="keywordflow">if</span> (d-&gt;<a class="code" href="structdict__t.html#af00f60319a7025361e291af5addb6b31" title="#Occupied entries in dict; ie, excluding empty slots">n_word</a> &gt;= d-&gt;<a class="code" href="structdict__t.html#af6142600cef73f846b58ba9bc36b02ac" title="#Entries allocated in dict, including empty slots">max_words</a>) {
<a name="l00088"></a>00088         E_INFO(<span class="stringliteral">&quot;Reallocating to %d KiB for word entries\n&quot;</span>,
<a name="l00089"></a>00089                (d-&gt;<a class="code" href="structdict__t.html#af6142600cef73f846b58ba9bc36b02ac" title="#Entries allocated in dict, including empty slots">max_words</a> + S3DICT_INC_SZ) * <span class="keyword">sizeof</span>(<a class="code" href="structdictword__t.html" title="a structure for one dictionary word.">dictword_t</a>) / 1024);
<a name="l00090"></a>00090         d-&gt;<a class="code" href="structdict__t.html#a9e6636bbe45936a03381fea430addd31" title="Array of entries in dictionary.">word</a> =
<a name="l00091"></a>00091             (<a class="code" href="structdictword__t.html" title="a structure for one dictionary word.">dictword_t</a> *) ckd_realloc(d-&gt;<a class="code" href="structdict__t.html#a9e6636bbe45936a03381fea430addd31" title="Array of entries in dictionary.">word</a>,
<a name="l00092"></a>00092                                        (d-&gt;<a class="code" href="structdict__t.html#af6142600cef73f846b58ba9bc36b02ac" title="#Entries allocated in dict, including empty slots">max_words</a> +
<a name="l00093"></a>00093                                         S3DICT_INC_SZ) * <span class="keyword">sizeof</span>(<a class="code" href="structdictword__t.html" title="a structure for one dictionary word.">dictword_t</a>));
<a name="l00094"></a>00094         d-&gt;<a class="code" href="structdict__t.html#af6142600cef73f846b58ba9bc36b02ac" title="#Entries allocated in dict, including empty slots">max_words</a> = d-&gt;<a class="code" href="structdict__t.html#af6142600cef73f846b58ba9bc36b02ac" title="#Entries allocated in dict, including empty slots">max_words</a> + S3DICT_INC_SZ;
<a name="l00095"></a>00095         <span class="keywordflow">return</span> <a class="code" href="s3types_8h.html#a5c42410b7125da611210c5a4be29898b" title="Dictionary word id.">BAD_S3WID</a>;
<a name="l00096"></a>00096     }
<a name="l00097"></a>00097 
<a name="l00098"></a>00098     wordp = d-&gt;<a class="code" href="structdict__t.html#a9e6636bbe45936a03381fea430addd31" title="Array of entries in dictionary.">word</a> + d-&gt;<a class="code" href="structdict__t.html#af00f60319a7025361e291af5addb6b31" title="#Occupied entries in dict; ie, excluding empty slots">n_word</a>;
<a name="l00099"></a>00099     wordp-&gt;<a class="code" href="structdictword__t.html#a3f3371918a406e26817bd4f2cecd7329" title="Ascii word string.">word</a> = (<span class="keywordtype">char</span> *) ckd_salloc(word);    <span class="comment">/* Freed in dict_free */</span>
<a name="l00100"></a>00100 
<a name="l00101"></a>00101     <span class="comment">/* Associate word string with d-&gt;n_word in hash table */</span>
<a name="l00102"></a>00102     <span class="keywordflow">if</span> (hash_table_enter_int32(d-&gt;<a class="code" href="structdict__t.html#a7205aae4fbeef3aaa53f94b6af529af2" title="Hash table for mapping word strings to word ids.">ht</a>, wordp-&gt;<a class="code" href="structdictword__t.html#a3f3371918a406e26817bd4f2cecd7329" title="Ascii word string.">word</a>, d-&gt;<a class="code" href="structdict__t.html#af00f60319a7025361e291af5addb6b31" title="#Occupied entries in dict; ie, excluding empty slots">n_word</a>) != d-&gt;<a class="code" href="structdict__t.html#af00f60319a7025361e291af5addb6b31" title="#Occupied entries in dict; ie, excluding empty slots">n_word</a>) {
<a name="l00103"></a>00103         ckd_free(wordp-&gt;<a class="code" href="structdictword__t.html#a3f3371918a406e26817bd4f2cecd7329" title="Ascii word string.">word</a>);
<a name="l00104"></a>00104         wordp-&gt;<a class="code" href="structdictword__t.html#a3f3371918a406e26817bd4f2cecd7329" title="Ascii word string.">word</a> = NULL;
<a name="l00105"></a>00105         <span class="keywordflow">return</span> <a class="code" href="s3types_8h.html#a5c42410b7125da611210c5a4be29898b" title="Dictionary word id.">BAD_S3WID</a>;
<a name="l00106"></a>00106     }
<a name="l00107"></a>00107 
<a name="l00108"></a>00108     <span class="comment">/* Fill in word entry, and set defaults */</span>
<a name="l00109"></a>00109     <span class="keywordflow">if</span> (p &amp;&amp; (np &gt; 0)) {
<a name="l00110"></a>00110         wordp-&gt;<a class="code" href="structdictword__t.html#acf5836b5a681485868e9090ad67366d5" title="Pronunciation.">ciphone</a> = (<a class="code" href="s3types_8h.html#ae5f70241ce62a79747f0611029a6409d" title="Size definitions for more semantially meaningful units.">s3cipid_t</a> *) ckd_malloc(np * <span class="keyword">sizeof</span>(<a class="code" href="s3types_8h.html#ae5f70241ce62a79747f0611029a6409d" title="Size definitions for more semantially meaningful units.">s3cipid_t</a>));      <span class="comment">/* Freed in dict_free */</span>
<a name="l00111"></a>00111         memcpy(wordp-&gt;<a class="code" href="structdictword__t.html#acf5836b5a681485868e9090ad67366d5" title="Pronunciation.">ciphone</a>, p, np * <span class="keyword">sizeof</span>(<a class="code" href="s3types_8h.html#ae5f70241ce62a79747f0611029a6409d" title="Size definitions for more semantially meaningful units.">s3cipid_t</a>));
<a name="l00112"></a>00112         wordp-&gt;<a class="code" href="structdictword__t.html#a50509f28a4b64d76519bfadea12f0fa0" title="Pronunciation length.">pronlen</a> = np;
<a name="l00113"></a>00113     }
<a name="l00114"></a>00114     <span class="keywordflow">else</span> {
<a name="l00115"></a>00115         wordp-&gt;<a class="code" href="structdictword__t.html#acf5836b5a681485868e9090ad67366d5" title="Pronunciation.">ciphone</a> = NULL;
<a name="l00116"></a>00116         wordp-&gt;<a class="code" href="structdictword__t.html#a50509f28a4b64d76519bfadea12f0fa0" title="Pronunciation length.">pronlen</a> = 0;
<a name="l00117"></a>00117     }
<a name="l00118"></a>00118     wordp-&gt;<a class="code" href="structdictword__t.html#a84b63cd03706221645f46b2da09e9540" title="Next alternative pronunciation id, NOT_S3WID if none.">alt</a> = <a class="code" href="s3types_8h.html#a5c42410b7125da611210c5a4be29898b" title="Dictionary word id.">BAD_S3WID</a>;
<a name="l00119"></a>00119     wordp-&gt;<a class="code" href="structdictword__t.html#a53dd72f96a9de21d8925e246cc7c036f" title="Base pronunciation id.">basewid</a> = d-&gt;<a class="code" href="structdict__t.html#af00f60319a7025361e291af5addb6b31" title="#Occupied entries in dict; ie, excluding empty slots">n_word</a>;
<a name="l00120"></a>00120 
<a name="l00121"></a>00121     <span class="comment">/* Determine base/alt wids */</span>
<a name="l00122"></a>00122     wword = ckd_salloc(word);
<a name="l00123"></a>00123     <span class="keywordflow">if</span> ((len = dict_word2basestr(wword)) &gt; 0) {
<a name="l00124"></a>00124         int32 w;
<a name="l00125"></a>00125 
<a name="l00126"></a>00126         <span class="comment">/* Truncated to a baseword string; find its ID */</span>
<a name="l00127"></a>00127         <span class="keywordflow">if</span> (hash_table_lookup_int32(d-&gt;<a class="code" href="structdict__t.html#a7205aae4fbeef3aaa53f94b6af529af2" title="Hash table for mapping word strings to word ids.">ht</a>, wword, &amp;w) &lt; 0) {
<a name="l00128"></a>00128             E_ERROR(<span class="stringliteral">&quot;Missing base word for: %s\n&quot;</span>, word);
<a name="l00129"></a>00129             ckd_free(wword);
<a name="l00130"></a>00130             ckd_free(wordp-&gt;<a class="code" href="structdictword__t.html#a3f3371918a406e26817bd4f2cecd7329" title="Ascii word string.">word</a>);
<a name="l00131"></a>00131             wordp-&gt;<a class="code" href="structdictword__t.html#a3f3371918a406e26817bd4f2cecd7329" title="Ascii word string.">word</a> = NULL;
<a name="l00132"></a>00132             <span class="keywordflow">return</span> <a class="code" href="s3types_8h.html#a5c42410b7125da611210c5a4be29898b" title="Dictionary word id.">BAD_S3WID</a>;
<a name="l00133"></a>00133         }
<a name="l00134"></a>00134 
<a name="l00135"></a>00135         <span class="comment">/* Link into alt list */</span>
<a name="l00136"></a>00136         wordp-&gt;<a class="code" href="structdictword__t.html#a53dd72f96a9de21d8925e246cc7c036f" title="Base pronunciation id.">basewid</a> = w;
<a name="l00137"></a>00137         wordp-&gt;<a class="code" href="structdictword__t.html#a84b63cd03706221645f46b2da09e9540" title="Next alternative pronunciation id, NOT_S3WID if none.">alt</a> = d-&gt;<a class="code" href="structdict__t.html#a9e6636bbe45936a03381fea430addd31" title="Array of entries in dictionary.">word</a>[w].<a class="code" href="structdictword__t.html#a84b63cd03706221645f46b2da09e9540" title="Next alternative pronunciation id, NOT_S3WID if none.">alt</a>;
<a name="l00138"></a>00138         d-&gt;<a class="code" href="structdict__t.html#a9e6636bbe45936a03381fea430addd31" title="Array of entries in dictionary.">word</a>[w].<a class="code" href="structdictword__t.html#a84b63cd03706221645f46b2da09e9540" title="Next alternative pronunciation id, NOT_S3WID if none.">alt</a> = d-&gt;<a class="code" href="structdict__t.html#af00f60319a7025361e291af5addb6b31" title="#Occupied entries in dict; ie, excluding empty slots">n_word</a>;
<a name="l00139"></a>00139     }
<a name="l00140"></a>00140     ckd_free(wword);
<a name="l00141"></a>00141 
<a name="l00142"></a>00142     newwid = d-&gt;<a class="code" href="structdict__t.html#af00f60319a7025361e291af5addb6b31" title="#Occupied entries in dict; ie, excluding empty slots">n_word</a>++;
<a name="l00143"></a>00143 
<a name="l00144"></a>00144     <span class="keywordflow">return</span> newwid;
<a name="l00145"></a>00145 }
<a name="l00146"></a>00146 
<a name="l00147"></a>00147 
<a name="l00148"></a>00148 <span class="keyword">static</span> int32
<a name="l00149"></a>00149 dict_read(FILE * fp, <a class="code" href="structdict__t.html" title="a structure for a dictionary.">dict_t</a> * d)
<a name="l00150"></a>00150 {
<a name="l00151"></a>00151     lineiter_t *li;
<a name="l00152"></a>00152     <span class="keywordtype">char</span> **wptr;
<a name="l00153"></a>00153     <a class="code" href="s3types_8h.html#ae5f70241ce62a79747f0611029a6409d" title="Size definitions for more semantially meaningful units.">s3cipid_t</a> *p;
<a name="l00154"></a>00154     int32 lineno, nwd;
<a name="l00155"></a>00155     s3wid_t w;
<a name="l00156"></a>00156     int32 i, maxwd;
<a name="l00157"></a>00157     <span class="keywordtype">size_t</span> stralloc, phnalloc;
<a name="l00158"></a>00158 
<a name="l00159"></a>00159     maxwd = 512;
<a name="l00160"></a>00160     p = (<a class="code" href="s3types_8h.html#ae5f70241ce62a79747f0611029a6409d" title="Size definitions for more semantially meaningful units.">s3cipid_t</a> *) ckd_calloc(maxwd + 4, <span class="keyword">sizeof</span>(*p));
<a name="l00161"></a>00161     wptr = (<span class="keywordtype">char</span> **) ckd_calloc(maxwd, <span class="keyword">sizeof</span>(<span class="keywordtype">char</span> *)); <span class="comment">/* Freed below */</span>
<a name="l00162"></a>00162 
<a name="l00163"></a>00163     lineno = 0;
<a name="l00164"></a>00164     stralloc = phnalloc = 0;
<a name="l00165"></a>00165     <span class="keywordflow">for</span> (li = lineiter_start(fp); li; li = lineiter_next(li)) {
<a name="l00166"></a>00166         lineno++;
<a name="l00167"></a>00167         <span class="keywordflow">if</span> (0 == strncmp(li-&gt;buf, <span class="stringliteral">&quot;##&quot;</span>, 2)
<a name="l00168"></a>00168             || 0 == strncmp(li-&gt;buf, <span class="stringliteral">&quot;;;&quot;</span>, 2))
<a name="l00169"></a>00169             <span class="keywordflow">continue</span>;
<a name="l00170"></a>00170 
<a name="l00171"></a>00171         <span class="keywordflow">if</span> ((nwd = str2words(li-&gt;buf, wptr, maxwd)) &lt; 0) {
<a name="l00172"></a>00172             <span class="comment">/* Increase size of p, wptr. */</span>
<a name="l00173"></a>00173             nwd = str2words(li-&gt;buf, NULL, 0);
<a name="l00174"></a>00174             assert(nwd &gt; maxwd); <span class="comment">/* why else would it fail? */</span>
<a name="l00175"></a>00175             maxwd = nwd;
<a name="l00176"></a>00176             p = (<a class="code" href="s3types_8h.html#ae5f70241ce62a79747f0611029a6409d" title="Size definitions for more semantially meaningful units.">s3cipid_t</a> *) ckd_realloc(p, (maxwd + 4) * <span class="keyword">sizeof</span>(*p));
<a name="l00177"></a>00177             wptr = (<span class="keywordtype">char</span> **) ckd_realloc(wptr, maxwd * <span class="keyword">sizeof</span>(*wptr));
<a name="l00178"></a>00178         }
<a name="l00179"></a>00179 
<a name="l00180"></a>00180         <span class="keywordflow">if</span> (nwd == 0)           <span class="comment">/* Empty line */</span>
<a name="l00181"></a>00181             <span class="keywordflow">continue</span>;
<a name="l00182"></a>00182         <span class="comment">/* wptr[0] is the word-string and wptr[1..nwd-1] the pronunciation sequence */</span>
<a name="l00183"></a>00183         <span class="keywordflow">if</span> (nwd == 1) {
<a name="l00184"></a>00184             E_ERROR(<span class="stringliteral">&quot;Line %d: No pronunciation for word &#39;%s&#39;; ignored\n&quot;</span>,
<a name="l00185"></a>00185                     lineno, wptr[0]);
<a name="l00186"></a>00186             <span class="keywordflow">continue</span>;
<a name="l00187"></a>00187         }
<a name="l00188"></a>00188 
<a name="l00189"></a>00189 
<a name="l00190"></a>00190         <span class="comment">/* Convert pronunciation string to CI-phone-ids */</span>
<a name="l00191"></a>00191         <span class="keywordflow">for</span> (i = 1; i &lt; nwd; i++) {
<a name="l00192"></a>00192             p[i - 1] = dict_ciphone_id(d, wptr[i]);
<a name="l00193"></a>00193             <span class="keywordflow">if</span> (NOT_S3CIPID(p[i - 1])) {
<a name="l00194"></a>00194                 E_ERROR(<span class="stringliteral">&quot;Line %d: Phone &#39;%s&#39; is mising in the acoustic model; word &#39;%s&#39; ignored\n&quot;</span>,
<a name="l00195"></a>00195                         lineno, wptr[i], wptr[0]);
<a name="l00196"></a>00196                 <span class="keywordflow">break</span>;
<a name="l00197"></a>00197             }
<a name="l00198"></a>00198         }
<a name="l00199"></a>00199 
<a name="l00200"></a>00200         <span class="keywordflow">if</span> (i == nwd) {         <span class="comment">/* All CI-phones successfully converted to IDs */</span>
<a name="l00201"></a>00201             w = dict_add_word(d, wptr[0], p, nwd - 1);
<a name="l00202"></a>00202             <span class="keywordflow">if</span> (NOT_S3WID(w))
<a name="l00203"></a>00203                 E_ERROR
<a name="l00204"></a>00204                     (<span class="stringliteral">&quot;Line %d: Failed to add the word &#39;%s&#39; (duplicate?); ignored\n&quot;</span>,
<a name="l00205"></a>00205                      lineno, wptr[0]);
<a name="l00206"></a>00206             <span class="keywordflow">else</span> {
<a name="l00207"></a>00207                 stralloc += strlen(d-&gt;<a class="code" href="structdict__t.html#a9e6636bbe45936a03381fea430addd31" title="Array of entries in dictionary.">word</a>[w].<a class="code" href="structdictword__t.html#a3f3371918a406e26817bd4f2cecd7329" title="Ascii word string.">word</a>);
<a name="l00208"></a>00208                 phnalloc += d-&gt;<a class="code" href="structdict__t.html#a9e6636bbe45936a03381fea430addd31" title="Array of entries in dictionary.">word</a>[w].<a class="code" href="structdictword__t.html#a50509f28a4b64d76519bfadea12f0fa0" title="Pronunciation length.">pronlen</a> * <span class="keyword">sizeof</span>(<a class="code" href="s3types_8h.html#ae5f70241ce62a79747f0611029a6409d" title="Size definitions for more semantially meaningful units.">s3cipid_t</a>);
<a name="l00209"></a>00209             }
<a name="l00210"></a>00210         }
<a name="l00211"></a>00211     }
<a name="l00212"></a>00212     E_INFO(<span class="stringliteral">&quot;Allocated %d KiB for strings, %d KiB for phones\n&quot;</span>,
<a name="l00213"></a>00213            (<span class="keywordtype">int</span>)stralloc / 1024, (<span class="keywordtype">int</span>)phnalloc / 1024);
<a name="l00214"></a>00214     ckd_free(p);
<a name="l00215"></a>00215     ckd_free(wptr);
<a name="l00216"></a>00216 
<a name="l00217"></a>00217     <span class="keywordflow">return</span> 0;
<a name="l00218"></a>00218 }
<a name="l00219"></a>00219 
<a name="l00220"></a>00220 <span class="keywordtype">int</span>
<a name="l00221"></a><a class="code" href="dict_8h.html#a4bfa8e3b7b9ff30165375d1c97bb04b8">00221</a> dict_write(<a class="code" href="structdict__t.html" title="a structure for a dictionary.">dict_t</a> *dict, <span class="keywordtype">char</span> <span class="keyword">const</span> *filename, <span class="keywordtype">char</span> <span class="keyword">const</span> *format)
<a name="l00222"></a>00222 {
<a name="l00223"></a>00223     FILE *fh;
<a name="l00224"></a>00224     <span class="keywordtype">int</span> i;
<a name="l00225"></a>00225 
<a name="l00226"></a>00226     <span class="keywordflow">if</span> ((fh = fopen(filename, <span class="stringliteral">&quot;w&quot;</span>)) == NULL) {
<a name="l00227"></a>00227         E_ERROR_SYSTEM(<span class="stringliteral">&quot;Failed to open &#39;%s&#39;&quot;</span>, filename);
<a name="l00228"></a>00228         <span class="keywordflow">return</span> -1;
<a name="l00229"></a>00229     }
<a name="l00230"></a>00230     <span class="keywordflow">for</span> (i = 0; i &lt; dict-&gt;<a class="code" href="structdict__t.html#af00f60319a7025361e291af5addb6b31" title="#Occupied entries in dict; ie, excluding empty slots">n_word</a>; ++i) {
<a name="l00231"></a>00231         <span class="keywordtype">char</span> *phones;
<a name="l00232"></a>00232         <span class="keywordtype">int</span> j, phlen;
<a name="l00233"></a>00233         <span class="keywordflow">if</span> (!dict_real_word(dict, i))
<a name="l00234"></a>00234             <span class="keywordflow">continue</span>;
<a name="l00235"></a>00235         <span class="keywordflow">for</span> (phlen = j = 0; j &lt; dict_pronlen(dict, i); ++j)
<a name="l00236"></a>00236             phlen += strlen(dict_ciphone_str(dict, i, j)) + 1;
<a name="l00237"></a>00237         phones = ckd_calloc(1, phlen);
<a name="l00238"></a>00238         <span class="keywordflow">for</span> (j = 0; j &lt; dict_pronlen(dict, i); ++j) {
<a name="l00239"></a>00239             strcat(phones, dict_ciphone_str(dict, i, j));
<a name="l00240"></a>00240             <span class="keywordflow">if</span> (j != dict_pronlen(dict, i) - 1)
<a name="l00241"></a>00241                 strcat(phones, <span class="stringliteral">&quot; &quot;</span>);
<a name="l00242"></a>00242         }
<a name="l00243"></a>00243         fprintf(fh, <span class="stringliteral">&quot;%-30s %s\n&quot;</span>, dict_wordstr(dict, i), phones);
<a name="l00244"></a>00244         ckd_free(phones);
<a name="l00245"></a>00245     }
<a name="l00246"></a>00246     fclose(fh);
<a name="l00247"></a>00247     <span class="keywordflow">return</span> 0;
<a name="l00248"></a>00248 }
<a name="l00249"></a>00249 
<a name="l00250"></a>00250 
<a name="l00251"></a>00251 <a class="code" href="structdict__t.html" title="a structure for a dictionary.">dict_t</a> *
<a name="l00252"></a><a class="code" href="dict_8h.html#a05d8dac3e5fe5399ccb8bf7776e203e2">00252</a> dict_init(cmd_ln_t *config, <a class="code" href="structbin__mdef__s.html">bin_mdef_t</a> * mdef)
<a name="l00253"></a>00253 {
<a name="l00254"></a>00254     FILE *fp, *fp2;
<a name="l00255"></a>00255     int32 n;
<a name="l00256"></a>00256     lineiter_t *li;
<a name="l00257"></a>00257     <a class="code" href="structdict__t.html" title="a structure for a dictionary.">dict_t</a> *d;
<a name="l00258"></a>00258     <a class="code" href="s3types_8h.html#ae5f70241ce62a79747f0611029a6409d" title="Size definitions for more semantially meaningful units.">s3cipid_t</a> sil;
<a name="l00259"></a>00259     <span class="keywordtype">char</span> <span class="keyword">const</span> *dictfile = NULL, *fillerfile = NULL;
<a name="l00260"></a>00260 
<a name="l00261"></a>00261     <span class="keywordflow">if</span> (config) {
<a name="l00262"></a>00262         dictfile = cmd_ln_str_r(config, <span class="stringliteral">&quot;-dict&quot;</span>);
<a name="l00263"></a>00263         fillerfile = cmd_ln_str_r(config, <span class="stringliteral">&quot;-fdict&quot;</span>);
<a name="l00264"></a>00264     }
<a name="l00265"></a>00265 
<a name="l00266"></a>00266     <span class="comment">/*</span>
<a name="l00267"></a>00267 <span class="comment">     * First obtain #words in dictionary (for hash table allocation).</span>
<a name="l00268"></a>00268 <span class="comment">     * Reason: The PC NT system doesn&#39;t like to grow memory gradually.  Better to allocate</span>
<a name="l00269"></a>00269 <span class="comment">     * all the required memory in one go.</span>
<a name="l00270"></a>00270 <span class="comment">     */</span>
<a name="l00271"></a>00271     fp = NULL;
<a name="l00272"></a>00272     n = 0;
<a name="l00273"></a>00273     <span class="keywordflow">if</span> (dictfile) {
<a name="l00274"></a>00274         <span class="keywordflow">if</span> ((fp = fopen(dictfile, <span class="stringliteral">&quot;r&quot;</span>)) == NULL)
<a name="l00275"></a>00275             E_FATAL_SYSTEM(<span class="stringliteral">&quot;Failed to open dictionary file &#39;%s&#39; for reading&quot;</span>, dictfile);
<a name="l00276"></a>00276         <span class="keywordflow">for</span> (li = lineiter_start(fp); li; li = lineiter_next(li)) {
<a name="l00277"></a>00277             <span class="keywordflow">if</span> (li-&gt;buf[0] != <span class="charliteral">&#39;#&#39;</span>)
<a name="l00278"></a>00278                 n++;
<a name="l00279"></a>00279         }
<a name="l00280"></a>00280         rewind(fp);
<a name="l00281"></a>00281     }
<a name="l00282"></a>00282 
<a name="l00283"></a>00283     fp2 = NULL;
<a name="l00284"></a>00284     <span class="keywordflow">if</span> (fillerfile) {
<a name="l00285"></a>00285         <span class="keywordflow">if</span> ((fp2 = fopen(fillerfile, <span class="stringliteral">&quot;r&quot;</span>)) == NULL)
<a name="l00286"></a>00286             E_FATAL_SYSTEM(<span class="stringliteral">&quot;Failed to open filler dictionary file &#39;%s&#39; for reading&quot;</span>, fillerfile);
<a name="l00287"></a>00287         <span class="keywordflow">for</span> (li = lineiter_start(fp2); li; li = lineiter_next(li)) {
<a name="l00288"></a>00288             <span class="keywordflow">if</span> (li-&gt;buf[0] != <span class="charliteral">&#39;#&#39;</span>)
<a name="l00289"></a>00289                 n++;
<a name="l00290"></a>00290         }
<a name="l00291"></a>00291         rewind(fp2);
<a name="l00292"></a>00292     }
<a name="l00293"></a>00293 
<a name="l00294"></a>00294     <span class="comment">/*</span>
<a name="l00295"></a>00295 <span class="comment">     * Allocate dict entries.  HACK!!  Allow some extra entries for words not in file.</span>
<a name="l00296"></a>00296 <span class="comment">     * Also check for type size restrictions.</span>
<a name="l00297"></a>00297 <span class="comment">     */</span>
<a name="l00298"></a>00298     d = (<a class="code" href="structdict__t.html" title="a structure for a dictionary.">dict_t</a> *) ckd_calloc(1, <span class="keyword">sizeof</span>(<a class="code" href="structdict__t.html" title="a structure for a dictionary.">dict_t</a>));       <span class="comment">/* freed in dict_free() */</span>
<a name="l00299"></a>00299     d-&gt;refcnt = 1;
<a name="l00300"></a>00300     d-&gt;<a class="code" href="structdict__t.html#af6142600cef73f846b58ba9bc36b02ac" title="#Entries allocated in dict, including empty slots">max_words</a> =
<a name="l00301"></a>00301         (n + S3DICT_INC_SZ &lt; MAX_S3WID) ? n + S3DICT_INC_SZ : MAX_S3WID;
<a name="l00302"></a>00302     <span class="keywordflow">if</span> (n &gt;= MAX_S3WID)
<a name="l00303"></a>00303         E_FATAL(<span class="stringliteral">&quot;Number of words in dictionaries (%d) exceeds limit (%d)\n&quot;</span>, n,
<a name="l00304"></a>00304                 MAX_S3WID);
<a name="l00305"></a>00305 
<a name="l00306"></a>00306     E_INFO(<span class="stringliteral">&quot;Allocating %d * %d bytes (%d KiB) for word entries\n&quot;</span>,
<a name="l00307"></a>00307            d-&gt;<a class="code" href="structdict__t.html#af6142600cef73f846b58ba9bc36b02ac" title="#Entries allocated in dict, including empty slots">max_words</a>, <span class="keyword">sizeof</span>(<a class="code" href="structdictword__t.html" title="a structure for one dictionary word.">dictword_t</a>),
<a name="l00308"></a>00308            d-&gt;<a class="code" href="structdict__t.html#af6142600cef73f846b58ba9bc36b02ac" title="#Entries allocated in dict, including empty slots">max_words</a> * <span class="keyword">sizeof</span>(<a class="code" href="structdictword__t.html" title="a structure for one dictionary word.">dictword_t</a>) / 1024);
<a name="l00309"></a>00309     d-&gt;<a class="code" href="structdict__t.html#a9e6636bbe45936a03381fea430addd31" title="Array of entries in dictionary.">word</a> = (<a class="code" href="structdictword__t.html" title="a structure for one dictionary word.">dictword_t</a> *) ckd_calloc(d-&gt;<a class="code" href="structdict__t.html#af6142600cef73f846b58ba9bc36b02ac" title="#Entries allocated in dict, including empty slots">max_words</a>, <span class="keyword">sizeof</span>(<a class="code" href="structdictword__t.html" title="a structure for one dictionary word.">dictword_t</a>));      <span class="comment">/* freed in dict_free() */</span>
<a name="l00310"></a>00310     d-&gt;<a class="code" href="structdict__t.html#af00f60319a7025361e291af5addb6b31" title="#Occupied entries in dict; ie, excluding empty slots">n_word</a> = 0;
<a name="l00311"></a>00311     <span class="keywordflow">if</span> (mdef)
<a name="l00312"></a>00312         d-&gt;<a class="code" href="structdict__t.html#a3a01eb5a3ebda5652d434be26e0cfdd2" title="Model definition used for phone IDs; NULL if none used.">mdef</a> = bin_mdef_retain(mdef);
<a name="l00313"></a>00313 
<a name="l00314"></a>00314     <span class="comment">/* Create new hash table for word strings; case-insensitive word strings */</span>
<a name="l00315"></a>00315     <span class="keywordflow">if</span> (config &amp;&amp; cmd_ln_exists_r(config, <span class="stringliteral">&quot;-dictcase&quot;</span>))
<a name="l00316"></a>00316         d-&gt;nocase = cmd_ln_boolean_r(config, <span class="stringliteral">&quot;-dictcase&quot;</span>);
<a name="l00317"></a>00317     d-&gt;<a class="code" href="structdict__t.html#a7205aae4fbeef3aaa53f94b6af529af2" title="Hash table for mapping word strings to word ids.">ht</a> = hash_table_new(d-&gt;<a class="code" href="structdict__t.html#af6142600cef73f846b58ba9bc36b02ac" title="#Entries allocated in dict, including empty slots">max_words</a>, d-&gt;nocase);
<a name="l00318"></a>00318 
<a name="l00319"></a>00319     <span class="comment">/* Digest main dictionary file */</span>
<a name="l00320"></a>00320     <span class="keywordflow">if</span> (fp) {
<a name="l00321"></a>00321         E_INFO(<span class="stringliteral">&quot;Reading main dictionary: %s\n&quot;</span>, dictfile);
<a name="l00322"></a>00322         dict_read(fp, d);
<a name="l00323"></a>00323         fclose(fp);
<a name="l00324"></a>00324         E_INFO(<span class="stringliteral">&quot;%d words read\n&quot;</span>, d-&gt;<a class="code" href="structdict__t.html#af00f60319a7025361e291af5addb6b31" title="#Occupied entries in dict; ie, excluding empty slots">n_word</a>);
<a name="l00325"></a>00325     }
<a name="l00326"></a>00326 
<a name="l00327"></a>00327     <span class="comment">/* Now the filler dictionary file, if it exists */</span>
<a name="l00328"></a>00328     d-&gt;<a class="code" href="structdict__t.html#abd48fdafaaa68a8df2fd82163c51a95c" title="First filler word id (read from filler dict)">filler_start</a> = d-&gt;<a class="code" href="structdict__t.html#af00f60319a7025361e291af5addb6b31" title="#Occupied entries in dict; ie, excluding empty slots">n_word</a>;
<a name="l00329"></a>00329     <span class="keywordflow">if</span> (fillerfile) {
<a name="l00330"></a>00330         E_INFO(<span class="stringliteral">&quot;Reading filler dictionary: %s\n&quot;</span>, fillerfile);
<a name="l00331"></a>00331         dict_read(fp2, d);
<a name="l00332"></a>00332         fclose(fp2);
<a name="l00333"></a>00333         E_INFO(<span class="stringliteral">&quot;%d words read\n&quot;</span>, d-&gt;<a class="code" href="structdict__t.html#af00f60319a7025361e291af5addb6b31" title="#Occupied entries in dict; ie, excluding empty slots">n_word</a> - d-&gt;<a class="code" href="structdict__t.html#abd48fdafaaa68a8df2fd82163c51a95c" title="First filler word id (read from filler dict)">filler_start</a>);
<a name="l00334"></a>00334     }
<a name="l00335"></a>00335     <span class="keywordflow">if</span> (mdef)
<a name="l00336"></a>00336         sil = bin_mdef_silphone(mdef);
<a name="l00337"></a>00337     <span class="keywordflow">else</span>
<a name="l00338"></a>00338         sil = 0;
<a name="l00339"></a>00339     <span class="keywordflow">if</span> (dict_wordid(d, S3_START_WORD) == <a class="code" href="s3types_8h.html#a5c42410b7125da611210c5a4be29898b" title="Dictionary word id.">BAD_S3WID</a>) {
<a name="l00340"></a>00340         dict_add_word(d, S3_START_WORD, &amp;sil, 1);
<a name="l00341"></a>00341     }
<a name="l00342"></a>00342     <span class="keywordflow">if</span> (dict_wordid(d, S3_FINISH_WORD) == <a class="code" href="s3types_8h.html#a5c42410b7125da611210c5a4be29898b" title="Dictionary word id.">BAD_S3WID</a>) {
<a name="l00343"></a>00343         dict_add_word(d, S3_FINISH_WORD, &amp;sil, 1);
<a name="l00344"></a>00344     }
<a name="l00345"></a>00345     <span class="keywordflow">if</span> (dict_wordid(d, S3_SILENCE_WORD) == <a class="code" href="s3types_8h.html#a5c42410b7125da611210c5a4be29898b" title="Dictionary word id.">BAD_S3WID</a>) {
<a name="l00346"></a>00346         dict_add_word(d, S3_SILENCE_WORD, &amp;sil, 1);
<a name="l00347"></a>00347     }
<a name="l00348"></a>00348 
<a name="l00349"></a>00349     d-&gt;<a class="code" href="structdict__t.html#a77c6692e56308968804add1292275cb7" title="Last filler word id (read from filler dict)">filler_end</a> = d-&gt;<a class="code" href="structdict__t.html#af00f60319a7025361e291af5addb6b31" title="#Occupied entries in dict; ie, excluding empty slots">n_word</a> - 1;
<a name="l00350"></a>00350 
<a name="l00351"></a>00351     <span class="comment">/* Initialize distinguished word-ids */</span>
<a name="l00352"></a>00352     d-&gt;<a class="code" href="structdict__t.html#a22bc6c52ce9e04c4f3f7d0ba1972ee51" title="FOR INTERNAL-USE ONLY.">startwid</a> = dict_wordid(d, S3_START_WORD);
<a name="l00353"></a>00353     d-&gt;<a class="code" href="structdict__t.html#a3875be5336e2d9888f6d5cb83ded82c5" title="FOR INTERNAL-USE ONLY.">finishwid</a> = dict_wordid(d, S3_FINISH_WORD);
<a name="l00354"></a>00354     d-&gt;<a class="code" href="structdict__t.html#aad07b22b94c360923f151c02890f6e68" title="FOR INTERNAL-USE ONLY.">silwid</a> = dict_wordid(d, S3_SILENCE_WORD);
<a name="l00355"></a>00355 
<a name="l00356"></a>00356     <span class="keywordflow">if</span> ((d-&gt;<a class="code" href="structdict__t.html#abd48fdafaaa68a8df2fd82163c51a95c" title="First filler word id (read from filler dict)">filler_start</a> &gt; d-&gt;<a class="code" href="structdict__t.html#a77c6692e56308968804add1292275cb7" title="Last filler word id (read from filler dict)">filler_end</a>)
<a name="l00357"></a>00357         || (!dict_filler_word(d, d-&gt;<a class="code" href="structdict__t.html#aad07b22b94c360923f151c02890f6e68" title="FOR INTERNAL-USE ONLY.">silwid</a>)))
<a name="l00358"></a>00358         E_FATAL(<span class="stringliteral">&quot;Word &#39;%s&#39; must occur (only) in filler dictionary\n&quot;</span>,
<a name="l00359"></a>00359                 S3_SILENCE_WORD);
<a name="l00360"></a>00360 
<a name="l00361"></a>00361     <span class="comment">/* No check that alternative pronunciations for filler words are in filler range!! */</span>
<a name="l00362"></a>00362 
<a name="l00363"></a>00363     <span class="keywordflow">return</span> d;
<a name="l00364"></a>00364 }
<a name="l00365"></a>00365 
<a name="l00366"></a>00366 
<a name="l00367"></a>00367 s3wid_t
<a name="l00368"></a><a class="code" href="dict_8h.html#ad3729eb1a02a9a321e17933f7e90c80e">00368</a> dict_wordid(<a class="code" href="structdict__t.html" title="a structure for a dictionary.">dict_t</a> *d, <span class="keyword">const</span> <span class="keywordtype">char</span> *word)
<a name="l00369"></a>00369 {
<a name="l00370"></a>00370     int32 w;
<a name="l00371"></a>00371 
<a name="l00372"></a>00372     assert(d);
<a name="l00373"></a>00373     assert(word);
<a name="l00374"></a>00374 
<a name="l00375"></a>00375     <span class="keywordflow">if</span> (hash_table_lookup_int32(d-&gt;<a class="code" href="structdict__t.html#a7205aae4fbeef3aaa53f94b6af529af2" title="Hash table for mapping word strings to word ids.">ht</a>, word, &amp;w) &lt; 0)
<a name="l00376"></a>00376         <span class="keywordflow">return</span> (<a class="code" href="s3types_8h.html#a5c42410b7125da611210c5a4be29898b" title="Dictionary word id.">BAD_S3WID</a>);
<a name="l00377"></a>00377     <span class="keywordflow">return</span> w;
<a name="l00378"></a>00378 }
<a name="l00379"></a>00379 
<a name="l00380"></a>00380 
<a name="l00381"></a>00381 <span class="keywordtype">int</span>
<a name="l00382"></a><a class="code" href="dict_8h.html#aa5cade4dc6464c620718b86344540aff">00382</a> dict_filler_word(<a class="code" href="structdict__t.html" title="a structure for a dictionary.">dict_t</a> *d, s3wid_t w)
<a name="l00383"></a>00383 {
<a name="l00384"></a>00384     assert(d);
<a name="l00385"></a>00385     assert((w &gt;= 0) &amp;&amp; (w &lt; d-&gt;n_word));
<a name="l00386"></a>00386 
<a name="l00387"></a>00387     w = dict_basewid(d, w);
<a name="l00388"></a>00388     <span class="keywordflow">if</span> ((w == d-&gt;<a class="code" href="structdict__t.html#a22bc6c52ce9e04c4f3f7d0ba1972ee51" title="FOR INTERNAL-USE ONLY.">startwid</a>) || (w == d-&gt;<a class="code" href="structdict__t.html#a3875be5336e2d9888f6d5cb83ded82c5" title="FOR INTERNAL-USE ONLY.">finishwid</a>))
<a name="l00389"></a>00389         <span class="keywordflow">return</span> 0;
<a name="l00390"></a>00390     <span class="keywordflow">if</span> ((w &gt;= d-&gt;<a class="code" href="structdict__t.html#abd48fdafaaa68a8df2fd82163c51a95c" title="First filler word id (read from filler dict)">filler_start</a>) &amp;&amp; (w &lt;= d-&gt;filler_end))
<a name="l00391"></a>00391         <span class="keywordflow">return</span> 1;
<a name="l00392"></a>00392     <span class="keywordflow">return</span> 0;
<a name="l00393"></a>00393 }
<a name="l00394"></a>00394 
<a name="l00395"></a>00395 <span class="keywordtype">int</span>
<a name="l00396"></a><a class="code" href="dict_8h.html#ad2eba4ca92dd1a3721608e003d95d8c1">00396</a> dict_real_word(<a class="code" href="structdict__t.html" title="a structure for a dictionary.">dict_t</a> *d, s3wid_t w)
<a name="l00397"></a>00397 {
<a name="l00398"></a>00398     assert(d);
<a name="l00399"></a>00399     assert((w &gt;= 0) &amp;&amp; (w &lt; d-&gt;n_word));
<a name="l00400"></a>00400 
<a name="l00401"></a>00401     w = dict_basewid(d, w);
<a name="l00402"></a>00402     <span class="keywordflow">if</span> ((w == d-&gt;<a class="code" href="structdict__t.html#a22bc6c52ce9e04c4f3f7d0ba1972ee51" title="FOR INTERNAL-USE ONLY.">startwid</a>) || (w == d-&gt;<a class="code" href="structdict__t.html#a3875be5336e2d9888f6d5cb83ded82c5" title="FOR INTERNAL-USE ONLY.">finishwid</a>))
<a name="l00403"></a>00403         <span class="keywordflow">return</span> 0;
<a name="l00404"></a>00404     <span class="keywordflow">if</span> ((w &gt;= d-&gt;<a class="code" href="structdict__t.html#abd48fdafaaa68a8df2fd82163c51a95c" title="First filler word id (read from filler dict)">filler_start</a>) &amp;&amp; (w &lt;= d-&gt;filler_end))
<a name="l00405"></a>00405         <span class="keywordflow">return</span> 0;
<a name="l00406"></a>00406     <span class="keywordflow">return</span> 1;
<a name="l00407"></a>00407 }
<a name="l00408"></a>00408 
<a name="l00409"></a>00409 
<a name="l00410"></a>00410 int32
<a name="l00411"></a><a class="code" href="dict_8h.html#a3a128531ae9c077be9882119ed05fe3a">00411</a> dict_word2basestr(<span class="keywordtype">char</span> *word)
<a name="l00412"></a>00412 {
<a name="l00413"></a>00413     int32 i, len;
<a name="l00414"></a>00414 
<a name="l00415"></a>00415     len = strlen(word);
<a name="l00416"></a>00416     <span class="keywordflow">if</span> (word[len - 1] == <span class="charliteral">&#39;)&#39;</span>) {
<a name="l00417"></a>00417         <span class="keywordflow">for</span> (i = len - 2; (i &gt; 0) &amp;&amp; (word[i] != <span class="charliteral">&#39;(&#39;</span>); --i);
<a name="l00418"></a>00418 
<a name="l00419"></a>00419         <span class="keywordflow">if</span> (i &gt; 0) {
<a name="l00420"></a>00420             <span class="comment">/* The word is of the form &lt;baseword&gt;(...); strip from left-paren */</span>
<a name="l00421"></a>00421             word[i] = <span class="charliteral">&#39;\0&#39;</span>;
<a name="l00422"></a>00422             <span class="keywordflow">return</span> i;
<a name="l00423"></a>00423         }
<a name="l00424"></a>00424     }
<a name="l00425"></a>00425 
<a name="l00426"></a>00426     <span class="keywordflow">return</span> -1;
<a name="l00427"></a>00427 }
<a name="l00428"></a>00428 
<a name="l00429"></a>00429 <a class="code" href="structdict__t.html" title="a structure for a dictionary.">dict_t</a> *
<a name="l00430"></a><a class="code" href="dict_8h.html#a0edf70be186e8940af9d21243083cb8b">00430</a> dict_retain(<a class="code" href="structdict__t.html" title="a structure for a dictionary.">dict_t</a> *d)
<a name="l00431"></a>00431 {
<a name="l00432"></a>00432     ++d-&gt;refcnt;
<a name="l00433"></a>00433     <span class="keywordflow">return</span> d;
<a name="l00434"></a>00434 }
<a name="l00435"></a>00435 
<a name="l00436"></a>00436 <span class="keywordtype">int</span>
<a name="l00437"></a><a class="code" href="dict_8h.html#a51ee6c067decce8dbc182f95f7b33e91">00437</a> dict_free(<a class="code" href="structdict__t.html" title="a structure for a dictionary.">dict_t</a> * d)
<a name="l00438"></a>00438 {
<a name="l00439"></a>00439     <span class="keywordtype">int</span> i;
<a name="l00440"></a>00440     <a class="code" href="structdictword__t.html" title="a structure for one dictionary word.">dictword_t</a> *word;
<a name="l00441"></a>00441 
<a name="l00442"></a>00442     <span class="keywordflow">if</span> (d == NULL)
<a name="l00443"></a>00443         <span class="keywordflow">return</span> 0;
<a name="l00444"></a>00444     <span class="keywordflow">if</span> (--d-&gt;refcnt &gt; 0)
<a name="l00445"></a>00445         <span class="keywordflow">return</span> d-&gt;refcnt;
<a name="l00446"></a>00446 
<a name="l00447"></a>00447     <span class="comment">/* First Step, free all memory allocated for each word */</span>
<a name="l00448"></a>00448     <span class="keywordflow">for</span> (i = 0; i &lt; d-&gt;<a class="code" href="structdict__t.html#af00f60319a7025361e291af5addb6b31" title="#Occupied entries in dict; ie, excluding empty slots">n_word</a>; i++) {
<a name="l00449"></a>00449         word = (<a class="code" href="structdictword__t.html" title="a structure for one dictionary word.">dictword_t</a> *) &amp; (d-&gt;<a class="code" href="structdict__t.html#a9e6636bbe45936a03381fea430addd31" title="Array of entries in dictionary.">word</a>[i]);
<a name="l00450"></a>00450         <span class="keywordflow">if</span> (word-&gt;<a class="code" href="structdictword__t.html#a3f3371918a406e26817bd4f2cecd7329" title="Ascii word string.">word</a>)
<a name="l00451"></a>00451             ckd_free((<span class="keywordtype">void</span> *) word-&gt;<a class="code" href="structdictword__t.html#a3f3371918a406e26817bd4f2cecd7329" title="Ascii word string.">word</a>);
<a name="l00452"></a>00452         <span class="keywordflow">if</span> (word-&gt;<a class="code" href="structdictword__t.html#acf5836b5a681485868e9090ad67366d5" title="Pronunciation.">ciphone</a>)
<a name="l00453"></a>00453             ckd_free((<span class="keywordtype">void</span> *) word-&gt;<a class="code" href="structdictword__t.html#acf5836b5a681485868e9090ad67366d5" title="Pronunciation.">ciphone</a>);
<a name="l00454"></a>00454     }
<a name="l00455"></a>00455 
<a name="l00456"></a>00456     <span class="keywordflow">if</span> (d-&gt;<a class="code" href="structdict__t.html#a9e6636bbe45936a03381fea430addd31" title="Array of entries in dictionary.">word</a>)
<a name="l00457"></a>00457         ckd_free((<span class="keywordtype">void</span> *) d-&gt;<a class="code" href="structdict__t.html#a9e6636bbe45936a03381fea430addd31" title="Array of entries in dictionary.">word</a>);
<a name="l00458"></a>00458     <span class="keywordflow">if</span> (d-&gt;<a class="code" href="structdict__t.html#a7205aae4fbeef3aaa53f94b6af529af2" title="Hash table for mapping word strings to word ids.">ht</a>)
<a name="l00459"></a>00459         hash_table_free(d-&gt;<a class="code" href="structdict__t.html#a7205aae4fbeef3aaa53f94b6af529af2" title="Hash table for mapping word strings to word ids.">ht</a>);
<a name="l00460"></a>00460     <span class="keywordflow">if</span> (d-&gt;<a class="code" href="structdict__t.html#a3a01eb5a3ebda5652d434be26e0cfdd2" title="Model definition used for phone IDs; NULL if none used.">mdef</a>)
<a name="l00461"></a>00461         bin_mdef_free(d-&gt;<a class="code" href="structdict__t.html#a3a01eb5a3ebda5652d434be26e0cfdd2" title="Model definition used for phone IDs; NULL if none used.">mdef</a>);
<a name="l00462"></a>00462     ckd_free((<span class="keywordtype">void</span> *) d);
<a name="l00463"></a>00463 
<a name="l00464"></a>00464     <span class="keywordflow">return</span> 0;
<a name="l00465"></a>00465 }
<a name="l00466"></a>00466 
<a name="l00467"></a>00467 <span class="keywordtype">void</span>
<a name="l00468"></a><a class="code" href="dict_8h.html#a41cca433a75fd2663bee115296639666">00468</a> dict_report(<a class="code" href="structdict__t.html" title="a structure for a dictionary.">dict_t</a> * d)
<a name="l00469"></a>00469 {
<a name="l00470"></a>00470     E_INFO_NOFN(<span class="stringliteral">&quot;Initialization of dict_t, report:\n&quot;</span>);
<a name="l00471"></a>00471     E_INFO_NOFN(<span class="stringliteral">&quot;Max word: %d\n&quot;</span>, d-&gt;<a class="code" href="structdict__t.html#af6142600cef73f846b58ba9bc36b02ac" title="#Entries allocated in dict, including empty slots">max_words</a>);
<a name="l00472"></a>00472     E_INFO_NOFN(<span class="stringliteral">&quot;No of word: %d\n&quot;</span>, d-&gt;<a class="code" href="structdict__t.html#af00f60319a7025361e291af5addb6b31" title="#Occupied entries in dict; ie, excluding empty slots">n_word</a>);
<a name="l00473"></a>00473     E_INFO_NOFN(<span class="stringliteral">&quot;\n&quot;</span>);
<a name="l00474"></a>00474 }
</pre></div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><b>dict.c</b>      </li>
      <li class="footer">Generated on Wed Apr 20 2011 for PocketSphinx by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.3 </li>
    </ul>
  </div>

</body>
</html>