2008-06-11 14:52:57 +04:00
|
|
|
// $Id$
|
|
|
|
|
2010-02-24 14:15:44 +03:00
|
|
|
#ifndef moses_ConfusionNet_h
|
|
|
|
#define moses_ConfusionNet_h
|
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
#include <vector>
|
|
|
|
#include <iostream>
|
|
|
|
#include "Word.h"
|
|
|
|
#include "InputType.h"
|
2013-08-02 18:54:49 +04:00
|
|
|
#include "NonTerminal.h"
|
2013-11-19 17:19:23 +04:00
|
|
|
#include "util/exception.hh"
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2008-10-09 03:51:26 +04:00
|
|
|
namespace Moses
|
|
|
|
{
|
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
class FactorCollection;
|
|
|
|
class TranslationOptionCollection;
|
|
|
|
class Sentence;
|
2015-03-15 23:38:31 +03:00
|
|
|
class TranslationTask;
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
/** An input to the decoder where each position can be 1 of a number of words,
|
2012-06-27 03:45:02 +04:00
|
|
|
* each with an associated probability. Compared with a sentence, where each position is a word
|
|
|
|
*/
|
2011-02-24 16:14:42 +03:00
|
|
|
class ConfusionNet : public InputType
|
|
|
|
{
|
|
|
|
public:
|
2013-09-08 21:22:55 +04:00
|
|
|
typedef std::vector<std::pair<Word, ScorePair > > Column;
|
2011-02-24 16:14:42 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
std::vector<Column> data;
|
2013-08-02 18:54:49 +04:00
|
|
|
NonTerminalSet m_defaultLabelSet;
|
2011-02-24 16:14:42 +03:00
|
|
|
|
2015-12-10 06:17:36 +03:00
|
|
|
bool ReadFormat0(std::istream&);
|
|
|
|
bool ReadFormat1(std::istream&);
|
2011-02-24 16:14:42 +03:00
|
|
|
void String2Word(const std::string& s,Word& w,const std::vector<FactorType>& factorOrder);
|
|
|
|
|
|
|
|
public:
|
2015-12-10 02:05:00 +03:00
|
|
|
ConfusionNet(AllOptions::ptr const& opts);
|
2011-02-24 16:14:42 +03:00
|
|
|
virtual ~ConfusionNet();
|
|
|
|
|
|
|
|
ConfusionNet(Sentence const& s);
|
|
|
|
|
|
|
|
InputTypeEnum GetType() const {
|
|
|
|
return ConfusionNetworkInput;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Column& GetColumn(size_t i) const {
|
2013-11-23 00:27:46 +04:00
|
|
|
UTIL_THROW_IF2(i >= data.size(),
|
2015-12-11 03:00:33 +03:00
|
|
|
"Out of bounds. Trying to access " << i
|
|
|
|
<< " when vector only contains " << data.size());
|
2011-02-24 16:14:42 +03:00
|
|
|
return data[i];
|
|
|
|
}
|
|
|
|
const Column& operator[](size_t i) const {
|
|
|
|
return GetColumn(i);
|
|
|
|
}
|
|
|
|
virtual size_t GetColumnIncrement(size_t i, size_t j) const; //! returns 1 for CNs
|
|
|
|
|
|
|
|
bool Empty() const {
|
|
|
|
return data.empty();
|
|
|
|
}
|
|
|
|
size_t GetSize() const {
|
|
|
|
return data.size();
|
|
|
|
}
|
|
|
|
void Clear() {
|
|
|
|
data.clear();
|
|
|
|
}
|
|
|
|
|
2015-12-10 06:17:36 +03:00
|
|
|
bool ReadF(std::istream&, int format=0);
|
2011-02-24 16:14:42 +03:00
|
|
|
virtual void Print(std::ostream&) const;
|
|
|
|
|
2015-12-10 06:17:36 +03:00
|
|
|
int Read(std::istream& in);
|
2011-02-24 16:14:42 +03:00
|
|
|
|
2015-10-25 16:37:59 +03:00
|
|
|
Phrase GetSubString(const Range&) const; //TODO not defined
|
2011-02-24 16:14:42 +03:00
|
|
|
std::string GetStringRep(const std::vector<FactorType> factorsToPrint) const; //TODO not defined
|
|
|
|
const Word& GetWord(size_t pos) const;
|
|
|
|
|
2015-04-30 08:05:11 +03:00
|
|
|
TranslationOptionCollection*
|
2015-03-30 03:20:17 +03:00
|
|
|
CreateTranslationOptionCollection(ttasksptr const& ttask) const;
|
2011-02-24 16:14:42 +03:00
|
|
|
|
|
|
|
const NonTerminalSet &GetLabelSet(size_t /*startPos*/, size_t /*endPos*/) const {
|
2013-08-07 17:18:12 +04:00
|
|
|
return m_defaultLabelSet;
|
2011-02-24 16:14:42 +03:00
|
|
|
}
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2013-10-02 23:02:05 +04:00
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
std::ostream& operator<<(std::ostream& out,const ConfusionNet& cn);
|
2008-10-09 03:51:26 +04:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
#endif
|