00001 #include "moses/TranslationTask.h"
00002
00003 #include <boost/foreach.hpp>
00004 #include <boost/format.hpp>
00005 #include <boost/tokenizer.hpp>
00006 #include <boost/shared_ptr.hpp>
00007
00008 #include <iostream>
00009
00010 using namespace Moses;
00011 using namespace std;
00012 using namespace boost;
00013
00014 int main(int argc, char const* argv[])
00015 {
00016
00017 Parameter params;
00018 if (!params.LoadParam(argc, argv) || !StaticData::LoadDataStatic(¶ms, argv[0])) {
00019 exit(2);
00020 }
00021
00022 StaticData const& global = StaticData::Instance();
00023 global.SetVerboseLevel(0);
00024 vector<FactorType> ifo = global.options()->input.factor_order;
00025
00026
00027 PhraseDictionary* pt = PhraseDictionary::GetColl()[PhraseDictionary::GetColl().size() - 1];
00028
00029
00030 unordered_set<string> seen;
00031
00032 string context_weight_spec;
00033 params.SetParameter(context_weight_spec,"context-weights",string(""));
00034 boost::shared_ptr<ContextScope> scope(new ContextScope);
00035 boost::shared_ptr<IOWrapper> none;
00036 if (context_weight_spec.size())
00037 scope->SetContextWeights(context_weight_spec);
00038
00039 string line;
00040 while (true) {
00041
00042 if (getline(cin, line, '\n').eof()) {
00043 break;
00044 }
00045 vector<string> words = Tokenize(line);
00046
00047
00048 for (size_t i = 0; i < words.size(); ++i) {
00049
00050 for (size_t j = i + 1; j <= words.size(); ++j) {
00051
00052 string phrase_str = Join(" ", words.begin() + i, words.begin() + j);
00053
00054 if (seen.find(phrase_str) != seen.end()) {
00055 continue;
00056 }
00057 seen.insert(phrase_str);
00058
00059
00060 boost::shared_ptr<Sentence> phrase(new Sentence(global.options()));
00061 phrase->init(phrase_str);
00062 Phrase const& src = *phrase;
00063
00064
00065
00066 boost::shared_ptr<TranslationTask> ttask;
00067 ttask = TranslationTask::create(phrase, none, scope);
00068
00069
00070 BOOST_FOREACH(PhraseDictionary* p, PhraseDictionary::GetColl()) {
00071 p->InitializeForInput(ttask);
00072 }
00073
00074
00075 TargetPhraseCollection::shared_ptr tgts = pt->GetTargetPhraseCollectionLEGACY(ttask, src);
00076
00077 if (!tgts) {
00078 break;
00079 }
00080
00081 for (size_t k = 0; k < tgts->GetSize(); ++k) {
00082 TargetPhrase const& tgt = static_cast<TargetPhrase const&>(*(*tgts)[k]);
00083 ScoreComponentCollection const& scc = tgt.GetScoreBreakdown();
00084 size_t start = pt->GetIndex();
00085 size_t stop = start + pt->GetNumScoreComponents();
00086 FVector const& scores = scc.GetScoresVector();
00087 cout << src << "||| " << static_cast<Phrase const>(tgt) << "|||";
00088 for (size_t k = start; k < stop; ++k) {
00089 float f = scores[k];
00090 cout << " " << f;
00091 }
00092 cout << " ||| " << tgt.GetAlignTerm() << endl;
00093 }
00094 }
00095 }
00096 }
00097 }