cst_item.h 6.3 KB

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