dict.h
Go to the documentation of this file.
/* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
/* ====================================================================
* Copyright (c) 1999-2004 Carnegie Mellon University. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* This work was supported in part by funding from the Defense Advanced
* Research Projects Agency and the National Science Foundation of the
* United States of America, and the CMU Sphinx Speech Consortium.
*
* THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
* NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ====================================================================
*
*/
#ifndef _S3_DICT_H_
#define _S3_DICT_H_
/* SphinxBase headers. */
#include <sphinxbase/hash_table.h>
/* Local headers. */
#include "s3types.h"
#include "bin_mdef.h"
#include "pocketsphinx_export.h"
#define S3DICT_INC_SZ 4096
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
char *word;
s3cipid_t *ciphone;
int32 pronlen;
s3wid_t alt;
s3wid_t basewid;
} dictword_t;
typedef struct {
int refcnt;
bin_mdef_t *mdef;
dictword_t *word;
hash_table_t *ht;
int32 max_words;
int32 n_word;
int32 filler_start;
int32 filler_end;
s3wid_t startwid;
s3wid_t finishwid;
s3wid_t silwid;
int nocase;
} dict_t;
dict_t *dict_init(cmd_ln_t *config,
bin_mdef_t *mdef
);
int dict_write(dict_t *dict, char const *filename, char const *format);
POCKETSPHINX_EXPORT
s3wid_t dict_wordid(dict_t *d, const char *word);
int dict_filler_word(dict_t *d,
s3wid_t w
);
POCKETSPHINX_EXPORT
int dict_real_word(dict_t *d,
s3wid_t w
);
s3wid_t dict_add_word(dict_t *d,
char const *word,
s3cipid_t const *p,
int32 np
);
const char *dict_ciphone_str(dict_t *d,
s3wid_t wid,
int32 pos
);
#define dict_size(d) ((d)->n_word)
#define dict_num_fillers(d) (dict_filler_end(d) - dict_filler_start(d))
#define dict_num_real_words(d) \
(dict_size(d) - (dict_filler_end(d) - dict_filler_start(d)) - 2)
#define dict_basewid(d,w) ((d)->word[w].basewid)
#define dict_wordstr(d,w) ((w) < 0 ? NULL : (d)->word[w].word)
#define dict_basestr(d,w) ((d)->word[dict_basewid(d,w)].word)
#define dict_nextalt(d,w) ((d)->word[w].alt)
#define dict_pronlen(d,w) ((d)->word[w].pronlen)
#define dict_pron(d,w,p) ((d)->word[w].ciphone[p])
#define dict_filler_start(d) ((d)->filler_start)
#define dict_filler_end(d) ((d)->filler_end)
#define dict_startwid(d) ((d)->startwid)
#define dict_finishwid(d) ((d)->finishwid)
#define dict_silwid(d) ((d)->silwid)
#define dict_is_single_phone(d,w) ((d)->word[w].pronlen == 1)
#define dict_first_phone(d,w) ((d)->word[w].ciphone[0])
#define dict_second_phone(d,w) ((d)->word[w].ciphone[1])
#define dict_second_last_phone(d,w) ((d)->word[w].ciphone[(d)->word[w].pronlen - 2])
#define dict_last_phone(d,w) ((d)->word[w].ciphone[(d)->word[w].pronlen - 1])
/* Hard-coded special words */
#define S3_START_WORD "<s>"
#define S3_FINISH_WORD "</s>"
#define S3_SILENCE_WORD "<sil>"
#define S3_UNKNOWN_WORD "<UNK>"
int32 dict_word2basestr(char *word);
dict_t *dict_retain(dict_t *d);
int dict_free(dict_t *d);
void dict_report(dict_t *d
);
#ifdef __cplusplus
}
#endif
#endif
bin_mdef.h
Binary format model definition files, with support for heterogeneous topologies and variable-size N-p...
dict_init
dict_t * dict_init(cmd_ln_t *config, bin_mdef_t *mdef)
Initialize a new dictionary.
Definition: dict.c:252
dict_retain
dict_t * dict_retain(dict_t *d)
Retain a pointer to an dict_t.
Definition: dict.c:461
dict_add_word
s3wid_t dict_add_word(dict_t *d, char const *word, s3cipid_t const *p, int32 np)
Add a word with the given ciphone pronunciation list to the dictionary.
Definition: dict.c:80
dict_word2basestr
int32 dict_word2basestr(char *word)
If the given word contains a trailing "(....)" (i.e., a Sphinx-II style alternative pronunciation spe...
Definition: dict.c:442
dict_report
void dict_report(dict_t *d)
Report a dictionary structure.
Definition: dict.c:499
dict_write
int dict_write(dict_t *dict, char const *filename, char const *format)
Write dictionary to a file.
Definition: dict.c:221
dict_free
int dict_free(dict_t *d)
Release a pointer to a dictionary.
Definition: dict.c:468
dict_ciphone_str
const char * dict_ciphone_str(dict_t *d, s3wid_t wid, int32 pos)
Return value: CI phone string for the given word, phone position.
Definition: dict.c:69
dict_filler_word
int dict_filler_word(dict_t *d, s3wid_t w)
Return 1 if w is a filler word, 0 if not.
Definition: dict.c:413
dict_real_word
POCKETSPHINX_EXPORT int dict_real_word(dict_t *d, s3wid_t w)
Test if w is a "real" word, i.e.
Definition: dict.c:427
dict_wordid
POCKETSPHINX_EXPORT s3wid_t dict_wordid(dict_t *d, const char *word)
Return word id for given word string if present.
Definition: dict.c:399
s3types.h
Size definition of semantically units.
s3cipid_t
int16 s3cipid_t
Size definitions for more semantially meaningful units.
Definition: s3types.h:63
bin_mdef_s
Definition: bin_mdef.h:117
dict_t
a structure for a dictionary.
Definition: dict.h:76
dict_t::startwid
s3wid_t startwid
FOR INTERNAL-USE ONLY.
Definition: dict.h:85
dict_t::finishwid
s3wid_t finishwid
FOR INTERNAL-USE ONLY.
Definition: dict.h:86
dict_t::mdef
bin_mdef_t * mdef
Model definition used for phone IDs; NULL if none used.
Definition: dict.h:78
dict_t::ht
hash_table_t * ht
Hash table for mapping word strings to word ids.
Definition: dict.h:80
dict_t::filler_end
int32 filler_end
Last filler word id (read from filler dict)
Definition: dict.h:84
dict_t::word
dictword_t * word
Array of entries in dictionary.
Definition: dict.h:79
dict_t::silwid
s3wid_t silwid
FOR INTERNAL-USE ONLY.
Definition: dict.h:87
dict_t::filler_start
int32 filler_start
First filler word id (read from filler dict)
Definition: dict.h:83
dict_t::n_word
int32 n_word
#Occupied entries in dict; ie, excluding empty slots
Definition: dict.h:82
dict_t::max_words
int32 max_words
#Entries allocated in dict, including empty slots
Definition: dict.h:81
dictword_t
a structure for one dictionary word.
Definition: dict.h:63
dictword_t::word
char * word
Ascii word string.
Definition: dict.h:64
dictword_t::pronlen
int32 pronlen
Pronunciation length.
Definition: dict.h:66
dictword_t::basewid
s3wid_t basewid
Base pronunciation id.
Definition: dict.h:68
dictword_t::alt
s3wid_t alt
Next alternative pronunciation id, NOT_S3WID if none.
Definition: dict.h:67
dictword_t::ciphone
s3cipid_t * ciphone
Pronunciation.
Definition: dict.h:65