"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "ling_class/EST_Item.cc" between
speech_tools-2.4-release.tar.gz and speech_tools-2.5.0-release.tar.gz

About: The speech_tools - Edinburgh Speech Tools Library (used by the Festival Speech Synthesis System).

EST_Item.cc  (speech_tools-2.4-release):EST_Item.cc  (speech_tools-2.5.0-release)
skipping to change at line 167 skipping to change at line 167
EST_Utterance *u = get_utt(s); EST_Utterance *u = get_utt(s);
if (u != 0) if (u != 0)
s->set("id", "_" + itoString(u->next_id())); s->set("id", "_" + itoString(u->next_id()));
} }
EST_Item::EST_Item(EST_Relation *rel, EST_Item *li) EST_Item::EST_Item(EST_Relation *rel, EST_Item *li)
{ {
p_relation = rel; p_relation = rel;
p_contents = 0; p_contents = 0;
n=p=u=d=0; n=p=u=d=0;
set_contents(li->contents()); if (li)
set_contents(li->contents());
else
set_contents(0);
assign_id(this); assign_id(this);
} }
void EST_Item::evaluate_features() void EST_Item::evaluate_features()
{ {
evaluate(this,p_contents->f); evaluate(this,p_contents->f);
} }
void EST_Item::unref_contents() void EST_Item::unref_contents()
skipping to change at line 317 skipping to change at line 320
if (p_relation && (p_relation->p_tail == this)) if (p_relation && (p_relation->p_tail == this))
p_relation->p_tail = new_node; p_relation->p_tail = new_node;
return new_node; return new_node;
} }
EST_Item *EST_Item::insert_parent(EST_Item *si) EST_Item *EST_Item::insert_parent(EST_Item *si)
{ {
// Insert new parent here, by added a new below node and moving // Insert new parent here, by added a new below node and moving
// the contents down to it. // the contents down to it.
if (this == 0) return 0;
insert_below(0); insert_below(0);
down()->set_contents(grab_contents()); d->set_contents(grab_contents());
if (si != 0) if (si != 0)
set_contents(si->grab_contents()); set_contents(si->grab_contents());
else else
set_contents(0); set_contents(0);
return this; return this;
} }
EST_Item *EST_Item::last() const EST_Item *inext(const EST_Item *x)
{
if (x == NULL)
return NULL;
else
return x->n;
}
EST_Item *iprev(const EST_Item *x)
{
if (x == NULL)
return NULL;
else
return x->p;
}
EST_Item *idown(const EST_Item *x)
{
if (x == NULL)
return NULL;
else
return x->d;
}
EST_Item *iup(const EST_Item *x)
{
if (x == NULL)
return NULL;
else
return x->u;
}
EST_Item *last(const EST_Item *x)
{ {
// To get round the const access to this // To get round the const access to this
EST_Item *node = (EST_Item *)(void *)this; EST_Item *node = (EST_Item *)(void *)x;
if (this == 0) return 0; for (; node && inext(node) != 0; node=inext(node));
for (; node->n != 0; node=node->n);
return node; return node;
} }
EST_Item *EST_Item::first() const EST_Item *first(const EST_Item *x)
{ {
// To get round the const access to this // To get round the const access to this
EST_Item *node = (EST_Item *)(void *)this; EST_Item *node = (EST_Item *)(void *)x;
if (this == 0) return 0; for (; node && iprev(node) != 0; node=iprev(node));
for (; node->p != 0; node=node->p);
return node; return node;
} }
EST_Item *EST_Item::top() const EST_Item *top(const EST_Item *x)
{ {
EST_Item *node = (EST_Item *)(void *)this; EST_Item *node = (EST_Item *)(void *)x;
if (this == 0) return 0; for (; node && parent(node) != 0; node=parent(node));
for (; parent(node) != 0; node=parent(node));
return node; return node;
} }
EST_Item *EST_Item::next_leaf() const EST_Item *next_leaf(const EST_Item *x)
{ {
if (this == 0) if (x == NULL) return NULL;
return 0; if (inext(x) != NULL)
else if (next() != 0) return first_leaf(inext(x));
return next()->first_leaf();
else else
return parent(this)->next_leaf(); return next_leaf(parent(x));
} }
EST_Item *EST_Item::next_item() const EST_Item *next_item(const EST_Item *x)
{ {
// For traversal through a relation, in pre-order (root then daughters) // For traversal through a relation, in pre-order (root then daughters)
if (this == 0) if (x == NULL)
return 0; return NULL;
else if (down() != 0) else if (idown(x) != NULL)
return down(); return idown(x);
else if (next() != 0) else if (inext(x) != NULL)
return next(); return inext(x);
else else
{ // at the right most leaf so go up until you find a parent with a next { // at the right most leaf so go up until you find a parent with a next
for (EST_Item *pp = parent(this); pp != 0; pp = parent(pp)) for (EST_Item *pp = parent(x); pp != 0; pp = parent(pp))
if (pp->next()) if (inext(pp)) return inext(pp);
return pp->next(); return NULL;
return 0;
} }
} }
EST_Item *EST_Item::first_leaf() const EST_Item *first_leaf(const EST_Item *x)
{ {
// Leafs are defined as those nodes with no daughters // Leafs are defined as those nodes with no daughters
if (this == 0) if (x == NULL) return NULL;
return 0; if (idown(x) == NULL)
if (down() == 0) return (EST_Item *)(void *)x;
return (EST_Item *)(void *)this;
else else
return down()->first_leaf(); return first_leaf(idown(x));
} }
EST_Item *EST_Item::last_leaf() const EST_Item *last_leaf(const EST_Item *x)
{ {
// Leafs are defined as those nodes with no daughters // Leafs are defined as those nodes with no daughters
if (this == 0) if (x == NULL) return NULL;
return 0; if (inext(x))
else if (next()) return last_leaf(last(x));
return next()->last_leaf(); else if (idown(x))
else if (down()) return last_leaf(idown(x));
return down()->last_leaf();
else else
return (EST_Item *)(void *)this; return (EST_Item *)(void *)x;
} }
EST_Item *first_leaf_in_tree(const EST_Item *root) EST_Item *first_leaf_in_tree(const EST_Item *root)
{ {
return root->first_leaf(); if (root == NULL) return NULL;
return first_leaf(root);
} }
EST_Item *last_leaf_in_tree(const EST_Item *root) EST_Item *last_leaf_in_tree(const EST_Item *root)
{ {
if (root == 0) if (root == NULL) return NULL;
return 0; if (idown(root) == NULL)
else if (root->down() == 0)
return (EST_Item *)(void *)root; return (EST_Item *)(void *)root;
else else
return root->down()->last_leaf(); return last_leaf(idown(root));
} }
EST_Item *EST_Item::append_daughter(EST_Item *si) EST_Item *EST_Item::append_daughter(EST_Item *si)
{ {
if (this == 0)
return 0;
EST_Item *nnode; EST_Item *nnode;
EST_Item *its_downs; EST_Item *its_downs;
EST_Item *c = NULL;
// Because we don't distinguish forests properly we need // Because we don't distinguish forests properly we need
// to do nasty things if this si is already associated to a // to do nasty things if this si is already associated to a
// this relation and its "in the top list" // this relation and its "in the top list"
EST_Item *c = si->as_relation(relation_name()); if (si)
c = si->as_relation(relation_name());
if (in_list(c,p_relation->head())) if (in_list(c,p_relation->head()))
{ {
// need to save its daughters to put on the new node // need to save its daughters to put on the new node
its_downs = c->d; its_downs = c->d;
c->d = 0; // otherwise it could delete its sub tree c->d = 0; // otherwise it could delete its sub tree
if (its_downs) its_downs->u = 0; if (its_downs) its_downs->u = 0;
if (down() == 0) if (d == 0)
nnode = insert_below(si); nnode = insert_below(si);
else else
nnode = down()->last()->insert_after(si); nnode = last(d)->insert_after(si);
// put daughters back on the new item // put daughters back on the new item
if (its_downs) if (its_downs)
{ {
its_downs->u = nnode; its_downs->u = nnode;
nnode->d = its_downs; nnode->d = its_downs;
} }
delete c; // delete its old form from the top level delete c; // delete its old form from the top level
} }
else if (down() == 0) else if (d == 0)
nnode = insert_below(si); nnode = insert_below(si);
else else
nnode = down()->last()->insert_after(si); nnode = last(d)->insert_after(si);
return nnode; return nnode;
} }
EST_Item *EST_Item::prepend_daughter(EST_Item *si) EST_Item *EST_Item::prepend_daughter(EST_Item *si)
{ {
if (this == 0)
return 0;
EST_Item *nnode; EST_Item *nnode;
EST_Item *its_downs; EST_Item *its_downs;
// Because we don't distinguish forests properly we need // Because we don't distinguish forests properly we need
// to do nasty things if this si is already associated to a // to do nasty things if this si is already associated to a
// this relation and its "in the top list" // this relation and its "in the top list"
EST_Item *c = si->as_relation(relation_name()); EST_Item *c = si->as_relation(relation_name());
if (in_list(c,p_relation->head())) if (in_list(c,p_relation->head()))
{ {
// need to save its daughters to put on the new node // need to save its daughters to put on the new node
its_downs = c->d; its_downs = c->d;
c->d = 0; // otherwise it could delete its sub tree c->d = 0; // otherwise it could delete its sub tree
if (its_downs) its_downs->u = 0; if (its_downs) its_downs->u = 0;
if (down() == 0) if (d == 0)
nnode = insert_below(si); nnode = insert_below(si);
else else
nnode = down()->insert_before(si); nnode = d->insert_before(si);
// put daughters back on the new item // put daughters back on the new item
if (its_downs) if (its_downs)
{ {
its_downs->u = nnode; its_downs->u = nnode;
nnode->d = its_downs; nnode->d = its_downs;
} }
delete c; // delete its old form from the top level delete c; // delete its old form from the top level
} }
else if (down() == 0) else if (d == 0)
nnode = insert_below(si); nnode = insert_below(si);
else else
nnode = down()->insert_before(si); nnode = d->insert_before(si);
return nnode; return nnode;
} }
EST_Item *EST_Item::grab_daughters() EST_Item *EST_Item::grab_daughters()
{ {
EST_Item *dd = down(); EST_Item *dd = d;
if (dd) if (dd)
{ {
dd->u = 0; dd->u = 0;
d = 0; d = 0;
} }
return dd; return dd;
} }
EST_Item_Content *EST_Item::grab_contents(void) EST_Item_Content *EST_Item::grab_contents(void)
{ {
skipping to change at line 532 skipping to change at line 556
c->unref_relation(relation_name()); c->unref_relation(relation_name());
p_contents = 0; p_contents = 0;
set_contents(0); // can't sit without contents set_contents(0); // can't sit without contents
return c; return c;
} }
void copy_node_tree(EST_Item *from, EST_Item *to) void copy_node_tree(EST_Item *from, EST_Item *to)
{ {
// Copy this node and all its siblings and daughters // Copy this node and all its siblings and daughters
if (from->next() != 0) if (inext(from) != 0)
copy_node_tree(from->next(),to->insert_after(from->next())); copy_node_tree(inext(from),to->insert_after(inext(from)));
if (from->down() != 0) if (idown(from) != 0)
copy_node_tree(from->down(),to->insert_below(from->down())); copy_node_tree(idown(from),to->insert_below(idown(from)));
} }
void copy_node_tree_contents(EST_Item *from, EST_Item *to) void copy_node_tree_contents(EST_Item *from, EST_Item *to)
{ {
// Copy this node and all its siblings and daughters // Copy this node and all its siblings and daughters
// also copy the item's contents // also copy the item's contents
if (from->next() != 0) if (inext(from) != 0)
{ {
EST_Item i = *from->next(); // copies the contents EST_Item i = *inext(from); // copies the contents
copy_node_tree_contents(from->next(),to->insert_after(&i)); copy_node_tree_contents(inext(from),to->insert_after(&i));
} }
if (from->down() != 0) if (idown(from) != 0)
{ {
EST_Item i = *from->down(); EST_Item i = *idown(from);
copy_node_tree_contents(from->down(),to->insert_below(&i)); copy_node_tree_contents(idown(from),to->insert_below(&i));
} }
} }
int EST_Item::verify() const int EST_Item::verify() const
{ {
// Return FALSE if this node and its neighbours aren't // Return FALSE if this node and its neighbours aren't
// properly linked // properly linked
if (this == 0)
return TRUE;
if (((d == 0) || (d->u == this)) && if (((d == 0) || (d->u == this)) &&
((n == 0) || (n->p == this)) && ((n == 0) || (n->p == this)))
(d->verify()) && {
(n->verify())) if ((d) && (!d->verify()))
return FALSE;
if ((n) && (!n->verify()))
return FALSE;
return TRUE; return TRUE;
}
else else
return FALSE; return FALSE;
} }
EST_Item *append_daughter(EST_Item *n, EST_Item *p) EST_Item *append_daughter(EST_Item *n, EST_Item *p)
{ {
return n->append_daughter(p); return n->append_daughter(p);
} }
EST_Item *append_daughter(EST_Item *n,const char *relname, EST_Item *p) EST_Item *append_daughter(EST_Item *n,const char *relname, EST_Item *p)
 End of changes. 49 change blocks. 
81 lines changed or deleted 107 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)