示例#1
0
void
xcl_sentence_labels(struct xcl_context *xc, struct xcl_c *c)
{
  const char *first = NULL, *last = NULL;
  int n_lems = 0;

  if (c->type != xcl_c_sentence || !c->nchildren)
    return;

  first = first_l(c);
  last = last_l(c);

  if (first)
    {
      if (last)
	{
	  char *l = malloc(strlen(first)+strlen(last)+4);
	  sprintf(l,"%s - %s",first,last);
	  c->label = cc(pool_copy(ucc(l)));
	  free(l);
	}
      else
	c->label = cc(pool_copy(ucc(first)));
    }
  else if (n_lems) /* sentences that don't have lemmata don't matter */
    {
      vwarning("couldn't compute label for sentence with id=%s",c->ref);
    }
}
/* Aplica una funcion a todos los elementos del árbol */
void map_tree(void (*func)(void *), TREE *t)
{
    TREE *c;

    if(t->childs != NULL)
    {
        c = (TREE *)first_l(t->childs);
        while(c != NULL)
        {
            map_tree(func, c);
            c = (TREE *)next_l(t->childs);
        }
    }
    (*func)(t->value);
}
示例#3
0
static const char *
first_l(struct xcl_c *c)
{
  const char *ret = NULL;
  int i;
  for (i = 0; i < c->nchildren; ++i)
    {
      if (c->children[i].c->node_type == xcl_node_l)
	return cc(label_from_line_id(get_line_id(c->children[i].l->ref)));
      else if (c->children[i].c->node_type == xcl_node_c
	       && (ret = first_l(c->children[i].c)))
	return ret;
    }
  return ret;
}
/* Libera todo el árbol */
void free_tree(TREE *t)
{
    TREE *c;

    if(t->childs != NULL)
    {
        c = (TREE *)first_l(t->childs);
        while(c != NULL)
        {
            free_tree(c);
            c = (TREE *)next_l(t->childs);
        }
        free_l(t->childs);
    }
    free(t);
}