示例#1
0
void
build_filenames(cmd_ln_t *config, char const *basename,
                char **out_infile, char **out_outfile)
{
    char const *di, *do_, *ei, *eo;

    di = cmd_ln_str_r(config, "-di");
    do_ = cmd_ln_str_r(config, "-do");
    ei = cmd_ln_str_r(config, "-ei");
    eo = cmd_ln_str_r(config, "-eo");

    *out_infile = string_join(di ? di : "",
                              di ? "/" : "",
                              basename,
                              ei ? "." : "",
                              ei ? ei : "",
                              NULL);
    *out_outfile = string_join(do_ ? do_ : "",
                               do_ ? "/" : "",
                               basename,
                               eo ? "." : "",
                               eo ? eo : "",
                              NULL);
    /* Build output directory structure if possible/requested (it is
     * by default). */
    if (cmd_ln_boolean_r(config, "-build_outdirs")) {
        char *dirname = ckd_salloc(*out_outfile);
        path2dirname(*out_outfile, dirname);
        build_directory(dirname);
        ckd_free(dirname);
    }
}
示例#2
0
void SigmoidCrossEntropy<T, Tl>::setup_impl(const Variables &inputs,
                                            const Variables &outputs) {

  NBLA_CHECK(inputs[0]->shape() == inputs[1]->shape(), error_code::value,
             "Dimensions of inputs must match. "
             "inputs[0]: %s != inputs[1]: %s.",
             string_join(inputs[0]->shape(), string(", ")).c_str(),
             string_join(inputs[1]->shape(), string(", ")).c_str());
  outputs[0]->reshape(inputs[0]->shape(), true);
}
示例#3
0
void
ps_default_search_args(cmd_ln_t *config)
{
#ifdef MODELDIR
    /* Set default acoustic and language models. */
    const char *hmmdir = cmd_ln_str_r(config, "-hmm");
    if (hmmdir == NULL && hmmdir_exists(MODELDIR "/en-us/en-us")) {
        hmmdir = MODELDIR "/en-us/en-us";
        cmd_ln_set_str_r(config, "-hmm", hmmdir);
    }

    const char *lmfile = cmd_ln_str_r(config, "-lm");

    if (lmfile == NULL && !cmd_ln_str_r(config, "-fsg")
        && !cmd_ln_str_r(config, "-jsgf")
        && !cmd_ln_str_r(config, "-lmctl")
        && !cmd_ln_str_r(config, "-kws")
        && !cmd_ln_str_r(config, "-keyphrase")
        && file_exists(MODELDIR "/en-us/en-us.lm.dmp")) {
        lmfile = MODELDIR "/en-us/en-us.lm.dmp";
        cmd_ln_set_str_r(config, "-lm", lmfile);
    }

    const char *dictfile = cmd_ln_str_r(config, "-dict");
    if (dictfile == NULL && file_exists(MODELDIR "/en-us/cmudict-en-us.dict")) {
        dictfile = MODELDIR "/en-us/cmudict-en-us.dict";
        cmd_ln_set_str_r(config, "-dict", dictfile);
    }

    /* Expand acoustic and language model filenames relative to installation
     * path. */
    if (hmmdir && !path_is_absolute(hmmdir) && !hmmdir_exists(hmmdir)) {
        char *tmphmm = string_join(MODELDIR "/hmm/", hmmdir, NULL);
        if (hmmdir_exists(tmphmm)) {
            cmd_ln_set_str_r(config, "-hmm", tmphmm);
        } else {
            E_ERROR("Failed to find mdef file inside the model folder "
                    "specified with -hmm `%s'\n", hmmdir);
        }
        ckd_free(tmphmm);
    }
    if (lmfile && !path_is_absolute(lmfile) && !file_exists(lmfile)) {
        char *tmplm = string_join(MODELDIR "/lm/", lmfile, NULL);
        cmd_ln_set_str_r(config, "-lm", tmplm);
        ckd_free(tmplm);
    }
    if (dictfile && !path_is_absolute(dictfile) && !file_exists(dictfile)) {
        char *tmpdict = string_join(MODELDIR "/lm/", dictfile, NULL);
        cmd_ln_set_str_r(config, "-dict", tmpdict);
        ckd_free(tmpdict);
    }
#endif
}
示例#4
0
int main(){

  /* Test the string_join function. */

  char *s1 = "Hello ";
  char *s2 = "World";
  printf("%s\n", string_join(s1, s2));

  printf("s1 len=%d\n", (int)strlen(s1));
  printf("s2 len=%d\n", (int)strlen(s2));
  printf("s3 len=%d\n", (int)strlen(string_join(s1, s2)));

  return 0;

}
示例#5
0
static int
write_nbest(ps_decoder_t *ps, char const *nbestdir, char const *uttid)
{
    cmd_ln_t *config;
    char *outfile;
    FILE *fh;
    ps_nbest_t *nbest;
    int32 i, n, score;
    const char* hyp;

    config = ps_get_config(ps);
    outfile = string_join(nbestdir, "/", uttid,
                          cmd_ln_str_r(config, "-nbestext"), NULL);
    n = cmd_ln_int32_r(config, "-nbest");
    fh = fopen(outfile, "w");
    if (fh == NULL) {
        E_ERROR_SYSTEM("Failed to write a lattice to file %s\n", outfile);
        return -1;
    }
    nbest = ps_nbest(ps, 0, -1, NULL, NULL);
    for (i = 0; i < n && nbest && (nbest = ps_nbest_next(nbest)); i++) {
        hyp = ps_nbest_hyp(nbest, &score);
        fprintf(fh, "%s %d\n", hyp, score);        
    }
    if (nbest)
	ps_nbest_free(nbest);
    fclose(fh);

    return 0;
}
示例#6
0
static int
write_lattice(ps_decoder_t *ps, char const *latdir, char const *uttid)
{
    ps_lattice_t *lat;
    logmath_t *lmath;
    cmd_ln_t *config;
    char *outfile;
    int32 beam;

    if ((lat = ps_get_lattice(ps)) == NULL) {
        E_ERROR("Failed to obtain word lattice for utterance %s\n", uttid);
        return -1;
    }
    config = ps_get_config(ps);
    outfile = string_join(latdir, "/", uttid,
                          cmd_ln_str_r(config, "-outlatext"), NULL);
    /* Prune lattice. */
    lmath = ps_get_logmath(ps);
    beam = logmath_log(lmath, cmd_ln_float64_r(config, "-outlatbeam"));
    ps_lattice_posterior_prune(lat, beam);
    if (0 == strcmp("htk", cmd_ln_str_r(config, "-outlatfmt"))) {
        if (ps_lattice_write_htk(lat, outfile) < 0) {
            E_ERROR("Failed to write lattice to %s\n", outfile);
            return -1;
        }
    }
    else {
        if (ps_lattice_write(lat, outfile) < 0) {
            E_ERROR("Failed to write lattice to %s\n", outfile);
            return -1;
        }
    }
    return 0;
}
示例#7
0
String NormalPath(const String& file_)
{
	String file(file_);
	file.replace('\\','/');
	arr_1t<String> arr=string_split(file,"/");

	arr_1t<String> tmp;

	for(size_t i=0;i<arr.size();i++)
	{
		if(arr[i]=="")
		{
			if(i==0) tmp.push_back("");
		}
		else if(arr[i]!="..")
		{
			tmp.push_back(arr[i]);
		}
		else if(tmp.empty()||tmp.back()=="..")
		{
			tmp.push_back(arr[i]);
		}
		else
		{
			tmp.pop_back();
		}
	}

	return string_join(tmp.begin(),tmp.end(),"/");
}
示例#8
0
void populate_entries(struct s_gui_data *gui_data) 
{
  GtkTreeModel *modelEntries;
  GtkTreeIter iter;

  gtk_list_store_clear(gui_data->listStoreEntries);
  GList *item = g_list_first(gui_data->conf->entrylist);
  while(item)
  {
    monconf_entry *entry = (monconf_entry *)item->data;
    char *str_ignores = string_join(entry->ignore_files);
    gtk_list_store_append(gui_data->listStoreEntries, &iter);
    gtk_list_store_set(gui_data->listStoreEntries,&iter,
           COL_ENTRY_PATH, entry->file_name,
           COL_ENTRY_RECURSIVE, (gboolean)(entry->recursive),
           COL_ENTRY_EVENT_CREATE, (gboolean)(entry->events & MON_CREATE),
           COL_ENTRY_EVENT_MODIFY, (gboolean)(entry->events & MON_MODIFY),
           COL_ENTRY_EVENT_DELETE, (gboolean)(entry->events & MON_DELETE),
           COL_ENTRY_EVENT_ATTRIBS, (gboolean)(entry->events & MON_ATTRIB),
           COL_ENTRY_EVENT_MOVED_FROM, (gboolean)(entry->events & MON_MOVED_FROM),
           COL_ENTRY_EVENT_MOVED_TO, (gboolean)(entry->events & MON_MOVED_TO),
           COL_ENTRY_IGNORE, str_ignores,           
           -1
          );
    free(str_ignores);
    item = item->next;
  }
}
示例#9
0
std::string Parallel::name() const
   {
   std::vector<std::string> names;

   for(auto&& hash : m_hashes)
      names.push_back(hash->name());

   return "Parallel(" + string_join(names, ',') + ")";
   }
