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

91 lines
1.7 KiB
C++
Raw Normal View History

2015-10-23 22:53:36 +03:00
/*
2015-11-03 17:20:10 +03:00
* PhraseImpl.cpp
2015-10-23 22:53:36 +03:00
*
* Created on: 23 Oct 2015
* Author: hieu
*/
2015-12-07 17:43:10 +03:00
#include <boost/functional/hash.hpp>
2015-10-23 22:53:36 +03:00
#include "Phrase.h"
#include "Word.h"
2015-10-28 19:11:12 +03:00
#include "MemPool.h"
2016-02-23 15:41:48 +03:00
#include "Scores.h"
2016-02-23 19:52:17 +03:00
#include "System.h"
2015-10-24 01:19:31 +03:00
using namespace std;
2015-12-10 23:49:30 +03:00
namespace Moses2
{
2015-12-07 17:43:10 +03:00
size_t Phrase::hash() const
{
size_t seed = 0;
for (size_t i = 0; i < GetSize(); ++i) {
const Word &word = (*this)[i];
size_t wordHash = word.hash();
boost::hash_combine(seed, wordHash);
}
return seed;
}
2015-12-15 16:36:44 +03:00
bool Phrase::operator==(const Phrase &compare) const
{
if (GetSize() != compare.GetSize()) {
return false;
}
for (size_t i = 0; i < GetSize(); ++i) {
const Word &word = (*this)[i];
const Word &otherWord = compare[i];
if (word != otherWord) {
return false;
}
}
return true;
}
2015-12-18 21:38:24 +03:00
std::string Phrase::GetString(const FactorList &factorTypes) const
{
if (GetSize() == 0) {
return "";
}
std::stringstream ret;
const Word &word = (*this)[0];
ret << word.GetString(factorTypes);
2015-12-20 03:10:28 +03:00
for (size_t i = 1; i < GetSize(); ++i) {
const Word &word = (*this)[i];
2015-12-18 21:38:24 +03:00
ret << " " << word.GetString(factorTypes);
}
return ret.str();
}
2016-02-19 23:58:31 +03:00
std::ostream& operator<<(std::ostream &out, const Phrase &obj)
{
if (obj.GetSize()) {
out << obj[0];
for (size_t i = 1; i < obj.GetSize(); ++i) {
const Word &word = obj[i];
out << " " << word;
}
}
return out;
}
2016-02-23 15:41:48 +03:00
////////////////////////////////////////////////////////////////////////
2016-02-23 19:52:17 +03:00
TPBase::TPBase(MemPool &pool, const PhraseTable &pt, const System &system)
:pt(pt)
{
m_scores = new (pool.Allocate<Scores>()) Scores(system, pool, system.featureFunctions.GetNumScores());
}
2016-02-23 15:41:48 +03:00
SCORE TPBase::GetFutureScore() const
{ return m_scores->GetTotalScore() + m_estimatedScore; }
2015-12-10 23:49:30 +03:00
}