Merge branch 'master' of github.com:moses-smt/mosesdecoder

This commit is contained in:
Barry Haddow 2013-05-03 10:15:55 +01:00
commit 652d0f0a94
3 changed files with 36 additions and 33 deletions

View File

@ -42,23 +42,33 @@ void HoleCollection::SortSourceHoles()
void HoleCollection::Add(int startT, int endT, int startS, int endS)
{
Hole hole(startS, endS, startT, endT);
m_scope = Scope(hole);
m_sourceHoleStartPoints.insert(startS);
m_sourceHoleEndPoints.insert(endS);
m_scope.push_back(Scope(hole));
m_sourceHoleStartPoints.push_back(startS);
m_sourceHoleEndPoints.push_back(endS);
m_holes.push_back(hole);
m_sortedSourceHoles.clear();
}
void HoleCollection::RemoveLast()
{
m_scope.pop_back();
m_sourceHoleStartPoints.pop_back();
m_sourceHoleEndPoints.pop_back();
m_holes.pop_back();
m_sortedSourceHoles.clear();
}
int HoleCollection::Scope(const Hole &proposedHole) const
{
const int holeStart = proposedHole.GetStart(0);
const int holeEnd = proposedHole.GetEnd(0);
int scope = m_scope;
if (holeStart == m_sourcePhraseStart ||
m_sourceHoleEndPoints.find(holeStart-1) != m_sourceHoleEndPoints.end()) {
int scope = m_scope[-1];
if (holeStart == m_sourcePhraseStart[-1] ||
find(m_sourceHoleEndPoints.begin(), m_sourceHoleEndPoints.end(), holeStart-1) != m_sourceHoleEndPoints.end()) {
++scope; // Adding hole would introduce choice point at start of hole.
}
if (holeEnd == m_sourcePhraseEnd ||
m_sourceHoleStartPoints.find(holeEnd+1) != m_sourceHoleStartPoints.end()) {
if (holeEnd == m_sourcePhraseEnd[-1] ||
find(m_sourceHoleStartPoints.begin(), m_sourceHoleStartPoints.end(), holeEnd-1) != m_sourceHoleStartPoints.end()) {
++scope; // Adding hole would introduce choice point at end of hole.
}
return scope;

View File

@ -34,28 +34,19 @@ class HoleCollection
protected:
HoleList m_holes;
std::vector<Hole*> m_sortedSourceHoles;
std::set<int> m_sourceHoleStartPoints;
std::set<int> m_sourceHoleEndPoints;
int m_scope;
int m_sourcePhraseStart;
int m_sourcePhraseEnd;
std::vector<int> m_sourceHoleStartPoints;
std::vector<int> m_sourceHoleEndPoints;
std::vector<int> m_scope;
std::vector<int> m_sourcePhraseStart;
std::vector<int> m_sourcePhraseEnd;
public:
HoleCollection(int sourcePhraseStart, int sourcePhraseEnd)
: m_scope(0)
, m_sourcePhraseStart(sourcePhraseStart)
, m_sourcePhraseEnd(sourcePhraseEnd)
: m_scope(1, 0)
, m_sourcePhraseStart(1, sourcePhraseStart)
, m_sourcePhraseEnd(1, sourcePhraseEnd)
{}
HoleCollection(const HoleCollection &copy)
: m_holes(copy.m_holes)
, m_sourceHoleStartPoints(copy.m_sourceHoleStartPoints)
, m_sourceHoleEndPoints(copy.m_sourceHoleEndPoints)
, m_scope(copy.m_scope)
, m_sourcePhraseStart(copy.m_sourcePhraseStart)
, m_sourcePhraseEnd(copy.m_sourcePhraseEnd)
{} // don't copy sorted target holes. messes up sorting fn
const HoleList &GetHoles() const {
return m_holes;
}
@ -70,6 +61,8 @@ public:
void Add(int startT, int endT, int startS, int endS);
void RemoveLast();
bool OverlapSource(const Hole &sourceHole) const {
HoleList::const_iterator iter;
for (iter = m_holes.begin(); iter != m_holes.end(); ++iter) {

View File

@ -74,7 +74,7 @@ private:
// subs
void addRule( int, int, int, int, int, RuleExist &ruleExist);
void addHieroRule( int startT, int endT, int startS, int endS
, RuleExist &ruleExist, const HoleCollection &holeColl, int numHoles, int initStartF, int wordCountT, int wordCountS);
, RuleExist &ruleExist, HoleCollection &holeColl, int numHoles, int initStartF, int wordCountT, int wordCountS);
void saveHieroPhrase( int startT, int endT, int startS, int endS
, HoleCollection &holeColl, LabelIndex &labelIndex, int countS);
string saveTargetHieroPhrase( int startT, int endT, int startS, int endS
@ -754,7 +754,7 @@ void ExtractTask::saveAllHieroPhrases( int startT, int endT, int startS, int end
// this function is called recursively
// it pokes a new hole into the phrase pair, and then calls itself for more holes
void ExtractTask::addHieroRule( int startT, int endT, int startS, int endS
, RuleExist &ruleExist, const HoleCollection &holeColl
, RuleExist &ruleExist, HoleCollection &holeColl
, int numHoles, int initStartT, int wordCountT, int wordCountS)
{
// done, if already the maximum number of non-terminals in phrase pair
@ -850,9 +850,7 @@ void ExtractTask::addHieroRule( int startT, int endT, int startS, int endS
}
// update list of holes in this phrase pair
HoleCollection copyHoleColl(holeColl);
copyHoleColl.Add(startHoleT, endHoleT, sourceHole.GetStart(0), sourceHole.GetEnd(0));
holeColl.Add(startHoleT, endHoleT, sourceHole.GetStart(0), sourceHole.GetEnd(0));
// now some checks that disallow this phrase pair, but not further recursion
bool allowablePhrase = true;
@ -864,14 +862,16 @@ void ExtractTask::addHieroRule( int startT, int endT, int startS, int endS
allowablePhrase = false;
// passed all checks...
if (allowablePhrase)
saveAllHieroPhrases(startT, endT, startS, endS, copyHoleColl, wordCountS);
if (allowablePhrase)
saveAllHieroPhrases(startT, endT, startS, endS, holeColl, wordCountS);
// recursively search for next hole
int nextInitStartT = m_options.nonTermConsecTarget ? endHoleT + 1 : endHoleT + 2;
addHieroRule(startT, endT, startS, endS
, ruleExist, copyHoleColl, numHoles + 1, nextInitStartT
, ruleExist, holeColl, numHoles + 1, nextInitStartT
, newWordCountT, newWordCountS);
holeColl.RemoveLast();
}
}
}