|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <iostream> |
|
#include "moses/Util.h" |
|
#include "Phrase.h" |
|
#include "util/exception.hh" |
|
|
|
using namespace std; |
|
|
|
namespace OnDiskPt |
|
{ |
|
|
|
|
|
void Phrase::AddWord(WordPtr word) |
|
{ |
|
m_words.push_back(word); |
|
} |
|
|
|
void Phrase::AddWord(WordPtr word, size_t pos) |
|
{ |
|
UTIL_THROW_IF2(!(pos < m_words.size()), |
|
"Trying to get word " << pos << " when phrase size is " << m_words.size()); |
|
m_words.insert(m_words.begin() + pos + 1, word); |
|
} |
|
|
|
int Phrase::Compare(const Phrase &compare) const |
|
{ |
|
int ret = 0; |
|
for (size_t pos = 0; pos < GetSize(); ++pos) { |
|
if (pos >= compare.GetSize()) { |
|
|
|
ret = -1; |
|
break; |
|
} |
|
|
|
const Word &thisWord = GetWord(pos) |
|
,&compareWord = compare.GetWord(pos); |
|
int wordRet = thisWord.Compare(compareWord); |
|
if (wordRet != 0) { |
|
ret = wordRet; |
|
break; |
|
} |
|
} |
|
|
|
if (ret == 0) { |
|
assert(compare.GetSize() >= GetSize()); |
|
ret = (compare.GetSize() > GetSize()) ? 1 : 0; |
|
} |
|
return ret; |
|
} |
|
|
|
|
|
bool Phrase::operator<(const Phrase &compare) const |
|
{ |
|
int ret = Compare(compare); |
|
return ret < 0; |
|
} |
|
|
|
bool Phrase::operator>(const Phrase &compare) const |
|
{ |
|
int ret = Compare(compare); |
|
return ret > 0; |
|
} |
|
|
|
bool Phrase::operator==(const Phrase &compare) const |
|
{ |
|
int ret = Compare(compare); |
|
return ret == 0; |
|
} |
|
|
|
void Phrase::DebugPrint(ostream &out, const Vocab &vocab) const |
|
{ |
|
for (size_t pos = 0; pos < GetSize(); ++pos) { |
|
const Word &word = GetWord(pos); |
|
word.DebugPrint(out, vocab); |
|
out << " "; |
|
} |
|
} |
|
|
|
std::ostream& operator<<(std::ostream &out, const Phrase &phrase) |
|
{ |
|
for (size_t pos = 0; pos < phrase.GetSize(); ++pos) { |
|
const Word &word = phrase.GetWord(pos); |
|
out << word << " "; |
|
} |
|
|
|
return out; |
|
} |
|
|
|
} |
|
|
|
|