当前位置: 首页>>代码示例>>C++>>正文


C++ Alphabet::size方法代码示例

本文整理汇总了C++中Alphabet::size方法的典型用法代码示例。如果您正苦于以下问题:C++ Alphabet::size方法的具体用法?C++ Alphabet::size怎么用?C++ Alphabet::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Alphabet的用法示例。


在下文中一共展示了Alphabet::size方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: printDecomposition

/** Prints one decomposition to stdout */
void printDecomposition(const Alphabet& alphabet, const decomposition_t& decomposition)
{
	assert(alphabet.size() == decomposition.size());
	bool first = true;
	for (Alphabet::size_type i = 0; i < alphabet.size(); ++i) {
		if (decomposition[i] > 0) {
			if (!first) {
				cout << " ";
			} else {
				first = false;
			}
			cout << alphabet.getName(i) << decomposition[i];
		}
	}
}
开发者ID:nathaniel-mahieu,项目名称:Rdisop,代码行数:16,代码来源:imsintdecomp.cpp

示例2: OTWS_Load

otws_t OTWS_Load(const char *cfg_file) {

    // allocate config parser and set default config.
    ltp_configure *cfg = new ltp_configure();

    cfg->set_cfg("target", "test");
    cfg->set_cfg("agenda", "1");
    cfg->set_cfg("model", "./");
    cfg->set_cfg("dict", "./");

    // load config.
    if (-1 == cfg->load_cfg(cfg_file)) {
        WARNING_LOG("Failed to load config file");
        delete cfg;
        return NULL;
    }

    OTWS_Engine *engine = new OTWS_Engine();

    // allocate alphabet
    Alphabet *features = new HashDict();
    Alphabet *labels   = new HashDict();
    Alphabet *words    = new HashDict();
    Parameter *param   = new CParameter(0, 0);

    // load model.
    Model *model       = new Model();
    model->registAlphabet("FEATURES", features);
    model->registAlphabet("LABELS", labels);
    model->registParameter("PARAMETER", param);
    model->loadModel(cfg->config("model").c_str());

    TRACE_LOG("Loading model is done.");
    TRACE_LOG("Num Features: %d", features->size());
    TRACE_LOG("Num Labels: %d", labels->size());

    Extractor *extractor = new SegmentExtractor(
            cfg->config("dict").c_str(),
            features, labels, words);

    Decoder *decoder = new SegmentDecoder(model, 1);

    engine->model = model;
    engine->extractor = extractor;
    engine->decoder = decoder;

    return reinterpret_cast<otws_t>(engine);
}
开发者ID:shannonyu,项目名称:online-tagger,代码行数:48,代码来源:otws_dll.cpp

示例3:

// ----------------------------------------------
// PLAIN DECODER
// ----------------------------------------------
SegmentDecoder::SegmentDecoder(
        Model *model,
        int agenda) {
    this->m_Model  = model;
    this->m_Agenda = agenda;
    Alphabet *labelAlpha = model->getAlphabet("LABELS");
    this->m_NumLabels = labelAlpha->size();

    m_Legal = new int *[m_NumLabels + 1];
    for (int i = 0; i <= m_NumLabels; ++ i) {
        char prev = 'X';
        if (i < m_NumLabels)
            prev = labelAlpha->rlookup(i)[0];

        m_Legal[i] = new int[m_NumLabels];
        for (int j = 0; j < m_NumLabels; ++ j) {
            char curr = labelAlpha->rlookup(j)[0];

            m_Legal[i][j] = 0;
            if ((prev == 'X' || prev == 'S' || prev == 'E') 
                    && (curr == 'S' || curr == 'B'))
                m_Legal[i][j] = 1;
            if ((prev == 'M' || prev == 'B') && 
                    (curr == 'M' || curr == 'E'))
                m_Legal[i][j] = 1;
        }
    }
}
开发者ID:shannonyu,项目名称:online-tagger,代码行数:31,代码来源:seg-decoder.cpp

示例4: alignment

