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


C++ SyntaxTree::GetNumWords方法代码示例

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


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

示例1: SAMT

void SAMT( SyntaxTree &tree, ParentNodes &parents )
{
	int numWords = tree.GetNumWords();

	SyntaxTree newTree; // to store new nodes

	// look through parents to combine children
	for(ParentNodes::const_iterator p = parents.begin(); p != parents.end(); p++)
	{
		const SplitPoints &point = *p;
		
		// neighboring childen: DET+ADJ
		if (point.size() >= 3) {
			// cerr << "complex parent: ";
			// for(int i=0;i<point.size();i++) cerr << point[i] << " ";
			// cerr << endl;

			for(int i = 0; i+2 < point.size(); i++)
			{
				// cerr << "\tadding " << point[i] << ";" << point[i+1] << ";" << (point[i+2]-1) << ": " << tree.GetNodes(point[i  ],point[i+1]-1)[0]->GetLabel() << "+" << tree.GetNodes(point[i+1],point[i+2]-1)[0]->GetLabel() << endl;
				
				newTree.AddNode( point[i],point[i+2]-1,
												 tree.GetNodes(point[i  ],point[i+1]-1)[0]->GetLabel() 
												 + "+" + 
												 tree.GetNodes(point[i+1],point[i+2]-1)[0]->GetLabel() );
			} 
		}
		if (point.size() >= 4) {
			int ps = point.size();
			string topLabel = tree.GetNodes(point[0],point[ps-1]-1)[0]->GetLabel();

			// cerr << "\tadding " << topLabel + "\\" + tree.GetNodes(point[0],point[1]-1)[0]->GetLabel() << endl;
			newTree.AddNode( point[1],point[ps-1]-1,
											 topLabel 
											 + "\\" +
											 tree.GetNodes(point[0],point[1]-1)[0]->GetLabel() );

			// cerr << "\tadding " << topLabel + "/" + tree.GetNodes(point[ps-2],point[ps-1]-1)[0]->GetLabel() << endl;
			newTree.AddNode( point[0],point[ps-2]-1,
											 topLabel 
											 + "/" +
											 tree.GetNodes(point[ps-2],point[ps-1]-1)[0]->GetLabel() );
		}
	}

	// rules for any bordering constituents...
	for(int size = 2; size < numWords; size++)
	{
		for(int start = 0; start < numWords-size+1; start++)
		{
			int end = start+size-1;
			bool done = false;

			if (tree.HasNode( start,end ) || newTree.HasNode( start,end )
					|| SAMTLevel <= 1)
			{
				continue;
			}

			// if matching two adjacent parse constituents: use ++
	
			for(int mid=start+1; mid<=end && !done; mid++)
			{
				if (tree.HasNode(start,mid-1) && tree.HasNode(mid,end)) {
					// cerr << "\tadding " << tree.GetNodes(start,mid-1)[0]->GetLabel() << "++" << tree.GetNodes(mid,  end  )[0]->GetLabel() << endl;

					newTree.AddNode( start, end, 
													 tree.GetNodes(start,mid-1)[0]->GetLabel() 
													 + "++" + 
													 tree.GetNodes(mid,  end  )[0]->GetLabel() );
					done = true;
				}
			}
			if (done) continue;

			// if matching a constituent A right-minus const. B: use A//B
			for(int postEnd=end+1; postEnd<numWords && !done; postEnd++)
			{
				if (tree.HasNode(start,postEnd) && tree.HasNode(end+1,postEnd))
				{
					newTree.AddNode( start, end, 
													 tree.GetNodes(start,postEnd)[0]->GetLabel() 
													 + "//" + 
													 tree.GetNodes(end+1,postEnd)[0]->GetLabel() );
					done = true;
				}
			}
			if (done) continue;

			// if matching a constituent A left-minus constituent B: use A\\B
			for(int preStart=start-1; preStart>=0; preStart--)
			{
				if (tree.HasNode(preStart,end) && tree.HasNode(preStart,start-1))
				{
					// cerr << "\tadding " << tree.GetNodes(preStart,end    )[0]->GetLabel() << "\\\\" <<tree.GetNodes(preStart,start-1)[0]->GetLabel() << endl;
					newTree.AddNode( start, end, 
													 tree.GetNodes(preStart,end    )[0]->GetLabel() 
													 + "\\\\" + 
													 tree.GetNodes(preStart,start-1)[0]->GetLabel() );
					done = true;
//.........这里部分代码省略.........
开发者ID:obo,项目名称:Moses-Extensions-at-UFAL,代码行数:101,代码来源:relax-parse.cpp


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