diff options
author | Michael Denkowski <mdenkows@amazon.com> | 2016-08-08 17:33:24 +0300 |
---|---|---|
committer | Michael Denkowski <mdenkows@amazon.com> | 2016-08-12 13:05:12 +0300 |
commit | ae1e51d81ad450f7ee497386eea16ebe3792f68b (patch) | |
tree | baa538edd1b5b92bb7e08e3ece5a1face44483d5 /moses/XmlOption.cpp | |
parent | d29916bbb3973b18acd80b1ef19841399f7247b0 (diff) |
Support storing coordinates of target phrase
- Keep track of named spaces in StaticData
- Adding coords to phrases implemented for Mmsapt
Diffstat (limited to 'moses/XmlOption.cpp')
-rw-r--r-- | moses/XmlOption.cpp | 34 |
1 files changed, 11 insertions, 23 deletions
diff --git a/moses/XmlOption.cpp b/moses/XmlOption.cpp index 3e367aa9e..b7969ae51 100644 --- a/moses/XmlOption.cpp +++ b/moses/XmlOption.cpp @@ -405,33 +405,21 @@ ProcessAndStripXMLTags(AllOptions const& opts, string &line, // Coord: coordinates of the input sentence in a user-defined space // <coord space="NAME" coord="X Y Z ..." /> // where NAME is the name of the space and X Y Z ... are floats. See - // PScoreDist in PhraseDictionaryBitextSampling (Mmsapt) for an example - // of using this information for feature scoring. + // TODO for an example of using this information for feature scoring. else if (tagName == "coord") { // Parse tag string space = ParseXmlTagAttribute(tagContent, "space"); - vector<string> toks = Tokenize(ParseXmlTagAttribute(tagContent, "coord")); - boost::shared_ptr<vector<float> > coord(new vector<float>); - Scan<float>(*coord, toks); - // Init if needed - if (!input.m_pd2InputCoord) { - input.m_pd2InputCoord.reset(new std::map<PhraseDictionary const*, std::vector<boost::shared_ptr<std::vector<float> > > >); - } - // Scan phrase dictionaries to see which (if any) use this space - BOOST_FOREACH(PhraseDictionary const* pd, PhraseDictionary::GetColl()) { - const vector<string>& pdKnownSpaces = pd->GetKnownSpaces(); - for (size_t i = 0; i < pdKnownSpaces.size(); ++i) { - // Match - if (pdKnownSpaces[i] == space) { - // Make sure a slot to store the coordinates exists - std::vector<boost::shared_ptr<std::vector<float> > >& inputCoord = (*input.m_pd2InputCoord)[pd]; - if (inputCoord.size() < i + 1) { - inputCoord.resize(i + 1); - } - // Store - inputCoord[i] = coord; - } + vector<string> tok = Tokenize(ParseXmlTagAttribute(tagContent, "coord")); + size_t id = StaticData::Instance().GetCoordSpace(space); + if (!id) { + TRACE_ERR("ERROR: no models use space " << space << ", will be ignored" << endl); + } else { + // Init if needed + if (!input.m_coordMap) { + input.m_coordMap.reset(new std::map<size_t const, std::vector<float> >); } + vector<float>& coord = (*input.m_coordMap)[id]; + Scan<float>(coord, tok); } } |