Esempio n. 1
0
void read_ascii_trans(FILE *fp, Trans *t)
{int i,j,size;
 Score *pi;
 Score *gamma;
 Score *trans;
 double x,y,z;
 
 char  line[2000]; 
 
 fgets(line,sizeof(line),fp);
 sscanf(&line[0],"%d",&size);
 if (size != tags_all)
   error_exit2("Map file indicates %d tags, array has %d entries\n",
	       (void *)tags_all, (void *)size);
    
 if (t->trans == NULL || t->pi == NULL || t->gamma == NULL)
   {create_trans(t, size);
    clear_trans_all(t);
   }
 pi = t->pi;gamma = t->gamma;trans = t->trans; 
 
 for (i = 0 ; i < size ; i++)
   {fgets(line,sizeof(line),fp);
    sscanf(&line[0],"%d %lf %lf\n", &i, &x, &y);
    pi[i] += x; 
    gamma[i] += y; 
    for (j = 0 ; j < size ; j++)
      {fgets(line,sizeof(line),fp);
       sscanf(&line[0],"%lf\n", &z );
       Trans_(trans,i,j,size) += z;
      }
   }

 t->pi = pi;t->gamma = gamma;t->trans = trans;
}
Esempio n. 2
0
void * trans_thread(void *unuse){
    CURLcode retcode;
    CURL *curl = curl_easy_init();
    if(curl==NULL){
        fprintf(stderr,"translate failed_1\n");
        pthread_exit("-1");
    }
    char buf[512],ret_buf[MAXBUF*2],*convert_str;
    sprintf(buf, "%s", APIkey);
    convert_space(str_to_trans);
    convert_str = curl_easy_escape(curl,str_to_trans,strlen(str_to_trans));
    
    strcat(buf, convert_str);
    curl_easy_setopt(curl, CURLOPT_URL, buf);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_func);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ret_buf);
    retcode = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
    if(retcode != 0){
        fprintf(stderr,"translate failed_2\n");
        pthread_exit("-1");
    }
    cJSON *json;
    json = cJSON_Parse(ret_buf);
    if(create_trans(&trans_res, json) == -1){
        fprintf(stderr,"translate failed_3\n");
        pthread_exit("-1");
    }
    if(simple_flag == 1)
        clprint_simple(&trans_res);
    else
        clprint_full(&trans_res);
    curl_free(convert_str);
    pthread_exit("0");
}
Esempio n. 3
0
void read_trans(FILE *fp, Trans *t)
{
    int i, j;
    int ntags;
    Score f;
    Score *s;

    /* Check the code byte */
    if (fgetc(fp) != TranCode)
	error_exit("Wrong file code (is it really a transitions file?)\n");

    /* Read number of tags and check for consistency */
    if (fread(&ntags, sizeof(int), 1, fp) != 1)
	error_exit("Trans read failure\n");
    if (ntags != tags_all)
	error_exit2("Map file indicates %d tags, array has %d entries\n",
		(void *)tags_all, (void *)ntags);

    /* Create and clear the arrays */
    if (t->trans == NULL || t->pi == NULL || t->gamma == NULL)
    {
	create_trans(t, ntags);
	clear_trans_all(t);
    }

    /* Read and accumulate values */
    for (j = 0, s = t->pi ; j < ntags ; j++, s++)
    {
	if (fread( &f, sizeof(Score), 1, fp) != 1)
	    error_exit("Trans read failure\n");
	*s += f;
    }

    for (j = 0, s = t->gamma ; j < ntags ; j++, s++)
    {
	if (fread( &f, sizeof(Score), 1, fp) != 1)
	    error_exit("Trans read failure\n");
	*s += f;
    }

    for (j = 0, s = t->trans ; j < ntags ; j++)
    {
	for (i = 0 ; i < ntags ; i++, s++)
	{
	    if (fread(&f, sizeof(Score), 1, fp) != 1)
		error_exit("Trans read failure\n");

	    *s += f;
	}
    }
}
Esempio n. 4
0
// Send 10 transactions through initiator socket
void top::thread_process() {
  tlm_phase             phase = tlm::BEGIN_REQ;
  sc_time               time((sc_dt::uint64)5050,true);
  tlm_sync_enum         status;
  unsigned int          ind;
  tlm_generic_payload * tgp;

  tgp = mem_manager.allocate();
  tgp->acquire();
  ind = 0;
  cout<<"[SC "<<sc_time_stamp()<<"] staring SC thread process."<<endl;

  for (int j = 0; j < 10; j++) {
     create_trans(ind, tgp, tlm::TLM_WRITE_COMMAND);
     wait(sc_time(1, SC_NS));
     cout<<"[SC "<<sc_time_stamp()<<"] Calling nb_transport_fw with data size "<< tgp->get_data_length() << endl;
     status = i.isocket->nb_transport_fw(*tgp, phase, time);
     cout<<"[SC "<<sc_time_stamp()<<"] After nb_transport_fw status = "<<status<<endl;
     ind++;
   };
   sc_assert(i.trans_count==ind);
   tgp->release();
   cout<<"[SC "<<sc_time_stamp()<<"] End of SC thread process"<<endl;
}
Esempio n. 5
0
void Tagger::Init(int argc, char * argv[])
{

	setlocale(LC_CTYPE, "iso_8858_1");
#ifdef SpecialMalloc
	/* Force fast allocation */
	set_small_allocation(100);
#endif

	/* Clear data structures */
	InitDict(dict);
	InitDict(skip_dict);
	InitTrans(trans);
	InitTrans(c_newtrans);
	odictfile = otranfile = NULL;

	/* Verify command line */
	if (argc <= 2)
	  error_exit("Usage: label corpus options\n");

	/* Form options */
	InitOptions;

	set_up_options(argc, argv, &iterations, &initialise, &dict_size,
				dictname, tranname, odictname, otranname, outname, mapname,
				skipname, reducename, fsmname, grammarname, infername, ukwname,
				ofeaturesname, obadwordname, bdbmname, runkstatname, wunkstatname);

	any_output = !no_output || Option(report_stats) || OutOpt(prob_dist);


	/* Open BDBM dictionary */
	if (Option(bdbm)){
		/* Berkeley DB: first of all need to create the dbp data structure*/
		if((ret = db_create(&dbp, NULL, 0)) != 0) {
			fprintf(stderr, "db_create: %s\n", db_strerror(ret));
			exit (1);
		}
		/* Berkeley DB: Then you open it, readonly  */
		if((ret = dbp->open(dbp,bdbmname, NULL, DB_BTREE, DB_RDONLY, 0777)) != 0) {
			dbp->err(dbp, ret, "%s", bdbmname);
			exit(1);
		} 
	}

	/* Read mappings */
	if (Option(verbose)) printf("Read mappings\n");
	read_mapping(mapname);

	/* Read tag reduction mappings */
	if (Option(reduced_tags))
	{
		if (Option(verbose)) printf("Read reduced tag set\n");
		read_reduce_mapping(reducename);
	}

#ifdef Use_Parser
	/* Read parse rules */
	if (Option(use_parser))
	{
		if (Option(verbose)) printf("Read parse rules\n");
		parser_read_named(grammarname);
	}
#endif
#ifdef Use_FSM
	/* Read FSM definitions */
	if (Option(use_fsm))
	{
		if (Option(verbose)) printf("Read FSMs\n");
		fsm_read_named(fsmname);
	}
#endif

	/* Read skip list */
	if (Option(skip_list))
	{
		if (Option(verbose)) printf("Read skip list\n");
		read_named_dict(skipname, &skip_dict, -1);
	}

	/* Read unknown word rules */
	if (Option(unknown_rules))
	{
		if (Option(verbose)) printf("Read unknown word rules\n");
		read_unknown_rules(ukwname);
	}

	/* Set up dictionary [note]:it costs a few seconds*/
	if (dictname[0] == 0)
	{
		create_dict(&dict, dict_size);
		clear_dict(&dict);
	}
	else
	{
		if (Option(verbose)) printf("Read dictionary\n");
		read_named_dict(dictname, &dict, -1);
		if (infername[0] != 0)
		{
			if (Option(verbose)) printf("Read inference rules\n");
			infer_tags((char *)infername, &dict);

		}
	}

	/* Set up transitions [note] it costs a few seconds*/
	if (tranname[0] == 0)
	{
		create_trans(&trans, tags_all);
		clear_trans_all(&trans);
	}
	else
	{
		if (Option(verbose)) printf("Read transitions\n");
		read_named_ascii_trans(tranname, &trans);

		/* Analyze selected features of lexicon to generate tag probabilities for unknown words. */
		if ( Option(unknown_morph) || Option(unknown_rules))
		{
			/* Initialize feature values */

			Allocate(features->featuretags, sizeof(FeatureTagSt), "features->featuretags: main");
			features->featuretags->next_open_slot = 0;

			features->gamma = trans.gamma;

			if ( features->maxsuffix == 0 )
			  features->maxsuffix = MinSuffixLen;
			if ( features->maxunkwords == 0 )
			  features->maxunkwords = MAXUNKWORDS;
			if ( features->maxprefcut == 0 )
			  features->maxprefcut = MinPrefixLen;
			if ( features->maxsuffcut == 0 )
			  features->maxsuffcut = MinSuffixLen;

			unknown_word_handling_initialization();
			gather_unigram_freqs( &dict );
		}

		if ( Option(unknown_morph) )
		{
			analyze_features( &dict, ofeaturesname, obadwordname, &trans, dbp, &dict, runkstatname );
		}
	}

	set_special_words(&dict, features );

	/* Create space for re-estimation or training */
	if (Option(reestimate) || Option(training))
	{
		c_newtrans.gamma = trans.gamma; /* Share arrays */
		create_trans(&c_newtrans, tags_all);
	}

	if (odictname[0] != 0)
	  odictfile = open_file(odictname, "w");
	if (otranname[0] != 0)
	  otranfile = open_file(otranname, "w");

	/* Set up anchor word */
	set_anchor(&dict);

	adjust_dict(&dict, trans.gamma, FALSE);
	adjust_trans(&trans, NULL);
}