Edinburgh Speech Tools  2.1-release
EST_Relation_tree.h
Go to the documentation of this file.
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 /* Functions for TREE relations */
35 /* */
36 /*************************************************************************/
37 #ifndef __EST_RELATION_TREE_H__
38 #define __EST_RELATION_TREE_H__
39 
40 #include "EST_Item.h"
41 
42 /**@defgroup buildtraversetrees Functions for building and traversing tree relations
43 
44  */
45 
46 /**@defgroup treetraversalfunctions Tree traversal functions
47  * @ingroup buildtraversetrees
48 */
49 
50 ///@{
51 
52 /// \brief return parent of `n`
53 inline EST_Item *parent(const EST_Item *n) { return n->first()->up(); }
54 
55 /// \brief return first daughter of `n`
56 inline EST_Item *daughter1(const EST_Item *n) { return n->down(); }
57 
58 /// \brief return second daughter of `n`
59 inline EST_Item *daughter2(const EST_Item *n) { return n->down()->next(); }
60 
61 /// \brief return nth daughter of `n`
62 EST_Item *daughtern(const EST_Item *n, int nth);
63 
64 /// \brief return last daughter of `n`
65 inline EST_Item *daughtern(const EST_Item *n) { return n->down()->last(); }
66 
67 /// \brief return next sibling (sister) of `n`
68 inline EST_Item *next_sibling(const EST_Item *n) { return n->next(); }
69 
70 /// \brief return previous sibling (sister) of `n`
71 inline EST_Item *prev_sibling(const EST_Item *n) { return n->prev(); }
72 
73 /// \brief return root node of treeprevious sibling (sister) of `n`
74 inline EST_Item *root(const EST_Item *n) { return n->top(); }
75 
76 /** \brief return parent of `n` as seen from relation `relname` */
77 inline EST_Item *parent(const EST_Item *n,const char *relname)
78  { return parent(as(n,relname)); }
79 
80 //inline EST_Item *daughters(const EST_Item *n,const char *relname)
81 // { return daughters(as(n,relname)); }
82 
83 /** \brief return first daughter of `n` as seen from relation
84  `relname` */
85 inline EST_Item *daughter1(const EST_Item *n,const char *relname)
86  { return daughter1(as(n,relname)); }
87 
88 /** \brief return second daughter of `n` as seen from relation
89  `relname` */
90 inline EST_Item *daughter2(const EST_Item *n,const char *relname)
91  { return daughter2(as(n,relname)); }
92 
93 /** \brief return last daughter of `n` as seen from relation
94  `relname` */
95 inline EST_Item *daughtern(const EST_Item *n,const char *relname)
96  { return daughtern(as(n,relname)); }
97 
98 /** \brief return next sibling (sister) of `n` as seen
99  from relation `relname` */
100 inline EST_Item *next_sibling(const EST_Item *n,const char *relname)
101  { return next_sibling(as(n,relname)); }
102 
103 /** \brief return previous sibling (sister) of `n` as seen
104  from relation `relname` */
105 inline EST_Item *prev_sibling(const EST_Item *n,const char *relname)
106  { return prev_sibling(as(n,relname)); }
107 
108 /** \brief return root of tree of `n` as seen from
109  relation `relname` */
110 inline EST_Item *root(const EST_Item *n,const char *relname)
111  { return root(as(n,relname)); }
112 
113 // should be deleted.
115 
116 // should be deleted.
117 EST_Item *last_leaf_in_tree(const EST_Item *root);
118 
119 /** \brief return the first leaf (terminal node) which is dominated by
120  `n`. Note that this is different from daughter1 etc
121 as this descends the tree to find the leftmost terminal node (it
122 is like the transitive closure of daughter1).
123 */
124 inline EST_Item *first_leaf(const EST_Item *n) {return first_leaf_in_tree(n);}
125 
126 /** return the last leaf (terminal node) which is dominated by
127  `n`. Note that this is different from daughter1 etc
128 as this descends the tree to find the right terminal node (it is
129 like the transitive closure of daughtern).
130 */
131 inline EST_Item *last_leaf(const EST_Item *n) { return last_leaf_in_tree(n); }
132 
133 /** Return next leaf in tree given `n`. If
134 `n` is a terminal node, next_leaf() will return
135 the next leaf in the tree. If `n` is not
136 terminal, this will return the leftmost terminal node dominated by
137 `n`. This will return 0 only when the last leaf in
138 the relation has been passed.
139 */
140 inline EST_Item *next_leaf(const EST_Item *n) { return n->next_leaf(); }
141 
142 /** Return number of leaves (terminal nodes) under `n`
143  */
144 int num_leaves(const EST_Item *n);
145 
146 /** Given a node `t`, return true if
147  `c` is under it in a tree */
148 int in_tree(const EST_Item *c,const EST_Item *t);
149 
150 ///@}
151 
152 /**@defgroup treebuildfunctions Tree building functions
153  @ingroup buildtraversetrees
154  */
155 ///@{
156 
157 /** Add a daughter to node `n`, after any
158 existing daughters, and return the next daughter. If
159 `p` is 0, make a new node for the daughter,
160 otherwise add `p` to this relation as
161 `n`'s daughter. */
162 
164 
165 /** Add a daughter to node `n` as seen from
166 relation `relname`, after any existing
167 daughters, and return the next daughter. If `p`
168 is 0, make a new node for the daughter, otherwise add
169 `p` to this relation as
170 `n`'s daughter. */
171 
172 EST_Item *append_daughter(EST_Item *n, const char *relname, EST_Item *p=0);
173 
174 /** Add a daughter to node `n`, before any
175 existing daughters, and return the next daughter. If
176 `p` is 0, make a new node for the daughter,
177 otherwise add `p` to this relation as
178 `n`'s daughter. */
179 
181 
182 /** Add a daughter to node `n` as seen from
183 relation `relname`, before any existing
184 daughters, and return the next daughter. If `p`
185 is 0, make a new node for the daughter, otherwise add
186 `p` to this relation as
187 `n`'s daughter. */
188 
189 EST_Item *prepend_daughter(EST_Item *n, const char *relname, EST_Item *p=0);
190 
191 ///@}
192 
193 #endif
EST_Item * first_leaf(const EST_Item *n)
return the first leaf (terminal node) which is dominated by n. Note that this is different from daugh...
EST_Item * next_sibling(const EST_Item *n)
return next sibling (sister) of n
EST_Item * append_daughter(EST_Item *n, EST_Item *p=0)
Definition: EST_Item.cc:594
EST_Item * as(const EST_Item *n, const char *relname)
Definition: EST_Item.h:419
EST_Item * last() const
Definition: EST_Item.cc:329
EST_Item * first() const
Definition: EST_Item.cc:339
EST_Item * prepend_daughter(EST_Item *n, EST_Item *p=0)
Definition: EST_Item.cc:604
int nth(EST_String name, EST_TList< EST_String > &lex)
Definition: confusion.cc:46
int in_tree(const EST_Item *c, const EST_Item *t)
Definition: item_aux.cc:57
EST_Item * daughter2(const EST_Item *n)
return second daughter of n
EST_Item * root(const EST_Item *n)
return root node of treeprevious sibling (sister) of n
EST_Item * up() const
Definition: EST_Item.h:354
EST_Item * prev_sibling(const EST_Item *n)
return previous sibling (sister) of n
int num_leaves(const EST_Item *n)
EST_Item * prev() const
Definition: EST_Item.h:350
EST_Item * top() const
Definition: EST_Item.cc:349
EST_Item * down() const
Definition: EST_Item.h:352
EST_Item * first_leaf_in_tree(const EST_Item *root)
Definition: EST_Item.cc:410
EST_Item * next() const
Definition: EST_Item.h:348
EST_Item * last_leaf(const EST_Item *n)
EST_Item * next_leaf(const EST_Item *n)
EST_Item * daughtern(const EST_Item *n, int nth)
return nth daughter of n
EST_Item * last_leaf_in_tree(const EST_Item *root)
Definition: EST_Item.cc:415
EST_Item * parent(const EST_Item *n)
return parent of n
EST_Item * next_leaf() const
Definition: EST_Item.cc:358
EST_Item * daughter1(const EST_Item *n)
return first daughter of n