mosesdecoder/contrib/other-builds/moses2/Phrase.h

89 lines
1.9 KiB
C
Raw Normal View History

2015-10-23 22:53:36 +03:00
/*
2015-11-03 17:20:10 +03:00
* PhraseImpl.h
2015-10-23 22:53:36 +03:00
*
* Created on: 23 Oct 2015
* Author: hieu
*/
#pragma once
#include <cstddef>
2015-10-24 01:19:31 +03:00
#include <string>
2015-10-26 19:32:47 +03:00
#include <iostream>
2015-10-24 01:19:31 +03:00
#include "Word.h"
2015-10-28 19:11:12 +03:00
#include "MemPool.h"
2015-11-13 13:40:55 +03:00
#include "legacy/FactorCollection.h"
2015-10-23 22:53:36 +03:00
2015-12-10 23:49:30 +03:00
namespace Moses2
{
2015-11-03 17:20:10 +03:00
class SubPhrase;
2016-02-23 15:41:48 +03:00
class Scores;
2016-02-23 19:52:17 +03:00
class PhraseTable;
class MemPool;
class System;
2015-11-03 17:20:10 +03:00
class Phrase
2015-10-24 01:19:31 +03:00
{
2015-11-04 19:46:04 +03:00
friend std::ostream& operator<<(std::ostream &, const Phrase &);
2015-10-24 01:19:31 +03:00
public:
virtual const Word& operator[](size_t pos) const = 0;
virtual size_t GetSize() const = 0;
2015-12-15 16:36:44 +03:00
virtual size_t hash() const;
virtual bool operator==(const Phrase &compare) const;
virtual bool operator!=(const Phrase &compare) const
{
return !( (*this) == compare );
}
2015-12-18 21:38:24 +03:00
virtual std::string GetString(const FactorList &factorTypes) const;
virtual SubPhrase GetSubPhrase(size_t start, size_t end) const = 0;
2015-12-15 16:36:44 +03:00
2015-10-24 01:19:31 +03:00
};
2016-02-23 15:41:48 +03:00
////////////////////////////////////////////////////////////////////////
class TPBase : public Phrase
{
public:
2016-02-23 19:52:17 +03:00
const PhraseTable &pt;
TPBase(MemPool &pool, const PhraseTable &pt, const System &system);
2016-02-23 15:41:48 +03:00
Scores &GetScores()
{ return *m_scores; }
const Scores &GetScores() const
{ return *m_scores; }
SCORE GetFutureScore() const;
2015-10-24 01:19:31 +03:00
2016-02-23 15:41:48 +03:00
void SetEstimatedScore(const SCORE &value)
{ m_estimatedScore = value; }
SCORE *GetScoresProperty(int propertyInd) const;
protected:
Scores *m_scores;
SCORE m_estimatedScore;
};
2015-11-25 20:35:22 +03:00
2016-02-23 15:41:48 +03:00
////////////////////////////////////////////////////////////////////////
2015-11-25 20:35:22 +03:00
class PhraseOrdererLexical
{
public:
bool operator()(const Phrase &a, const Phrase &b) const {
size_t minSize = std::min(a.GetSize(), b.GetSize());
for (size_t i = 0; i < minSize; ++i) {
const Word &aWord = a[i];
const Word &bWord = b[i];
2015-11-26 03:53:12 +03:00
int cmp = aWord.Compare(bWord);
2015-11-26 01:22:35 +03:00
//std::cerr << "WORD: " << aWord << " ||| " << bWord << " ||| " << lessThan << std::endl;
2015-11-26 03:53:12 +03:00
if (cmp) {
return (cmp < 0);
2015-11-25 20:35:22 +03:00
}
}
return a.GetSize() < b.GetSize();
}
};
2015-12-10 23:49:30 +03:00
}