示例#1
0
/*word segment,scw_out memory init*/
int segment_memory_init(scw_out_t **pout)
{
    if(*pout){
        UB_LOG_FATAL("word segment memory pout init again");
        scw_destroy_out(*pout);
    }

	u_int scw_out_flag;
	scw_out_flag = SCW_OUT_WPCOMP | SCW_OUT_PROP;
	if((*pout=scw_create_out(10000, scw_out_flag))==NULL)
	{
		UB_LOG_FATAL("error: initializing the output buffer error");
		return -1;
	}
    return 0;
}
示例#2
0
int main(int argc,char** argv)
{
  scw_worddict_t * pwdict;
  scw_out_t *pout;
  char line[1024000];
  u_int scw_out_flag;
  int flag = 0;

  if(argc!= 3 )
  {
    fprintf(stderr, "usage: %s worddict_dir outtype\n", argv[0]);
    exit(-1);
  }

  if((pwdict=scw_load_worddict(argv[1]))==NULL)
  {
    fprintf(stderr,"Load worddict failed.Filename=worddict/bin/");
    return 1;
  }

  flag = atoi(argv[0]);

  scw_out_flag = SCW_OUT_ALL | SCW_OUT_PROP;
  if((pout=scw_create_out(80000, scw_out_flag))==NULL)
  {
    fprintf(stderr,"Init the output buffer error.\n");
    return -1;
  }

  while(fgets(line,sizeof(line),stdin))
  {    
    int len=strlen(line);
    while((line[len-1]=='\r') ||(line[len-1]=='\n'))
      line[--len]=0;
    
    if(scw_segment_words(pwdict,pout,line,len)<0)
    {
      fprintf(stderr, "query %s error\n", line);
      scw_destroy_out(pout);
      return -1;
    }
    scw_dump_out2(pout,flag,pwdict->m_wdtype);
  }

  return 0;
}