Ejemplo n.º 1
0
opencc_t opencc_open(const char * config_file, const char* home_path)
{
    if (!lib_initialized)
        lib_initialize();

    opencc_desc * opencc;
    opencc = (opencc_desc *) malloc(sizeof(opencc_desc));

    opencc->dictionary_set = NULL;
    opencc->converter = converter_open();
    converter_set_conversion_mode(opencc->converter, OPENCC_CONVERSION_FAST);

    /* 加載默認辭典 */
    int retval;
    if (config_file == NULL)
        retval = 0;
    else
    {
        config_t config = config_open(config_file, home_path);

        if (config == (config_t) -1)
        {
            errnum = OPENCC_ERROR_CONFIG;
            return (opencc_t) -1;
        }

        opencc->dictionary_set = config_get_dictionary_set(config);
        converter_assign_dictionary(opencc->converter, opencc->dictionary_set);

        config_close(config);
    }

    return (opencc_t) opencc;
}
Ejemplo n.º 2
0
opencc_t opencc_open(const char* config_file) {
  if (!lib_initialized) {
    lib_initialize();
  }
  OpenccDesc* opencc;
  opencc = (OpenccDesc*)malloc(sizeof(OpenccDesc));
  opencc->dict_chain = NULL;
  opencc->converter = converter_open();
  converter_set_conversion_mode(opencc->converter, OPENCC_CONVERSION_FAST);
  if (config_file == NULL) {
    /* TODO load default */
    assert(0);
  } else {
    /* Load config */
    Config* config = config_open(config_file);
    if (config == (Config*)-1) {
      errnum = OPENCC_ERROR_CONFIG;
      return (opencc_t)-1;
    }
    opencc->dict_chain = config_get_dict_chain(config);
    converter_assign_dictionary(opencc->converter, opencc->dict_chain);
    config_close(config);
  }
  return (opencc_t)opencc;
}
Ejemplo n.º 3
0
int opencc_dict_load(opencc_t t_opencc, const char * dict_filename,
		opencc_dictionary_type dict_type)
{
	if (!lib_initialized)
		lib_initialize();

	opencc_desc * opencc = (opencc_desc *) t_opencc;

	dictionary_group_t dictionary_group;
	if (opencc->dictionary_set == NULL)
	{
		opencc->dictionary_set = dictionary_set_open();
		dictionary_group = dictionary_set_new_group(opencc->dictionary_set);
	}
	else
	{
		dictionary_group = dictionary_set_get_group(opencc->dictionary_set, 0);
	}

	int retval;
	retval = dictionary_group_load(dictionary_group, dict_filename, dict_type);

	if (retval == -1)
	{
		errnum = OPENCC_ERROR_DICTLOAD;
		return -1;
	}

	converter_assign_dictionary(opencc->converter, opencc->dictionary_set);

	return retval;
}
Ejemplo n.º 4
0
int opencc_dict_load(opencc_t t_opencc,
                     const char* dict_filename,
                     opencc_dictionary_type dict_type) {
  if (!lib_initialized) {
    lib_initialize();
  }
  OpenccDesc* opencc = (OpenccDesc*)t_opencc;
  DictGroup* DictGroup;
  if (opencc->dict_chain == NULL) {
    opencc->dict_chain = dict_chain_new(NULL);
    DictGroup = dict_chain_add_group(opencc->dict_chain);
  } else {
    DictGroup = dict_chain_get_group(opencc->dict_chain, 0);
  }
  int retval = dict_group_load(DictGroup, dict_filename, dict_type);
  if (retval == -1) {
    errnum = OPENCC_ERROR_DICTLOAD;
    return -1;
  }
  converter_assign_dictionary(opencc->converter, opencc->dict_chain);
  return retval;
}