本文整理汇总了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);
}
}
示例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);
}
}
示例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);
}
示例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;
}