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


C++ Phrase::push_back方法代码示例

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


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

示例1: main

int main() {
	std::unordered_map< std::string, int > dictionary;
	//std::ifstream input("../data/corpus/europarl.lowercased.en", std::ios::in);
	int phrases[][3] = {
		{ 0, 1, 2 },
		{ 0, 2, 3 },
		{ 2, 3, 1 },
	};
	/*for (std::string line; std::getline(input, line); ) {
		std::istringstream iss(line);
		Phrase phrase;
		for (std::string word; iss >> word; )
			phrase.push_back(getId(dictionary, word));
		phrases.push_back(phrase);
		if (phrases.size() == 1000)
			break;
	}*/
	std::vector< Phrase > phs;
	for (int i = 0; i < 3; ++i)
		phs.push_back(Phrase(phrases[i], phrases[i+1]));
	LanguageModel model(learn_ngram_language_model(phs, 4, 2, 0.0001));

	for (int i = 0; i < 4; ++i) {

		for (int j=  0; j < 4; ++j) {
			Phrase phrase;
			phrase.push_back(i);
			phrase.push_back(j);
			printf("%d %d %lf\n", i, j, model.get_probability(phrase));
		}
		Phrase phrase;
		phrase.push_back(i);
			printf("%d %lf\n", i, model.get_probability(phrase));
	}

	Phrase phrase;
	phrase.push_back(2);
	phrase.push_back(3);
	phrase.push_back(1);
	printf("2 3 1 %lf\n", model.get_probability(phrase));
	


	model.save("lmodel.bin");
	if (!(model == load_ngram_language_model("lmodel.bin")))
		throw 42;
}
开发者ID:alshedivat,项目名称:machine-trans-shared-task,代码行数:47,代码来源:testlanguagemodel.cpp

示例2: XMLParse

void AlignedSentenceSyntax::XMLParse(Phrase &output,
                                     SyntaxTree &tree,
                                     const pugi::xml_node &parentNode,
                                     const Parameter &params)
{
  int childNum = 0;
  for (pugi::xml_node childNode = parentNode.first_child(); childNode; childNode = childNode.next_sibling()) {
    string nodeName = childNode.name();

    // span label
    string label;
    int startPos = output.size();

    if (!nodeName.empty()) {
      pugi::xml_attribute attribute = childNode.attribute("label");
      label = attribute.as_string();

      // recursively call this function. For proper recursive trees
      XMLParse(output, tree, childNode, params);
    }



    // fill phrase vector
    string text = childNode.value();
    Escape(text);
    //cerr << childNum << " " << label << "=" << text << endl;

    std::vector<string> toks;
    Moses::Tokenize(toks, text);

    for (size_t i = 0; i < toks.size(); ++i) {
      const string &tok = toks[i];
      Word *word = new Word(output.size(), tok);
      output.push_back(word);
    }

    // is it a labelled span?
    int endPos = output.size() - 1;

    // fill syntax labels
    if (!label.empty()) {
      label = "[" + label + "]";
      tree.Add(startPos, endPos, label, params);
    }

    ++childNum;
  }

}
开发者ID:Deseaus,项目名称:mosesdecoder,代码行数:50,代码来源:AlignedSentenceSyntax.cpp


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