ProfileFelsenstein::ProfileFelsenstein(const MultSeqAlignment &A,
				       const Alphabet &alphabet,
				       const AlphabetMap &alphabetMap)
  : alignment(A), alphabet(alphabet), numAlpha(alphabet.size()),
    alphabetMap(alphabetMap)
{
  // ctor
}
开发者ID:bmajoros,项目名称:alignment,代码行数:8,代码来源:ProfileFelsenstein.C

示例5: convertNmerCode

unsigned convertNmerCode(unsigned rawCode,int seqLength,const Alphabet &alphabet)
{
  Sequence S;
  S.resize(seqLength);
  unsigned base=alphabet.size();
  for(int i=seqLength-1 ; i>=0 ; --i) {
    unsigned digit=rawCode%base;
    Symbol s=(int)digit;
    S[i]=s;
    rawCode/=base;
  }	
  return S.asInt(alphabet,0,S.getLength());
}
开发者ID:bmajoros,项目名称:PhyLib,代码行数:13,代码来源:NmerRateMatrix.C

示例6: readEmbeddings

void Segmentor::readEmbeddings(Alphabet &alpha, const string& inFile, NRMat<dtype>& emb) {
  static ifstream inf;
  if (inf.is_open()) {
    inf.close();
    inf.clear();
  }
  inf.open(inFile.c_str());

  static string strLine, curWord;
  static int wordId;

  //find the first line, decide the wordDim;
  while (1) {
    if (!my_getline(inf, strLine)) {
      break;
    }
    if (!strLine.empty())
      break;
  }

  int unknownId = alpha.from_string(m_classifier.fe.unknownkey);

  static vector<string> vecInfo;
  split_bychar(strLine, vecInfo, ' ');
  int wordDim = vecInfo.size() - 1;

  std::cout << "embedding dim is " << wordDim << std::endl;

  emb.resize(alpha.size(), wordDim);
  emb = 0.0;
  curWord = normalize_to_lowerwithdigit(vecInfo[0]);
  wordId = alpha.from_string(curWord);
  hash_set<int> indexers;
  dtype sum[wordDim];
  int count = 0;
  bool bHasUnknown = false;
  if (wordId >= 0) {
    count++;
    if (unknownId == wordId)
      bHasUnknown = true;
    indexers.insert(wordId);
    for (int idx = 0; idx < wordDim; idx++) {
      dtype curValue = atof(vecInfo[idx + 1].c_str());
      sum[idx] = curValue;
      emb[wordId][idx] = curValue;
    }

  } else {
    for (int idx = 0; idx < wordDim; idx++) {
      sum[idx] = 0.0;
    }
  }

  while (1) {
    if (!my_getline(inf, strLine)) {
      break;
    }
    if (strLine.empty())
      continue;
    split_bychar(strLine, vecInfo, ' ');
    if (vecInfo.size() != wordDim + 1) {
      std::cout << "error embedding file" << std::endl;
    }
    curWord = normalize_to_lowerwithdigit(vecInfo[0]);
    wordId = alpha.from_string(curWord);
    if (wordId >= 0) {
      count++;
      if (unknownId == wordId)
        bHasUnknown = true;
      indexers.insert(wordId);

      for (int idx = 0; idx < wordDim; idx++) {
        dtype curValue = atof(vecInfo[idx + 1].c_str());
        sum[idx] += curValue;
        emb[wordId][idx] += curValue;
      }
    }

  }

  if (!bHasUnknown) {
    for (int idx = 0; idx < wordDim; idx++) {
      emb[unknownId][idx] = sum[idx] / count;
    }
    count++;
    std::cout << unknownkey << " not found, using averaged value to initialize." << std::endl;
  }

  int oovWords = 0;
  int totalWords = 0;
  for (int id = 0; id < alpha.size(); id++) {
    if (indexers.find(id) == indexers.end()) {
      oovWords++;
      for (int idx = 0; idx < wordDim; idx++) {
        emb[id][idx] = emb[unknownId][idx];
      }
    }
    totalWords++;
  }

//.........这里部分代码省略.........
开发者ID:LinguList,项目名称:NNTransitionSegmentor,代码行数:101,代码来源:LSTMNCSegmentor.cpp


注:本文中的Alphabet::size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。