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


C++ Traversal::createTreeWalker方法代码示例

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


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

示例1: annotateSentence

void NistXmlDocument::annotateSentence(uint sentno, const std::string &annot) {
	typedef Arabica::DOM::Traversal::DocumentTraversal<std::string> Traversal;
	typedef Arabica::DOM::Comment<std::string> Comment;

	Traversal dt = outnode_.getOwnerDocument().createDocumentTraversal();
	SegNodeFilter filter;
	Traversal::TreeWalkerT it = dt.createTreeWalker(outnode_,
					static_cast<unsigned long>(Arabica::DOM::Traversal::SHOW_TEXT),
					filter, true);

	for(uint i = 0; i < sentno; i++)
		assert(it.nextNode() != 0);

	Traversal::NodeT n = it.nextNode(); // the filter finds the next node inside the <seg> element
	assert(n != 0);
	n = n.getParentNode(); // get the <seg>

	Comment comm = n.getOwnerDocument().createComment(" SEG " + annot + " ");

	Traversal::NodeT p = n.getPreviousSibling();
	Traversal::NodeT txt;
	if(p != 0 && p.getNodeType() == Arabica::DOM::Node<std::string>::TEXT_NODE) {
		txt = p;
		p = p.getPreviousSibling();
	}

	if(p != 0 && p.getNodeType() == Arabica::DOM::Node<std::string>::COMMENT_NODE &&
			boost::starts_with(p.getNodeValue(), " SEG "))
		p.getParentNode().replaceChild(comm, p);
	else {
		n.getParentNode().insertBefore(comm, n);
		if(txt != 0)
			n.getParentNode().insertBefore(txt.cloneNode(false), n);
	}
}
开发者ID:mtfelix,项目名称:docent,代码行数:35,代码来源:NistXmlTestset.cpp

示例2: setTranslation

void NistXmlDocument::setTranslation(const PlainTextDocument &doc) {
	typedef Arabica::DOM::Traversal::DocumentTraversal<std::string> Traversal;

	Traversal dt = outnode_.getOwnerDocument().createDocumentTraversal();
	SegNodeFilter filter;
	Traversal::TreeWalkerT it = dt.createTreeWalker(outnode_,
					static_cast<unsigned long>(Arabica::DOM::Traversal::SHOW_TEXT),
					filter, true);

	uint i = 0;
	for(;;) {
		Traversal::NodeT n = it.nextNode();
		if(n == 0)
			break;
		std::ostringstream os;
		std::copy(doc.sentence_begin(i), doc.sentence_end(i), std::ostream_iterator<Word>(os, " "));
		i++;
		std::string str = os.str();
		str.erase(str.end() - 1);
		n.setNodeValue(str);
	}
}
开发者ID:mtfelix,项目名称:docent,代码行数:22,代码来源:NistXmlTestset.cpp

示例3: asPlainTextDocument

PlainTextDocument NistXmlDocument::asPlainTextDocument() const {
	std::vector<std::vector<Word> > txt;

	typedef Arabica::DOM::Traversal::DocumentTraversal<std::string> Traversal;

	Traversal dt = topnode_.getOwnerDocument().createDocumentTraversal();
	SegNodeFilter filter;
	Traversal::TreeWalkerT it = dt.createTreeWalker(topnode_,
					static_cast<unsigned long>(Arabica::DOM::Traversal::SHOW_TEXT),
					filter, true);

	for(;;) {
		Traversal::NodeT n = it.nextNode();
		if(n == 0)
			break;
		std::string seg = n.getNodeValue();
		boost::trim(seg);
		txt.push_back(std::vector<Word>());
		boost::split(txt.back(), seg, boost::is_any_of(" "));
	}

	return PlainTextDocument(txt);
}
开发者ID:mtfelix,项目名称:docent,代码行数:23,代码来源:NistXmlTestset.cpp

示例4:

boost::shared_ptr<const MMAXDocument> NistXmlDocument::asMMAXDocument() const {
	typedef Arabica::DOM::Traversal::DocumentTraversal<std::string> Traversal;

	Traversal dt = topnode_.getOwnerDocument().createDocumentTraversal();
	SegNodeFilter filter;
	Traversal::TreeWalkerT it = dt.createTreeWalker(topnode_,
					static_cast<unsigned long>(Arabica::DOM::Traversal::SHOW_TEXT),
					filter, true);

	boost::shared_ptr<MMAXDocument> mmax = boost::make_shared<MMAXDocument>();
	for(;;) {
		Traversal::NodeT n = it.nextNode();
		if(n == 0)
			break;
		std::string seg = n.getNodeValue();
		boost::trim(seg);
		std::vector<Word> snt;
		boost::split(snt, seg, boost::is_any_of(" "));
		mmax->addSentence(snt.begin(), snt.end());
	}

	return mmax;
}
开发者ID:mtfelix,项目名称:docent,代码行数:23,代码来源:NistXmlTestset.cpp


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