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


C++ PhraseTable::add方法代码示例

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


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

示例1: rule_refinement

void rule_refinement(JKArgs& args)
{
	if(!args.is_set("i"))usage();
	ifstream is(args.value("i").c_str());

	map<string,EntryInfo> srcPhrases,tarPhrases;
	while(is.good())
	{
		string curline="";
		getline(is,curline);
		if(curline=="")break;
		PhraseRuleEntry pre;
		pre.read(curline);
		if(srcPhrases.find(pre.srcPhrase)==srcPhrases.end())
		{
			EntryInfo ei;
			ei.ind=(int)srcPhrases.size();
			ei.score=pre.s2tScore;
			srcPhrases[pre.srcPhrase]=ei;
		}
		else
			srcPhrases[pre.srcPhrase].score+=pre.s2tScore;

		if(tarPhrases.find(pre.tarPhrase)==tarPhrases.end())
		{
			EntryInfo ei;
			ei.ind=(int)tarPhrases.size();
			ei.score=pre.s2tScore;
			tarPhrases[pre.tarPhrase]=ei;
		}
		else
			tarPhrases[pre.tarPhrase].score+=pre.s2tScore;
	}
	is.clear();
	is.seekg(0,ios::beg);
	PhraseTable pt;
	while(is.good())
	{
		string curline="";
		getline(is,curline);
		if(curline==""){pt.print(cout);break;}
		PhraseRuleEntry pre;
		pre.read(curline);
		pre.s2tScore/=srcPhrases[pre.srcPhrase].score;
		pre.t2sScore/=tarPhrases[pre.tarPhrase].score;
		
		if(pt.size()>0&&pt.data().find(pre.srcPhrase)==pt.data().end())
		{
			pt.print(cout);
			pt.clear();
		}
		pt.add(pre.srcPhrase,pre.tarPhrase,pre);
	}
}
开发者ID:hznlp,项目名称:pbmt,代码行数:54,代码来源:main-old.cpp

示例2:

void 
SearchSpace::
copeUNK(PhraseTable& pt)
{
	for(size_t i=0;i<_sentence.size();i++)
	{
		string wrd=_sentence[i];
		if(pt.queryRulesVec(wrd)==NULL)
		{
			PhraseRuleEntry e;
			e.s2tLexScore=e.t2sLexScore=e.t2sScore=e.s2tScore=-100;
			e.srcPhrase=e.tarPhrase=wrd;
			e.tarRepresent.push_back(wrd);
			pt.add(wrd,wrd,e);
			pt.rulesInVec()[wrd].push_back(&pt.data()[wrd][wrd]);
		}
	}
}
开发者ID:hznlp,项目名称:pbmt,代码行数:18,代码来源:Decode.cpp

示例3: extractPhrase

void extractPhrase(JKArgs& args)
{
	if(!args.is_set("src")||!args.is_set("tar")||!args.is_set("align"))
		usage();
	ifstream fsrc(args.value("src").c_str()),ftar(args.value("tar").c_str()),falign(args.value("align").c_str());
	ifstream fweight;
	ofstream os;
	double threshold=0;
	if(args.is_set("threshold"))threshold=atof(args.value("threshold").c_str());
	if(args.is_set("o"))os.open(args.value("o").c_str());
	if(args.is_set("w"))fweight.open(args.value("w").c_str());
	Dic<double> s2tLexDic,t2sLexDic;
	if(!args.is_set("s2tLex")||!args.is_set("t2sLex"))
	{
		cerr<<"making lex dic on the fly"<<endl;
		makeLexDic(args.value("src"),args.value("tar"),args.value("align"),args.value("w"),s2tLexDic,t2sLexDic);
	}
	else
	{
		s2tLexDic.load(args.value("s2tLex"));
		t2sLexDic.load(args.value("t2sLex"));
	}
	bool reverse=false,normalize=false;
	bool moore=false;
	if(args.is_set("moore"))if(args.value("moore")=="true")moore=true;
	if(args.is_set("reverse"))
		reverse=true;
	if(args.is_set("normalize"))
		if(args.value("normalize")=="true")
			normalize=true;
	int srcLengthLimit=8,tarLengthLimit=12;
	if(args.is_set("srcLengthLimit"))
		srcLengthLimit=atoi(args.value("srcLengthLimit").c_str());
	if(args.is_set("tarLengthLimit"))
		tarLengthLimit=atoi(args.value("tarLengthLimit").c_str());
	int maxNumOfUnAlignedWords=2;
	if(args.is_set("maxNumOfUnAlignedWords"))
		maxNumOfUnAlignedWords=atoi(args.value("maxNumOfUnAlignedWords").c_str());
	double start=1,stop=1E10;
	if(args.is_set("range"))
	{
		string range=args.value("range");
		start=atoi(range.substr(0,range.find("-")).c_str());
		stop=atof(range.substr(range.find("-")+1).c_str());
		cerr<<"start:"<<start<<",stop:"<<stop<<endl;
	}
	PhraseTable phraseTable;
	int count=0;
	while(!falign.eof())
	{
		string align="",src="",tar="";
		double weight=1;
		getline(falign,align);
		getline(fsrc,src);
		getline(ftar,tar);
		if(fweight.good())fweight>>weight;
		
		//Alignment alignment(align,maxNumOfUnAlignedWords);

		count++;
		if(count<start)continue;
		if(count>stop)break;
		if(weight==0||weight<threshold)continue;
		if(moore)weight=1;
		vector<PhraseRuleEntry> phrases;
		phraseExtractor(src,tar,align,s2tLexDic,t2sLexDic,phrases,srcLengthLimit,tarLengthLimit,maxNumOfUnAlignedWords,weight);
		for(size_t i=0;i<phrases.size();i++)
		{
			PhraseRuleEntry& pre=phrases[i];
			if(reverse)
			{
				string tmp=pre.srcPhrase;
				pre.srcPhrase=pre.tarPhrase;
				pre.tarPhrase=tmp;
			}
			if(os.good())phraseTable.add(pre.srcPhrase,pre.tarPhrase,pre);
		}
	}
	if(args.is_set("printTopEntrys"))
	{
		int topN=atoi(args.value("printTopEntrys").c_str());
		phraseTable.printTopEntrys(topN,"topEntrys.txt");
	}
	if(normalize)
		phraseTable.normalize();
	bool onlyonefeat=false;
	if(args.is_set("onlyonefeat"))
		onlyonefeat=true;
	if(os.good())phraseTable.print(os,onlyonefeat);
	string signal="mftsignal";
	if(args.is_set("signal"))signal=args.value("signal");
	ofstream o_sg(signal.c_str());
	o_sg.close();
}
开发者ID:hznlp,项目名称:pbmt,代码行数:94,代码来源:main-old.cpp


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