void sort(const DOM::Node<std::string>& node, Arabica::XPath::NodeSet<std::string>& nodes, ExecutionContext& context) const { if(!sort_) { if(!nodes.forward()) nodes.to_document_order(); return; } sort_->set_context(node, context); std::stable_sort(nodes.begin(), nodes.end(), SortP(*sort_)); } // sort
Arabica::XPath::NodeSet<std::string> nodeSetUnion(const std::string& keyClarkName, const Arabica::XPath::NodeSet<std::string> nodes, const Arabica::XPath::ExecutionContext<std::string>& executionContext) const { Arabica::XPath::NodeSet<std::string> results; for(Arabica::XPath::NodeSet<std::string>::const_iterator n = nodes.begin(), ne = nodes.end(); n != ne; ++n) { std::string id = Arabica::XPath::impl::nodeStringValue<std::string, Arabica::default_string_adaptor<std::string> >(*n); results.push_back(keys_.lookup(keyClarkName, id, executionContext)); } // for ... results.to_document_order(); return results; } // nodeSetUnion
NistXmlTestset::NistXmlTestset(const std::string &file) : logger_(logkw::channel = "NistXmlTestset") { Arabica::SAX2DOM::Parser<std::string> domParser; Arabica::SAX::InputSource<std::string> is(file); Arabica::SAX::CatchErrorHandler<std::string> errh; domParser.setErrorHandler(errh); domParser.parse(is); if(errh.errorsReported()) BOOST_LOG_SEV(logger_, error) << errh.errors(); Arabica::DOM::Document<std::string> doc = domParser.getDocument(); if(doc == 0) { BOOST_LOG_SEV(logger_, error) << "Error parsing input file: " << file; exit(1); } doc.getDocumentElement().normalize(); Arabica::XPath::XPath<std::string> xp; Arabica::XPath::NodeSet<std::string> docnodes = xp.compile("/mteval/srcset/doc").evaluateAsNodeSet(doc.getDocumentElement()); docnodes.to_document_order(); BOOST_FOREACH(Arabica::DOM::Node<std::string> n, docnodes) documents_.push_back(boost::make_shared<NistXmlDocument>(n)); outdoc_ = static_cast<Arabica::DOM::Document<std::string> >(doc.cloneNode(true)); Arabica::DOM::Element<std::string> srcset = static_cast<Arabica::DOM::Element<std::string> >( xp.compile("/mteval/srcset").evaluateAsNodeSet(outdoc_.getDocumentElement())[0]); Arabica::DOM::Element<std::string> tstset = outdoc_.createElement("tstset"); int docno = 0; while(srcset.hasChildNodes()) { Arabica::DOM::Node<std::string> n = srcset.removeChild(srcset.getFirstChild()); tstset.appendChild(n); if(n.getNodeType() == Arabica::DOM::Node<std::string>::ELEMENT_NODE && n.getNodeName() == "doc") documents_[docno++]->setOutputNode(n); } tstset.setAttribute("setid", srcset.getAttribute("setid")); tstset.setAttribute("srclang", srcset.getAttribute("srclang")); tstset.setAttribute("trglang", "TRGLANG"); tstset.setAttribute("sysid", "SYSID"); srcset.getParentNode().replaceChild(tstset, srcset); }