2008-06-11 14:52:57 +04:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
Moses - factored phrase-based language decoder
|
|
|
|
Copyright (C) 2006 University of Edinburgh
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
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-02-24 14:15:44 +03:00
|
|
|
#ifndef moses_PhraseDictionary_h
|
|
|
|
#define moses_PhraseDictionary_h
|
2008-06-11 14:52:57 +04:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <map>
|
2009-08-11 13:37:29 +04:00
|
|
|
#include <memory>
|
2008-06-11 14:52:57 +04:00
|
|
|
#include <list>
|
2012-09-13 21:16:13 +04:00
|
|
|
#include <stdexcept>
|
2008-06-11 14:52:57 +04:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2009-08-07 20:47:54 +04:00
|
|
|
|
|
|
|
#ifdef WITH_THREADS
|
|
|
|
#include <boost/thread/tss.hpp>
|
|
|
|
#endif
|
|
|
|
|
2012-11-27 19:08:31 +04:00
|
|
|
#include "moses/Phrase.h"
|
|
|
|
#include "moses/TargetPhrase.h"
|
|
|
|
#include "moses/TargetPhraseCollection.h"
|
|
|
|
#include "moses/DecodeFeature.h"
|
2013-07-09 17:19:35 +04:00
|
|
|
#include "moses/InputPath.h"
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2008-10-09 03:51:26 +04:00
|
|
|
namespace Moses
|
|
|
|
{
|
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
class StaticData;
|
|
|
|
class InputType;
|
|
|
|
class WordsRange;
|
2012-10-11 17:27:30 +04:00
|
|
|
class ChartCellCollectionBase;
|
2011-04-13 14:38:27 +04:00
|
|
|
class ChartRuleLookupManager;
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2009-08-07 20:47:54 +04:00
|
|
|
/**
|
|
|
|
* Abstract base class for phrase dictionaries (tables).
|
|
|
|
**/
|
2013-02-22 23:17:57 +04:00
|
|
|
class PhraseDictionary : public DecodeFeature
|
2011-02-24 16:14:42 +03:00
|
|
|
{
|
|
|
|
public:
|
2013-02-22 23:17:57 +04:00
|
|
|
PhraseDictionary(const std::string &description, const std::string &line);
|
|
|
|
|
2013-06-26 20:12:22 +04:00
|
|
|
virtual ~PhraseDictionary() {
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Load() = 0;
|
2013-02-05 23:13:26 +04:00
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
//! table limit number.
|
|
|
|
size_t GetTableLimit() const {
|
|
|
|
return m_tableLimit;
|
|
|
|
}
|
2013-02-05 22:47:25 +04:00
|
|
|
|
2013-07-11 23:18:06 +04:00
|
|
|
// LEGACY - The preferred method is to override GetTargetPhraseCollectionBatch().
|
2013-07-11 23:05:08 +04:00
|
|
|
// See class PhraseDictionaryMemory or PhraseDictionaryOnDisk for details
|
2011-02-24 16:14:42 +03:00
|
|
|
//! find list of translations that can translates src. Only for phrase input
|
2013-07-11 23:05:08 +04:00
|
|
|
virtual const TargetPhraseCollection *GetTargetPhraseCollection(const Phrase& src) const;
|
2011-02-24 16:14:42 +03:00
|
|
|
//! find list of translations that can translates a portion of src. Used by confusion network decoding
|
|
|
|
virtual const TargetPhraseCollection *GetTargetPhraseCollection(InputType const& src,WordsRange const& range) const;
|
2012-12-24 20:52:40 +04:00
|
|
|
|
2013-07-11 23:18:06 +04:00
|
|
|
virtual void GetTargetPhraseCollectionBatch(const InputPathList &phraseDictionaryQueue) const;
|
2013-07-11 23:05:08 +04:00
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
//! Create entry for translation of source to targetPhrase
|
2013-06-26 20:12:22 +04:00
|
|
|
virtual void InitializeForInput(InputType const& source) {
|
|
|
|
}
|
2012-12-24 19:17:13 +04:00
|
|
|
// clean up temporary memory, called after processing each sentence
|
2013-06-26 20:12:22 +04:00
|
|
|
virtual void CleanUpAfterSentenceProcessing(const InputType& source) {
|
|
|
|
}
|
2011-02-24 16:14:42 +03:00
|
|
|
|
|
|
|
//! Create a sentence-specific manager for SCFG rule lookup.
|
|
|
|
virtual ChartRuleLookupManager *CreateRuleLookupManager(
|
|
|
|
const InputType &,
|
2012-10-11 17:27:30 +04:00
|
|
|
const ChartCellCollectionBase &) = 0;
|
2011-02-24 16:14:42 +03:00
|
|
|
|
2013-06-26 20:12:22 +04:00
|
|
|
const std::string &GetFilePath() const {
|
|
|
|
return m_filePath;
|
2012-09-13 21:16:13 +04:00
|
|
|
}
|
|
|
|
|
2013-06-26 20:12:22 +04:00
|
|
|
const std::vector<FeatureFunction*> &GetFeaturesToApply() const {
|
|
|
|
return m_featuresToApply;
|
2012-09-13 21:16:13 +04:00
|
|
|
}
|
|
|
|
|
2013-06-26 20:12:22 +04:00
|
|
|
void SetParameter(const std::string& key, const std::string& value);
|
2013-02-25 18:50:33 +04:00
|
|
|
|
2013-07-03 19:57:23 +04:00
|
|
|
|
2013-02-22 23:17:57 +04:00
|
|
|
protected:
|
|
|
|
size_t m_tableLimit;
|
2011-02-24 16:14:42 +03:00
|
|
|
std::string m_filePath;
|
|
|
|
|
2013-06-26 20:12:22 +04:00
|
|
|
// features to apply evaluate target phrase when loading.
|
|
|
|
// NOT when creating translation options. Those are in DecodeStep
|
|
|
|
std::vector<FeatureFunction*> m_featuresToApply;
|
|
|
|
|
|
|
|
// MUST be called at the start of Load()
|
|
|
|
void SetFeaturesToApply();
|
2009-08-07 20:47:54 +04:00
|
|
|
};
|
2009-02-06 18:43:06 +03:00
|
|
|
|
2008-10-09 03:51:26 +04:00
|
|
|
}
|
2010-02-24 14:15:44 +03:00
|
|
|
#endif
|