Edinburgh Speech Tools 2.4-release
EST_Relation_mls.cc
1/*************************************************************************/
2/* */
3/* Centre for Speech Technology Research */
4/* University of Edinburgh, UK */
5/* Copyright (c) 1999 */
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 : Alan W Black */
34/* Date : April 1999 */
35/*-----------------------------------------------------------------------*/
36/* Multi-linear list relations */
37/* */
38/* These are to allow to linear list relations to have relations */
39/* between one item in one list and a list of items in the other */
40/* */
41/* */
42/* Ehh I'll explain how I do this once its done */
43/* */
44/* */
45/*=======================================================================*/
46#include <cstdlib>
47#include <cstdio>
48#include "ling_class/EST_Item.h"
49
50int linked(EST_Item *from, EST_Item *to)
51{
52 EST_Item *i;
53
54 for (i=link1(from); i; i=next_link(i))
55 if (i == to)
56 return TRUE;
57
58 return FALSE;
59}
60
61void add_link(EST_Item *from, EST_Item *to)
62{
63 EST_Item *d;
64
65 // structurally add it
66 d = idown(from);
67 if (!d)
68 d = from->append_daughter();
69 d->append_daughter()->append_daughter(to);
70 // Also add it to the simple list of the relation so traversal works
71 // append q
72
73}
74
75#if 0
76/* nope all wrong */
77static void mls_insert_up(EST_Item *c,EST_Item *d)
78{
79 if (c->up() == 0)
80 c->insert_above(d);
81 else
82 c->up()->last()->insert_after(d);
83}
84
85static void mls_insert_below(EST_Item *c,EST_Item *d)
86{
87 if (c->down() == 0)
88 c->insert_below(d);
89 else
90 c->down()->last()->insert_after(d);
91}
92
93static void mls_linked_down(EST_Item *c,EST_Item *d)
94{
95 return in_list(d,c->down());
96}
97
98static void mls_linked_up(EST_Item *c,EST_Item *d)
99{
100 return in_list(d,c->up());
101}
102
103int link_items(EST_Relation *mlsrel,EST_Item *i1, EST_item *i2)
104{
105 if ((i1->in_relation(mlsrel->name())) &&
106 (i2->in_relation(mlsrel->name())))
107 {
108 EST_error("can't link two items already in %s\n",
109 (const char *)mlsrel->name());
110 return FALSE;
111 }
112 else if (i1->in_relation(mlsrel->name()))
113 {
114 EST_Item *c = mls_cluster(as(i1,mlsrel->name()));
115 if (mls_linked_down(c,i1))
116 mls_insert_up(c,i2);
117 else
118 mls_insert_down(c,i2);
119 }
120 else if (i2->in_relation(mlsrel->name()))
121 {
122 EST_Item *c = mls_cluster(as(i2,mlsrel->name()));
123 if (mls_linked_down(c,i2))
124 mls_insert_up(c,i1);
125 else
126 mls_insert_down(c,i1);
127 }
128 else
129 {
130 // neither in MLS so create new cluster
131 EST_Item *c = mlsrel->append();
132 mls_insert_linked_up(c,i1);
133 mls_insert_linked_down(c,i1);
134 }
135 return TRUE;
136}
137#endif
138
139void remove_link(EST_Item *from, EST_Item *to)
140{
141 (void)from;
142 (void)to;
143
144 fprintf(stderr,"remove_link not written yet\n");
145}
146
int in_relation(const EST_String &relname) const
TRUE if this item is in named relation.
Definition: EST_Item.h:306
const EST_String & name() const
Definition: EST_Relation.h:122