2015-03-15 23:38:31 +03:00
|
|
|
// -*- c++ -*-
|
2015-02-02 19:34:17 +03:00
|
|
|
#ifndef moses_ForestInput_h
|
|
|
|
#define moses_ForestInput_h
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
|
|
|
|
#include <util/string_piece.hh>
|
|
|
|
|
|
|
|
#include "moses/Syntax/F2S/Forest.h"
|
|
|
|
|
|
|
|
#include "Sentence.h"
|
|
|
|
|
|
|
|
namespace Moses
|
|
|
|
{
|
2015-03-15 23:38:31 +03:00
|
|
|
class TranslationTask;
|
2015-02-02 19:34:17 +03:00
|
|
|
class ForestInput : public Sentence
|
|
|
|
{
|
2015-02-19 15:27:23 +03:00
|
|
|
public:
|
2015-02-02 19:34:17 +03:00
|
|
|
friend std::ostream &operator<<(std::ostream&, const ForestInput &);
|
|
|
|
|
2015-03-21 18:22:12 +03:00
|
|
|
ForestInput() : Sentence(), m_rootVertex(NULL) {}
|
2015-02-02 19:34:17 +03:00
|
|
|
|
|
|
|
InputTypeEnum GetType() const {
|
|
|
|
return ForestInputType;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! populate this InputType with data from in stream
|
|
|
|
virtual int Read(std::istream& in,const std::vector<FactorType>& factorOrder);
|
|
|
|
|
|
|
|
//! Output debugging info to stream out
|
|
|
|
virtual void Print(std::ostream&) const;
|
|
|
|
|
|
|
|
//! create trans options specific to this InputType
|
|
|
|
virtual TranslationOptionCollection*
|
|
|
|
CreateTranslationOptionCollection() const;
|
|
|
|
|
2015-02-19 15:27:23 +03:00
|
|
|
boost::shared_ptr<const Syntax::F2S::Forest> GetForest() const {
|
2015-02-02 19:34:17 +03:00
|
|
|
return m_forest;
|
|
|
|
}
|
|
|
|
|
2015-02-19 15:27:23 +03:00
|
|
|
const Syntax::F2S::Forest::Vertex *GetRootVertex() const {
|
2015-02-02 19:34:17 +03:00
|
|
|
return m_rootVertex;
|
|
|
|
}
|
|
|
|
|
2015-02-19 15:27:23 +03:00
|
|
|
private:
|
2015-02-02 19:34:17 +03:00
|
|
|
typedef Syntax::F2S::Forest Forest;
|
|
|
|
|
|
|
|
struct VertexSetHash {
|
|
|
|
std::size_t operator()(const Forest::Vertex *v) const {
|
|
|
|
std::size_t seed = 0;
|
|
|
|
boost::hash_combine(seed, v->pvertex.symbol);
|
|
|
|
boost::hash_combine(seed, v->pvertex.span.GetStartPos());
|
|
|
|
boost::hash_combine(seed, v->pvertex.span.GetEndPos());
|
|
|
|
return seed;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct VertexSetPred {
|
|
|
|
bool operator()(const Forest::Vertex *v, const Forest::Vertex *w) const {
|
|
|
|
return v->pvertex == w->pvertex;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef boost::unordered_set<Forest::Vertex *, VertexSetHash,
|
2015-02-19 15:27:23 +03:00
|
|
|
VertexSetPred> VertexSet;
|
2015-02-02 19:34:17 +03:00
|
|
|
|
|
|
|
Forest::Vertex *AddOrDeleteVertex(Forest::Vertex *);
|
|
|
|
|
|
|
|
std::size_t FindMaxEnd(const Forest &);
|
|
|
|
|
|
|
|
void FindTopVertices(Forest &, std::vector<Forest::Vertex *> &);
|
|
|
|
|
|
|
|
void ParseHyperedgeLine(const std::string &,
|
|
|
|
const std::vector<FactorType> &);
|
|
|
|
|
|
|
|
Forest::Vertex *ParseVertex(const StringPiece &,
|
|
|
|
const std::vector<FactorType> &);
|
|
|
|
|
|
|
|
boost::shared_ptr<Forest> m_forest;
|
|
|
|
Forest::Vertex *m_rootVertex;
|
|
|
|
VertexSet m_vertexSet;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Moses
|
|
|
|
|
|
|
|
#endif
|