示例#10
0
static void
ps_add_file(ps_decoder_t *ps, const char *arg,
            const char *hmmdir, const char *file)
{
    char *tmp = string_join(hmmdir, "/", file, NULL);

    if (cmd_ln_str_r(ps->config, arg) == NULL && file_exists(tmp))
        cmd_ln_set_str_r(ps->config, arg, tmp);
    ckd_free(tmp);
}
示例#11
0
static int
hmmdir_exists(const char *path)
{
    FILE *tmp;
    char *mdef = string_join(path, "/mdef", NULL);

    tmp = fopen(mdef, "rb");
    if (tmp) fclose(tmp);
    ckd_free(mdef);
    return (tmp != NULL);
}
示例#12
0
static int
process_fsgctl_line(ps_decoder_t *ps, cmd_ln_t *config, char const *fname)
{
    fsg_model_t *fsg;
    int err;
    char *path = NULL;
    const char *fsgdir = cmd_ln_str_r(config, "-fsgdir");
    const char *fsgext = cmd_ln_str_r(config, "-fsgext");

    if (fname == NULL)
        return 0;

    if (fsgdir)
        path = string_join(fsgdir, "/", fname, fsgext ? fsgext : "", NULL);
    else if (fsgext)
        path = string_join(fname, fsgext, NULL);
    else
        path = ckd_salloc(fname);

    fsg = fsg_model_readfile(path, ps_get_logmath(ps),
                                          cmd_ln_float32_r(config, "-lw"));
    err = 0;
    if (!fsg) {
        err = -1;
        goto error_out;
    }
    if (ps_set_fsg(ps, fname, fsg)) {
        err = -1;
        goto error_out;
    }

    E_INFO("Using FSG: %s\n", fname);
    if (ps_set_search(ps, fname))
        err = -1;

error_out:
    fsg_model_free(fsg);
    ckd_free(path);

    return err;
}
示例#13
0
static int
build_outdir_one(cmd_ln_t *config, char const *arg, char const *uttpath)
{
    char const *dir;

    if ((dir = cmd_ln_str_r(config, arg)) != NULL) {
        char *dirname = string_join(dir, "/", uttpath, NULL);
        build_directory(dirname);
        ckd_free(dirname);
    }
    return 0;
}
示例#14
0
文件: config.c 项目: fqxp/dvswitch
void dvswitch_read_config(void (*item_handler)(const char *, const char *))
{
    read_config("/etc/dvswitchrc", item_handler);

    const char * home = getenv("HOME");
    if (home)
    {
	char * home_dvswitchrc = string_join(home, "/.dvswitchrc");
	read_config(home_dvswitchrc, item_handler);
	free(home_dvswitchrc);
    }
}
示例#15
0
static int
process_mllrctl_line(ps_decoder_t *ps, cmd_ln_t *config, char const *file)
{
    char const *mllrdir, *mllrext;
    char *infile = NULL;
    ps_mllr_t *mllr;
    static char *lastfile;

    if (file == NULL)
        return 0;

    if (lastfile && 0 == strcmp(file, lastfile))
        return 0;

    ckd_free(lastfile);
    lastfile = ckd_salloc(file);

    mllrext = cmd_ln_str_r(config, "-mllrext");
    if ((mllrdir = cmd_ln_str_r(config, "-mllrdir")))
        infile = string_join(mllrdir, "/", file, 
                             mllrext ? mllrext : "", NULL);
    else if (mllrext)
        infile = string_join(file, mllrext, NULL);
    else
        infile = ckd_salloc(file);

    if ((mllr = ps_mllr_read(infile)) == NULL) {
        ckd_free(infile);
        return -1;
    }
    if (ps_update_mllr(ps, mllr) == NULL) {
        ps_mllr_free(mllr);
        ckd_free(infile);
        return -1;
    }

    E_INFO("Using MLLR: %s\n", file);
    ckd_free(infile);
    return 0;
}
示例#16
0
int batch_decoder_decode(batch_decoder_t *bd, char *file, char *uttid,
        int32 sf, int32 ef, alignment_t *al)
{
    featbuf_t *fb;
    FILE *infh;
    char const *cepdir, *cepext;
    char *infile;
    int rv;

    if (ef != -1 && ef < sf) {
        E_ERROR("End frame %d is < start frame %d\n", ef, sf);
        return -1;
    }

    cepdir = cmd_ln_str_r(bd->config, "-cepdir");
    cepext = cmd_ln_str_r(bd->config, "-cepext");

    /* Build input filename. */
    infile = string_join(cepdir ? cepdir : "",
            "/", file,
            cepext ? cepext : "", NULL);
    if (uttid == NULL) uttid = file;

    if ((infh = fopen(infile, "rb")) == NULL)
    {
        E_ERROR_SYSTEM("Failed to open %s", infile);
        return -1;
    }

    fb = search_factory_featbuf(bd->sf);
    gettimeofday(&bd->utt_start, NULL);
    featbuf_producer_start_utt(fb, uttid);

    if (cmd_ln_boolean_r(bd->config, "-adcin"))
    rv = batch_decoder_decode_adc(bd, infh, sf, ef, al);
    else
    rv = batch_decoder_decode_mfc(bd, infh, sf, ef, al);

    featbuf_producer_end_utt(fb);
    if (bd->hypfh) {
        char const *hyp;
        int32 score;
        hyp = search_hyp(bd->fwdflat, &score);
        fprintf(bd->hypfh, "%s (%s %d)\n",
                hyp, uttid, score);
    }

    fclose(infh);
    ckd_free(infile);

    return rv;
}
示例#17
0
void KLMultinomial<T>::setup_impl(const Variables &inputs,
                                  const Variables &outputs) {
  NBLA_CHECK(inputs[0]->shape() == inputs[1]->shape(), error_code::value,
             "Dimensions of inputs must match. "
             "inputs[0]: %s != inputs[1]: %s.",
             string_join(inputs[0]->shape(), string(", ")).c_str(),
             string_join(inputs[1]->shape(), string(", ")).c_str());

  Shape_t inshape = inputs[0]->shape();
  NBLA_CHECK(base_axis_ < inshape.size(), error_code::value,
             "base_axis must be less than ndim of inputs[0]. "
             "base_axis: %d >= ndim of inputs[0]: %d.",
             base_axis_, inshape.size());

  Shape_t outshape(base_axis_ + 1);
  for (int i = 0; i < base_axis_; i++) {
    outshape[i] = inshape[i];
  }
  outshape[base_axis_] = 1;

  outputs[0]->reshape(outshape, true);
}
示例#18
0
jsgf_rule_t *
jsgf_get_rule(jsgf_t * grammar, char const *name)
{
    void *val;
    char *fullname;

    fullname = string_join("<", name, ">", NULL);
    if (hash_table_lookup(grammar->rules, fullname, &val) < 0) {
        ckd_free(fullname);
        return NULL;
    }
    ckd_free(fullname);
    return (jsgf_rule_t *) val;
}
示例#19
0
//static
std::string CPUID::to_string()
   {
   std::vector<std::string> flags;

#define CPUID_PRINT(flag) do { if(has_##flag()) { flags.push_back(#flag); } } while(0)

#if defined(BOTAN_TARGET_CPU_IS_X86_FAMILY)
   CPUID_PRINT(sse2);
   CPUID_PRINT(ssse3);
   CPUID_PRINT(sse41);
   CPUID_PRINT(sse42);
   CPUID_PRINT(avx2);
   CPUID_PRINT(avx512f);

   CPUID_PRINT(rdtsc);
   CPUID_PRINT(bmi1);
   CPUID_PRINT(bmi2);
   CPUID_PRINT(adx);

   CPUID_PRINT(aes_ni);
   CPUID_PRINT(clmul);
   CPUID_PRINT(rdrand);
   CPUID_PRINT(rdseed);
   CPUID_PRINT(intel_sha);
#endif

#if defined(BOTAN_TARGET_CPU_IS_PPC_FAMILY)
   CPUID_PRINT(altivec);
   CPUID_PRINT(ppc_crypto);
#endif

#if defined(BOTAN_TARGET_CPU_IS_ARM_FAMILY)
   CPUID_PRINT(neon);
   CPUID_PRINT(arm_sve);

   CPUID_PRINT(arm_sha1);
   CPUID_PRINT(arm_sha2);
   CPUID_PRINT(arm_aes);
   CPUID_PRINT(arm_pmull);
   CPUID_PRINT(arm_sha2_512);
   CPUID_PRINT(arm_sha3);
   CPUID_PRINT(arm_sm3);
   CPUID_PRINT(arm_sm4);
#endif

#undef CPUID_PRINT

   return string_join(flags, ' ');
   }
