Ejemplo n.º 1
0
cst_val *get_wavelist(const char *wavelistfile)
{
    cst_val *l = 0;
    cst_tokenstream *ts;
    const char *token;
    int i=0;

    ts = ts_open(wavelistfile);
    if (!ts)
    {
	fprintf(stderr,"combine_waves: can't open \"%s\"\n",wavelistfile);
	return 0;
    }

    while ((token=ts_get(ts)) != 0)
    {
	l = cons_val(string_val(token),l);
	i++;
    }

    if (i%2 != 0)
    {
	fprintf(stderr,"combine_waves: doesn't have matched pairs \"%s\"\n",wavelistfile);
	delete_val(l);
	l = 0;
    }

    ts_close(ts);

    return val_reverse(l);
}
Ejemplo n.º 2
0
int flite_voice_add_lex_addenda(cst_voice *v, const cst_string *lexfile)
{
    /* Add addenda in lexfile to current voice */
    cst_lexicon *lex;
    const cst_val *lex_addenda = NULL;
    cst_val *new_addenda;

    lex = val_lexicon(feat_val(v->features,"lexicon"));
    if (feat_present(v->features, "lex_addenda"))
	lex_addenda = feat_val(v->features, "lex_addenda");

    new_addenda = cst_lex_load_addenda(lex,lexfile);
#if 0
    printf("\naddenda: ");
    val_print(stdout,new_addenda);
    printf("\n");
#endif

    new_addenda = val_append(new_addenda,(cst_val *)lex_addenda);
    if (lex->lex_addenda)
        delete_val(lex->lex_addenda);
    lex->lex_addenda = new_addenda;

    return 0;
}
Ejemplo n.º 3
0
int feat_remove(cst_features *f, const char *name)
{
    cst_featvalpair *n,*p,*np;
    
    if (f == NULL)
	return FALSE; /* didn't remove it */
    else
    {
	for (p=NULL,n=f->head; n; p=n,n=np)
	{
	    np = n->next;
	    if (cst_streq(name,n->name))
	    {
		if (p == 0)
		    f->head = np;
		else
		    p->next = np;
		delete_val(n->val);
		cst_local_free(f->ctx,n);
		return TRUE;
	    }
	}
	return FALSE;
    }
}
Ejemplo n.º 4
0
void feat_set(cst_features *f, const char* name, const cst_val *val)
{
    cst_featvalpair *n;
    n = feat_find_featpair(f,name);

    if (val == NULL)
    {
	cst_errmsg("cst_val: trying to set a NULL val for feature \"%s\"\n",
		   name);
    }
    else if (n == NULL)
    {   /* first reference to this feature so create new fpair */
	cst_featvalpair *p;
	p = (cst_featvalpair *)cst_local_alloc(f->ctx, sizeof(*p));
#import "OpenEarsStaticAnalysisToggle.h"
#ifdef STATICANALYZEDEPENDENCIES
#define __clang_analyzer__ 1
#endif
#if !defined(__clang_analyzer__) || defined(STATICANALYZEDEPENDENCIES)
#undef __clang_analyzer__
        
	p->next = f->head;
      
	p->name = name; 
	p->val = val_inc_refcount(val);
	f->head = p;
    }
    else
    {
	delete_val(n->val);
	n->val = val_inc_refcount(val);
    }
#endif      
}
Ejemplo n.º 5
0
void feat_set(cst_features *f, const char* name, const cst_val *val)
{
    cst_featvalpair *n;
    n = feat_find_featpair(f,name);

    if (val == NULL)
    {
	cst_errmsg("cst_val: trying to set a NULL val for feature \"%s\"\n",
		   name);
    }
    else if (n == NULL)
    {   /* first reference to this feature so create new fpair */
	cst_featvalpair *p;
	p = (cst_featvalpair *)cst_local_alloc(f->ctx, sizeof(*p));
	p->next = f->head;
	p->name = name; 
	p->val = val_inc_refcount(val);
	f->head = p;
    }
    else
    {
	delete_val(n->val);
	n->val = val_inc_refcount(val);
    }
}
Ejemplo n.º 6
0
cst_val* ru_lts_apply(const cst_val *input, const cst_lts_rewrites *rule)
{
  cst_val *l=add_lts_boundary_marks(input);
  cst_val *output=lts_rewrites(l, rule);
  delete_val(l);
  return output;
}
Ejemplo n.º 7
0
void delete_features(cst_features *f)
{
    cst_featvalpair *n, *np;

    if (f)
    {
	for (n=f->head; n; n=np)
	{
	    np = n->next;
	    delete_val(n->val);
	    cst_local_free(f->ctx,n);
	}
        delete_val(f->owned_strings);
	cst_local_free(f->ctx,f);
    }
}
Ejemplo n.º 8
0
void delete_val(cst_val *v)
{
    if (v)
    {
        if (cst_val_consp(v))
        {
            delete_val(CST_VAL_CAR(v));
            delete_val(CST_VAL_CDR(v));
            cst_free(v);
        }
        else if (val_dec_refcount(v) == 0)
        {
            if (CST_VAL_TYPE(v) == CST_VAL_TYPE_STRING)
                cst_free(CST_VAL_VOID(v));
            else if (CST_VAL_TYPE(v) >= CST_VAL_TYPE_FIRST_FREE)
                (cst_val_defs[CST_VAL_TYPE(v)/2].delete_function)(CST_VAL_VOID(v));
            cst_free(v);
        }
    }
}
Ejemplo n.º 9
0
void delete_val_list(cst_val *v)
{
    if (v)
    {
	if (cst_val_consp(v))
	{
	    delete_val_list(CST_VAL_CDR(v));
	    cst_free(v);
	}
	else
	    delete_val(v);
    }
}
Ejemplo n.º 10
0
cst_val *en_exp_ordinal(const char *rawnumstring)
{
    /* return ordinal for digit string */
    cst_val *card, *o;
    const cst_val *t;
    const char *l;
    const char *ord;
    char *numstring;
    int i,j;

    numstring = cst_strdup(rawnumstring);
    for (j=i=0; i < cst_strlen(rawnumstring); i++)
	if (rawnumstring[i] != ',')
	{
	    numstring[j] = rawnumstring[i];
	    j++;
	}
    numstring[j] = '\0';
    card = val_reverse(en_exp_number(numstring));
    cst_free(numstring);

    l = val_string(val_car(card));
    ord = 0;
    for (i=0; i<10; i++)
	if (cst_streq(l,digit2num[i]))
	    ord = ord2num[i];
    if (!ord)
	for (i=0; i<10; i++)
	    if (cst_streq(l,digit2teen[i]))
		ord = ord2teen[i];
    if (!ord)
	for (i=0; i<10; i++)
	    if (cst_streq(l,digit2enty[i]))
		ord = ord2enty[i];
    if (cst_streq(l,"hundred"))
	ord = "hundredth";
    if (cst_streq(l,"thousand"))
	ord = "thousandth";
    if (cst_streq(l,"billion"))
	ord = "billtionth";
    if (!ord)  /* dunno, so don't convert anything */
	return card;
    o = cons_val(string_val(ord),0);
    for (t=val_cdr(card); t; t=val_cdr(t))
	o = cons_val(val_car(t),o);
    delete_val(card);
    return o;
}
Ejemplo n.º 11
0
static cst_val* word_to_phones(const cst_item *word)
{
  cst_val*phones=NULL;
  const char *name=item_feat_string(word, "name");
  ustring32_t letters=ustring32_alloc(0);
  if(letters==NULL) return NULL;
  ustring32_assign8(letters,(const uint8_t*)name);
  if(ustring32_empty(letters))
    {
      ustring32_free(letters);
      return NULL;
    }
  unsigned int flags=classify_characters(ustring32_str(letters),ustring32_length(letters));
  int variant=item_feat_int(item_parent(item_as(word,"Token")),"variant");
  if((flags&cs_lc)&&cst_streq(ffeature_string(word,"gpos"),"content"))
    {
      if(variant==variant_pseudo_english)
        phones=ustring32_lts_apply(letters,&en_consonants_lts);
      else phones=ustring32_lts_apply(letters,&ru_consonants_lts);
      item_set_int(word,"no_vr",1);
    }
  else if((variant==variant_pseudo_english)&&(flags&cs_en))
    {
      cst_val *en_phones=lex_lookup(en_lex,name,(cst_streq(name,"a")?"n":NULL));
      if(en_phones)
        {
          phones=ru_lts_apply(en_phones,&ru_en_lts);
          delete_val(en_phones);
        }
      item_set_int(word,"no_pl",1);
    }
  else
    {
      const ru_dict_entry *e=bsearch(name,ru_dict,ru_dict_size,sizeof(ru_dict_entry),compare_entries);
      if(e!=NULL)
        {
          if(e->stress > 0)
            ustring32_set(letters,e->stress-1,1105);
          else
            item_set_int(word,"stressed_syl_num",e->stress);
        }
      phones=ustring32_lts_apply(letters,&ru_lts);
    }
  ustring32_free(letters);
  return phones;
}
Ejemplo n.º 12
0
cst_val* ustring32_lts_apply(const ustring32_t u32,const cst_lts_rewrites *rule)
{
  size_t n=ustring32_length(u32);
  if(n==0) return NULL;
  cst_val *l=cons_val(string_val("#"),NULL);
  uint8_t b[8];
  size_t i=n;
  int k;
  do
    {
      i--;
      k=u8_uctomb(b,ustring32_at(u32,i),sizeof(b));
      b[k]='\0';
      l=cons_val(string_val((char*)b),l);
    }
  while(i);
  l=cons_val(string_val("#"),l);
  cst_val *output=lts_rewrites(l, rule);
  delete_val(l);
  return output;
}
Ejemplo n.º 13
0
cst_val *cmu_grapheme_lex_lts_function(const struct lexicon_struct *l, 
                                       const char *word, const char *pos,
                                       const cst_features *feats)
{
    cst_val *phones = 0;
    cst_val *utflets = 0;
    const cst_val *v;
    char ord[10];
    int i,phindex;

    /* string to utf8 chars */
    utflets = cst_utf8_explode(word);

    for (v=utflets; v; v=val_cdr(v))
    {
        /* We will add the found phones in reverse order and reverse then */
        /* afterwards */
        cst_utf8_as_hex(val_string(val_car(v)),ord);
        phindex = cst_find_u2sampa(ord);
        if (phindex < 0)
            printf("awb_debug no sampa %s %s\n",val_string(val_car(v)),ord);
        for (i=4; (phindex>=0) && (i>0); i--)
        {
            if (unicode_sampa_mapping[phindex][i])
                phones = cons_val(string_val(unicode_sampa_mapping[phindex][i]),
                                  phones);
        }
    }

    phones = val_reverse(phones);
#if 1
    printf("cmu_grapheme_lex.c: word \"%s\" ",word);
    val_print(stdout,phones);
    printf("\n");
#endif

    delete_val(utflets);

    return phones;
}
Ejemplo n.º 14
0
void delete_cart(cst_cart *cart)
{
    /* have to compensate for previous over-zealous consting */
    /* It is assume that given carts, can be freed (i.e. they aren't in */
    /* in the data segment */
    int i;

    if (cart == NULL)
        return;

    for (i = 0; cart->rule_table[i].val; i++)
        delete_val((cst_val *) (void *) cart->rule_table[i].val);
    cst_free((void *) cart->rule_table);

    for (i = 0; cart->feat_table[i]; i++)
        cst_free((void *) cart->feat_table[i]);
    cst_free((void *) cart->feat_table);

    cst_free(cart);

    return;
}
Ejemplo n.º 15
0
cst_val *lts_rewrites_word(const char *word, const cst_lts_rewrites *r)
{
    cst_val *w, *p;
    char x[2];
    int i;

    x[1] = '\0';
    w = cons_val(string_val("#"),NULL);
    for (i=0; word[i]; i++)
    {
	x[0] = word[i];
	w = cons_val(string_val(x),w);
    }
    w = cons_val(string_val("#"),w);

    w = val_reverse(w);

    p = lts_rewrites(w,r);

    delete_val(w);

    return p;
}
Ejemplo n.º 16
0
cst_utterance *default_textanalysis(cst_utterance *u)
{
    cst_item *t,*word;
    cst_relation *word_rel;
    cst_val *words;
    const cst_val *w;
    const cst_val *ttwv;

    word_rel = utt_relation_create(u,"Word");
    ttwv = feat_val(u->features, "tokentowords_func");

    for (t=relation_head(utt_relation(u,"Token")); t; t=item_next(t))
    {
	if (ttwv)
	    words = (cst_val *)(*val_itemfunc(ttwv))(t);
	else
	    words = default_tokentowords(t);

	for (w=words; w; w=val_cdr(w))
	{
	    word = item_add_daughter(t,NULL);
	    if (cst_val_consp(val_car(w)))
	    {   /* Has extra features */
		item_set_string(word,"name",val_string(val_car(val_car(w))));
		feat_copy_into(val_features(val_cdr(val_car(w))),
			       item_feats(word));
	    }
	    else
		item_set_string(word,"name",val_string(val_car(w)));
	    relation_append(word_rel,word);
	}
	delete_val(words);
    }

    return u;
}
Ejemplo n.º 17
0
void main()
{
	link_list mylist;

	init_list(&mylist);

	int select = 1;
	elem_type item;
	node *p = NULL;
	while(select)
	{
		printf("*************************************************\n");
		printf("*  [1] push_back	 [2] push_front 	*\n");
		printf("*  [3] show_list	 [4] pop_back    	*\n");
		printf("*  [5] pop_front	 [6] insert_val 	*\n");
		printf("*  [7] find 	 	 [8] get_length 	*\n");
		printf("*  [9] delete_val	 [10] sort   	 	*\n");
		printf("*  [11] resever		 [12] clear 	 	*\n");
		printf("*  [13*] destroy	 [0] quit_system 	*\n");
		printf("*  [14] prior_node 	 [15] next_node 	*\n");
		printf("*************************************************\n");

		printf("请选择操作选项:> ");
		scanf("%d", &select);

		if(select == 0)
			break;

		switch(select)
		{
			case 1:
				printf("请输入要插入的数据(-1结束):>");
				while(scanf("%d", &item), item != -1)
				{
					push_back(&mylist, item);
				}
				break;
			case 2:
				printf("请输入要插入的数据(头插法, -1结束);>");
				while(scanf("%d", &item), item != -1)
				{
					push_front(&mylist, item);
				}
				break;
			case 3:
				show_list(&mylist);
				break;
			case 4:
				pop_back(&mylist);
				break;
			case 5:
				pop_front(&mylist);
				break;
			case 6:
				printf("请输入要插入的数据:>");
				scanf("%d", &item);
				insert_val(&mylist, item);
				break;
			case 7:
				printf("请输入要查找的数据:>");
				scanf("%d", &item);
				p = find(&mylist, item);
				if (p == NULL)
				{
					printf("要查找的数据在单链表中不存在.");
				}
				else
				 	printf("在单链表查找到数据: %d\n", p->data);
				break;
			case 8:
				printf("单链表的长度为: %d\n", get_length(&mylist));
				break;
			case 9:
				printf("请输入要删除的值:> ");
				scanf("%d", &item);
				delete_val(&mylist, item);
				break;
			case 10:
				sort(&mylist);
				break;
			case 11:
				resver(&mylist);
				break;
			case 12:
				clear(&mylist);
				break;
			case 14:
				printf("请输入要查找的数据:>");
				scanf("%d", &item);
				p = prior_node(&mylist, item);
				if (p == NULL || p == (&mylist)->head)
				{
					printf("要查找的数据在单链表中不存在前驱.\n");
				}
				else
				{
			 	 	printf("要查找的数据在单链表中的前驱为:%d.\n", p->data);	
				}
				break;
 	 	 	case 15:
				printf("请输入要查找的数据:>");
				scanf("%d", &item);
				p = next_node(&mylist, item);
				if (p == NULL)
				{
					printf("要查找的数据在单链表中不存在后继.\n");
				}
				else
				{
			 	 	printf("要查找的数据在单链表中的后继为:%d.\n", p->data);	
				}
				break;

			default:
				printf("输入的选择有误,请重新输入.\n");
				break;
		}
	}
	destroy(&mylist);
}
Ejemplo n.º 18
0
int main(int argc, char **argv)
{
    struct timeval tv;
    cst_voice *v;
    const char *filename;
    const char *outtype;
    cst_voice *desired_voice = 0;
    const char *voicedir = NULL;
    int i;
    float durs;
    double time_start, time_end;
    int flite_verbose, flite_loop, flite_bench;
    int explicit_filename, explicit_text, explicit_phones, ssml_mode;
#define ITER_MAX 3
    int bench_iter = 0;
    cst_features *extra_feats;
    const char *lex_addenda_file = NULL;
    const char *voicedumpfile = NULL;
    cst_audio_streaming_info *asi;

    filename = 0;
    outtype = "play";   /* default is to play */
    flite_verbose = FALSE;
    flite_loop = FALSE;
    flite_bench = FALSE;
    explicit_text = explicit_filename = explicit_phones = FALSE;
    ssml_mode = FALSE;
    extra_feats = new_features();

    flite_init();
    flite_add_lang("eng",usenglish_init,cmu_lex_init);

    for (i=1; i<argc; i++)
    {
	if (cst_streq(argv[i],"--version"))
	{
	    flite_version();
	    return 1;
	}
	else if (cst_streq(argv[i],"-h") ||
		 cst_streq(argv[i],"--help") ||
		 cst_streq(argv[i],"-?"))
	    flite_usage();
	else if (cst_streq(argv[i],"-v"))
	    flite_verbose = TRUE;
	else if (cst_streq(argv[i],"-lv"))
        {
            if (flite_voice_list == NULL)
                flite_set_voice_list(voicedir);
            flite_voice_list_print();
            exit(0);
        }
	else if (cst_streq(argv[i],"-l"))
	    flite_loop = TRUE;
	else if (cst_streq(argv[i],"-b"))
	{
	    flite_bench = TRUE;
	    break; /* ignore other arguments */
	}
	else if ((cst_streq(argv[i],"-o")) && (i+1 < argc))
	{
	    outtype = argv[i+1];
	    i++;
	}
	else if ((cst_streq(argv[i],"-voice")) && (i+1 < argc))
	{
            if (flite_voice_list == NULL)
                flite_set_voice_list(voicedir);
            desired_voice = flite_voice_select(argv[i+1]);
	    i++;
	}
	else if ((cst_streq(argv[i],"-voicedir")) && (i+1 < argc))
	{
            voicedir = argv[i+1];
            if (flite_voice_list == NULL)
                flite_set_voice_list(voicedir);
	    i++;
	}
	else if ((cst_streq(argv[i],"-add_lex")) && (i+1 < argc))
	{
            lex_addenda_file = argv[i+1];
	    i++;
	}
	else if (cst_streq(argv[i],"-f") && (i+1 < argc))
	{
	    filename = argv[i+1];
	    explicit_filename = TRUE;
	    i++;
	}
	else if (cst_streq(argv[i],"-pw"))
	{
	    feat_set_string(extra_feats,"print_info_relation","Word");
	    feat_set(extra_feats,"post_synth_hook_func",
		     uttfunc_val(&print_info));
	}
	else if (cst_streq(argv[i],"-ps"))
	{
	    feat_set_string(extra_feats,"print_info_relation","Segment");
	    feat_set(extra_feats,"post_synth_hook_func",
		     uttfunc_val(&print_info));
	}
        else if (cst_streq(argv[i],"-ssml"))
        {
            ssml_mode = TRUE;
        }
	else if (cst_streq(argv[i],"-pr") && (i+1 < argc))
	{
	    feat_set_string(extra_feats,"print_info_relation",argv[i+1]);
	    feat_set(extra_feats,"post_synth_hook_func",
		     uttfunc_val(&print_info));
	    i++;
	}
	else if (cst_streq(argv[i],"-voicedump") && (i+1 < argc))
	{
            voicedumpfile = argv[i+1];
	    i++;
	}
	else if ((cst_streq(argv[i],"-set") || cst_streq(argv[i],"-s"))
		 && (i+1 < argc))
	{
	    ef_set(extra_feats,argv[i+1],0);
	    i++;
	}
	else if (cst_streq(argv[i],"--seti") && (i+1 < argc))
	{
	    ef_set(extra_feats,argv[i+1],"int");
	    i++;
	}
	else if (cst_streq(argv[i],"--setf") && (i+1 < argc))
	{
	    ef_set(extra_feats,argv[i+1],"float");
	    i++;
	}
	else if (cst_streq(argv[i],"--sets") && (i+1 < argc))
	{
	    ef_set(extra_feats,argv[i+1],"string");
	    i++;
	}
	else if (cst_streq(argv[i],"-p") && (i+1 < argc))
	{
	    filename = argv[i+1];
	    explicit_phones = TRUE;
	    i++;
	}
	else if (cst_streq(argv[i],"-t") && (i+1 < argc))
	{
	    filename = argv[i+1];
	    explicit_text = TRUE;
	    i++;
	}
	else if (filename)
	    outtype = argv[i];
	else
	    filename = argv[i];
    }

    if (filename == NULL) filename = "-";  /* stdin */
    if (flite_voice_list == NULL)
        flite_set_voice_list(voicedir);
    if (desired_voice == 0)
        desired_voice = flite_voice_select(NULL);

    v = desired_voice;
    feat_copy_into(extra_feats,v->features);
    durs = 0.0;

    if (voicedumpfile != NULL)
    {
        flite_voice_dump(v,voicedumpfile);
        exit(0);
    }

    if (lex_addenda_file)
        flite_voice_add_lex_addenda(v,lex_addenda_file);

    if (cst_streq("stream",outtype))
    {
        asi = new_audio_streaming_info();
        asi->asc = audio_stream_chunk;
        feat_set(v->features,"streaming_info",audio_streaming_info_val(asi));
    }

    if (flite_bench)
    {
	outtype = "none";
	filename = "A whole joy was reaping, but they've gone south, you should fetch azure mike.";
	explicit_text = TRUE;
    }

loop:
    gettimeofday(&tv,NULL);
    time_start = (double)(tv.tv_sec)+(((double)tv.tv_usec)/1000000.0);

    if (explicit_phones)
	durs = flite_phones_to_speech(filename,v,outtype);
    else if ((strchr(filename,' ') && !explicit_filename) || explicit_text)
    {
        if (ssml_mode)
            durs = flite_ssml_text_to_speech(filename,v,outtype);
        else
            durs = flite_text_to_speech(filename,v,outtype);
    }
    else
    {
        if (ssml_mode)
            durs = flite_ssml_file_to_speech(filename,v,outtype);
        else
            durs = flite_file_to_speech(filename,v,outtype);
    }

    gettimeofday(&tv,NULL);
    time_end = ((double)(tv.tv_sec))+((double)tv.tv_usec/1000000.0);

    if (flite_verbose || (flite_bench && bench_iter == ITER_MAX))
	printf("times faster than real-time: %f\n(%f seconds of speech synthesized in %f)\n",
	       durs/(float)(time_end-time_start),
	       durs,
	       (float)(time_end-time_start));

    if (flite_loop || (flite_bench && bench_iter++ < ITER_MAX))
	    goto loop;

    delete_features(extra_feats);
    delete_val(flite_voice_list); flite_voice_list=0;
    /*    cst_alloc_debug_summary(); */

    return 0;
}
Ejemplo n.º 19
0
int main()
{
    int choice,data,pos;
    header=NULL;

    while(1)
    {
        system("cls");
        printf("\nSelect your choice: ");
        printf("\n1. Create List ");
        printf("\n2. Insert Node ");
        printf("\n3. Display List ");
        printf("\n4. Delete Node ");
        printf("\n5. Arrange in Ascending order");
        printf("\n6. Exit\n");
        scanf("%d",&choice);

        switch(choice)
        {
            case 1: create();
                    break;

            case 2: system("cls");
                    printf("\nSelect your choice: ");
                    printf("\n1. Insert at the End ");
                    printf("\n2. Insert at the Beginning ");
                    printf("\n3. Insert at a Specified Position ");
                    printf("\n4. Back to main menu\n");
                    scanf("%d",&choice);

                    switch(choice)
                    {
                    case 1: system("cls");
                            printf("\nEnter the data of the node: ");
                            scanf("%d",&data);
                            insert_end(data);
                            printf("\nNode inserted at the end of the list");
                            break;

                    case 2: system("cls");
                            printf("\nEnter the data of the node: ");
                            scanf("%d",&data);
                            insert_beg(data);
                            printf("\nNode inserted at the beginning of the list");
                            break;

                    case 3: system("cls");
                            printf("\nEnter the position at which you want to insert the node: ");
                            scanf("%d",&pos);
                            printf("\nEnter the data of the node: ");
                            scanf("%d",&data);
                            insert_pos(data,pos);
                            break;

                    case 4: break;

                    default: printf("Invalid choice!!");

                    }
                    break;

            case 3: display();
                    break;

            case 4: system("cls");
                    printf("\nSelect your choice: ");
                    printf("\n1. Delete from the End ");
                    printf("\n2. Delete from the Beginning ");
                    printf("\n3. Delete from a Specified Position ");
                    printf("\n4. Delete by the data of the node");
                    printf("\n5. Back to main menu\n");
                    scanf("%d",&choice);

                    switch(choice)
                    {
                    case 1: system("cls");
                            delete_end();
                            printf("\nNode deleted from the end of the list");
                            break;

                    case 2: system("cls");
                            delete_beg();
                            printf("\nNode deleted from the beginning of the list");
                            break;

                    case 3: system("cls");
                            printf("\nEnter the position at which you want to delete the node: ");
                            scanf("%d",&pos);
                            delete_pos(pos);
                            break;

                    case 4: system("cls");
                            printf("\nEnter the data which you want to delete: ");
                            scanf("%d",&data);
                            delete_val(data);
                            break;

                    case 5: break;

                    default: printf("Invalid choice!!");

                    }
                    break;

            case 5: ascend();
                    system("cls");
                    printf("\nList rearranged in ascending order");
                    getch();
                    break;

            case 6: exit(0);
                    break;

            default: printf("Invalid choice!!");
                     getch();

        }
    }
    return 0;
}
Ejemplo n.º 20
0
int main(int argc, char * argv[])
{
	const char * tree_str = 0;
	NODE * t = 0;
	int limit = -1;
	opterr = 0;
	______________________________  = print_nothing;
	______________________________I = print_nothing;
	______________________________D = print_nothing;

	while (1) {
		int c;
		static struct option long_options[] = {
			{"help",           no_argument,       0, 'h'},
			{"algorithm",      required_argument, 0, 'a'},
			{"debug-level",    required_argument, 0, 'd'},
			{"tree",           required_argument, 0, 't'},
			{"limit",          required_argument, 0, 'l'},
			{0, 0, 0, 0}
		};
		/* getopt_long stores the option index here. */
		int option_index = 0;
     
		c = getopt_long(argc, argv, "ha:t:d:l:",
				long_options, &option_index);
     
		/* Detect the end of the options. */
		if (c == -1)
			break;
     
		switch (c) {
		case 0:
			/* If this option set a flag, do nothing else now. */
			if(long_options[option_index].flag != 0)
				break;
			printf("option %s", long_options[option_index].name);
			if(optarg)
				printf(" with arg %s", optarg);
			printf("\n");
			break;

		case 'h':
			print_usage(argv[0]);
			break;
     
		case 'a':
			if (strcmp(optarg, "CLRS") == 0) {
				insert_val = insert_CLRS;
				delete_val = delete_CLRS;
			} else if (strcmp(optarg, "Sedgewick") == 0) {
				insert_val = insert_Sedgewick;
				delete_val = delete_Sedgewick;
			} else {
				abort();
			}
			break;
     
		case 'd':
			dbg_level = atoi_or_abort(optarg);
			if (dbg_level == 1) {
				______________________________  = print_rbtree;
			} else if (dbg_level == 2) {
				______________________________  = print_rbtree;
				______________________________I = print_rbtree;
			} else if (dbg_level == 3) {
				______________________________  = print_rbtree;
				______________________________D = print_rbtree;
			} else if (dbg_level == 4) {
				______________________________  = print_rbtree;
				______________________________I = print_rbtree;
				______________________________D = print_rbtree;
			} else {
				; /* use default */
			}
			break;
     
		case 't':
			tree_str = optarg;
			break;
          
		case 'l':
			limit = atoi_or_abort(optarg);
			break;
          
		case '?':
			/* getopt_long already printed an error message. */
			printf("%s%s%s\n", RED_B, argv[optind-1], NOCOLOR);
			break;
     
		default:
			abort();
		}
	}

	printf("%sDebug Level: %s%d%s\n", YELLOW, CYAN, dbg_level, NOCOLOR);

	static const char * default_tree[] = {/* p.275 */ "(26(17+(14(10+(7(3+)())(12))(16(15+)()))(21(19()(20+))(23)))(41(30+(28)(38(35+)(39+)))(47)))",
					      /* p.282 */ "(11(2+(1)(7(5+)(8+)))(14()(15+)))",
					      ""};
	if (!tree_str) {
		tree_str = default_tree[0];
		printf("%sUsing default tree: %s%s%s\n", YELLOW, CYAN, tree_str, NOCOLOR);
	}
	t = init_rbtree(tree_str);
	assert(t->L->P == nil);

        ______________________________("./fig/", t, t, "init");
	printf("Node count: %d\n", node_cnt);

	/* default algorithms */
	if (insert_val == 0)
		insert_val = insert_Sedgewick;
	if (delete_val == 0)
		delete_val = delete_Sedgewick;

	/* printf("optind: %d, argc: %d\n", optind, argc); */
	/* for (int j = 0; j < argc; j++) */
	/* 	printf("        %s\n", argv[j]); */
	if (optind < argc)
	{
		while (optind < argc) {
			char * a = argv[optind++];
			if (*a == '~')
				delete_val(t, atoi_or_abort(a+1));
			else
				insert_val(t, atoi_or_abort(a));
			verify_rbtree(t->L, 0);
		}
	} else {
		srand(time(NULL));
		if (limit == -1)
			limit = 100;
		printf("%sWill run %s%d%s tests.%s\n", YELLOW, CYAN, limit, YELLOW, NOCOLOR);
		while (t->L != nil && limit--) {
			int k = rand() % 50;
			int r = rand();
			if (dbg_level != 0)
				printf("random: %d\n", r);
			if (r % 2 != 0)
				insert_val(t, k);
			else
				if (rb_search(t, k) != 0)
					delete_val(t, k);
		}
		verify_rbtree(t->L, 0);
	}

	fprintf(stderr, "\n");
	print_rbtree("./fig/", t, t, "END");
	printf("Node count: %d\n", node_cnt);
	return 0;
}
Ejemplo n.º 21
0
cst_utterance *russian_lexical_insertion(cst_utterance *u)
{
  cst_item *word;
  cst_relation *sylstructure,*seg,*syl,*sylvowel,*transcription;
  const cst_val *p;
  const char *phone_name;
  cst_val *phones;
  cst_item *ssword, *sssyl, *segitem, *sylitem, *seg_in_syl, *svsyl, *vowel_in_syl, *tword, *seg_in_word;
  cst_item *i,*tmp;
  int num_segs;
  int total_num_segs=0;
  syl = utt_relation_create(u,"Syllable");
  sylstructure = utt_relation_create(u,"SylStructure");
  seg = utt_relation_create(u,"Segment");
  sylvowel = utt_relation_create(u,"SylVowel");
  transcription = utt_relation_create(u,"Transcription");
  for (word=relation_head(utt_relation(u,"Word"));word;word=item_next(word))
    {
      phones=word_to_phones(word);
      if(!phones)
        continue;
      num_segs=val_length(phones);
      if((total_num_segs+num_segs)>max_num_segs)
        {
          delete_val(phones);
          break;
        }
      ssword = relation_append(sylstructure,word);
      tword = relation_append(transcription,word);
      for (sssyl=NULL,sylitem=NULL,p=phones; p; p=val_cdr(p))
        {
          if (sylitem == NULL)
            {
              sylitem = relation_append(syl,NULL);
              sssyl = item_add_daughter(ssword,sylitem);
            }
          segitem = relation_append(seg,NULL);
          phone_name = val_string(val_car(p));
          item_set_string(segitem,"name",phone_name);
          seg_in_syl = item_add_daughter(sssyl,segitem);
          seg_in_word = item_add_daughter(tword,segitem);
          if(is_vowel(phone_name))
            {
              svsyl=relation_append(sylvowel,sylitem);
              vowel_in_syl=item_add_daughter(svsyl,segitem);
            }
          if (ru_syl_boundary(seg_in_syl,val_cdr(p)))
            {
              sylitem = NULL;
              if (sssyl)
                item_set_string(sssyl,"stress","0");
            }
        }
      assign_stress(word);
      delete_val(phones);
      total_num_segs+=num_segs;
    }
  i=relation_head(utt_relation(u,"Word"));
  while(i)
    {
      tmp=item_next(i);
      if(item_as(i,"Transcription")==NULL)
        {
          delete_item(item_as(i,"Token"));
          delete_item(item_as(i,"Phrase"));
          delete_item(i);
        }
      i=tmp;
    }
  i=relation_head(utt_relation(u,"Phrase"));
  while(i)
    {
      tmp=item_next(i);
      if(item_daughter(i)==NULL)
        delete_item(i);
      i=tmp;
    }
  return u;
}
Ejemplo n.º 22
0
cst_utterance *default_lexical_insertion(cst_utterance *u)
{
    cst_item *word;
    cst_relation *sylstructure,*seg,*syl;
    cst_lexicon *lex;
    const cst_val *lex_addenda = NULL;
    const cst_val *p, *wp = NULL;
    char *phone_name;
    char *stress = "0";
    const char *pos;
    cst_val *phones;
    cst_item *ssword, *sssyl, *segitem, *sylitem, *seg_in_syl;

    lex = val_lexicon(feat_val(u->features,"lexicon"));
    if (lex->lex_addenda)
	lex_addenda = lex->lex_addenda;

    syl = utt_relation_create(u,"Syllable");
    sylstructure = utt_relation_create(u,"SylStructure");
    seg = utt_relation_create(u,"Segment");

    for (word=relation_head(utt_relation(u,"Word")); 
	 word; word=item_next(word))
    {
	ssword = relation_append(sylstructure,word);
        pos = ffeature_string(word,"pos");
	phones = NULL;
        wp = NULL;
        
        /*        printf("awb_debug word %s pos %s gpos %s\n",
               item_feat_string(word,"name"),
               pos,
               ffeature_string(word,"gpos")); */

	/* FIXME: need to make sure that textanalysis won't split
           tokens with explicit pronunciation (or that it will
           propagate such to words, then we can remove the path here) */
	if (item_feat_present(item_parent(item_as(word, "Token")), "phones"))
	    phones = (cst_val *) item_feat(item_parent(item_as(word, "Token")), "phones");
	else
	{
            wp = val_assoc_string(item_feat_string(word, "name"),lex_addenda);
            if (wp)
                phones = (cst_val *)val_cdr(val_cdr(wp));
            else
		phones = lex_lookup(lex,item_feat_string(word,"name"),pos);
	}

	for (sssyl=NULL,sylitem=NULL,p=phones; p; p=val_cdr(p))
	{
	    if (sylitem == NULL)
	    {
		sylitem = relation_append(syl,NULL);
		sssyl = item_add_daughter(ssword,sylitem);
		stress = "0";
	    }
	    segitem = relation_append(seg,NULL);
	    phone_name = cst_strdup(val_string(val_car(p)));
	    if (phone_name[cst_strlen(phone_name)-1] == '1')
	    {
		stress = "1";
		phone_name[cst_strlen(phone_name)-1] = '\0';
	    }
	    else if (phone_name[cst_strlen(phone_name)-1] == '0')
	    {
		stress = "0";
		phone_name[cst_strlen(phone_name)-1] = '\0';
	    }
	    item_set_string(segitem,"name",phone_name);
	    seg_in_syl = item_add_daughter(sssyl,segitem);
#if 0
            printf("awb_debug ph %s\n",phone_name);
#endif
	    if ((lex->syl_boundary)(seg_in_syl,val_cdr(p)))
	    {
#if 0
                printf("awb_debug SYL\n");
#endif
		sylitem = NULL;
		if (sssyl)
		    item_set_string(sssyl,"stress",stress);
	    }
	    cst_free(phone_name);
	}
	if (!item_feat_present(item_parent(item_as(word, "Token")), "phones")
            && ! wp)
	    delete_val(phones);
    }

    return u;
}
Ejemplo n.º 23
0
int main(int argc, char* argv[])
{
	int randnum = 0;
	char* nvram = NULL, *value = NULL;
	char* delimiter = NULL, *tmp, *del;
	int position=0, c, i = 0, func = 0, val;
	char help_msg[2048] = "Usage: xobjconf [-s | -x <nvram variable>] {[-a | -m <values> -p <position>] | [ -n <to get # of digits>] | [-i <position>] | [-v <value>] | [-e <value>] | [ -r <position>] | [ -o <new delimiter>]} [-d delimiter]\n\n";

	init_gen( );
	strcat(help_msg, "xobjconf command summary\n");
	strcat(help_msg, "\txobjconf is a function to insert/delete/modify/view nvram variable by delimiter(s).\n");
	strcat(help_msg, "\t<nvram variable>:input a nvram variable.\n");
	strcat(help_msg, "\tdelimiter:a delimiter which is a seperator.\n");
	strcat(help_msg, "\t-s : to specify a nvram variable.\n");
	strcat(help_msg, "\t-x : to get total counts of token by specified delimiter.\n");
	strcat(help_msg, "\t-d : to specify a delimiter.\n");
	strcat(help_msg, "\t-a:insert a value to the nvram variable by delimiter.\n");
	strcat(help_msg, "\t-r : remove a value from a nvram variable by specfied position.\n");
	strcat(help_msg, "\t-v : remove a value from a nvram variable by specfied value.\n");
	strcat(help_msg, "\t-e : to check a value in a nvram variable is exist or not.\n");
	strcat(help_msg, "\t-o : to replace delimiters in a token list by new delimiters.\n");
	strcat(help_msg, "\t-n : to get digits in a nvram variable by speficied counts.\n");
	strcat(help_msg, "\t-m : to change a value by spcified position from a nvram variable.\n");
	strcat(help_msg, "\t-i : to return the value which is at the specified position from a nvram variable by delimiter.\n\n");

	if(argc <= 1 || ((isgraph(*argv[1]) || ispunct(*argv[1])) && *argv[1]!='-')){
		fprintf(stderr, "%s", help_msg);
		exit(0);
	}
	while ((c = getopt(argc, argv, "a:d:e:i:m:n:o:p:r:v:s:x:h")) != -1){
		switch (c) {
			case 'a':
				func = 1;
				value = optarg;
				break;
			case 'r':
				func = 2;
				position = atoi(optarg);
				break;
			case 'm':
				func = 3;
				value = optarg;
				break;
			case 's':
				nvram = optarg;
				break;
			case 'i':
				func = 4;
				position = atoi(optarg);
				break;
			case 'v':
				func = 5;
				value = optarg;
				position = 1;
				break;
			case 'x':
				func = 6;
				nvram = optarg;
				break;
			case 'e':
				func = 7;
				value = optarg;
				position = 1;
				break;
			case 'n':
				func = 8;
				val = atoi(optarg);
				position = 1;
				break;
			case 'o':
				func = 9;
				value = optarg;
				break;
			case 'p':
				position = atoi(optarg);
				break;
			case 'd':
				delimiter = optarg;
				break;
			case 'h':
				fprintf(stderr, "%s", help_msg);
				exit(0);
				break;
			default:
				fprintf(stderr, "%s", help_msg);
				exit(0);
				break;
		}
	}

	if(nvram_get(nvram) == NULL && delimiter != NULL && nvram != NULL){
		if(func == 1 && value != NULL){
			nvram_set(nvram, "");
			//printf("Inserting '%s' at position 1 ...\n", value);
			//tmp = StrDup(nvram_get(nvram));
			//value = insert_str(tmp, value, delimiter, 1);
			//tmp = StrDup(insert_str(nvram_get(nvram), value, delimiter, 1));
			//nvram_set(nvram, value);
			nvram_set(nvram, StrDup(insert_str(nvram_get(nvram), value, delimiter, 1)));
			printf("%s\n", nvram_get(nvram));
		}
		else{
			fprintf(stderr, "%s", help_msg);
			exit(0);
		}
	}
	else if(delimiter != NULL && position > 0 && nvram != NULL){
		if(func == 1 && value != NULL){
			//printf("Inserting %s at position %d ...\n", value, position);
			//tmp = StrDup(nvram_get(nvram));
			//value = insert_str(tmp, value, delimiter, 1);
			//nvram_set(nvram, value);
			nvram_set(nvram, insert_str(nvram_get(nvram), value, delimiter, position));
			printf("%s\n", nvram_get(nvram));
		}
		else if(func == 2){
			//printf("Deleting position %d of %s ... \n", position, nvram);
			//tmp = StrDup(nvram_get(nvram));
			//value = delete_str(nvram_get(nvram), delimiter, position);
			//nvram_set(nvram, value);
			nvram_set(nvram, delete_str(nvram_get(nvram), delimiter, position));
			printf("%s\n", nvram_get(nvram));
		}
		else if(func == 3 && value != NULL){
			//printf("Modifying position %d by %s ... \n", position, value);
			//tmp = StrDup(nvram_get(nvram));
			//value = modify_str(nvram_get(nvram), value, delimiter, position);
			//nvram_set(nvram, value);
			nvram_set(nvram, StrDup(modify_str(nvram_get(nvram), value, delimiter, position)));
			printf("%s\n", nvram_get(nvram));
		}
		else if(func == 4){
			//printf("\nReading the values from nvram variable %s ... \n", nvram);
			tmp = StrDup(nvram_get(nvram));
			printf("%s\n", index_str(tmp, delimiter, position));
		}
		else if(func == 5){
			/*c = matchStrPosAt(delimiter, StrDup(nvram_get(nvram)), -1) + 1;
			for (i = 1; i <= c ; i++) {
				tmp = StrDup(nvram_get(nvram));
				printf("tmp = %s\n", tmp);
				del = StrDup(index_str(tmp, delimiter, i));
				printf("%s[%d] = %s\n", nvram, i, del);
				if(!strcmp(del, value)){
					printf("value %s is matched in %s\n", value, nvram_get(nvram));
					nvram_set(nvram, delete_str(nvram_get(nvram), delimiter, i));
					printf("delete '%s' which is spcified at position %d\n", value, i);
					break;
				}
			}*/
			nvram_set(nvram, delete_val(nvram_get(nvram), value, delimiter));
			printf("%s\n", nvram_get(nvram));
		}
		else if(func == 7){
			tmp = StrDup(nvram_get(nvram));
			if(val_exist(tmp, value, delimiter))
				printf("%s is exist\n", value);
			else
				printf("%s is not exist\n", value);
		}
		else if(func == 8){
			tmp = StrDup(nvram_get(nvram));
			printf("%s\n", str2digits(tmp, delimiter, val));
		}
		else{
			fprintf(stderr, "%s", help_msg);
			exit(0);
		}
	}
	else if(func == 6 && delimiter != NULL && nvram != NULL){
		position = matchStrPosAt(delimiter, nvram_get(nvram), -1) + 1;
		printf("%d\n", position);
		/*printf("Number of token counts is %d\n", position);
		for(i = 1; i <= position; i++){
			tmp = StrDup(nvram_get(nvram));
			printf("\t%s\n", index_str(tmp, delimiter, i));
		}*/
	}
	else if(func == 9 && delimiter != NULL && nvram != NULL && value != NULL){
		/* this code section is fix the old delimiter(s) is a subset of new delimiter(s) issue */
		randnum = number_range(6, 16);
		tmp = StrDup(nvram_get(nvram));
		if(strstr(value, delimiter) && strlen(value) > strlen(delimiter)){
			char temp_deli[]="olddeliisasubsetofnewdeli";
			random_string(temp_deli, randnum);
			nvram_set(nvram, replaceall(tmp, delimiter, temp_deli, -2, matchStrPosAt(delimiter, tmp, -1)));
			strcpy(tmp, nvram_get(nvram));
			nvram_set(nvram, replaceall(tmp, temp_deli, value, -2, matchStrPosAt(temp_deli, tmp, -1)));
		}
		else
			nvram_set(nvram, replaceall(tmp, delimiter, value, -2, matchStrPosAt(delimiter, tmp, -1)));
		printf("%s\n", nvram_get(nvram));
	}
	else{
		fprintf(stderr, "%s", help_msg);
		exit(0);
	}

	//StrFree(tmp);
	return 0;
}
Ejemplo n.º 24
0
cst_utterance *default_lexical_insertion(cst_utterance *u)
{
    cst_item *word;
    cst_relation *sylstructure,*seg,*syl;
    cst_lexicon *lex, *ulex = NULL;
    const cst_val *p;
    char *phone_name;
    char *stress = "0";
    cst_val *phones;
    cst_item *ssword, *sssyl, *segitem, *sylitem, *seg_in_syl;


    lex = val_lexicon(feat_val(u->features,"lexicon"));
    if (feat_present(u->features, "user_lexicon"))
	ulex = val_lexicon(feat_val(u->features, "user_lexicon"));

    syl = utt_relation_create(u,"Syllable");
    sylstructure = utt_relation_create(u,"SylStructure");
    seg = utt_relation_create(u,"Segment");

    for (word=relation_head(utt_relation(u,"Word")); 
	 word; word=item_next(word))
    {
	ssword = relation_append(sylstructure,word);
	phones = NULL;

	/* FIXME: need to make sure that textanalysis won't split
           tokens with explicit pronunciation (or that it will
           propagate such to words, then we can remove the path here) */
	if (item_feat_present(item_parent(item_as(word, "Token")), "phones"))
	    phones = (cst_val *) item_feat(item_parent(item_as(word, "Token")), "phones");
	else
	{
	    if (ulex)
		phones = lex_lookup(ulex,item_feat_string(word, "name"),0);
	    if (phones == NULL)
		phones = lex_lookup(lex,item_feat_string(word,"name"),0);
	}

	for (sssyl=NULL,sylitem=NULL,p=phones; p; p=val_cdr(p))
	{
	    if (sylitem == NULL)
	    {
		sylitem = relation_append(syl,NULL);
		sssyl = item_add_daughter(ssword,sylitem);
		stress = "0";
	    }
	    segitem = relation_append(seg,NULL);
	    phone_name = cst_strdup(val_string(val_car(p)));
	    if (phone_name[strlen(phone_name)-1] == '1')
	    {
		stress = "1";
		phone_name[strlen(phone_name)-1] = '\0';
	    }
	    else if (phone_name[strlen(phone_name)-1] == '0')
	    {
		stress = "0";
		phone_name[strlen(phone_name)-1] = '\0';
	    }
	    item_set_string(segitem,"name",phone_name);
	    seg_in_syl = item_add_daughter(sssyl,segitem);
	    if ((lex->syl_boundary)(seg_in_syl,val_cdr(p)))
	    {
		sylitem = NULL;
		if (sssyl)
		    item_set_string(sssyl,"stress",stress);
	    }
	    cst_free(phone_name);
	}
	if (!item_feat_present(item_parent(item_as(word, "Token")), "phones"))
	    delete_val(phones);
    }

    return u;
}