mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 11:25:40 +03:00
Instances of InputType (and derived classes) now know which TranslationTask (if any) created them.
This is a first step towards providing phrase tables etc. access to context information etc. associated with specific translation tasks.
This commit is contained in:
parent
16d8ef67f0
commit
ad805c133b
@ -61,8 +61,8 @@ GetColumnIncrement(size_t i, size_t j) const
|
||||
}
|
||||
|
||||
ConfusionNet::
|
||||
ConfusionNet()
|
||||
: InputType()
|
||||
ConfusionNet(TranslationTask const* ttask)
|
||||
: InputType(ttask)
|
||||
{
|
||||
stats.createOne();
|
||||
|
||||
@ -81,6 +81,7 @@ ConfusionNet::
|
||||
|
||||
ConfusionNet::
|
||||
ConfusionNet(Sentence const& s)
|
||||
: InputType(s.GetTranslationTask())
|
||||
{
|
||||
data.resize(s.GetSize());
|
||||
for(size_t i=0; i<s.GetSize(); ++i) {
|
||||
|
@ -16,6 +16,7 @@ namespace Moses
|
||||
class FactorCollection;
|
||||
class TranslationOptionCollection;
|
||||
class Sentence;
|
||||
class TranslationTask;
|
||||
|
||||
/** An input to the decoder where each position can be 1 of a number of words,
|
||||
* each with an associated probability. Compared with a sentence, where each position is a word
|
||||
@ -34,7 +35,7 @@ protected:
|
||||
void String2Word(const std::string& s,Word& w,const std::vector<FactorType>& factorOrder);
|
||||
|
||||
public:
|
||||
ConfusionNet();
|
||||
ConfusionNet(TranslationTask const* ttask);
|
||||
virtual ~ConfusionNet();
|
||||
|
||||
ConfusionNet(Sentence const& s);
|
||||
|
@ -1,3 +1,4 @@
|
||||
// -*- c++ -*-
|
||||
#ifndef moses_ForestInput_h
|
||||
#define moses_ForestInput_h
|
||||
|
||||
@ -14,13 +15,14 @@
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
|
||||
class TranslationTask;
|
||||
class ForestInput : public Sentence
|
||||
{
|
||||
public:
|
||||
friend std::ostream &operator<<(std::ostream&, const ForestInput &);
|
||||
|
||||
ForestInput() : m_rootVertex(NULL) {}
|
||||
ForestInput(TranslationTask const* ttask)
|
||||
: Sentence(ttask), m_rootVertex(NULL) {}
|
||||
|
||||
InputTypeEnum GetType() const {
|
||||
return ForestInputType;
|
||||
|
@ -235,27 +235,31 @@ GetInput(InputType* inputType)
|
||||
}
|
||||
}
|
||||
|
||||
bool IOWrapper::ReadInput(InputTypeEnum inputType, InputType*& source)
|
||||
bool
|
||||
IOWrapper
|
||||
::ReadInput(InputTypeEnum inputType,
|
||||
InputType*& source,
|
||||
TranslationTask const* ttask)
|
||||
{
|
||||
delete source;
|
||||
switch(inputType) {
|
||||
case SentenceInput:
|
||||
source = GetInput(new Sentence);
|
||||
source = GetInput(new Sentence(ttask));
|
||||
break;
|
||||
case ConfusionNetworkInput:
|
||||
source = GetInput(new ConfusionNet);
|
||||
source = GetInput(new ConfusionNet(ttask));
|
||||
break;
|
||||
case WordLatticeInput:
|
||||
source = GetInput(new WordLattice);
|
||||
source = GetInput(new WordLattice(ttask));
|
||||
break;
|
||||
case TreeInputType:
|
||||
source = GetInput(new TreeInput);
|
||||
source = GetInput(new TreeInput(ttask));
|
||||
break;
|
||||
case TabbedSentenceInput:
|
||||
source = GetInput(new TabbedSentence);
|
||||
source = GetInput(new TabbedSentence(ttask));
|
||||
break;
|
||||
case ForestInputType:
|
||||
source = GetInput(new ForestInput);
|
||||
source = GetInput(new ForestInput(ttask));
|
||||
break;
|
||||
default:
|
||||
TRACE_ERR("Unknown input type: " << inputType << "\n");
|
||||
|
@ -1,3 +1,4 @@
|
||||
// -*- c++ -*-
|
||||
// $Id$
|
||||
|
||||
/***********************************************************************
|
||||
@ -62,7 +63,7 @@ class ScoreComponentCollection;
|
||||
class Hypothesis;
|
||||
class ChartHypothesis;
|
||||
class Factor;
|
||||
|
||||
class TranslationTask;
|
||||
namespace Syntax
|
||||
{
|
||||
struct SHyperedge;
|
||||
@ -105,7 +106,8 @@ public:
|
||||
~IOWrapper();
|
||||
|
||||
Moses::InputType* GetInput(Moses::InputType *inputType);
|
||||
bool ReadInput(Moses::InputTypeEnum inputType, Moses::InputType*& source);
|
||||
bool ReadInput(Moses::InputTypeEnum inputType,
|
||||
Moses::InputType*& source, TranslationTask const* ttask=NULL);
|
||||
|
||||
Moses::OutputCollector *GetSingleBestOutputCollector() {
|
||||
return m_singleBestOutputCollector.get();
|
||||
|
@ -29,7 +29,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
namespace Moses
|
||||
{
|
||||
|
||||
InputType::InputType(long translationId) : m_translationId(translationId)
|
||||
InputType::InputType(TranslationTask const* ttask, long translationId)
|
||||
: m_translationId(translationId), m_ttask(ttask)
|
||||
{
|
||||
m_frontSpanCoveredLength = 0;
|
||||
m_sourceCompleted.resize(0);
|
||||
|
@ -1,3 +1,4 @@
|
||||
// -*- c++ -*-
|
||||
// $Id$
|
||||
// vim:tabstop=2
|
||||
|
||||
@ -37,7 +38,7 @@ class Factor;
|
||||
class PhraseDictionary;
|
||||
class TranslationOptionCollection;
|
||||
class ChartTranslationOptions;
|
||||
|
||||
class TranslationTask;
|
||||
/** base class for all types of inputs to the decoder,
|
||||
* eg. sentences, confusion networks, lattices and tree
|
||||
*/
|
||||
@ -57,6 +58,7 @@ protected:
|
||||
ReorderingConstraint m_reorderingConstraint; /**< limits on reordering specified either by "-mp" switch or xml tags */
|
||||
std::string m_textType;
|
||||
std::string m_passthrough;
|
||||
TranslationTask const* m_ttask; // Translation task that "owns" this instance
|
||||
|
||||
public:
|
||||
|
||||
@ -66,11 +68,14 @@ public:
|
||||
size_t m_frontSpanCoveredLength;
|
||||
// how many words from the beginning are covered
|
||||
|
||||
InputType(long translationId = 0);
|
||||
InputType(TranslationTask const* ttask, long translationId = 0);
|
||||
virtual ~InputType();
|
||||
|
||||
virtual InputTypeEnum GetType() const = 0;
|
||||
|
||||
TranslationTask const*
|
||||
GetTranslationTask() const { return m_ttask; }
|
||||
|
||||
long GetTranslationId() const {
|
||||
return m_translationId;
|
||||
}
|
||||
@ -179,7 +184,8 @@ public:
|
||||
virtual void Print(std::ostream&) const =0;
|
||||
|
||||
//! create trans options specific to this InputType
|
||||
virtual TranslationOptionCollection* CreateTranslationOptionCollection() const=0;
|
||||
virtual TranslationOptionCollection*
|
||||
CreateTranslationOptionCollection() const=0;
|
||||
|
||||
//! return substring. Only valid for Sentence class. TODO - get rid of this fn
|
||||
virtual Phrase GetSubString(const WordsRange&) const =0;
|
||||
|
@ -66,7 +66,7 @@ class BackwardLanguageModelTest
|
||||
|
||||
public:
|
||||
BackwardLanguageModelTest() :
|
||||
dummyInput(new Sentence()),
|
||||
dummyInput(new Sentence(NULL)),
|
||||
backwardLM(
|
||||
static_cast< BackwardLanguageModel<lm::ngram::ProbingModel> * >(
|
||||
ConstructBackwardLM(
|
||||
|
@ -37,7 +37,7 @@ MockHypothesisGuard::MockHypothesisGuard(
|
||||
const vector<Alignment>& alignments,
|
||||
const vector<string>& targetSegments)
|
||||
: m_initialTransOpt(),
|
||||
m_sentence(),
|
||||
m_sentence(NULL),
|
||||
m_wp("WordPenalty"),
|
||||
m_uwp("UnknownWordPenalty"),
|
||||
m_dist("Distortion"),
|
||||
|
@ -40,9 +40,9 @@ namespace Moses
|
||||
{
|
||||
|
||||
Sentence::
|
||||
Sentence()
|
||||
Sentence(TranslationTask const* ttask)
|
||||
: Phrase(0)
|
||||
, InputType()
|
||||
, InputType(ttask)
|
||||
{
|
||||
const StaticData& SD = StaticData::Instance();
|
||||
if (SD.IsSyntax())
|
||||
@ -279,7 +279,8 @@ ProcessPlaceholders(const std::vector< std::pair<size_t, std::string> > &placeho
|
||||
}
|
||||
|
||||
TranslationOptionCollection*
|
||||
Sentence::CreateTranslationOptionCollection() const
|
||||
Sentence::
|
||||
CreateTranslationOptionCollection() const
|
||||
{
|
||||
size_t maxNoTransOptPerCoverage = StaticData::Instance().GetMaxNoTransOptPerCoverage();
|
||||
float transOptThreshold = StaticData::Instance().GetTranslationOptionThreshold();
|
||||
@ -384,9 +385,10 @@ CreateFromString(vector<FactorType> const& FOrder, string const& phraseString)
|
||||
}
|
||||
|
||||
Sentence::
|
||||
Sentence(size_t const transId, string const& stext)
|
||||
Sentence(TranslationTask const* ttask,size_t const transId, string const& stext)
|
||||
: InputType(ttask, transId)
|
||||
{
|
||||
this->SetTranslationId(transId);
|
||||
// this->SetTranslationId(transId);
|
||||
vector<FactorType> const& IFO = StaticData::Instance().GetInputFactorOrder();
|
||||
init(stext, IFO);
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ namespace Moses
|
||||
class TranslationOption;
|
||||
class TranslationOptionCollection;
|
||||
class ChartTranslationOptions;
|
||||
class TranslationTask;
|
||||
struct XmlOption;
|
||||
|
||||
|
||||
@ -61,8 +62,9 @@ namespace Moses
|
||||
|
||||
|
||||
public:
|
||||
Sentence();
|
||||
Sentence(size_t const transId, std::string const& stext);
|
||||
Sentence(TranslationTask const* ttask);
|
||||
Sentence(TranslationTask const* ttask, size_t const transId,
|
||||
std::string const& stext);
|
||||
~Sentence();
|
||||
|
||||
InputTypeEnum GetType() const {
|
||||
|
@ -1,3 +1,4 @@
|
||||
// -*- c++ -*-
|
||||
// $Id$
|
||||
|
||||
/***********************************************************************
|
||||
@ -47,11 +48,12 @@ namespace Moses
|
||||
|
||||
typedef std::vector<std::string> TabbedColumns;
|
||||
|
||||
class TranslationTask;
|
||||
class TabbedSentence : public Sentence
|
||||
{
|
||||
|
||||
public:
|
||||
TabbedSentence() {}
|
||||
TabbedSentence(TranslationTask const* ttask) : Sentence(ttask) {}
|
||||
~TabbedSentence() {}
|
||||
|
||||
InputTypeEnum GetType() const {
|
||||
|
@ -67,7 +67,7 @@ int main(int argc, char* argv[])
|
||||
string line;
|
||||
while (true)
|
||||
{
|
||||
Sentence phrase;
|
||||
Sentence phrase(NULL);
|
||||
if (!phrase.Read(cin,ifo)) break;
|
||||
if (pdta)
|
||||
{
|
||||
|
@ -106,7 +106,7 @@ int main(int argc, char* argv[])
|
||||
cout << string(80,'-') << "\n" << srcline << "\n" << trgline << "\n" << endl;
|
||||
|
||||
// cout << srcline << " " << HERE << endl;
|
||||
Sentence snt;
|
||||
Sentence snt(NULL);
|
||||
istringstream buf(srcline+"\n");
|
||||
if (!snt.Read(buf,ifo)) break;
|
||||
// cout << Phrase(snt) << endl;
|
||||
|
@ -40,7 +40,7 @@ void TranslationTask::Run()
|
||||
const size_t translationId = m_source->GetTranslationId();
|
||||
|
||||
// input sentence
|
||||
Sentence sentence;
|
||||
Sentence sentence(this);
|
||||
|
||||
// report wall time spent on translation
|
||||
Timer translationTime;
|
||||
|
@ -1,3 +1,4 @@
|
||||
// -*- c++ -*-
|
||||
#ifndef moses_TreeInput_h
|
||||
#define moses_TreeInput_h
|
||||
|
||||
@ -7,6 +8,7 @@
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
class TranslationTask;
|
||||
//! @todo what is this?
|
||||
class XMLParseOutput
|
||||
{
|
||||
@ -44,8 +46,7 @@ protected:
|
||||
bool ProcessAndStripXMLTags(std::string &line, std::vector<XMLParseOutput> &sourceLabels, std::vector<XmlOption*> &res);
|
||||
|
||||
public:
|
||||
TreeInput() {
|
||||
}
|
||||
TreeInput(TranslationTask const* ttask) : Sentence(ttask) { }
|
||||
|
||||
InputTypeEnum GetType() const {
|
||||
return TreeInputType;
|
||||
|
@ -10,7 +10,8 @@
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
WordLattice::WordLattice()
|
||||
WordLattice::WordLattice(TranslationTask const* ttask)
|
||||
: ConfusionNet(ttask)
|
||||
{
|
||||
UTIL_THROW_IF2(&InputFeature::Instance() == NULL,
|
||||
"Input feature must be specified");
|
||||
|
@ -9,6 +9,8 @@
|
||||
namespace Moses
|
||||
{
|
||||
|
||||
class TranslationTask;
|
||||
|
||||
/** An input to the decoder that represent a word lattice.
|
||||
* @todo why is this inherited from confusion net?
|
||||
*/
|
||||
@ -20,7 +22,7 @@ private:
|
||||
std::vector<std::vector<int> > distances;
|
||||
|
||||
public:
|
||||
WordLattice();
|
||||
WordLattice(TranslationTask const* ttask);
|
||||
|
||||
InputTypeEnum GetType() const {
|
||||
return WordLatticeInput;
|
||||
|
Loading…
Reference in New Issue
Block a user