mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2025-01-05 02:22:21 +03:00
don't create xml options if we don't need it
This commit is contained in:
parent
66493f9718
commit
4fcc10a2c2
@ -15,7 +15,7 @@ using namespace std;
|
|||||||
|
|
||||||
namespace Moses2
|
namespace Moses2
|
||||||
{
|
{
|
||||||
std::ostream& operator<<(std::ostream &out, const XMLNode &obj)
|
std::ostream& operator<<(std::ostream &out, const XMLOption &obj)
|
||||||
{
|
{
|
||||||
out << "[" << obj.startPos << "," << obj.phraseSize << "]=" << obj.nodeName;
|
out << "[" << obj.startPos << "," << obj.phraseSize << "]=" << obj.nodeName;
|
||||||
return out;
|
return out;
|
||||||
@ -28,12 +28,13 @@ Sentence *Sentence::CreateFromString(MemPool &pool, FactorCollection &vocab,
|
|||||||
{
|
{
|
||||||
|
|
||||||
std::vector<std::string> toks;
|
std::vector<std::string> toks;
|
||||||
vector<XMLNode*> xmlNodes;
|
vector<XMLOption*> *xmlOptions;
|
||||||
|
|
||||||
Sentence *ret;
|
Sentence *ret;
|
||||||
|
|
||||||
if (system.options.input.xml_policy) {
|
if (system.options.input.xml_policy) {
|
||||||
// xml
|
// xml
|
||||||
|
xmlOptions = new vector<XMLOption*>();
|
||||||
pugi::xml_document doc;
|
pugi::xml_document doc;
|
||||||
|
|
||||||
string str2 = "<xml>" + str + "</xml>";
|
string str2 = "<xml>" + str + "</xml>";
|
||||||
@ -41,10 +42,10 @@ Sentence *Sentence::CreateFromString(MemPool &pool, FactorCollection &vocab,
|
|||||||
pugi::parse_default | pugi::parse_comments);
|
pugi::parse_default | pugi::parse_comments);
|
||||||
pugi::xml_node topNode = doc.child("xml");
|
pugi::xml_node topNode = doc.child("xml");
|
||||||
|
|
||||||
XMLParse(0, topNode, toks, xmlNodes);
|
XMLParse(0, topNode, toks, *xmlOptions);
|
||||||
|
|
||||||
for (size_t i = 0; i < xmlNodes.size(); ++i) {
|
for (size_t i = 0; i < xmlOptions->size(); ++i) {
|
||||||
cerr << *xmlNodes[i] << endl;
|
cerr << *(*xmlOptions)[i] << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -61,9 +62,10 @@ Sentence *Sentence::CreateFromString(MemPool &pool, FactorCollection &vocab,
|
|||||||
// xml
|
// xml
|
||||||
|
|
||||||
// clean up
|
// clean up
|
||||||
for (size_t i = 0; i < xmlNodes.size(); ++i) {
|
for (size_t i = 0; i < xmlOptions->size(); ++i) {
|
||||||
delete xmlNodes[i];
|
delete (*xmlOptions)[i];
|
||||||
}
|
}
|
||||||
|
delete xmlOptions;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +77,7 @@ void Sentence::XMLParse(
|
|||||||
size_t depth,
|
size_t depth,
|
||||||
const pugi::xml_node &parentNode,
|
const pugi::xml_node &parentNode,
|
||||||
std::vector<std::string> &toks,
|
std::vector<std::string> &toks,
|
||||||
vector<XMLNode*> &xmlNodes)
|
vector<XMLOption*> &xmlOptions)
|
||||||
{ // pugixml
|
{ // pugixml
|
||||||
for (pugi::xml_node childNode = parentNode.first_child(); childNode; childNode = childNode.next_sibling()) {
|
for (pugi::xml_node childNode = parentNode.first_child(); childNode; childNode = childNode.next_sibling()) {
|
||||||
string nodeName = childNode.name();
|
string nodeName = childNode.name();
|
||||||
@ -93,13 +95,13 @@ void Sentence::XMLParse(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!nodeName.empty()) {
|
if (!nodeName.empty()) {
|
||||||
XMLNode *xmlNode = new XMLNode();
|
XMLOption *xmlNode = new XMLOption();
|
||||||
xmlNode->nodeName = nodeName;
|
xmlNode->nodeName = nodeName;
|
||||||
xmlNode->startPos = startPos - 1;
|
xmlNode->startPos = startPos - 1;
|
||||||
xmlNodes.push_back(xmlNode);
|
xmlOptions.push_back(xmlNode);
|
||||||
|
|
||||||
// recursively call this function. For proper recursive trees
|
// recursively call this function. For proper recursive trees
|
||||||
XMLParse(depth + 1, childNode, toks, xmlNodes);
|
XMLParse(depth + 1, childNode, toks, xmlOptions);
|
||||||
|
|
||||||
size_t endPos = toks.size();
|
size_t endPos = toks.size();
|
||||||
xmlNode->phraseSize = endPos - startPos;
|
xmlNode->phraseSize = endPos - startPos;
|
||||||
|
@ -20,9 +20,9 @@ class FactorCollection;
|
|||||||
class System;
|
class System;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
class XMLNode
|
class XMLOption
|
||||||
{
|
{
|
||||||
friend std::ostream& operator<<(std::ostream &out, const XMLNode &obj);
|
friend std::ostream& operator<<(std::ostream &out, const XMLOption &obj);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::string nodeName;
|
std::string nodeName;
|
||||||
@ -49,7 +49,7 @@ protected:
|
|||||||
size_t depth,
|
size_t depth,
|
||||||
const pugi::xml_node &parentNode,
|
const pugi::xml_node &parentNode,
|
||||||
std::vector<std::string> &toks,
|
std::vector<std::string> &toks,
|
||||||
std::vector<XMLNode*> &xmlNodes);
|
std::vector<XMLOption*> &xmlOptions);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user