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


C++ Alignment::nextSentence方法代码示例

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


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

示例1: main

int main(int argc, char** argv)
{
	if (argc < 4)
	{
		cerr << "ERROR: not enough parameters" << endl << "Usage: " << argv[0] << " source-doc target-doc alignment" << endl;
		return 0; // EXIT_FAILURE;
	}

	// open files
	ifstream src(argv[1]);
	ifstream dest(argv[2]);

	if (!src.good())
	{
		cerr << "ERROR: Opening source-language ("<< argv[1] <<") failed." << endl;
		return 0; // EXIT_FAILURE;
	}

	if (!dest.good())
	{
		cerr << "ERROR: Opening target-language ("<< argv[2] <<") failed." << endl;
		return 0; // EXIT_FAILURE;
	}

	// variables holding all data

	/// holds the Alignment and finds all valid phrases etc..
	Alignment* aligObj;
	try
	{
		aligObj = new Alignment(argv[3]);
	}
	catch (bool openFileFail)
	{
		cerr << "ERROR: Opening alignment ("<< argv[3] <<") failed."  << endl;
		return 0; // EXIT_FAILURE;
	}

	/// src-lang phrase count (prefixtree of words) - initialized with the 0-word as root
	Tree *phrasesF = new Tree(new Node(0));

	/// target-lang phrase count (prefixtree of words) - initialized with the 0-word as root
	Tree *phrasesE = new Tree(new Node(0));

	/// phrasepair count (prefixtree of prefixtrees) - initialized with a Tree as root which is initialized with the 0-word as root
	TreeOfTrees* phrasePairs = new TreeOfTrees(new NodeOfTrees(0, NULL));

	vector<unsigned int> srcWords;
	vector<unsigned int> destWords;
	string srcLine, destLine;

	unsigned int lineNr = 1;
	// get src and dest lines
	while (getline(src,srcLine) && getline(dest,destLine))
	{

		//put all words of the sentence in source language-lexicon and the value of the word into the lang-object
		srcWords = f.insertSentence(srcLine);
		destWords = e.insertSentence(destLine);

		// init the alignment for these sentences
		aligObj->nextSentence(srcLine.size(), destLine.size());

		// get phrases
		unsigned int i1=0,i2=0;
		for (unsigned int j1 = 0; j1<srcLine.size(); j1++)
		{
			//for (unsigned int j2 = i1; j2<srcLine.size(); j2++)
			for (unsigned int j2 = i1; j2<srcLine.size() && j2-j1<=MAX_PHRASE_LENGTH; j2++)
			{
				i1 = aligObj->getMinTargetAlig(j1, j2);
				i2 = aligObj->getMaxTargetAlig(j1, j2);
				if (aligObj->getMinSrcAlig(i1, i2) == j1 && aligObj->getMaxSrcAlig(i1, i2) == j2)
				{
					PhrasePair* p = aligObj->outputPhrase(j1, j2, i1, i2, srcWords, destWords);

					// put phrase in source-lang-obj
					phrasesF->insert(p->src);

					// put phrase in target-lang-obj
					phrasesE->insert(p->target);

					// count phrasePair
					phrasePairs->insert(p);
				}
			}
		}

//		if (lineNr/100==(double)lineNr/(double)100) 
//			cout << "line" << lineNr << endl;
//		if (lineNr>TRAINING_LINES) break;
//		lineNr++;
	}	 

	showFreqPhrases(phrasePairs, phrasesF, phrasesE, f, e);

	return 0; //EXIT_SUCCESS;
}
开发者ID:Chefslayer,项目名称:Translator,代码行数:98,代码来源:phraseExtract.cpp


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