2014-03-21 14:53:15 +04:00
|
|
|
/***********************************************************************
|
|
|
|
Moses - factored phrase-based language decoder
|
|
|
|
Copyright (C) 2014 University of Edinburgh
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
***********************************************************************/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#ifndef moses_CompletedRuleCollectionS_h
|
|
|
|
#define moses_CompletedRuleCollectionS_h
|
|
|
|
|
|
|
|
#include <vector>
|
2014-09-01 21:07:30 +04:00
|
|
|
#include <numeric>
|
2014-03-21 14:53:15 +04:00
|
|
|
|
|
|
|
#include "moses/StackVec.h"
|
|
|
|
#include "moses/TargetPhraseCollection.h"
|
|
|
|
#include "moses/ChartTranslationOptions.h"
|
|
|
|
#include "moses/ChartCellLabel.h"
|
|
|
|
#include "moses/ChartParserCallback.h"
|
|
|
|
|
|
|
|
namespace Moses
|
|
|
|
{
|
|
|
|
|
|
|
|
// temporary storage for a completed rule (because we use lookahead to find rules before ChartManager wants us to)
|
2014-05-19 17:35:45 +04:00
|
|
|
struct CompletedRule {
|
2014-03-21 14:53:15 +04:00
|
|
|
public:
|
|
|
|
|
|
|
|
CompletedRule(const TargetPhraseCollection &tpc,
|
2014-05-19 17:35:45 +04:00
|
|
|
const StackVec &stackVec,
|
|
|
|
const float score)
|
|
|
|
: m_stackVec(stackVec)
|
|
|
|
, m_tpc(tpc)
|
|
|
|
, m_score(score) {}
|
2014-03-21 14:53:15 +04:00
|
|
|
|
|
|
|
const TargetPhraseCollection & GetTPC() const {
|
|
|
|
return m_tpc;
|
|
|
|
}
|
|
|
|
|
|
|
|
const StackVec & GetStackVector() const {
|
|
|
|
return m_stackVec;
|
|
|
|
}
|
|
|
|
|
|
|
|
const float GetScoreEstimate() const {
|
|
|
|
return m_score;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const StackVec m_stackVec;
|
|
|
|
const TargetPhraseCollection &m_tpc;
|
|
|
|
const float m_score;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class CompletedRuleOrdered
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool operator()(const CompletedRule* itemA, const CompletedRule* itemB) const {
|
|
|
|
return itemA->GetScoreEstimate() > itemB->GetScoreEstimate();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-05-19 17:35:45 +04:00
|
|
|
struct CompletedRuleCollection {
|
2014-03-21 14:53:15 +04:00
|
|
|
public:
|
|
|
|
|
|
|
|
CompletedRuleCollection();
|
2015-01-07 21:42:20 +03:00
|
|
|
~CompletedRuleCollection();
|
2014-03-21 14:53:15 +04:00
|
|
|
|
|
|
|
CompletedRuleCollection(const CompletedRuleCollection &old)
|
2014-05-19 17:35:45 +04:00
|
|
|
: m_collection(old.m_collection)
|
|
|
|
, m_scoreThreshold(old.m_scoreThreshold)
|
|
|
|
, m_ruleLimit(old.m_ruleLimit) {}
|
2014-03-21 14:53:15 +04:00
|
|
|
|
|
|
|
CompletedRuleCollection & operator=(const CompletedRuleCollection &old) {
|
|
|
|
|
2014-05-19 17:35:45 +04:00
|
|
|
m_collection = old.m_collection;
|
|
|
|
m_scoreThreshold = old.m_scoreThreshold;
|
|
|
|
m_ruleLimit = old.m_ruleLimit;
|
|
|
|
return *this;
|
2014-03-21 14:53:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<CompletedRule*>::const_iterator begin() const {
|
|
|
|
return m_collection.begin();
|
|
|
|
}
|
|
|
|
std::vector<CompletedRule*>::const_iterator end() const {
|
|
|
|
return m_collection.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Clear() {
|
|
|
|
RemoveAllInColl(m_collection);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Add(const TargetPhraseCollection &tpc,
|
|
|
|
const StackVec &stackVec,
|
|
|
|
const ChartParserCallback &outColl);
|
|
|
|
|
2014-09-01 21:07:30 +04:00
|
|
|
void Add(const TargetPhraseCollection &tpc,
|
|
|
|
const StackVec &stackVec,
|
|
|
|
const std::vector<float> &stackScores,
|
|
|
|
const ChartParserCallback &outColl);
|
|
|
|
|
2014-03-21 14:53:15 +04:00
|
|
|
private:
|
|
|
|
std::vector<CompletedRule*> m_collection;
|
|
|
|
float m_scoreThreshold;
|
|
|
|
size_t m_ruleLimit;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Moses
|
|
|
|
|
|
|
|
#endif
|