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
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <queue>
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
2011-03-11 16:08:43 +03:00
|
|
|
#include "Word.h"
|
2015-10-25 16:37:59 +03:00
|
|
|
#include "Range.h"
|
2011-03-11 16:08:43 +03:00
|
|
|
#include "NonTerminal.h"
|
2010-04-08 21:16:10 +04:00
|
|
|
#include "ChartHypothesis.h"
|
|
|
|
#include "ChartHypothesisCollection.h"
|
2011-03-11 19:28:36 +03:00
|
|
|
#include "RuleCube.h"
|
2011-06-29 17:38:11 +04:00
|
|
|
#include "ChartCellLabelSet.h"
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2012-10-02 17:30:55 +04:00
|
|
|
#include <boost/scoped_ptr.hpp>
|
2012-01-23 18:19:19 +04:00
|
|
|
#include <boost/functional/hash.hpp>
|
|
|
|
#include <boost/unordered_map.hpp>
|
|
|
|
#include <boost/version.hpp>
|
|
|
|
|
2010-09-23 20:32:44 +04:00
|
|
|
namespace Moses
|
|
|
|
{
|
2014-08-08 00:20:10 +04:00
|
|
|
class ChartSearchGraphWriter;
|
2011-02-24 15:36:50 +03:00
|
|
|
class ChartTranslationOptionList;
|
2010-04-08 21:16:10 +04:00
|
|
|
class ChartCellCollection;
|
2011-03-11 16:08:43 +03:00
|
|
|
class ChartManager;
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
class ChartCellBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ChartCellBase(size_t startPos, size_t endPos);
|
2012-10-02 17:30:55 +04:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
virtual ~ChartCellBase();
|
2012-10-02 19:34:25 +04:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
const ChartCellLabelSet &GetTargetLabelSet() const {
|
|
|
|
return m_targetLabelSet;
|
|
|
|
}
|
2012-10-02 19:34:25 +04:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
ChartCellLabelSet &MutableTargetLabelSet() {
|
|
|
|
return m_targetLabelSet;
|
|
|
|
}
|
2012-10-03 22:04:14 +04:00
|
|
|
|
2015-10-25 16:37:59 +03:00
|
|
|
const Range &GetCoverage() const {
|
2013-05-29 21:16:15 +04:00
|
|
|
return m_coverage;
|
|
|
|
}
|
2012-10-02 19:34:25 +04:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
protected:
|
2015-10-25 16:37:59 +03:00
|
|
|
const Range m_coverage;
|
2013-05-29 21:16:15 +04:00
|
|
|
ChartCellLabelSet m_targetLabelSet;
|
2012-10-02 17:30:55 +04:00
|
|
|
};
|
|
|
|
|
2012-06-27 03:45:02 +04:00
|
|
|
/** 1 cell in chart decoder.
|
2012-07-03 21:11:53 +04:00
|
|
|
* Doesn't directly hold hypotheses. Each cell contain a map of ChartHypothesisCollection that have different constituent labels
|
2012-06-27 03:45:02 +04:00
|
|
|
*/
|
2013-05-29 21:16:15 +04:00
|
|
|
class ChartCell : public ChartCellBase
|
|
|
|
{
|
2011-02-24 15:36:50 +03:00
|
|
|
friend std::ostream& operator<<(std::ostream&, const ChartCell&);
|
2010-04-08 21:16:10 +04:00
|
|
|
public:
|
2012-01-23 18:19:19 +04:00
|
|
|
#if defined(BOOST_VERSION) && (BOOST_VERSION >= 104200)
|
|
|
|
typedef boost::unordered_map<Word,
|
2013-05-29 21:16:15 +04:00
|
|
|
ChartHypothesisCollection,
|
|
|
|
NonTerminalHasher,
|
|
|
|
NonTerminalEqualityPred
|
|
|
|
> MapType;
|
2012-01-23 18:19:19 +04:00
|
|
|
#else
|
|
|
|
typedef std::map<Word, ChartHypothesisCollection> MapType;
|
|
|
|
#endif
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
protected:
|
2012-01-23 18:19:19 +04:00
|
|
|
MapType m_hypoColl;
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2011-02-24 15:36:50 +03:00
|
|
|
bool m_nBestIsEnabled; /**< flag to determine whether to keep track of old arcs */
|
2011-03-11 16:08:43 +03:00
|
|
|
ChartManager &m_manager;
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
public:
|
2011-03-11 16:08:43 +03:00
|
|
|
ChartCell(size_t startPos, size_t endPos, ChartManager &manager);
|
2011-06-29 17:38:11 +04:00
|
|
|
~ChartCell();
|
2011-02-24 15:36:50 +03:00
|
|
|
|
2014-12-26 10:41:52 +03:00
|
|
|
void Decode(const ChartTranslationOptionList &transOptList
|
2015-01-14 14:07:42 +03:00
|
|
|
,const ChartCellCollection &allChartCells);
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2012-07-03 21:11:53 +04:00
|
|
|
//! Get all hypotheses in the cell that have the specified constituent label
|
2013-05-29 21:16:15 +04:00
|
|
|
const HypoList *GetSortedHypotheses(const Word &constituentLabel) const {
|
2012-01-23 18:19:19 +04:00
|
|
|
MapType::const_iterator p = m_hypoColl.find(constituentLabel);
|
|
|
|
return (p == m_hypoColl.end()) ? NULL : &(p->second.GetSortedHypotheses());
|
|
|
|
}
|
|
|
|
|
2012-11-13 21:43:52 +04:00
|
|
|
//! for n-best list
|
|
|
|
const HypoList *GetAllSortedHypotheses() const;
|
|
|
|
|
2011-03-11 16:08:43 +03:00
|
|
|
bool AddHypothesis(ChartHypothesis *hypo);
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2011-02-24 15:36:50 +03:00
|
|
|
void SortHypotheses();
|
|
|
|
void PruneToSize();
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2011-03-11 16:08:43 +03:00
|
|
|
const ChartHypothesis *GetBestHypothesis() const;
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2011-02-24 15:36:50 +03:00
|
|
|
void CleanupArcList();
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2011-02-24 15:36:50 +03:00
|
|
|
void OutputSizes(std::ostream &out) const;
|
|
|
|
size_t GetSize() const;
|
2010-04-08 21:16:10 +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
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|