Esempio n. 1
0
int
write_mat_file (const char *filename, const disp_t *d, 
		double lmin, double lmax, double lstep)
{
  FILE *f;
  int jinf, jsup, step;
  int j;

  f = fopen(filename, "w");

  if (f == NULL)
    return 1;

  fprintf (f, "%s\n", CSTR(d->name));
  fprintf (f, "nm\n");
  fprintf (f, "NK\n");

  jinf = rint (lmin * 100.0);
  jsup = rint (lmax * 100.0);
  step = rint (lstep * 100.0);

  for (j = jinf; j <= jsup; j += step)
    {
      double lambda = j / 100.0;
      cmpl n = n_value (d, lambda);

      fprintf (f, "%7.2f\t%.7f\t%.7f\n", lambda, creal(n), - cimag(n));
    }

  fclose (f);

  return 0;
}
Esempio n. 2
0
File: count.cpp Progetto: drio/egrl
void *screen_reads(ss_probes *h_probes,
                   int probe_length,
                   std::string **buffer,
                   int n_reads,
                   int tid,
                   pthread_mutex_t *mutex,
                   int n_threads)
{
  google::dense_hash_map<std::string, Probe *>::iterator p_iter;
  const int n_pos = probe_length/2;
  std::string window;
  std::string n_value(" ");

  int p,i; // pointer to buffer, pointer in read
  for (p=0; p!=n_reads; ++p) {
    if ((n_threads>1) && (p % n_threads != tid)) continue;
    for (i=0; i+probe_length<=(int) buffer[p]->length(); ++i) {
      window        = buffer[p]->substr(i, probe_length);
      n_value[0]    = window[n_pos];
      window[n_pos] = 'N';
      if ((p_iter = h_probes->find(window)) != h_probes->end()) {
        pthread_mutex_lock(mutex);
        p_iter->second->update_counters(n_value);
        pthread_mutex_unlock(mutex);
      }
    }
  }
  return 0;
}
Esempio n. 3
0
void ngram_pos_analyzer::tokenize(corpus::document& doc)
{
    // first, get tokens
    stream_->set_content(get_content(doc));
    std::vector<sequence::sequence> sentences;
    sequence::sequence seq;

    // put tokens into sequences, excluding sentence markers
    while (*stream_)
    {
        auto next = stream_->next();
        if (next.empty() || next == " " || next == "<s>")
            continue;

        if (next == "</s>")
            sentences.emplace_back(std::move(seq));
        else
            seq.add_observation(
                {sequence::symbol_t{next}, sequence::tag_t{"[unknown]"}});
    }

    auto tagger = crf_->make_tagger();
    for (auto& seq : sentences)
    {
        // generate CRF features
        seq_analyzer_.analyze(seq);

        // POS-tag sentence
        tagger.tag(seq);

        // create ngrams
        for (size_t i = n_value() - 1; i < seq.size(); ++i)
        {
            std::string combined = seq_analyzer_.tag(seq[i].label());
            for (size_t j = 1; j < n_value(); ++j)
            {
                std::string next = seq_analyzer_.tag(seq[i - j].label());
                combined = next + "_" + combined;
            }

            doc.increment(combined, 1);
        }
    }
}