Edinburgh Speech Tools  2.1-release
EST_Utterance.h
Go to the documentation of this file.
1 /*************************************************************************/
2 /* */
3 /* Centre for Speech Technology Research */
4 /* University of Edinburgh, UK */
5 /* Copyright (c) 1995,1996 */
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 /* THE UNIVERSITY OF EDINBURGH 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 THE UNIVERSITY OF EDINBURGH 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 : Paul Taylor */
34 /* Date : May 1995 (redone May 1998) */
35 /*-----------------------------------------------------------------------*/
36 /* EST_Utterance Class header file */
37 /* */
38 /*=======================================================================*/
39 #ifndef __Utterance_H__
40 #define __Utterance_H__
41 
42 #include "EST_String.h"
43 #include "EST_TList.h"
45 #include "ling_class/EST_Item.h"
46 #include "EST_Features.h"
47 
48 /** @class EST_Utterance
49  @ingroup estlingclasses
50  A class that contains EST_Item and EST_Relation between them.
51 Used for holding interrelated linguistic structures.
52 */
54 private:
55  void copy(const EST_Utterance &u);
56  int highest_id;
57 public:
58  /**@name Constructor and initialisation Functions */
59  ///@{
60  /// default constructor
61  EST_Utterance();
62  EST_Utterance(const EST_Utterance &u) { copy(u); }
64  ///@}
65 
66  /**@name Utility Functions */
67  ///@{
68  /// initialise utterance
69  void init();
70 
71  /// remove everything in utterance
72  void clear();
73 
74  /// clear the contents of the relations only
75  void clear_relations();
76 
77  /// set the next id to be `n`
78  void set_highest_id(int n) {highest_id=n;}
79  /// return the id of the next item
80  int next_id();
81  ///@}
82 
83  /**@name File i/o */
84  ///@{
85  /** load an utterance from an ascii file
86  */
87  EST_read_status load(const EST_String &filename);
88  /** load an utterance from a already opened token stream
89  */
91 
92  /** save an utterance to an ascii file
93  */
94  EST_write_status save(const EST_String &filename,
95  const EST_String &type="est_ascii") const;
96 
97  /** save an utterance to an ostream
98  */
99  EST_write_status save(ostream &outf,const EST_String &type) const;
100  ///@}
101 
103  friend ostream& operator << (ostream &s, const EST_Utterance &u);
105  { return relation(name);}
106 
107  /** Utterance access
108  */
109  ///@{
110 
111  /// Utterance level features
113 
114  /// Evaluate all feature functions in utterance
115  void evaluate_all_features();
116 
117  /// The list of named relations
119 
120  /// number of relations in this utterance
121  int num_relations() const { return relations.length(); }
122 
123  /** returns true if utterance contains named relations.
124  **name** can be either a single string or a bracketed list
125  of strings e.g. "(Word Phone Syl)". */
126  bool relation_present(const EST_String name) const;
127 
128  /** returns true if utterance contains all the relations
129  named in the list **name**. */
130  bool relation_present(EST_StrList &names) const;
131 
132  /// get relation by name
133  EST_Relation *relation(const char *name,int err_on_not_found=1) const;
134 
135  /// return EST_Item whose id is `n`.
136  EST_Item *id(const EST_String &n) const;
137 
138  /// create a new relation called `n`.
139  EST_Relation *create_relation(const EST_String &relname);
140 
141  /// remove the relation called `n`.
142  void remove_relation(const EST_String &relname);
143 
144  void sub_utterance(EST_Item *i);
145  ///@}
146 };
147 
148 void utt_2_flat_repr( const EST_Utterance &utt,
149  EST_String &flat_repr );
150 
152  EST_Utterance &sub_utt,
153  EST_Item *utt_root,
154  EST_Item *sub_root);
155 
157  EST_Utterance &extra,
158  EST_String feature);
159 
161 
162 #endif
int utterance_merge(EST_Utterance &utt, EST_Utterance &sub_utt, EST_Item *utt_root, EST_Item *sub_root)
EST_Utterance(const EST_Utterance &u)
Definition: EST_Utterance.h:62
void clear_relations()
clear the contents of the relations only
EST_write_status save(const EST_String &filename, const EST_String &type="est_ascii") const
EST_read_status load(const EST_String &filename)
EST_write_status
EST_Utterance & operator=(const EST_Utterance &s)
void clear()
remove everything in utterance
EST_Relation * create_relation(const EST_String &relname)
create a new relation called n.
EST_Features f
Utterance level features.
void evaluate_all_features()
Evaluate all feature functions in utterance.
EST_Relation * operator()(const EST_String &name)
EST_Features relations
The list of named relations.
int length() const
Definition: EST_Features.h:251
EST_Utterance()
default constructor
EST_Item * id(const EST_String &n) const
return EST_Item whose id is n.
EST_FMatrix sub(const EST_FMatrix &a, ssize_t row, ssize_t col)
Definition: vec_mat_aux.cc:187
void set_highest_id(int n)
set the next id to be n
Definition: EST_Utterance.h:78
void utt_2_flat_repr(const EST_Utterance &utt, EST_String &flat_repr)
EST_read_status
void init()
initialise utterance
void sub_utterance(EST_Item *i)
int num_relations() const
number of relations in this utterance
int next_id()
return the id of the next item
friend ostream & operator<<(ostream &s, const EST_Utterance &u)
EST_Relation * relation(const char *name, int err_on_not_found=1) const
get relation by name
bool relation_present(const EST_String name) const
void remove_relation(const EST_String &relname)
remove the relation called n.