2012-06-16 00:44:45 +04:00
|
|
|
// vim:tabstop=2
|
2010-04-12 14:15:49 +04:00
|
|
|
/***********************************************************************
|
|
|
|
Moses - factored phrase-based language decoder
|
|
|
|
Copyright (C) 2010 Hieu Hoang
|
2011-02-24 16:14:42 +03:00
|
|
|
|
2010-04-12 14:15:49 +04:00
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
2011-02-24 16:14:42 +03:00
|
|
|
|
2010-04-12 14:15:49 +04:00
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
2011-02-24 16:14:42 +03:00
|
|
|
|
2010-04-12 14:15:49 +04:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
***********************************************************************/
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
#include "PhraseDictionaryOnDisk.h"
|
2012-11-12 23:56:18 +04:00
|
|
|
#include "moses/InputFileStream.h"
|
|
|
|
#include "moses/StaticData.h"
|
|
|
|
#include "moses/TargetPhraseCollection.h"
|
2012-11-27 21:23:31 +04:00
|
|
|
#include "moses/TranslationModel/CYKPlusParser/DotChartOnDisk.h"
|
|
|
|
#include "moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerOnDisk.h"
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2010-08-10 17:12:00 +04:00
|
|
|
|
2010-04-08 21:16:10 +04:00
|
|
|
namespace Moses
|
|
|
|
{
|
|
|
|
PhraseDictionaryOnDisk::~PhraseDictionaryOnDisk()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PhraseDictionaryOnDisk::Load(const std::vector<FactorType> &input
|
2011-02-24 16:14:42 +03:00
|
|
|
, const std::vector<FactorType> &output
|
|
|
|
, const std::string &filePath
|
2012-06-01 04:49:42 +04:00
|
|
|
, const std::vector<float> &weight
|
2011-02-24 16:14:42 +03:00
|
|
|
, size_t tableLimit
|
|
|
|
, const LMList& languageModels
|
|
|
|
, const WordPenaltyProducer* wpProducer)
|
2010-04-08 21:16:10 +04:00
|
|
|
{
|
2012-08-09 15:47:48 +04:00
|
|
|
PrintUserTime("Start loading binary SCFG phrase table. ");
|
|
|
|
|
2010-08-10 17:12:00 +04:00
|
|
|
m_languageModels = &(languageModels);
|
|
|
|
m_wpProducer = wpProducer;
|
2010-04-08 21:16:10 +04:00
|
|
|
m_filePath = filePath;
|
2011-02-24 16:14:42 +03:00
|
|
|
m_tableLimit = tableLimit;
|
|
|
|
m_inputFactorsVec = input;
|
|
|
|
m_outputFactorsVec = output;
|
|
|
|
|
|
|
|
LoadTargetLookup();
|
|
|
|
|
|
|
|
if (!m_dbWrapper.BeginLoad(filePath))
|
|
|
|
return false;
|
|
|
|
|
2012-10-16 19:57:06 +04:00
|
|
|
CHECK(m_dbWrapper.GetMisc("Version") == OnDiskPt::OnDiskWrapper::VERSION_NUM);
|
2011-11-18 16:07:41 +04:00
|
|
|
CHECK(m_dbWrapper.GetMisc("NumSourceFactors") == input.size());
|
|
|
|
CHECK(m_dbWrapper.GetMisc("NumTargetFactors") == output.size());
|
|
|
|
CHECK(m_dbWrapper.GetMisc("NumScores") == weight.size());
|
2011-02-24 16:14:42 +03:00
|
|
|
|
|
|
|
return true;
|
2010-04-08 21:16:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// PhraseDictionary impl
|
|
|
|
|
|
|
|
//! find list of translations that can translates src. Only for phrase input
|
2011-02-24 19:17:38 +03:00
|
|
|
const TargetPhraseCollection *PhraseDictionaryOnDisk::GetTargetPhraseCollection(const Phrase& /* src */) const
|
2010-04-08 21:16:10 +04:00
|
|
|
{
|
2011-11-18 16:07:41 +04:00
|
|
|
CHECK(false);
|
2011-02-24 16:14:42 +03:00
|
|
|
return NULL;
|
2010-04-08 21:16:10 +04:00
|
|
|
}
|
2011-02-24 16:14:42 +03:00
|
|
|
|
2011-02-24 19:17:38 +03:00
|
|
|
void PhraseDictionaryOnDisk::InitializeForInput(const InputType& /* input */)
|
2010-04-08 21:16:10 +04:00
|
|
|
{
|
2011-04-13 14:38:27 +04:00
|
|
|
// Nothing to do: sentence-specific state is stored in ChartRuleLookupManager
|
2010-04-08 21:16:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void PhraseDictionaryOnDisk::LoadTargetLookup()
|
|
|
|
{
|
2011-02-24 16:14:42 +03:00
|
|
|
// TODO
|
2010-04-08 21:16:10 +04:00
|
|
|
}
|
|
|
|
|
2011-04-13 14:38:27 +04:00
|
|
|
ChartRuleLookupManager *PhraseDictionaryOnDisk::CreateRuleLookupManager(
|
2011-02-24 16:14:42 +03:00
|
|
|
const InputType &sentence,
|
2012-10-11 17:27:30 +04:00
|
|
|
const ChartCellCollectionBase &cellCollection)
|
2011-04-13 14:38:27 +04:00
|
|
|
{
|
|
|
|
return new ChartRuleLookupManagerOnDisk(sentence, cellCollection, *this,
|
|
|
|
m_dbWrapper, m_languageModels,
|
|
|
|
m_wpProducer, m_inputFactorsVec,
|
2012-06-01 04:49:42 +04:00
|
|
|
m_outputFactorsVec, m_filePath);
|
2011-04-13 14:38:27 +04:00
|
|
|
}
|
|
|
|
|
2010-04-08 21:16:10 +04:00
|
|
|
}
|
|
|
|
|