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>
|
2012-09-27 01:49:33 +04:00
|
|
|
#include <boost/unordered_map.hpp>
|
2010-04-08 21:16:10 +04:00
|
|
|
#include "ChartCell.h"
|
|
|
|
#include "ChartCellCollection.h"
|
2011-03-11 16:08:43 +03:00
|
|
|
#include "InputType.h"
|
|
|
|
#include "WordsRange.h"
|
|
|
|
#include "SentenceStats.h"
|
2012-09-25 20:08:38 +04:00
|
|
|
#include "ChartTranslationOptionList.h"
|
2012-10-11 16:45:36 +04:00
|
|
|
#include "ChartParser.h"
|
2014-04-21 13:19:00 +04:00
|
|
|
#include "ChartKBestExtractor.h"
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2011-11-08 15:28:02 +04:00
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
|
2011-03-11 16:08:43 +03:00
|
|
|
namespace Moses
|
2010-04-08 21:16:10 +04:00
|
|
|
{
|
|
|
|
|
2011-03-11 16:08:43 +03:00
|
|
|
class ChartHypothesis;
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2012-06-27 03:45:02 +04:00
|
|
|
/** Holds everything you need to decode 1 sentence with the hierachical/syntax decoder
|
|
|
|
*/
|
2011-03-11 16:08:43 +03:00
|
|
|
class ChartManager
|
2010-04-08 21:16:10 +04:00
|
|
|
{
|
2011-10-06 14:31:09 +04:00
|
|
|
private:
|
2011-03-11 19:28:36 +03:00
|
|
|
InputType const& m_source; /**< source sentence to be translated */
|
2011-02-24 15:36:50 +03:00
|
|
|
ChartCellCollection m_hypoStackColl;
|
2011-03-11 19:28:36 +03:00
|
|
|
std::auto_ptr<SentenceStats> m_sentenceStats;
|
2011-02-24 15:36:50 +03:00
|
|
|
clock_t m_start; /**< starting time, used for logging */
|
2011-10-06 14:31:09 +04:00
|
|
|
unsigned m_hypothesisId; /* For handing out hypothesis ids to ChartHypothesis */
|
2014-08-06 19:37:09 +04:00
|
|
|
size_t m_lineNumber;
|
2011-02-24 15:36:50 +03:00
|
|
|
|
2012-10-11 15:29:02 +04:00
|
|
|
ChartParser m_parser;
|
2012-10-11 14:54:22 +04:00
|
|
|
|
2012-09-25 20:08:38 +04:00
|
|
|
ChartTranslationOptionList m_translationOptionList; /**< pre-computed list of translation options for the phrases in this sentence */
|
|
|
|
|
2010-04-08 21:16:10 +04:00
|
|
|
public:
|
2014-08-06 19:37:09 +04:00
|
|
|
ChartManager(size_t lineNumber, InputType const& source);
|
2011-03-11 16:08:43 +03:00
|
|
|
~ChartManager();
|
2011-02-24 15:36:50 +03:00
|
|
|
void ProcessSentence();
|
2012-03-28 07:29:24 +04:00
|
|
|
void AddXmlChartOptions();
|
2011-03-11 16:08:43 +03:00
|
|
|
const ChartHypothesis *GetBestHypothesis() const;
|
2014-04-21 13:19:00 +04:00
|
|
|
void CalcNBest(size_t n, std::vector<boost::shared_ptr<ChartKBestExtractor::Derivation> > &nBestList, bool onlyDistinct=false) const;
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2011-02-24 15:36:50 +03:00
|
|
|
void GetSearchGraph(long translationId, std::ostream &outputSearchGraphStream) const;
|
2013-05-29 21:16:15 +04:00
|
|
|
void FindReachableHypotheses( const ChartHypothesis *hypo, std::map<unsigned,bool> &reachable ) const; /* auxilliary function for GetSearchGraph */
|
2014-08-06 19:37:09 +04:00
|
|
|
/** Output in (modified) Kenneth hypergraph format */
|
|
|
|
void OutputSearchGraphAsHypergraph(std::ostream &outputSearchGraphStream) const;
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2012-07-03 21:11:53 +04:00
|
|
|
//! the input sentence being decoded
|
2011-03-11 19:28:36 +03:00
|
|
|
const InputType& GetSource() const {
|
2011-02-24 15:36:50 +03:00
|
|
|
return m_source;
|
|
|
|
}
|
2013-05-29 21:16:15 +04:00
|
|
|
|
2012-07-03 21:11:53 +04:00
|
|
|
//! debug data collected when decoding sentence
|
2011-03-11 19:28:36 +03:00
|
|
|
SentenceStats& GetSentenceStats() const {
|
2010-04-08 21:16:10 +04:00
|
|
|
return *m_sentenceStats;
|
|
|
|
}
|
2013-05-29 21:16:15 +04:00
|
|
|
|
2013-09-23 18:30:28 +04:00
|
|
|
//DIMw
|
|
|
|
const ChartCellCollection& GetChartCellCollection() const {
|
|
|
|
return m_hypoStackColl;
|
|
|
|
}
|
|
|
|
|
2011-02-24 15:36:50 +03:00
|
|
|
/***
|
|
|
|
* to be called after processing a sentence (which may consist of more than just calling ProcessSentence() )
|
2012-07-03 21:11:53 +04:00
|
|
|
* currently an empty function
|
2011-02-24 15:36:50 +03:00
|
|
|
*/
|
2013-06-10 21:11:55 +04:00
|
|
|
void CalcDecoderStatistics() const {
|
|
|
|
}
|
2013-05-29 21:16:15 +04:00
|
|
|
|
2011-03-11 19:28:36 +03:00
|
|
|
void ResetSentenceStats(const InputType& source) {
|
|
|
|
m_sentenceStats = std::auto_ptr<SentenceStats>(new SentenceStats(source));
|
2010-04-08 21:16:10 +04:00
|
|
|
}
|
2011-02-24 15:36:50 +03:00
|
|
|
|
2012-07-03 21:11:53 +04:00
|
|
|
//! contigious hypo id for each input sentence. For debugging purposes
|
2013-05-29 21:16:15 +04:00
|
|
|
unsigned GetNextHypoId() {
|
|
|
|
return m_hypothesisId++;
|
|
|
|
}
|
2014-03-17 17:09:54 +04:00
|
|
|
|
|
|
|
const ChartParser &GetParser() const { return m_parser; }
|
2014-08-06 19:37:09 +04:00
|
|
|
|
|
|
|
size_t GetLineNumber() const {
|
|
|
|
return m_lineNumber;
|
|
|
|
}
|
2010-04-08 21:16:10 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|