use array for source phrase

This commit is contained in:
Hieu Hoang 2015-12-10 22:01:43 +00:00
parent 5b40374cb6
commit aefa04027d
4 changed files with 12 additions and 13 deletions

View File

@ -102,11 +102,13 @@ TargetPhrases* ProbingPT::CreateTargetPhrase(MemPool &pool, const System &system
{
// create a target phrase from the 1st word of the source, prefix with 'ProbingPT:'
assert(sourcePhrase.GetSize());
size_t sourceSize = sourcePhrase.GetSize();
assert(sourceSize);
TargetPhrases *tpSharedPtr = NULL;
uint64_t probingSource[sourceSize];
bool ok;
Vector<uint64_t> *probingSource = ConvertToProbingSourcePhrase(sourcePhrase, ok, pool);
ConvertToProbingSourcePhrase(sourcePhrase, ok, probingSource);
if (!ok) {
// source phrase contains a word unknown in the pt.
// We know immediately there's no translation for it
@ -116,7 +118,7 @@ TargetPhrases* ProbingPT::CreateTargetPhrase(MemPool &pool, const System &system
std::pair<bool, std::vector<target_text> > query_result;
//Actual lookup
query_result = m_engine->query(*probingSource);
query_result = m_engine->query(probingSource, sourceSize);
if (query_result.first) {
//m_engine->printTargetInfo(query_result.second);
@ -178,25 +180,22 @@ TargetPhrase *ProbingPT::CreateTargetPhrase(MemPool &pool, const System &system,
}
Vector<uint64_t> *ProbingPT::ConvertToProbingSourcePhrase(const Phrase &sourcePhrase, bool &ok, MemPool &pool) const
void ProbingPT::ConvertToProbingSourcePhrase(const Phrase &sourcePhrase, bool &ok, uint64_t probingSource[]) const
{
size_t size = sourcePhrase.GetSize();
Vector<uint64_t> *ret = new (pool.Allocate< Vector<uint64_t> >()) Vector<uint64_t>(pool, size);
for (size_t i = 0; i < size; ++i) {
const Factor *factor = sourcePhrase[i][0];
uint64_t probingId = GetSourceProbingId(factor);
if (probingId == m_unkId) {
ok = false;
return ret;
return;
} else {
(*ret)[i] = probingId;
probingSource[i] = probingId;
}
}
ok = true;
return ret;
}
}

View File

@ -41,7 +41,7 @@ protected:
TargetPhrases *CreateTargetPhrase(MemPool &pool, const System &system, const Phrase &sourcePhrase) const;
TargetPhrase *CreateTargetPhrase(MemPool &pool, const System &system, const Phrase &sourcePhrase, const target_text &probingTargetPhrase) const;
Vector<uint64_t> *ConvertToProbingSourcePhrase(const Phrase &sourcePhrase, bool &ok, MemPool &pool) const;
void ConvertToProbingSourcePhrase(const Phrase &sourcePhrase, bool &ok, uint64_t probingSource[]) const;
inline const Factor *GetTargetFactor(uint64_t probingId) const
{

View File

@ -89,7 +89,7 @@ QueryEngine::~QueryEngine()
}
std::pair<bool, std::vector<target_text> > QueryEngine::query(const Vector<uint64_t> &source_phrase)
std::pair<bool, std::vector<target_text> > QueryEngine::query(uint64_t source_phrase[], size_t size)
{
bool found;
std::vector<target_text> translation_entries;
@ -97,7 +97,7 @@ std::pair<bool, std::vector<target_text> > QueryEngine::query(const Vector<uint6
//TOO SLOW
//uint64_t key = util::MurmurHashNative(&source_phrase[0], source_phrase.size());
uint64_t key = 0;
for (int i = 0; i < source_phrase.size(); i++) {
for (int i = 0; i < size; i++) {
key += (source_phrase[i] << i);
}

View File

@ -34,7 +34,7 @@ public:
QueryEngine (const char *);
~QueryEngine();
std::pair<bool, std::vector<target_text> > query(const StringPiece &source_phrase);
std::pair<bool, std::vector<target_text> > query(const Vector<uint64_t> &source_phrase);
std::pair<bool, std::vector<target_text> > query(uint64_t source_phrase[], size_t size);
void printTargetInfo(const std::vector<target_text> &target_phrases);
const std::map<unsigned int, std::string> getVocab() const {
return decoder.get_target_lookup_map();