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()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-02-25 18:19:48 +04:00
|
|
|
bool PhraseDictionaryOnDisk::InitDictionary()
|
2010-04-08 21:16:10 +04:00
|
|
|
{
|
2013-02-25 18:19:48 +04:00
|
|
|
const StaticData &staticData = StaticData::Instance();
|
|
|
|
m_languageModels = &staticData.GetLMList();
|
|
|
|
m_wpProducer = staticData.GetWordPenaltyProducer();
|
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-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,
|
2013-03-05 18:02:55 +04:00
|
|
|
GetImplementation(), m_languageModels,
|
2013-02-25 18:19:48 +04:00
|
|
|
m_wpProducer, m_input,
|
|
|
|
m_output, m_filePath);
|
2011-04-13 14:38:27 +04:00
|
|
|
}
|
|
|
|
|
2013-03-05 18:02:55 +04:00
|
|
|
OnDiskPt::OnDiskWrapper &PhraseDictionaryOnDisk::GetImplementation()
|
|
|
|
{
|
|
|
|
OnDiskPt::OnDiskWrapper* dict;
|
|
|
|
dict = m_implementation.get();
|
|
|
|
CHECK(dict);
|
|
|
|
return *dict;
|
|
|
|
}
|
|
|
|
|
|
|
|
const OnDiskPt::OnDiskWrapper &PhraseDictionaryOnDisk::GetImplementation() const
|
|
|
|
{
|
|
|
|
OnDiskPt::OnDiskWrapper* dict;
|
|
|
|
dict = m_implementation.get();
|
|
|
|
CHECK(dict);
|
|
|
|
return *dict;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PhraseDictionaryOnDisk::InitializeForInput(InputType const& source)
|
|
|
|
{
|
|
|
|
const StaticData &staticData = StaticData::Instance();
|
|
|
|
|
|
|
|
OnDiskPt::OnDiskWrapper *obj = new OnDiskPt::OnDiskWrapper();
|
|
|
|
if (!obj->BeginLoad(m_filePath))
|
|
|
|
return;
|
|
|
|
|
|
|
|
CHECK(obj->GetMisc("Version") == OnDiskPt::OnDiskWrapper::VERSION_NUM);
|
|
|
|
CHECK(obj->GetMisc("NumSourceFactors") == m_input.size());
|
|
|
|
CHECK(obj->GetMisc("NumTargetFactors") == m_output.size());
|
|
|
|
CHECK(obj->GetMisc("NumScores") == m_numScoreComponents);
|
|
|
|
|
|
|
|
m_implementation.reset(obj);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PhraseDictionaryOnDisk::CleanUpAfterSentenceProcessing(InputType const& source)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-04-08 21:16:10 +04:00
|
|
|
}
|
|
|
|
|