2010-07-18 03:23:09 +04:00
|
|
|
// $Id$
|
2010-04-12 14:15:49 +04:00
|
|
|
// vim:tabstop=2
|
|
|
|
/***********************************************************************
|
|
|
|
Moses - factored phrase-based language decoder
|
|
|
|
Copyright (C) 2010 Hieu Hoang
|
2011-02-24 15:36:50 +03:00
|
|
|
|
2010-04-12 14:15:49 +04:00
|
|
|
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.
|
2011-02-24 15:36:50 +03:00
|
|
|
|
2010-04-12 14:15:49 +04:00
|
|
|
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.
|
2011-02-24 15:36:50 +03:00
|
|
|
|
2010-04-12 14:15:49 +04:00
|
|
|
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
|
|
|
|
***********************************************************************/
|
2010-04-08 21:16:10 +04:00
|
|
|
#pragma once
|
2010-04-12 14:15:49 +04:00
|
|
|
|
2010-04-08 21:16:10 +04:00
|
|
|
#include <set>
|
|
|
|
#include "ChartHypothesis.h"
|
2011-03-11 19:28:36 +03:00
|
|
|
#include "RuleCube.h"
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
|
2011-03-11 16:08:43 +03:00
|
|
|
namespace Moses
|
2010-04-08 21:16:10 +04:00
|
|
|
{
|
2011-02-24 15:36:50 +03:00
|
|
|
|
2014-08-08 00:20:10 +04:00
|
|
|
class ChartSearchGraphWriter;
|
2015-11-02 03:00:37 +03:00
|
|
|
class AllOptions;
|
2014-08-08 00:20:10 +04:00
|
|
|
|
2012-06-27 03:45:02 +04:00
|
|
|
//! functor to compare (chart) hypotheses by (descending) score
|
2010-04-08 21:16:10 +04:00
|
|
|
class ChartHypothesisScoreOrderer
|
2011-02-24 15:36:50 +03:00
|
|
|
{
|
|
|
|
public:
|
2011-03-11 16:08:43 +03:00
|
|
|
bool operator()(const ChartHypothesis* hypoA, const ChartHypothesis* hypoB) const {
|
2015-11-09 15:44:39 +03:00
|
|
|
return hypoA->GetFutureScore() > hypoB->GetFutureScore();
|
2011-02-24 15:36:50 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-06-27 03:45:02 +04:00
|
|
|
/** Contains a set of unique hypos that have the same HS non-term.
|
|
|
|
* ie. 1 of these for each target LHS in each cell
|
|
|
|
*/
|
2011-03-11 16:08:43 +03:00
|
|
|
class ChartHypothesisCollection
|
2010-04-08 21:16:10 +04:00
|
|
|
{
|
2011-03-11 16:08:43 +03:00
|
|
|
friend std::ostream& operator<<(std::ostream&, const ChartHypothesisCollection&);
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
protected:
|
2015-10-14 12:37:51 +03:00
|
|
|
//typedef std::set<ChartHypothesis*, ChartHypothesisRecombinationOrderer> HCType;
|
2015-10-18 03:02:38 +03:00
|
|
|
typedef boost::unordered_set< ChartHypothesis*, UnorderedComparer<ChartHypothesis>, UnorderedComparer<ChartHypothesis> > HCType;
|
2011-02-24 15:36:50 +03:00
|
|
|
HCType m_hypos;
|
|
|
|
HypoList m_hyposOrdered;
|
|
|
|
|
|
|
|
float m_bestScore; /**< score of the best hypothesis in collection */
|
|
|
|
float m_beamWidth; /**< minimum score due to threashold pruning */
|
|
|
|
size_t m_maxHypoStackSize; /**< maximum number of hypothesis allowed in this stack */
|
|
|
|
bool m_nBestIsEnabled; /**< flag to determine whether to keep track of old arcs */
|
|
|
|
|
2011-03-11 16:08:43 +03:00
|
|
|
std::pair<HCType::iterator, bool> Add(ChartHypothesis *hypo, ChartManager &manager);
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
public:
|
2011-02-24 15:36:50 +03:00
|
|
|
typedef HCType::iterator iterator;
|
|
|
|
typedef HCType::const_iterator const_iterator;
|
|
|
|
//! iterators
|
|
|
|
const_iterator begin() const {
|
|
|
|
return m_hypos.begin();
|
|
|
|
}
|
|
|
|
const_iterator end() const {
|
|
|
|
return m_hypos.end();
|
|
|
|
}
|
|
|
|
|
2015-10-31 15:50:52 +03:00
|
|
|
ChartHypothesisCollection(AllOptions const& opts);
|
2011-03-11 16:08:43 +03:00
|
|
|
~ChartHypothesisCollection();
|
|
|
|
bool AddHypothesis(ChartHypothesis *hypo, ChartManager &manager);
|
2011-02-24 15:36:50 +03:00
|
|
|
|
|
|
|
void Detach(const HCType::iterator &iter);
|
|
|
|
void Remove(const HCType::iterator &iter);
|
|
|
|
|
2011-03-11 16:08:43 +03:00
|
|
|
void PruneToSize(ChartManager &manager);
|
2011-02-24 15:36:50 +03:00
|
|
|
|
|
|
|
size_t GetSize() const {
|
|
|
|
return m_hypos.size();
|
|
|
|
}
|
|
|
|
size_t GetHypo() const {
|
|
|
|
return m_hypos.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SortHypotheses();
|
|
|
|
void CleanupArcList();
|
|
|
|
|
2012-07-02 23:01:07 +04:00
|
|
|
//! return vector of hypothesis that has been sorted by score
|
2011-02-24 15:36:50 +03:00
|
|
|
const HypoList &GetSortedHypotheses() const {
|
|
|
|
return m_hyposOrdered;
|
|
|
|
}
|
|
|
|
|
2012-07-02 23:01:07 +04:00
|
|
|
//! return the best total score of all hypos in this collection
|
2013-05-29 21:16:15 +04:00
|
|
|
float GetBestScore() const {
|
|
|
|
return m_bestScore;
|
|
|
|
}
|
2011-07-19 16:57:02 +04:00
|
|
|
|
2014-08-08 00:20:10 +04:00
|
|
|
void WriteSearchGraph(const ChartSearchGraphWriter& writer, const std::map<unsigned,bool> &reachable) const;
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|