| 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 (awb@cs.cmu.edu) */ |
| 34 | /* Date: December 1999 */ |
| 35 | /*************************************************************************/ |
| 36 | /* */ |
| 37 | /* Item */ |
| 38 | /* */ |
| 39 | /*************************************************************************/ |
| 40 | #ifndef _CST_ITEM_H__ |
| 41 | #define _CST_ITEM_H__ |
| 42 | |
| 43 | #include "cst_file.h" |
| 44 | #include "cst_features.h" |
| 45 | |
| 46 | /* Everyone needs these so forward define these */ |
| 47 | typedef struct cst_relation_struct cst_relation; |
| 48 | typedef struct cst_utterance_struct cst_utterance; |
| 49 | typedef struct cst_item_struct cst_item; |
| 50 | |
| 51 | /* So items, relations and utterances can be used as vals */ |
| 52 | CST_VAL_USER_TYPE_DCLS(relation,cst_relation) |
| 53 | CST_VAL_USER_TYPE_DCLS(item,cst_item) |
| 54 | CST_VAL_USER_TYPE_DCLS(utterance,cst_utterance) |
| 55 | |
| 56 | typedef struct cst_item_contents_struct { |
| 57 | cst_features *features; |
| 58 | cst_features *relations; |
| 59 | } cst_item_contents; |
| 60 | |
| 61 | struct cst_item_struct { |
| 62 | cst_item_contents *contents; /* the shared part of an item */ |
| 63 | cst_relation *relation; |
| 64 | cst_item *n; |
| 65 | cst_item *p; |
| 66 | cst_item *u; |
| 67 | cst_item *d; |
| 68 | }; |
| 69 | |
| 70 | /* Constructor functions */ |
| 71 | cst_item *new_item_relation(cst_relation *r,cst_item *i); |
| 72 | cst_item_contents *new_item_contents(cst_item *i); |
| 73 | |
| 74 | /* Remove this item from this references */ |
| 75 | void delete_item(cst_item *item); |
| 76 | |
| 77 | void item_contents_set(cst_item *current, cst_item *i); |
| 78 | void item_unref_contents(cst_item *i); |
| 79 | |
| 80 | cst_item *item_as(const cst_item *i,const char *rname); |
| 81 | |
| 82 | cst_utterance *item_utt(const cst_item *i); |
| 83 | |
| 84 | /* List accessor/manipulator function */ |
| 85 | cst_item *item_next(const cst_item *i); |
| 86 | cst_item *item_prev(const cst_item *i); |
| 87 | |
| 88 | cst_item *item_append(cst_item *i,cst_item *new_item); |
| 89 | cst_item *item_prepend(cst_item *i,cst_item *new_item); |
| 90 | |
| 91 | /* Tree accessor/manipulator function */ |
| 92 | cst_item *item_parent(const cst_item *i); |
| 93 | cst_item *item_nth_daughter(const cst_item *i,int n); |
| 94 | cst_item *item_daughter(const cst_item *i); |
| 95 | cst_item *item_last_daughter(const cst_item *i); |
| 96 | cst_item *item_first(const cst_item *i); |
| 97 | cst_item *item_last(const cst_item *i); |
| 98 | |
| 99 | cst_item *item_add_daughter(cst_item *i,cst_item *new_item); |
| 100 | cst_item *item_append_sibling(cst_item *i,cst_item *new_item); |
| 101 | cst_item *item_prepend_sibling(cst_item *i,cst_item *new_item); |
| 102 | |
| 103 | /* Feature accessor/manipulator functions */ |
| 104 | int item_feat_present(const cst_item *i,const char *name); |
| 105 | int item_feat_remove(const cst_item *i,const char *name); |
| 106 | cst_features *item_feats(const cst_item *i); |
| 107 | const cst_val *item_feat(const cst_item *i,const char *name); |
| 108 | int item_feat_int(const cst_item *i,const char *name); |
| 109 | float item_feat_float(const cst_item *i,const char *name); |
| 110 | const char *item_feat_string(const cst_item *i,const char *name); |
| 111 | void item_set(const cst_item *i,const char *name,const cst_val *val); |
| 112 | void item_set_int(const cst_item *i,const char *name,int val); |
| 113 | void item_set_float(const cst_item *i,const char *name,float val); |
| 114 | void item_set_string(const cst_item *i,const char *name,const char *val); |
| 115 | |
| 116 | #define item_name(I) item_feat_string(I,"name") |
| 117 | |
| 118 | int item_equal(const cst_item *a, const cst_item *b); |
| 119 | |
| 120 | const char *ffeature_string(const cst_item *item,const char *featpath); |
| 121 | int ffeature_int(const cst_item *item,const char *featpath); |
| 122 | float ffeature_float(const cst_item *item,const char *featpath); |
| 123 | const cst_val *ffeature(const cst_item *item,const char *featpath); |
| 124 | cst_item* path_to_item(const cst_item *item,const char *featpath); |
| 125 | |
| 126 | /* Feature function, for features that are derived algorithmically from others. */ |
| 127 | typedef const cst_val *(*cst_ffunction)(const cst_item *i); |
| 128 | CST_VAL_USER_FUNCPTR_DCLS(ffunc,cst_ffunction) |
| 129 | void ff_register(cst_features *ffeatures, const char *name, |
| 130 | cst_ffunction f); |
| 131 | void ff_unregister(cst_features *ffeatures, const char *name); |
| 132 | |
| 133 | /* Generalized item hook function, like cst_uttfunc. */ |
| 134 | typedef cst_val *(*cst_itemfunc)(cst_item *i); |
| 135 | CST_VAL_USER_FUNCPTR_DCLS(itemfunc,cst_itemfunc) |
| 136 | |
| 137 | #endif |
| 138 | |