Debian Codegraph @

src/hrg/cst_utterance.c

raw
1 /*************************************************************************/
2 /* */
3 /* Language Technologies Institute */
4 /* Carnegie Mellon University */
5 /* Copyright (c) 1999 */
6 /* All Rights Reserved. */
7 /* */
8 /* Permission is hereby granted, free of charge, to use and distribute */
9 /* this software and its documentation without restriction, including */
10 /* without limitation the rights to use, copy, modify, merge, publish, */
11 /* distribute, sublicense, and/or sell copies of this work, and to */
12 /* permit persons to whom this work is furnished to do so, subject to */
13 /* the following conditions: */
14 /* 1. The code must retain the above copyright notice, this list of */
15 /* conditions and the following disclaimer. */
16 /* 2. Any modifications must be clearly marked as such. */
17 /* 3. Original authors' names are not deleted. */
18 /* 4. The authors' names are not used to endorse or promote products */
19 /* derived from this software without specific prior written */
20 /* permission. */
21 /* */
22 /* CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK */
23 /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24 /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25 /* SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE */
26 /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27 /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28 /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29 /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
30 /* THIS SOFTWARE. */
31 /* */
32 /*************************************************************************/
33 /* Author: Alan W Black ([email protected]) */
34 /* Date: December 1999 */
35 /*************************************************************************/
36 /* */
37 /* Utterances */
38 /* */
39 /*************************************************************************/
40 #include "cst_alloc.h"
41 #include "cst_utterance.h"
42
43 /* utterance functions are the modules that do the meat in synthesis */
44 CST_VAL_REGISTER_FUNCPTR(uttfunc,cst_uttfunc)
45
46 cst_utterance *new_utterance()
47 {
48 cst_utterance *u;
49
50 u = cst_alloc(struct cst_utterance_struct,1);
51 u->ctx = new_alloc_context(128*1024);
52
53 u->features = new_features_local(u->ctx);
54 u->ffunctions = new_features_local(u->ctx);
55 u->relations = new_features_local(u->ctx);
56
57 return u;
58 }
59
60 void delete_utterance(cst_utterance *u)
61 {
62 cst_featvalpair *fp;
63 if (u)
64 {
65 delete_features(u->features);
66 delete_features(u->ffunctions);
67 /* Relation vals don't delete their contents */
68 for (fp=u->relations->head; fp; fp=fp->next)
69 delete_relation(val_relation(fp->val));
70 delete_features(u->relations);
71 delete_alloc_context(u->ctx);
72 cst_free(u);
73 }
74 }
75
76 cst_relation *utt_relation_create(cst_utterance *u,const char *name)
77 {
78 cst_relation *r;
79
80 utt_relation_delete(u,name); /* remove if already there */
81 r = new_relation(name,u);
82 feat_set(u->relations,name,relation_val(r));
83 return r;
84 }
85
86 int utt_relation_delete(cst_utterance *u,const char *name)
87 {
88 /* Relation vals don't delete their contents */
89 if (feat_present(u->relations, name))
90 delete_relation(val_relation(feat_val(u->relations,name)));
91 return feat_remove(u->relations,name);
92 }
93
94 int utt_relation_present(cst_utterance *u,const char *name)
95 {
96 return feat_present(u->relations,name);
97 }
98
99 cst_relation *utt_relation(const cst_utterance *u,const char *name)
100 {
101 const cst_val *v = feat_val(u->relations,name);
102 if (v != NULL)
103 return val_relation(v);
104 else
105 {
106 cst_errmsg("Relation: %s not present in utterance\n",
107 name);
108 cst_error();
109 }
110 return NULL;
111 }