示例#20
0
int ps_set_jsgf_file(ps_decoder_t *ps, const char *name, const char *path)
{
  fsg_model_t *fsg;
  jsgf_rule_t *rule;
  char const *toprule;
  jsgf_t *jsgf = jsgf_parse_file(path, NULL);
  float lw;
  int result;

  if (!jsgf)
      return -1;

  rule = NULL;
  /* Take the -toprule if specified. */
  if ((toprule = cmd_ln_str_r(ps->config, "-toprule"))) {
      char *ruletok;
      ruletok = string_join("<", toprule, ">", NULL);
      rule = jsgf_get_rule(jsgf, ruletok);
      ckd_free(ruletok);
      if (rule == NULL) {
          E_ERROR("Start rule %s not found\n", toprule);
          return -1;
      }
  } else {
      /* Otherwise, take the first public rule. */
      jsgf_rule_iter_t *itor;

      for (itor = jsgf_rule_iter(jsgf); itor;
           itor = jsgf_rule_iter_next(itor)) {
          rule = jsgf_rule_iter_rule(itor);
          if (jsgf_rule_public(rule)) {
              jsgf_rule_iter_free(itor);
              break;
          }
      }
      if (rule == NULL) {
          E_ERROR("No public rules found in %s\n", path);
          return -1;
      }
  }

  lw = cmd_ln_float32_r(ps->config, "-lw");
  fsg = jsgf_build_fsg(jsgf, rule, ps->lmath, lw);
  result = ps_set_fsg(ps, name, fsg);
  fsg_model_free(fsg);
  return result;
}
static void
ps_expand_file_config(ps_decoder_t *ps, const char *arg, const char *extra_arg,
	              const char *hmmdir, const char *file)
{
    const char *val;
    if ((val = cmd_ln_str_r(ps->config, arg)) != NULL) {
	cmd_ln_set_str_extra_r(ps->config, extra_arg, val);
    } else if (hmmdir == NULL) {
        cmd_ln_set_str_extra_r(ps->config, extra_arg, NULL);
    } else {
        char *tmp = string_join(hmmdir, "/", file, NULL);
        if (file_exists(tmp))
	    cmd_ln_set_str_extra_r(ps->config, extra_arg, tmp);
	else
	    cmd_ln_set_str_extra_r(ps->config, extra_arg, NULL);
        ckd_free(tmp);
    }
}
示例#22
0
void populate_entry_config(struct s_gui_data *gui_data)
{
  monconf_entry *entry = gui_data->curr_entry;
  if(gui_data->curr_entry)
  {
    char *ignores = string_join(entry->ignore_files);
    gtk_entry_set_text(GTK_ENTRY(gtk_builder_get_object(gui_data->builder,"entryIgnores")), ignores);
    free(ignores);
    gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(gtk_builder_get_object(gui_data->builder,"filechooserPath")), gui_data->curr_entry->file_name);
    gtk_toggle_button_set_active(&(GTK_CHECK_BUTTON(gtk_builder_get_object(gui_data->builder,"checkboxRecursive"))->toggle_button), entry->recursive);	
    gtk_toggle_button_set_active(&(GTK_CHECK_BUTTON(gtk_builder_get_object(gui_data->builder,"checkboxOnCreate"))->toggle_button), 
				  entry->events & MON_CREATE);	
    gtk_toggle_button_set_active(&(GTK_CHECK_BUTTON(gtk_builder_get_object(gui_data->builder,"checkboxOnModify"))->toggle_button), 
				  entry->events & MON_MODIFY);	
    gtk_toggle_button_set_active(&(GTK_CHECK_BUTTON(gtk_builder_get_object(gui_data->builder,"checkboxOnDelete"))->toggle_button), 
				  entry->events & MON_DELETE);	
    gtk_toggle_button_set_active(&(GTK_CHECK_BUTTON(gtk_builder_get_object(gui_data->builder,"checkboxOnAttrib"))->toggle_button), 
				  entry->events & MON_ATTRIB);	
    gtk_toggle_button_set_active(&(GTK_CHECK_BUTTON(gtk_builder_get_object(gui_data->builder,"checkboxOnMovedFrom"))->toggle_button), 
				  entry->events & MON_MOVED_FROM);	
    gtk_toggle_button_set_active(&(GTK_CHECK_BUTTON(gtk_builder_get_object(gui_data->builder,"checkboxOnMovedTo"))->toggle_button), 
				  entry->events & MON_MOVED_TO);	
    populate_entry_actions(gui_data, entry);
  } 
  else
  {
    gtk_entry_set_text(GTK_ENTRY(gtk_builder_get_object(gui_data->builder,"entryIgnores")), "");
    gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(gtk_builder_get_object(gui_data->builder,"filechooserPath")), NULL);
    gtk_toggle_button_set_active(&(GTK_CHECK_BUTTON(gtk_builder_get_object(gui_data->builder,"checkboxRecursive"))->toggle_button), 0);	
    gtk_toggle_button_set_active(&(GTK_CHECK_BUTTON(gtk_builder_get_object(gui_data->builder,"checkboxOnCreate"))->toggle_button), 
				  0);	
    gtk_toggle_button_set_active(&(GTK_CHECK_BUTTON(gtk_builder_get_object(gui_data->builder,"checkboxOnModify"))->toggle_button), 
				  0);	
    gtk_toggle_button_set_active(&(GTK_CHECK_BUTTON(gtk_builder_get_object(gui_data->builder,"checkboxOnDelete"))->toggle_button), 
				  0);	
    gtk_toggle_button_set_active(&(GTK_CHECK_BUTTON(gtk_builder_get_object(gui_data->builder,"checkboxOnAttrib"))->toggle_button), 
				  0);	
    gtk_toggle_button_set_active(&(GTK_CHECK_BUTTON(gtk_builder_get_object(gui_data->builder,"checkboxOnMovedFrom"))->toggle_button), 
				  0);	
    gtk_toggle_button_set_active(&(GTK_CHECK_BUTTON(gtk_builder_get_object(gui_data->builder,"checkboxOnMovedTo"))->toggle_button), 
				  0);	
    populate_entry_actions(gui_data, NULL);
  }  
}
示例#23
0
/* FIXME: This should go in libsphinxutil */
static char *
path_list_search(glist_t paths, char *path)
{
    gnode_t *gn;

    for (gn = paths; gn; gn = gnode_next(gn)) {
        char *fullpath;
        FILE *tmp;

        fullpath = string_join(gnode_ptr(gn), "/", path, NULL);
        tmp = fopen(fullpath, "r");
        if (tmp != NULL) {
            fclose(tmp);
            return fullpath;
        }
        else
            ckd_free(fullpath);
    }
    return NULL;
}
示例#24
0
void populate_entry_actions(struct s_gui_data *gui_data, monconf_entry *conf_entry)
{
  GtkTreeModel *modelEntries;  
  GtkTreeIter iter;
  monaction_entry *action_entry = NULL;
  monconf_action_entry *conf_action_entry = NULL;
  gtk_list_store_clear(gui_data->listStoreEntryActions);
  GList *action_keys = g_hash_table_get_values(gui_data->conf->actionMap);
  GList *item = g_list_first(action_keys);
  char *str_globs;
  
  while(item)
  {
    action_entry = (monaction_entry *)item->data;
    str_globs = NULL;
    if(conf_entry != NULL) 
    {
      conf_action_entry = monconf_action_entry_get_by_name(conf_entry, action_entry->name);    
      if(conf_action_entry != NULL)
	str_globs = string_join(conf_action_entry->globs);
    }    
    gtk_list_store_append(gui_data->listStoreEntryActions, &iter);
    gtk_list_store_set(gui_data->listStoreEntryActions,&iter,
           COL_ACTION_ENTRY_ENABLED, (gboolean)(conf_action_entry != NULL),       
	   COL_ACTION_ENTRY_NAME, (gchar *)action_entry->name,		       
           COL_ACTION_ENTRY_GLOBS, (conf_action_entry != NULL ? str_globs : ""),           
           COL_ACTION_ENTRY_CREATE, (conf_action_entry != NULL ? (gboolean)(conf_action_entry->events & MON_CREATE) : (gboolean)0),
           COL_ACTION_ENTRY_MODIFY, (conf_action_entry != NULL ? (gboolean)(conf_action_entry->events & MON_MODIFY) : (gboolean)0),
           COL_ACTION_ENTRY_DELETE, (conf_action_entry != NULL ? (gboolean)(conf_action_entry->events & MON_DELETE) : (gboolean)0),
           COL_ACTION_ENTRY_ATTRIBS, (conf_action_entry != NULL ? (gboolean)(conf_action_entry->events & MON_ATTRIB) : (gboolean)0),
           COL_ACTION_ENTRY_MOVED_FROM, (conf_action_entry != NULL ? (gboolean)(conf_action_entry->events & MON_MOVED_FROM) : (gboolean)0),
           COL_ACTION_ENTRY_MOVED_TO, (conf_action_entry != NULL ? (gboolean)(conf_action_entry->events & MON_MOVED_TO) : (gboolean)0),           		      
           -1
          );
    if(str_globs)
      free(str_globs);
    item = item->next;
  }  
  g_list_free(action_keys);
}
示例#25
0
static int
detect_sph2pipe(sphinx_wave2feat_t *wtf)
{
    FILE *fh;
    char *cmdline;
    int rv;

    /* Determine if it's NIST file and get parameters. */
    if ((rv = open_nist_file(wtf, wtf->infile, NULL, FALSE)) != TRUE)
        return rv;

    /* Now popen it with sph2pipe. */
    cmdline = string_join("sph2pipe -f raw '", wtf->infile, "'", NULL);
    if ((fh = popen(cmdline, "r")) == NULL) {
        E_ERROR_SYSTEM("Failed to popen(\"sph2pipe -f raw '%s'\")", wtf->infile);
        ckd_free(cmdline);
        return -1;
    }

    wtf->infh = fh;
    return TRUE;
}
示例#26
0
float lexical_model_rescore_function(const hypothesis* h, unsigned int id)
{
    information* info = h->get_input();
    const std::vector<const symbol*>& source = *info->get_sentence();
    std::pair<unsigned int, unsigned int> span = h->get_span();

    // check if is the last chart cell
    if (span.first != 0 || span.second != source.size()) {
        return 0.0f;
    }

    configuration* config = configuration::get_instance();
    model* system_model = config->get_model();
    language_model* lm = system_model->get_language_model(id);
    lexical_model* lex = static_cast<lexical_model*>(lm);
    lexical_model_type type = lex->get_model_type();
    std::vector<const std::string*> target;
    std::vector<std::pair<unsigned int, unsigned int>> full_align;
    std::vector<const std::string*> input;
    unsigned int source_size = source.size();
    unsigned int target_size = target.size();
    unsigned int window_size = lex->get_window_size();
    unsigned int rwin = window_size / 2;
    unsigned int lwin = window_size - rwin - 1;
    unsigned int align_size;
    float score = 0.0f;

    output_hypothesis(h, target);
    output_full_alignment(h, full_align);
    input.reserve(window_size + 1);
    align_size = full_align.size();

    symbol_table* symtab = symbol_table::get_instance();
    const symbol* bos = symtab->search_symbol("<s>");
    const symbol* eos = symtab->search_symbol("</s>");
    const symbol* null = symtab->search_symbol("<null>");

    if (type == lexical_model_type::source_to_target) {
        std::vector<std::vector<int>> align_vec;
        align_vec.resize(source_size);

        for (unsigned int i = 0; i < align_size; i++) {
            auto& pair = full_align[i];
            align_vec[pair.first].push_back(pair.second);
        }

        for (unsigned int i = 0; i < source_size; i++) {
            auto& tgt_align = align_vec[i];
            unsigned int vec_size = tgt_align.size();

            for (unsigned int j = 0; j < lwin; j++) {
                int index = i - lwin + j;

                if (index < 0)
                    input.push_back(bos->get_name());
                else
                    input.push_back(source[index]->get_name());
            }

            input.push_back(source[i]->get_name());

            for (unsigned int j = 0; j < rwin; j++) {
                int index = i + 1 + j;

                if (index >= static_cast<int>(source_size))
                    input.push_back(eos->get_name());
                else
                    input.push_back(source[index]->get_name());
            }

            if (vec_size == 0) {
                input.push_back(null->get_name());
            } else {
                std::string word;
                std::vector<std::string> str_vec;
                str_vec.reserve(vec_size);
                const symbol* sym;

                for (unsigned int j = 0; j < vec_size; j++) {
                    str_vec.push_back(*target[tgt_align[j]]);
                }

                string_join(str_vec, "+++", word);
                sym = symtab->search_symbol(word);
                input.push_back(sym->get_name());
            }

            score += lex->probability(input.data());
            input.clear();
        }
    } else {
        std::vector<std::vector<int>> align_vec;
        align_vec.resize(target_size);

        for (unsigned int i = 0; i < align_size; i++) {
            auto& pair = full_align[i];
            align_vec[pair.second].push_back(pair.first);
        }

        for (unsigned int i = 0; i < target_size; i++) {
            auto& src_align = align_vec[i];
            unsigned int vec_size = src_align.size();

            for (unsigned int j = 0; j < lwin; j++) {
                int index = i - lwin + j;

                if (index < 0)
                    input.push_back(bos->get_name());
                else
                    input.push_back(target[index]);
            }

            input.push_back(target[i]);

            for (unsigned int j = 0; j < rwin; j++) {
                int index = i + 1 + j;

                if (index >= static_cast<int>(target_size))
                    input.push_back(bos->get_name());
                else
                    input.push_back(target[index]);
            }

            if (vec_size == 0) {
                input.push_back(null->get_name());
            } else {
                std::string word;
                std::vector<std::string> str_vec;
                str_vec.reserve(vec_size);
                const symbol* sym;

                for (unsigned int j = 0; j < vec_size; j++) {
                    str_vec.push_back(*source[src_align[j]]->get_name());
                }

                string_join(str_vec, "+++", word);
                sym = symtab->search_symbol(word);
                input.push_back(sym->get_name());
            }

            score += lex->probability(input.data());
            input.clear();
        }
    }

    return score;
}
示例#27
0
void CG_GGVar::add(CallableData* p,const String& s,int f)
{

	CG_GGVar& gi(CG_GGVar::current());
	arr_1t<String> ap = string_split(s, ".");

	size_t n = ap.size();

	if(n==0)
	{
		return;
	}
	
	if(n==1)
	{
		gi[s].kptr(p);
		return;
	}

	if(f!=0)
	{
		gi[ap[n-1]].kptr(p);
	}


	VariantTable *pt=&gi;
	for(size_t i=0;i<n;i++)
	{
		if(i+1==n)
		{
			if (i == 1 && _bInited)
			{
				gi[s].kptr(p);
			}

			(*pt)[ap[i]].kptr(p);
			break;
		}

		intptr_t d=pt->find1(ap[i]);
		if(d>=0)
		{
			pt=pt->get(d).second.ptr<VariantTable>();
			if (!pt)
			{
				return;
			}
		}
		else
		{
			String libname=string_join(ap.begin(),ap.begin()+i+1,".");
			DataPtrT<CallableModule> tb = new CallableModule(libname);

			(*pt)[ap[i]].kptr(tb);pt=&tb->value;

			if (i == 1 && _bInited)
			{
				gi[ap[0]+"."+ap[1]].kptr(tb);
			}

		}
	}

}
示例#28
0
FILE *
fopen_comp(const char *file, const char *mode, int32 * ispipe)
{
    FILE *fp;

#ifndef HAVE_POPEN
    *ispipe = 0; /* No popen() on WinCE */
#else /* HAVE_POPEN */
    int32 isgz;
    guess_comptype(file, ispipe, &isgz);
#endif /* HAVE_POPEN */

    if (*ispipe) {
#ifndef HAVE_POPEN
        /* Shouldn't get here, anyway */
        E_FATAL("No popen() on WinCE\n");
#else
        if (strcmp(mode, "r") == 0) {
            char *command;
            switch (isgz) {
            case COMP_GZIP:
                command = string_join("gunzip" EXEEXT, " -c ", file, NULL);
                break;
            case COMP_COMPRESS:
                command = string_join("zcat" EXEEXT, " ", file, NULL);
                break;
            case COMP_BZIP2:
                command = string_join("bunzip2" EXEEXT, " -c ", file, NULL);
                break;
            default:
                command = NULL; /* Make compiler happy. */
                E_FATAL("Unknown  compression type %d\n", isgz);
            }
            if ((fp = popen(command, mode)) == NULL) {
                E_ERROR_SYSTEM("Failed to open a pipe for a command '%s' mode '%s'", command, mode);
                ckd_free(command);
                return NULL;
            }
            ckd_free(command);
        }
        else if (strcmp(mode, "w") == 0) {
            char *command;
            switch (isgz) {
            case COMP_GZIP:
                command = string_join("gzip" EXEEXT, " > ", file, NULL);
                break;
            case COMP_COMPRESS:
                command = string_join("compress" EXEEXT, " -c > ", file, NULL);
                break;
            case COMP_BZIP2:
                command = string_join("bzip2" EXEEXT, " > ", file, NULL);
                break;
            default:
                command = NULL; /* Make compiler happy. */
                E_FATAL("Unknown compression type %d\n", isgz);
            }
            if ((fp = popen(command, mode)) == NULL) {
                E_ERROR_SYSTEM("Failed to open a pipe for a command '%s' mode '%s'", command, mode);
                ckd_free(command);
                return NULL;
            }
            ckd_free(command);
        }
        else {
            E_ERROR("Compressed file operation for mode %s is not supported", mode);
            return NULL;
        }
#endif /* HAVE_POPEN */
    }
    else {
        fp = fopen(file, mode);
    }

    return (fp);
}
示例#29
0
int
main(int argc, char *argv[])
{
    if (argc < 2)
        return 1;

    if (!strcmp(argv[1], "string_join")) {
        char *foo = string_join("bar", "baz", "quux", NULL);
        if (strcmp(foo, "barbazquux") != 0) {
            printf("%s != barbazquux\n", foo);
            return 1;
        }
        foo = string_join("hello", NULL);
        if (strcmp(foo, "hello") != 0) {
            printf("%s != hello\n", foo);
            return 1;
        }
        return 0;
    }
    else if (!strcmp(argv[1], "fread_line")) {
        FILE *fp = fopen(TESTDATADIR "/_fread_line.txt", "r");
        char *line;
        size_t len;

        if (fp == NULL) {
            perror("Failed to open " TESTDATADIR "/_fread_line.txt");
            return 1;
        }
        line = fread_line(fp, &len);
        printf("len = %d orig = %d\n", len,
               strlen("Hello world!\n"));
        if (strcmp(line, "Hello world!\n") != 0) {
            printf("'%s' != 'Hello world!\\n'\n", line);
            return 1;
        }
        ckd_free(line);
        line = fread_line(fp, &len);
        /* A line of exactly 127 characters. */
        printf("len = %d orig = %d\n", len,
               strlen("123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456\n"));
        if (strcmp(line, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456\n") != 0) {
            printf("'%s' != '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456\\n'\n", line);
            return 1;
        }
        ckd_free(line);
        /* A very long line. */
        line = fread_line(fp, &len);
        printf("len = %d orig = %d\n", len,
               strlen("All work and no play makes Jack a very dull boy.  All work and no play makes Jack a very dull boy.  All work and no play makes Jack a very dull boy.  All work and no play makes Jack a very dull boy.  All work and no play makes Jack a very dull boy.  All work and no play makes Jack a very dull boy.  \n"));
        if (strcmp(line, "All work and no play makes Jack a very dull boy.  All work and no play makes Jack a very dull boy.  All work and no play makes Jack a very dull boy.  All work and no play makes Jack a very dull boy.  All work and no play makes Jack a very dull boy.  All work and no play makes Jack a very dull boy.  \n") != 0) {
            printf("'%s' != 'All work and no play makes Jack a very dull boy.  All work and no play makes Jack a very dull boy.  All work and no play makes Jack a very dull boy.  All work and no play makes Jack a very dull boy.  All work and no play makes Jack a very dull boy.  All work and no play makes Jack a very dull boy.  \\n'\n", line);
            return 1;
        }
        ckd_free(line);
        line = fread_line(fp, &len);
        if (line != NULL) {
            printf("%p != NULL\n", line);
            return 1;
        }
    }
    else if (!strcmp(argv[1], "string_trim")) {
        char *foo = ckd_salloc("\t foo bar baz  \n");
        string_trim(foo, STRING_BOTH);
        if (strcmp(foo, "foo bar baz") != 0) {
            printf("'%s' != 'foo bar baz'\n", foo);
            return 1;
        }
        string_trim(foo, STRING_BOTH);
        if (strcmp(foo, "foo bar baz") != 0) {
            printf("'%s' != 'foo bar baz'\n", foo);
            return 1;
        }
        strcpy(foo, "foo\nbar\n\n");
        string_trim(foo, STRING_END);
        if (strcmp(foo, "foo\nbar") != 0) {
            printf("'%s' != 'foo\\nbar'\n", foo);
            return 1;
        }
        strcpy(foo, " \t \t foobar\n");
        string_trim(foo, STRING_START);
        if (strcmp(foo, "foobar\n") != 0) {
            printf("'%s' != 'foobar\\n'\n", foo);
            return 1;
        }
    }
    else if (!strcmp(argv[1], "str2words")) {
        char *line = ckd_salloc("    foo bar baz argh");
        char **words;
        int n;

        n = str2words(line, NULL, 0);
        if (n != 4) {
            printf("%d != 4\n", n);
            return 1;
        }
        words = ckd_calloc(n, sizeof(*words));
        n = str2words(line, words, n);
        if (n != 4) {
            printf("%d != 4\n", n);
            return 1;
        }
        if (strcmp(words[0], "foo") != 0
            || strcmp(words[1], "bar") != 0
            || strcmp(words[2], "baz") != 0
            || strcmp(words[3], "argh") != 0) {
            printf("%s, %s, %s, %s != foo, bar, baz, argh\n",
                   words[0], words[1], words[2], words[3]);
            return 1;
        }
        return 0;
    }
    else if (!strcmp(argv[1], "nextword")) {
        char *line = ckd_salloc(" \tfoo bar\nbaz argh");
        char *word;
        const char *delim = " \t\n";
        char delimfound;
        int n;

        n = nextword(line, delim, &word, &delimfound);
        if (strcmp(word, "foo") != 0) {
            printf("%s != foo\n", word);
            return 1;
        }
        if (delimfound != ' ') {
            printf("didn't find ' '\n");
            return 1;
        }
        word[n] = delimfound;
        line = word + n;
        n = nextword(line, delim, &word, &delimfound);
        if (strcmp(word, "bar") != 0) {
            printf("%s != bar\n", word);
            return 1;
        }
        if (delimfound != '\n') {
            printf("didn't find '\\n'\n");
            return 1;
        }
        word[n] = delimfound;
        line = word + n;
        n = nextword(line, delim, &word, &delimfound);
        if (strcmp(word, "baz") != 0) {
            printf("%s != baz\n", word);
            return 1;
        }
        if (delimfound != ' ') {
            printf("didn't find ' '\n");
            return 1;
        }
        word[n] = delimfound;
        line = word + n;
        n = nextword(line, delim, &word, &delimfound);
        if (strcmp(word, "argh") != 0) {
            printf("%s != argh\n", word);
            return 1;
        }
        if (delimfound != '\0') {
            printf("didn't find NUL\n");
            return 1;
        }
        word[n] = delimfound;
        line = word + n;
        n = nextword(line, delim, &word, &delimfound);
        if (n != -1) {
            printf("didn't get -1 at end of string\n");
        }

        line = ckd_salloc("FOO!");
        n = nextword(line, delim, &word, &delimfound);
        if (strcmp(word, "FOO!") != 0) {
            printf("%s != FOO!\n", word);
            return 1;
        }
        if (delimfound != '\0') {
            printf("didn't find NUL\n");
            return 1;
        }

        return 0;
    }
    return 0;
}
示例#30
0
void Command::init_command_map()
{
   command_map["NOOP"] = [](EventHandler &, std::vector<std::string> arg) -> std::string {
      std::cerr << "NOOP begin" << std::endl;
      std::cerr << string_join(arg, "\n") << std::endl << "end" << std::endl;
      return "OK";
   };

   command_map["PLAY"] = [this](EventHandler &, std::vector<std::string> arg) -> std::string {
      if (arg.empty())
         arg.push_back("");

      try
      {
         remote->play(arg.front());
         arg.erase(arg.begin());
         for (auto &str : arg)
            remote->add(str);
         return "OK";
      }
      catch(const std::exception &e)
      {
         std::cerr << e.what() << std::endl;
         return "ERROR";
      }
   };

   command_map["QUEUE"] = [this](EventHandler &, std::vector<std::string> arg) -> std::string {
      if (arg.empty())
         arg.push_back("");

      try
      {
         for (auto &str : arg)
         remote->add(str);
         return "OK";
      }
      catch(const std::exception &e)
      {
         std::cerr << e.what() << std::endl;
         return "ERROR";
      }
   };

   command_map["NEXT"] = [this](EventHandler &, std::vector<std::string>) -> std::string {
      return plain_action(std::bind(&Remote::next, remote));
   };

   command_map["PREV"] = [this](EventHandler &, std::vector<std::string>) -> std::string {
      return plain_action(std::bind(&Remote::prev, remote));
   };

   command_map["STOP"] = [this](EventHandler &, std::vector<std::string>) -> std::string {
      return plain_action(std::bind(&Remote::stop, remote));
   };

   command_map["PAUSE"] = [this](EventHandler &, std::vector<std::string>) -> std::string {
      return plain_action(std::bind(&Remote::pause, remote));
   };

   command_map["UNPAUSE"] = [this](EventHandler &, std::vector<std::string>) -> std::string {
      return plain_action(std::bind(&Remote::unpause, remote));
   };

   command_map["SEEK"] = [this](EventHandler &, std::vector<std::string> arg) -> std::string {
      if (arg.empty())
         throw std::logic_error("SEEK requires argument.");

      int time = std::strtol(arg[0].c_str(), nullptr, 0);
      return plain_action(std::bind(&Remote::seek, remote, time));
   };

   command_map["POS"] = [this](EventHandler &, std::vector<std::string>) -> std::string {
      try
      {
         auto pos = remote->pos();
         return stringify(static_cast<int>(pos.first), " ", static_cast<int>(pos.second));
      }
      catch (const std::exception &e)
      {
         std::cerr << e.what() << std::endl;
         return "ERROR";
      }
   };

   command_map["DIE"] = [this](EventHandler &event, std::vector<std::string>) -> std::string {
      event.kill();
      return "OK";
   };

   command_map["TITLE"] = [this](EventHandler &, std::vector<std::string>) -> std::string {
      return metadata_action(*remote, [](const FF::MediaInfo &info) { return info.title; });
   };

   command_map["ARTIST"] = [this](EventHandler &, std::vector<std::string>) -> std::string {
      return metadata_action(*remote, [](const FF::MediaInfo &info) { return info.artist; });
   };

   command_map["ALBUM"] = [this](EventHandler &, std::vector<std::string>) -> std::string {
      return metadata_action(*remote, [](const FF::MediaInfo &info) { return info.album; });
   };

   command_map["STATUS"] = [this](EventHandler &, std::vector<std::string>) -> std::string {
      return remote->status();
   };
}