Пример #1
0
static void
serialize_psus(FILE *f_xcl,Hash_table*psus)
{
  static_f_xcl = f_xcl;
  fputs("<psus>",f_xcl);
  hash_exec2(psus, (hash_exec2_func*)serialize_psu_list);
  fputs("</psus>",f_xcl);
  static_f_xcl = NULL;
}
Пример #2
0
int
main(int argc, char **argv)
{
  setlocale(LC_ALL,LOCALE);
  sig_pool = npool_init();
  signiary = hash_create(1000);
  pertext = hash_create(1000);
  psl_init();
  runexpatNS(i_stdin,NULL,sH,eH,":");
  hash_exec2(signiary, printsigns);
  npool_term(sig_pool);
  psl_term();
  return 1;
}
Пример #3
0
static void
serialize_one_node(FILE*f_xcl,void *vp)
{
  enum xcl_node_types t = ((struct xcl_c *)vp)->node_type;
  /* int need_ll = 0; */
  int i, unwrapping = 0, phrase_index = 0;

#define cp ((struct xcl_c*)vp)
#define dp ((struct xcl_d*)vp)
#define lp ((struct xcl_l*)vp)

  switch (t)
    {
    case xcl_node_c:
      if (cp->type == xcl_c_sentence)
	{ 
	  if (no_words(cp))
	    unwrapping = 1;
	  else
	    {
	      int skipped_any_phrases = 0;
	      int set_cp_subtype = 0;
	      while (cp->nchildren && singleton_phrase_children(cp, &phrase_index))
		{
		  const char *phrase_subtype = cp->children[phrase_index].c->subtype;
		  int skip_phrase = 0;
		  if (!phrase_subtype)
		    phrase_subtype = (const char *)ilem_para_head_label(cp,1);
		  if (phrase_subtype)
		    {
		      if ((set_cp_subtype || !cp->subtype) 
			  && (!phrase_subtype || 'S' == *phrase_subtype))
			{
			  cp->subtype = phrase_subtype;
			  set_cp_subtype = 1;
			  skip_phrase = 1;
			  /* either this was already NULL or we've used it as
			     phrase_subtype */
			  cp->children[phrase_index].c->subtype = NULL;
			}
		    }
		  else
		    skip_phrase = 1;
		  if (skip_phrase)
		    {
		      union xcl_u tmp = cp->children[phrase_index];
		      union xcl_u *free_me = cp->children;
		      union xcl_u *new_c = NULL;
		      int n_new_c = 0, src, dest;

		      n_new_c = cp->nchildren + tmp.c->nchildren - 1;
		      new_c = malloc(n_new_c * sizeof(union xcl_u));
		      for (src = dest = 0; src < phrase_index; )
			new_c[dest++].c = cp->children[src++].c;
		      for (src = 0; src < tmp.c->nchildren; ++src)
			new_c[dest++].c = tmp.c->children[src].c;
		      for (src = phrase_index + 1; src < cp->nchildren; )
			new_c[dest++].c = cp->children[src++].c;
		      cp->nchildren = cp->children_alloced = n_new_c;
		      cp->children = new_c;
#if 0
		      cp->children = tmp.c->children;
		      cp->nchildren = tmp.c->nchildren;
		      cp->children_alloced = tmp.c->children_alloced;
#endif
		      free(free_me);
		      tmp.c->nchildren = tmp.c->children_alloced = 0;
		      tmp.c->children = NULL;
		      ++skipped_any_phrases;
		    }
		  else
		    break;
		}
	      /* if (skipped_any_phrases) */
		goto skipping_phrase;
	    }
	}
      else if (cp->type == xcl_c_phrase && singleton_phrase_children(cp, &phrase_index))
	{
	  unwrapping = 1;
	  if (cp->subtype && !cp->children[phrase_index].c->subtype)
	    cp->children[phrase_index].c->subtype = cp->subtype;
	}
      else
	{
	skipping_phrase:
	  fprintf(f_xcl,"<c");
	  x2_attr(f_xcl,"type",xcl_c_type_str[cp->type]);
	  if (cp->type == xcl_c_sentence)
	    x2_attr(f_xcl,"implicit","yes");
	  if (cp->subtype && *cp->subtype)
	    {
	      if (cp->type == xcl_c_sentence
		  || cp->type == xcl_c_clause
		  || cp->type == xcl_c_phrase)
		x2_attr(f_xcl,"tag",cp->subtype);
	      else
		x2_attr(f_xcl,"subtype",cp->subtype);
	    }
	  if (cp->id)
	    x2_attr(f_xcl,"xml:id",cp->id);
	  x2_attr(f_xcl,"label",cp->label);
	  x2_attr(f_xcl,"ref",cp->ref);
	  x2_attr_i(f_xcl,"level",cp->level);
	  fprintf(f_xcl," bracketing_level=\"%d\"",cp->bracketing_level);
	  fprintf(f_xcl,">");
	  if (cp->meta)
	    {
	      fprintf(f_xcl,"<mds xml:id=\"%s\">",(char*)hash_find(cp->meta,
								   (unsigned char *)"#xml:id"));
	      static_f_xcl = f_xcl;
	      hash_exec2(cp->meta,serialize_m);
	      fputs("</mds>",f_xcl);
	    }
	}
      for (i = 0; i < cp->nchildren; ++i)
	{
	  switch (cp->children[i].c->node_type)
	    {
	    case xcl_node_c:
	      serialize_one_node(f_xcl,cp->children[i].c);
	      break;
	    case xcl_node_d:
	      serialize_one_node(f_xcl,cp->children[i].d);
	      break;
	    case xcl_node_l:
	      serialize_one_node(f_xcl,cp->children[i].l);
	      break;
	    }
	}
      if (!unwrapping)
	fprintf(f_xcl,"</c>");
      break;
    case xcl_node_d:
      fprintf(f_xcl,"<d type=\"%s\"",xcl_d_type_str[dp->type]);
      if (dp->ref)
	fprintf(f_xcl, " ref=\"%s\"", dp->ref);
      if (dp->subtype)
	fprintf(f_xcl, " subtype=\"%s\"", dp->subtype);
      fputs("/>", f_xcl);
      break;
    case xcl_node_l:
#if 0
      if (lp->f && lp->f->acount)
	{
	  fprintf(f_xcl,"<ll type=\"ambig\" xml:id=\"%s\" ref=\"%s\">",lp->xml_id, lp->ref);
	  need_ll = 1;
	}
#endif
      serialize_one_l(f_xcl,lp);
#if 0
      while (need_ll)
	{
	  fprintf(f_xcl,"</ll>");
	  --need_ll;
	}
#endif
      break;
    }

#undef cp
#undef dp
#undef lp
}