|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once |
|
|
|
#include <iostream> |
|
#include <queue> |
|
#include <map> |
|
#include <vector> |
|
#include "Word.h" |
|
#include "Range.h" |
|
#include "NonTerminal.h" |
|
#include "ChartHypothesis.h" |
|
#include "ChartHypothesisCollection.h" |
|
#include "RuleCube.h" |
|
#include "ChartCellLabelSet.h" |
|
|
|
#include <boost/scoped_ptr.hpp> |
|
#include <boost/functional/hash.hpp> |
|
#include <boost/unordered_map.hpp> |
|
#include <boost/version.hpp> |
|
|
|
namespace Moses |
|
{ |
|
class ChartSearchGraphWriter; |
|
class ChartTranslationOptionList; |
|
class ChartCellCollection; |
|
class ChartManager; |
|
|
|
class ChartCellBase |
|
{ |
|
public: |
|
ChartCellBase(size_t startPos, size_t endPos); |
|
|
|
virtual ~ChartCellBase(); |
|
|
|
const ChartCellLabelSet &GetTargetLabelSet() const { |
|
return m_targetLabelSet; |
|
} |
|
|
|
ChartCellLabelSet &MutableTargetLabelSet() { |
|
return m_targetLabelSet; |
|
} |
|
|
|
const Range &GetCoverage() const { |
|
return m_coverage; |
|
} |
|
|
|
protected: |
|
const Range m_coverage; |
|
ChartCellLabelSet m_targetLabelSet; |
|
}; |
|
|
|
|
|
|
|
|
|
class ChartCell : public ChartCellBase |
|
{ |
|
friend std::ostream& operator<<(std::ostream&, const ChartCell&); |
|
public: |
|
#if defined(BOOST_VERSION) && (BOOST_VERSION >= 104200) |
|
typedef boost::unordered_map<Word, |
|
ChartHypothesisCollection, |
|
NonTerminalHasher, |
|
NonTerminalEqualityPred |
|
> MapType; |
|
#else |
|
typedef std::map<Word, ChartHypothesisCollection> MapType; |
|
#endif |
|
|
|
protected: |
|
MapType m_hypoColl; |
|
|
|
bool m_nBestIsEnabled; |
|
ChartManager &m_manager; |
|
|
|
public: |
|
ChartCell(size_t startPos, size_t endPos, ChartManager &manager); |
|
~ChartCell(); |
|
|
|
void Decode(const ChartTranslationOptionList &transOptList |
|
,const ChartCellCollection &allChartCells); |
|
|
|
|
|
const HypoList *GetSortedHypotheses(const Word &constituentLabel) const { |
|
MapType::const_iterator p = m_hypoColl.find(constituentLabel); |
|
return (p == m_hypoColl.end()) ? NULL : &(p->second.GetSortedHypotheses()); |
|
} |
|
|
|
|
|
const HypoList *GetAllSortedHypotheses() const; |
|
|
|
bool AddHypothesis(ChartHypothesis *hypo); |
|
|
|
void SortHypotheses(); |
|
void PruneToSize(); |
|
|
|
const ChartHypothesis *GetBestHypothesis() const; |
|
|
|
void CleanupArcList(); |
|
|
|
void OutputSizes(std::ostream &out) const; |
|
size_t GetSize() const; |
|
|
|
void WriteSearchGraph(const ChartSearchGraphWriter& writer, const std::map<unsigned,bool> &reachable) const; |
|
|
|
}; |
|
|
|
} |
|
|
|
|