00001 #include "moses/TranslationModel/PhraseDictionaryDynSuffixArray.h"
00002 #include "moses/FactorCollection.h"
00003 #include "moses/StaticData.h"
00004 #include "moses/TargetPhrase.h"
00005 #include <iomanip>
00006 #include <boost/foreach.hpp>
00007 using namespace std;
00008
00009 namespace Moses
00010 {
00011 PhraseDictionaryDynSuffixArray::
00012 PhraseDictionaryDynSuffixArray(const std::string &line)
00013 : PhraseDictionary(line, true)
00014 ,m_biSA(new BilingualDynSuffixArray())
00015 {
00016 ReadParameters();
00017 }
00018
00019
00020 void
00021 PhraseDictionaryDynSuffixArray::
00022 Load()
00023 {
00024 SetFeaturesToApply();
00025
00026 vector<float> weight = StaticData::Instance().GetWeights(this);
00027 m_biSA->Load(m_input, m_output, m_source, m_target, m_alignments, weight);
00028 }
00029
00030 PhraseDictionaryDynSuffixArray::
00031 ~PhraseDictionaryDynSuffixArray()
00032 {
00033 delete m_biSA;
00034 }
00035
00036 void
00037 PhraseDictionaryDynSuffixArray::
00038 SetParameter(const std::string& key, const std::string& value)
00039 {
00040 if (key == "source") {
00041 m_source = value;
00042 } else if (key == "target") {
00043 m_target = value;
00044 } else if (key == "alignment") {
00045 m_alignments = value;
00046 } else {
00047 PhraseDictionary::SetParameter(key, value);
00048 }
00049 }
00050
00051 const TargetPhraseCollection*
00052 PhraseDictionaryDynSuffixArray::
00053 GetTargetPhraseCollectionLEGACY(const Phrase& src) const
00054 {
00055 typedef map<SAPhrase, vector<float> >::value_type pstat_entry;
00056 map<SAPhrase, vector<float> > pstats;
00057 m_biSA->GatherCands(src,pstats);
00058
00059 TargetPhraseCollection *ret = new TargetPhraseCollection();
00060 BOOST_FOREACH(pstat_entry & e, pstats) {
00061 TargetPhrase* tp = m_biSA->GetMosesFactorIDs(e.first, src, this);
00062 tp->GetScoreBreakdown().Assign(this,e.second);
00063 tp->EvaluateInIsolation(src);
00064 ret->Add(tp);
00065 }
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 ret->NthElement(m_tableLimit);
00084 return ret;
00085 }
00086
00087 void
00088 PhraseDictionaryDynSuffixArray::
00089 insertSnt(string& source, string& target, string& alignment)
00090 {
00091 m_biSA->addSntPair(source, target, alignment);
00092
00093 }
00094
00095 void
00096 PhraseDictionaryDynSuffixArray::
00097 deleteSnt(unsigned , unsigned )
00098 {
00099
00100 }
00101
00102 ChartRuleLookupManager*
00103 PhraseDictionaryDynSuffixArray::
00104 CreateRuleLookupManager(const ChartParser &, const ChartCellCollectionBase&, std::size_t)
00105 {
00106 UTIL_THROW(util::Exception, "SCFG decoding not supported with dynamic suffix array");
00107 return 0;
00108 }
00109
00110 }