00001
00002 #include "SkeletonPT.h"
00003 #include "moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerSkeleton.h"
00004
00005 using namespace std;
00006
00007 namespace Moses
00008 {
00009 SkeletonPT::SkeletonPT(const std::string &line)
00010 : PhraseDictionary(line, true)
00011 {
00012 ReadParameters();
00013 }
00014
00015 void SkeletonPT::Load(AllOptions::ptr const& opts)
00016 {
00017 m_options = opts;
00018 SetFeaturesToApply();
00019 }
00020
00021 void SkeletonPT::InitializeForInput(ttasksptr const& ttask)
00022 {
00023 ReduceCache();
00024 }
00025
00026 void SkeletonPT::GetTargetPhraseCollectionBatch(const InputPathList &inputPathQueue) const
00027 {
00028 CacheColl &cache = GetCache();
00029
00030 InputPathList::const_iterator iter;
00031 for (iter = inputPathQueue.begin(); iter != inputPathQueue.end(); ++iter) {
00032 InputPath &inputPath = **iter;
00033 const Phrase &sourcePhrase = inputPath.GetPhrase();
00034
00035 TargetPhrase *tp = CreateTargetPhrase(sourcePhrase);
00036 TargetPhraseCollection::shared_ptr tpColl(new TargetPhraseCollection);
00037 tpColl->Add(tp);
00038
00039
00040 size_t hash = hash_value(sourcePhrase);
00041 std::pair<TargetPhraseCollection::shared_ptr, clock_t>
00042 value(tpColl, clock());
00043 cache[hash] = value;
00044
00045 inputPath.SetTargetPhrases(*this, tpColl, NULL);
00046 }
00047 }
00048
00049 TargetPhrase *SkeletonPT::CreateTargetPhrase(const Phrase &sourcePhrase) const
00050 {
00051
00052 assert(sourcePhrase.GetSize());
00053 assert(m_output.size() == 1);
00054
00055 string str = sourcePhrase.GetWord(0).GetFactor(0)->GetString().as_string();
00056 str = "SkeletonPT:" + str;
00057
00058 TargetPhrase *tp = new TargetPhrase(this);
00059 Word &word = tp->AddWord();
00060 word.CreateFromString(Output, m_output, str, false);
00061
00062
00063 vector<float> scores(m_numScoreComponents, 1.3);
00064 tp->GetScoreBreakdown().PlusEquals(this, scores);
00065
00066
00067 tp->EvaluateInIsolation(sourcePhrase, GetFeaturesToApply());
00068
00069 return tp;
00070 }
00071
00072 ChartRuleLookupManager* SkeletonPT::CreateRuleLookupManager(const ChartParser &parser,
00073 const ChartCellCollectionBase &cellCollection,
00074 std::size_t )
00075 {
00076 return new ChartRuleLookupManagerSkeleton(parser, cellCollection, *this);
00077 }
00078
00079 TO_STRING_BODY(SkeletonPT);
00080
00081
00082 ostream& operator<<(ostream& out, const SkeletonPT& phraseDict)
00083 {
00084 return out;
00085 }
00086
00087 }