mosesdecoder/contrib/moses2/SCFG/TargetPhrases.cpp

67 lines
1.3 KiB
C++
Raw Normal View History

2016-04-17 13:02:05 +03:00
/*
* TargetPhrases.cpp
*
* Created on: 15 Apr 2016
* Author: hieu
*/
2016-06-13 18:58:08 +03:00
#include <boost/foreach.hpp>
2016-06-20 16:59:31 +03:00
#include <sstream>
2016-04-27 20:43:57 +03:00
#include <algorithm>
2016-04-17 13:02:05 +03:00
#include "TargetPhrases.h"
2016-06-13 16:34:50 +03:00
#include "TargetPhraseImpl.h"
2016-04-27 20:43:57 +03:00
#include "../TargetPhrase.h"
2016-06-13 16:34:50 +03:00
#include "../TranslationModel/PhraseTable.h"
2016-04-17 13:02:05 +03:00
namespace Moses2
{
namespace SCFG
{
2016-05-26 16:46:27 +03:00
TargetPhrases::TargetPhrases(MemPool &pool)
2016-06-13 15:47:15 +03:00
:m_coll(pool)
2016-05-26 16:46:27 +03:00
{
}
2016-04-17 13:02:05 +03:00
2016-04-27 20:43:57 +03:00
TargetPhrases::TargetPhrases(MemPool &pool, size_t size)
2016-06-13 15:47:15 +03:00
:m_coll(pool)
2016-04-17 13:02:05 +03:00
{
2016-06-13 15:47:15 +03:00
m_coll.reserve(size);
2016-04-17 13:02:05 +03:00
}
TargetPhrases::~TargetPhrases()
{
// TODO Auto-generated destructor stub
}
2016-04-27 20:43:57 +03:00
void TargetPhrases::SortAndPrune(size_t tableLimit)
{
iterator iterMiddle;
iterMiddle =
2016-06-13 15:47:15 +03:00
(tableLimit == 0 || m_coll.size() < tableLimit) ?
m_coll.end() : m_coll.begin() + tableLimit;
2016-06-23 00:23:51 +03:00
2016-04-27 20:43:57 +03:00
std::partial_sort(m_coll.begin(), iterMiddle, m_coll.end(),
2016-07-15 18:35:38 +03:00
CompareScoreForPruning<SCFG::TargetPhraseImpl>());
2016-06-23 00:23:51 +03:00
2016-06-13 15:47:15 +03:00
if (tableLimit && m_coll.size() > tableLimit) {
m_coll.resize(tableLimit);
2016-04-27 20:43:57 +03:00
}
//cerr << "TargetPhrases=" << GetSize() << endl;
}
2016-06-20 16:59:31 +03:00
std::string TargetPhrases::Debug(const System &system) const
2016-06-13 18:58:08 +03:00
{
2016-06-20 16:59:31 +03:00
std::stringstream out;
out << m_coll.size() << std::endl;
2016-06-13 18:58:08 +03:00
BOOST_FOREACH(const SCFG::TargetPhraseImpl *tp, m_coll) {
2016-06-20 16:59:31 +03:00
out << tp->Debug(system);
2016-08-15 15:21:29 +03:00
out << std::endl;
2016-06-13 18:58:08 +03:00
}
2016-06-20 16:59:31 +03:00
return out.str();
2016-06-13 18:58:08 +03:00
}
2016-04-17 13:02:05 +03:00
}
} /* namespace Moses2 */