00001 #include "mmsapt.h"
00002 #include "moses/Manager.h"
00003 #include "moses/TranslationModel/PhraseDictionaryTreeAdaptor.h"
00004 #include <boost/foreach.hpp>
00005 #include <boost/format.hpp>
00006 #include <boost/tokenizer.hpp>
00007 #include <boost/shared_ptr.hpp>
00008 #include <algorithm>
00009 #include <iostream>
00010
00011 using namespace Moses;
00012 using namespace sapt;
00013 using namespace std;
00014 using namespace boost;
00015
00016 vector<FactorType> fo(1,FactorType(0));
00017
00018 ostream&
00019 operator<<(ostream& out, Hypothesis const* x)
00020 {
00021 vector<const Hypothesis*> H;
00022 for (const Hypothesis* h = x; h; h = h->GetPrevHypo())
00023 H.push_back(h);
00024 for (; H.size(); H.pop_back())
00025 {
00026 Phrase const& p = H.back()->GetCurrTargetPhrase();
00027 for (size_t pos = 0 ; pos < p.GetSize() ; pos++)
00028 out << *p.GetFactor(pos, 0) << (H.size() ? " " : "");
00029 }
00030 return out;
00031 }
00032
00033 vector<FactorType> ifo;
00034 size_t lineNumber;
00035
00036 string
00037 translate(string const& source)
00038 {
00039 StaticData const& global = StaticData::Instance();
00040
00041 Sentence sentence;
00042 istringstream ibuf(source+"\n");
00043 sentence.Read(ibuf,ifo);
00044
00045
00046 Manager manager(sentence, global.GetSearchAlgorithm());
00047 manager.ProcessSentence();
00048
00049 ostringstream obuf;
00050 const Hypothesis* h = manager.GetBestHypothesis();
00051 obuf << h;
00052 return obuf.str();
00053
00054 }
00055
00056 int main(int argc, char* argv[])
00057 {
00058 Parameter params;
00059 if (!params.LoadParam(argc,argv) || !StaticData::LoadDataStatic(¶ms, argv[0]))
00060 exit(1);
00061
00062 StaticData const& global = StaticData::Instance();
00063 global.SetVerboseLevel(0);
00064 ifo = global.GetInputFactorOrder();
00065
00066 lineNumber = 0;
00067 string source, target, alignment;
00068 while (getline(cin,source))
00069 {
00070 getline(cin,target);
00071 getline(cin,alignment);
00072 cout << "[S] " << source << endl;
00073 cout << "[H] " << translate(source) << endl;
00074 cout << "[T] " << target << endl;
00075 Mmsapt* pdsa = reinterpret_cast<Mmsapt*>(PhraseDictionary::GetColl()[0]);
00076 pdsa->add(source,target,alignment);
00077 cout << "[X] " << translate(source) << endl;
00078 cout << endl;
00079 }
00080 exit(0);
00081 }
00082
00083
00084