Edinburgh Speech Tools 2.4-release
 
Loading...
Searching...
No Matches
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/**@name Functions for building and traversing tree relations
41
42 */
43//@{
44
45/**@name Tree traversal functions
46*/
47
48//@{
49
50/// return parent of <parameter>n</parameter>
51inline EST_Item *parent(const EST_Item *n) { return iup(first(n)); }
52
53/// return first daughter of <parameter>n</parameter>
54inline EST_Item *daughter1(const EST_Item *n) { return idown(n); }
55
56/// return second daughter of <parameter>n</parameter>
57inline EST_Item *daughter2(const EST_Item *n) { return inext(idown(n)); }
58
59/// return nth daughter of <parameter>n</parameter>
60EST_Item *daughtern(const EST_Item *n, int nth);
61
62/// return last daughter of <parameter>n</parameter>
63inline EST_Item *daughtern(const EST_Item *n) { return last(idown(n)); }
64
65/// return next sibling (sister) of <parameter>n</parameter>
66inline EST_Item *next_sibling(const EST_Item *n) { return inext(n); }
67
68/// return previous sibling (sister) of <parameter>n</parameter>
69inline EST_Item *prev_sibling(const EST_Item *n) { return iprev(n); }
70
71/// return root node of treeprevious sibling (sister) of <parameter>n</parameter>
72inline EST_Item *root(const EST_Item *n) { return top(n); }
73
74/** return parent of <parameter>n</parameter> as seen from relation
75<parameter>relname</parameter> */
76inline EST_Item *parent(const EST_Item *n,const char *relname)
77 { return parent(as(n,relname)); }
78
79//inline EST_Item *daughters(const EST_Item *n,const char *relname)
80// { return daughters(as(n,relname)); }
81
82/** return first daughter of <parameter>n</parameter> as seen from relation
83 <parameter>relname</parameter> */
84inline EST_Item *daughter1(const EST_Item *n,const char *relname)
85 { return daughter1(as(n,relname)); }
86
87/** return second daughter of <parameter>n</parameter> as seen from relation
88 <parameter>relname</parameter> */
89inline EST_Item *daughter2(const EST_Item *n,const char *relname)
90 { return daughter2(as(n,relname)); }
91
92/** return last daughter of <parameter>n</parameter> as seen from relation
93 <parameter>relname</parameter> */
94inline EST_Item *daughtern(const EST_Item *n,const char *relname)
95 { return daughtern(as(n,relname)); }
96
97/** return next sibling (sister) of <parameter>n</parameter> as seen
98 from relation <parameter>relname</parameter> */
99inline EST_Item *next_sibling(const EST_Item *n,const char *relname)
100 { return next_sibling(as(n,relname)); }
101
102/** return previous sibling (sister) of <parameter>n</parameter> as seen
103 from relation <parameter>relname</parameter> */
104inline EST_Item *prev_sibling(const EST_Item *n,const char *relname)
105 { return prev_sibling(as(n,relname)); }
106
107/** return root of tree of <parameter>n</parameter> as seen from
108 relation <parameter>relname</parameter> */
109inline EST_Item *root(const EST_Item *n,const char *relname)
110 { return root(as(n,relname)); }
111
112// should be deleted.
113EST_Item *first_leaf_in_tree(const EST_Item *root);
114
115// should be deleted.
116EST_Item *last_leaf_in_tree(const EST_Item *root);
117
118/** Return number of leaves (terminal nodes) under <parameter>n</parameter>
119 */
120int num_leaves(const EST_Item *n);
121
122/** Given a node <parameter>t</parameter>, return true if
123 <parameter>c</parameter> is under it in a tree */
124int in_tree(const EST_Item *c,const EST_Item *t);
125
126//@}
127
128/**@name Tree building functions */
129//@{
130
131/** Add a daughter to node <parameter>n</parameter>, after any
132existing daughters, and return the next daughter. If
133<parameter>p</parameter> is 0, make a new node for the daughter,
134otherwise add <parameter>p</parameter> to this relation as
135<parameter>n</parameter>'s daughter. */
136
137EST_Item *append_daughter(EST_Item *n, EST_Item *p=0);
138
139/** Add a daughter to node <parameter>n</parameter> as seen from
140relation <parameter>relname</parameter>, after any existing
141daughters, and return the next daughter. If <parameter>p</parameter>
142is 0, make a new node for the daughter, otherwise add
143<parameter>p</parameter> to this relation as
144<parameter>n</parameter>'s daughter. */
145
146EST_Item *append_daughter(EST_Item *n, const char *relname, EST_Item *p=0);
147
148/** Add a daughter to node <parameter>n</parameter>, before any
149existing daughters, and return the next daughter. If
150<parameter>p</parameter> is 0, make a new node for the daughter,
151otherwise add <parameter>p</parameter> to this relation as
152<parameter>n</parameter>'s daughter. */
153
154EST_Item *prepend_daughter(EST_Item *n, EST_Item *p=0);
155
156/** Add a daughter to node <parameter>n</parameter> as seen from
157relation <parameter>relname</parameter>, before any existing
158daughters, and return the next daughter. If <parameter>p</parameter>
159is 0, make a new node for the daughter, otherwise add
160<parameter>p</parameter> to this relation as
161<parameter>n</parameter>'s daughter. */
162
163EST_Item *prepend_daughter(EST_Item *n, const char *relname, EST_Item *p=0);
164
165//@}
166
167//@}
168#endif