Edinburgh Speech Tools 2.4-release
 
Loading...
Searching...
No Matches
EST_Relation.h
1/*************************************************************************/
2/* */
3/* Centre for Speech Technology Research */
4/* University of Edinburgh, UK */
5/* Copyright (c) 1998 */
6/* All Rights Reserved. */
7/* Permission is hereby granted, free of charge, to use and distribute */
8/* this software and its documentation without restriction, including */
9/* without limitation the rights to use, copy, modify, merge, publish, */
10/* distribute, sublicense, and/or sell copies of this work, and to */
11/* permit persons to whom this work is furnished to do so, subject to */
12/* the following conditions: */
13/* 1. The code must retain the above copyright notice, this list of */
14/* conditions and the following disclaimer. */
15/* 2. Any modifications must be clearly marked as such. */
16/* 3. Original authors' names are not deleted. */
17/* 4. The authors' names are not used to endorse or promote products */
18/* derived from this software without specific prior written */
19/* permission. */
20/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
21/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
22/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
23/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
24/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
25/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
26/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
27/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
28/* THIS SOFTWARE. */
29/* */
30/*************************************************************************/
31/* Author : Alan W Black */
32/* Date : February 1998 */
33/* --------------------------------------------------------------------- */
34/* another architecture */
35/* */
36/*************************************************************************/
37#ifndef __EST_RELATION_H__
38#define __EST_RELATION_H__
39
40#include "EST_String.h"
41#include "EST_TList.h"
42#include "EST_TKVL.h"
43#include "EST_THash.h"
44#include "EST_Val.h"
45#include "EST_types.h"
46#include "EST_Token.h"
47#include "EST_Features.h"
48#include "ling_class/EST_Item.h"
49
50class EST_Utterance;
51
53
54/** Relations are a container class for EST_Items. Three types of
55relation structure are supported:
56
57<variablelist>
58
59<varlistentry><term>Linear lists</term><listitem></listitem></varlistentry>
60<varlistentry><term>Trees</term><listitem></listitem></varlistentry>
61<varlistentry><term>Multi-linear structures</term><listitem> as used
62in autosegmental phonology etc</listitem></varlistentry>
63
64</variablelist>
65*/
66
68{
69 EST_String p_name;
70 EST_Utterance *p_utt;
71 EST_Item *p_head;
72 EST_Item *p_tail; // less meaningful in a tree
73
74 EST_Item *get_item_from_name(EST_THash<int,EST_Val> &inames,int name);
75 EST_Item *get_item_from_name(EST_TVector< EST_Item * > &inames,int name);
76 EST_write_status save_items(EST_Item *item,
80 int &node_count) const;
81
82 static void node_tidy_up_val(int &k, EST_Val &v);
83 static void node_tidy_up(int &k, EST_Item *node);
84
85 EST_read_status load_items(EST_TokenStream &ts,
86 const EST_THash<int,EST_Val> &contents);
87 EST_read_status load_items(EST_TokenStream &ts,
89 );
90 void copy(const EST_Relation &r);
91 public:
92
93 /** default constructor */
95 /** Constructor which sets name of relation */
97 /** Constructor which copies relation r */
98 EST_Relation(const EST_Relation &r) { copy(r); }
99 /** default destructor */
101
102 /** Features which belong to the relation rather than its items*/
104
105 /** Evaluate the relation's feature functions */
106 //void evaluate_features();
107 /** Evaluate the feature functions of all the items in the relation */
109
110 /** Clear the relation of items */
111 void clear();
112
113 /** Return the <link linkend="est-utterance">EST_Utterance</link>
114 to which this relation belongs */
115 EST_Utterance *utt(void) { return p_utt; }
116
117 /** Set the <link linkend="est-utterance">EST_Utterance</link>
118 to which this relation belongs */
119 void set_utt(EST_Utterance *u) { p_utt = u; }
120
121 /** Return the name of the relation */
122 const EST_String &name() const { return (this == 0) ? EST_String::Empty : p_name; }
123
124 /** Return the head (first) item of the relation */
125 EST_Item *head() const {return (this == 0) ? 0 : p_head;}
126
127 /** Return the root item of the relation */
128 EST_Item *root() const {return head();}
129
130 /** Return the tail (last) item of the relation */
131 EST_Item *tail() const {return (this == 0) ? 0 : p_tail;}
132
133 // This have been replaced by Relation_Tree functions
134 EST_Item *first() const { return head(); }
135 EST_Item *rlast() const { return tail(); }
136
137 /** Return the tail (last) item of the relation */
138// EST_Item *id(int i);
139
140 /** number of items in this relation */
141 int length() const;
142// int num_nodes() const;
143// int num_leafs() const;
144 /** return true if relation does not contain any items */
145 int empty() const { return p_head == 0; }
146
147 /** remove EST_Item <parameter>item</parameter> from relation */
148 void remove_item(EST_Item *item);
149
150 /** remove all occurrences of feature
151 <parameter>name</parameter> from relation's items
152 */
154
155 /** Load relation from file */
156 EST_read_status load(const EST_String &filename,
157 const EST_String &type="esps");
158
159 /** Load relation from already open tokenstream */
160// EST_read_status load(EST_TokenStream &ts,
161// const EST_THash<int,EST_Val> &contents);
162
163 /** Load relation from already open tokenstream */
164 EST_read_status load(EST_TokenStream &ts,
166 );
167
168 /** Load relation from already open tokenstream */
169 EST_read_status load(const EST_String &filename,
171 const EST_String &type);
172
173 /** Save relation to file */
174 EST_write_status save(const EST_String &filename,
175 bool evaluate_ff = false) const;
176
177 /** Save relation to file, evaluating all feature functions before hand */
178 EST_write_status save(const EST_String &filename,
179 const EST_String &type,
180 bool evaluate_ff = false) const;
181
182 /** Save relation from already open ostream */
183 EST_write_status save(ostream &outf,EST_TKVL<void *,int> contents) const;
184
185 /** Save relation from already open ostream */
186 EST_write_status save(ostream &outf,
187 const EST_String &type,
188 bool evaluate_ff) const;
189 /** Iteration */
191
192 EST_Relation &operator=(const EST_Relation &s);
193 friend ostream& operator << (ostream &s, const EST_Relation &u);
194
195 EST_Item *append(EST_Item *si);
196 EST_Item *append();
197 EST_Item *prepend(EST_Item *si);
198 EST_Item *prepend();
199
200 friend class EST_Item;
201};
202
203VAL_REGISTER_CLASS_DCLS(relation,EST_Relation)
204
205inline bool operator==(const EST_Relation &a, const EST_Relation &b)
206 { return (&a == &b); }
207
208void copy_relation(const EST_Relation &from, EST_Relation &to);
209
210EST_Utterance *get_utt(EST_Item *s);
211
213{
214private:
215 const EST_Relation &rel;
216 EST_Item *next;
217
218public:
220 : rel(r), next(NULL) { reset();};
221
222 void reset()
223 { next=rel.head(); }
224 bool has_more_elements()
225 { return next != NULL; }
226
227 EST_Item *next_element();
228};
229
231
232#endif
EST_Relation * relation(void) const
The relation of this particular item.
Definition EST_Item.h:316
void remove_item_feature(const EST_String &name)
EST_Relation(const EST_Relation &r)
void remove_item(EST_Item *item)
EST_Features f
EST_read_status load(const EST_String &filename, const EST_String &type="esps")
EST_Item * head() const
EST_Item * root() const
EST_write_status save(const EST_String &filename, bool evaluate_ff=false) const
int length() const
EST_Utterance * utt(void)
int empty() const
EST_Relation_Iterator Iterator
EST_Item * tail() const
const EST_String & name() const
void set_utt(EST_Utterance *u)
void evaluate_item_features()
static const EST_String Empty
Constant empty string.
Definition EST_String.h:111