// Converts a SyntaxNode tree to a Moses::GHKM::ParseTree. std::auto_ptr<ParseTree> XmlTreeParser::ConvertTree( const SyntaxNode &tree, const std::vector<std::string> &words) { std::auto_ptr<ParseTree> root(new ParseTree(tree.GetLabel())); const std::vector<SyntaxNode*> &children = tree.GetChildren(); if (children.empty()) { if (tree.GetStart() != tree.GetEnd()) { std::ostringstream msg; msg << "leaf node covers multiple words (" << tree.GetStart() << "-" << tree.GetEnd() << "): this is currently unsupported"; throw Exception(msg.str()); } std::auto_ptr<ParseTree> leaf(new ParseTree(words[tree.GetStart()])); leaf->SetParent(root.get()); root->AddChild(leaf.release()); } else { for (std::vector<SyntaxNode*>::const_iterator p = children.begin(); p != children.end(); ++p) { assert(*p); std::auto_ptr<ParseTree> child = ConvertTree(**p, words); child->SetParent(root.get()); root->AddChild(child.release()); } } return root; }