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 <vector>
|
|
|
|
#include <map>
|
|
|
|
#include <queue>
|
|
|
|
#include <set>
|
|
|
|
#include <iostream>
|
2011-03-11 16:08:43 +03:00
|
|
|
#include "WordsRange.h"
|
|
|
|
#include "Word.h"
|
2010-04-08 21:16:10 +04:00
|
|
|
#include "ChartHypothesis.h"
|
|
|
|
|
|
|
|
namespace Moses
|
|
|
|
{
|
2011-02-24 15:36:50 +03:00
|
|
|
class WordConsumed;
|
|
|
|
class ChartTranslationOption;
|
|
|
|
extern bool g_debug;
|
2010-04-08 21:16:10 +04:00
|
|
|
class TranslationOptionCollection;
|
|
|
|
class TranslationOptionList;
|
|
|
|
class ChartCell;
|
|
|
|
class ChartCellCollection;
|
|
|
|
class QueueEntry;
|
|
|
|
class Cube;
|
|
|
|
|
2011-03-11 16:08:43 +03:00
|
|
|
typedef std::vector<const ChartHypothesis*> HypoList;
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2011-02-24 15:36:50 +03:00
|
|
|
// wrapper around list of hypothese for a particular non-term of a trans opt
|
2010-04-08 21:16:10 +04:00
|
|
|
class ChildEntry
|
|
|
|
{
|
2011-02-24 15:36:50 +03:00
|
|
|
friend std::ostream& operator<<(std::ostream&, const ChildEntry&);
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
protected:
|
2011-02-24 15:36:50 +03:00
|
|
|
size_t m_pos;
|
|
|
|
const HypoList *m_orderedHypos;
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
public:
|
2011-03-11 16:08:43 +03:00
|
|
|
ChildEntry(size_t pos, const HypoList &orderedHypos)
|
2011-02-24 15:36:50 +03:00
|
|
|
:m_pos(pos)
|
|
|
|
,m_orderedHypos(&orderedHypos)
|
|
|
|
{}
|
|
|
|
|
|
|
|
size_t IncrementPos() {
|
|
|
|
return m_pos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HasMoreHypo() const {
|
|
|
|
return m_pos + 1 < m_orderedHypos->size();
|
|
|
|
}
|
|
|
|
|
2011-03-11 16:08:43 +03:00
|
|
|
const ChartHypothesis *GetHypothesis() const {
|
2011-02-24 15:36:50 +03:00
|
|
|
return (*m_orderedHypos)[m_pos];
|
|
|
|
}
|
|
|
|
|
|
|
|
//! transitive comparison used for adding objects into FactorCollection
|
|
|
|
bool operator<(const ChildEntry &compare) const {
|
|
|
|
return GetHypothesis() < compare.GetHypothesis();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const ChildEntry & compare) const {
|
|
|
|
return GetHypothesis() == compare.GetHypothesis();
|
|
|
|
}
|
2010-04-08 21:16:10 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// entry in the cub of 1 trans opt and all the hypotheses that goes with each non term.
|
|
|
|
class QueueEntry
|
|
|
|
{
|
2011-02-24 15:36:50 +03:00
|
|
|
friend std::ostream& operator<<(std::ostream&, const QueueEntry&);
|
2010-04-08 21:16:10 +04:00
|
|
|
protected:
|
2011-02-24 15:36:50 +03:00
|
|
|
const Moses::ChartTranslationOption &m_transOpt;
|
|
|
|
std::vector<ChildEntry> m_childEntries;
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2011-02-24 15:36:50 +03:00
|
|
|
float m_combinedScore;
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2011-02-24 15:36:50 +03:00
|
|
|
QueueEntry(const QueueEntry ©, size_t childEntryIncr);
|
|
|
|
void CreateChildEntry(const Moses::WordConsumed *wordsConsumed, const ChartCellCollection &allChartCells);
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2011-02-24 15:36:50 +03:00
|
|
|
void CalcScore();
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
public:
|
2011-02-24 15:36:50 +03:00
|
|
|
QueueEntry(const Moses::ChartTranslationOption &transOpt
|
|
|
|
, const ChartCellCollection &allChartCells);
|
|
|
|
~QueueEntry();
|
|
|
|
|
|
|
|
const Moses::ChartTranslationOption &GetTranslationOption() const {
|
|
|
|
return m_transOpt;
|
|
|
|
}
|
|
|
|
const std::vector<ChildEntry> &GetChildEntries() const {
|
|
|
|
return m_childEntries;
|
|
|
|
}
|
|
|
|
float GetCombinedScore() const {
|
|
|
|
return m_combinedScore;
|
|
|
|
}
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2011-03-11 16:08:43 +03:00
|
|
|
void CreateNeighbors(Cube &) const;
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2011-02-24 15:36:50 +03:00
|
|
|
bool operator<(const QueueEntry &compare) const;
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2010-10-01 01:10:25 +04:00
|
|
|
#ifdef HAVE_BOOST
|
|
|
|
std::size_t hash_value(const ChildEntry &);
|
|
|
|
#endif
|
|
|
|
|
2010-04-08 21:16:10 +04:00
|
|
|
}
|