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