54 #include "ling_class/EST_Item.h"
55 #include "ling_class/EST_Relation.h"
56 #include "ling_class/EST_Utterance.h"
58 #include "EST_UList.h"
59 #include "EST_string_aux.h"
61 #include "ling_class_init.h"
66 void EST_Item::class_init(
void)
69 cerr <<
"Calling EST_Item init\n";
72 ling_class_init::use();
74 EST_register_feature_functions(standard);
77 cerr <<
"Finished EST_Item init\n";
89 void EST_Item::copy(
const EST_Item &s)
100 *p_contents = *s.p_contents;
121 if (p != 0) p->n = n;
122 if (u != 0) u->d = n;
126 if (p_relation->p_head ==
this)
127 p_relation->p_head = n;
128 if (p_relation->p_tail ==
this)
129 p_relation->p_tail = p;
133 for (ds=d; ds != 0; ds=nds)
168 set_contents(li->contents());
177 evaluate(
this,p_contents->
f);
180 void EST_Item::unref_contents()
192 void EST_Item::unref_all()
196 p_contents->unref_and_delete();
201 return ((
this == 0) || (p_relation == 0)) ?
210 if (new_contents == 0)
231 int EST_Item::length()
const
235 for (; nn; nn=nn->n,i++);
247 new_node->n = this->n;
248 if (new_node->n != 0)
249 new_node->n->p = new_node;
252 if (p_relation && (p_relation->p_tail ==
this))
253 p_relation->p_tail = new_node;
264 new_node->p = this->p;
265 if (new_node->p != 0)
266 new_node->p->n = new_node;
272 new_node->u = this->u;
273 new_node->u->d = new_node;
277 if (p_relation && (p_relation->p_head ==
this))
278 p_relation->p_head = new_node;
289 new_node->d = this->d;
290 if (new_node->d != 0)
291 new_node->d->u = new_node;
303 new_node->u = this->u;
304 if (new_node->u != 0)
305 new_node->u->d = new_node;
308 if (p_relation && (p_relation->p_head ==
this))
309 p_relation->p_head = new_node;
310 if (p_relation && (p_relation->p_tail ==
this))
311 p_relation->p_tail = new_node;
321 d->set_contents(grab_contents());
323 set_contents(si->grab_contents());
367 for (; node && inext(node) != 0; node=inext(node));
376 for (; node && iprev(node) != 0; node=iprev(node));
384 for (; node && parent(node) != 0; node=parent(node));
390 if (x == NULL)
return NULL;
391 if (inext(x) != NULL)
392 return first_leaf(inext(x));
394 return next_leaf(parent(x));
402 else if (idown(x) != NULL)
404 else if (inext(x) != NULL)
408 for (
EST_Item *pp = parent(x); pp != 0; pp = parent(pp))
409 if (inext(pp))
return inext(pp);
417 if (x == NULL)
return NULL;
418 if (idown(x) == NULL)
421 return first_leaf(idown(x));
427 if (x == NULL)
return NULL;
429 return last_leaf(last(x));
431 return last_leaf(idown(x));
438 if (root == NULL)
return NULL;
439 return first_leaf(root);
444 if (root == NULL)
return NULL;
445 if (idown(root) == NULL)
448 return last_leaf(idown(root));
462 if (in_list(c,p_relation->
head()))
467 if (its_downs) its_downs->u = 0;
470 nnode = insert_below(si);
472 nnode = last(d)->insert_after(si);
476 its_downs->u = nnode;
477 nnode->d = its_downs;
483 nnode = insert_below(si);
485 nnode = last(d)->insert_after(si);
499 if (in_list(c,p_relation->
head()))
504 if (its_downs) its_downs->u = 0;
507 nnode = insert_below(si);
509 nnode = d->insert_before(si);
513 its_downs->u = nnode;
514 nnode->d = its_downs;
520 nnode = insert_below(si);
522 nnode = d->insert_before(si);
527 EST_Item *EST_Item::grab_daughters()
556 if (inext(from) != 0)
557 copy_node_tree(inext(from),to->insert_after(inext(from)));
559 if (idown(from) != 0)
560 copy_node_tree(idown(from),to->insert_below(idown(from)));
569 if (inext(from) != 0)
572 copy_node_tree_contents(inext(from),to->insert_after(&i));
575 if (idown(from) != 0)
578 copy_node_tree_contents(idown(from),to->insert_below(&i));
583 int EST_Item::verify()
const
588 if (((d == 0) || (d->u ==
this)) &&
589 ((n == 0) || (n->p ==
this)))
591 if ((d) && (!d->verify()))
593 if ((n) && (!n->verify()))
603 return n->append_daughter(p);
608 return append_daughter(as(n,relname),p);
613 return n->prepend_daughter(p);
618 return prepend_daughter(as(n,relname),p);
621 void remove_item(
EST_Item *l,
const char *relname)
626 if ((lr != 0) && (r != 0))
636 ostream& operator << (ostream &s,
const EST_Item &a)
638 a.features().
save(s);
647 for(p.
begin(f); p; ++p)
648 if (p->v.type() == val_type_featfunc)
650 if (featfunc(p->v) != NULL)
651 p->v = (featfunc(p->v))(a);
654 fprintf(stderr,
"NULL %s function\n", (
const char *) p->k );
655 p->v = EST_Features::feature_default_value;
660 VAL_REGISTER_CLASS_NODEL(item,
EST_Item)
EST_write_status save(ostream &outf) const
save features in already opened ostream
EST_Features f
General features for this item.
void set(const EST_String &name, int ival)
EST_Relation * relation(void) const
The relation of this particular item.
EST_Item * as_relation(const char *relname) const
View item from another relation (const char *) method.
const EST_String & relation_name() const
The relation name of this particular item.
EST_Item()
Default constructor.
int f_present(const EST_String &name) const
~EST_Item()
Deletes it and references to it in its contents.
const EST_String & name() const
void remove_item(EST_Item *item)
static const EST_String Empty
Constant empty string.
int add_item(const K &rkey, const V &rval, int no_search=0)
add key-val pair to list
void begin(Container &over)
Set the iterator ready to run over this container.
int next_id()
return the id of the next item