diff options
author | Ulrich Germann <ugermann@inf.ed.ac.uk> | 2014-07-09 05:41:28 +0400 |
---|---|---|
committer | Ulrich Germann <ugermann@inf.ed.ac.uk> | 2014-07-09 05:41:28 +0400 |
commit | 4d41211c2cd6eb75c5a229c10e98fdfa1acff3b4 (patch) | |
tree | 142dca24625b301147a931f728825dd40cf74e53 /moses/TranslationModel/UG/sim-pe.cc | |
parent | 28d64e23396cba53a83b75e01e9977db636e2285 (diff) |
Major overhaul of Mmsapt. Reorganization of old and addition of new features in phrase tables. Many critical bug fixes.
Diffstat (limited to 'moses/TranslationModel/UG/sim-pe.cc')
-rw-r--r-- | moses/TranslationModel/UG/sim-pe.cc | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/moses/TranslationModel/UG/sim-pe.cc b/moses/TranslationModel/UG/sim-pe.cc new file mode 100644 index 000000000..58a70cab4 --- /dev/null +++ b/moses/TranslationModel/UG/sim-pe.cc @@ -0,0 +1,83 @@ +#include "mmsapt.h" +#include "moses/Manager.h" +#include "moses/TranslationModel/PhraseDictionaryTreeAdaptor.h" +#include <boost/foreach.hpp> +#include <boost/format.hpp> +#include <boost/tokenizer.hpp> +#include <boost/shared_ptr.hpp> +#include <algorithm> +#include <iostream> + +using namespace Moses; +using namespace bitext; +using namespace std; +using namespace boost; + +vector<FactorType> fo(1,FactorType(0)); + +ostream& +operator<<(ostream& out, Hypothesis const* x) +{ + vector<const Hypothesis*> H; + for (const Hypothesis* h = x; h; h = h->GetPrevHypo()) + H.push_back(h); + for (; H.size(); H.pop_back()) + { + Phrase const& p = H.back()->GetCurrTargetPhrase(); + for (size_t pos = 0 ; pos < p.GetSize() ; pos++) + out << *p.GetFactor(pos, 0) << (H.size() ? " " : ""); + } + return out; +} + +vector<FactorType> ifo; +size_t lineNumber; + +string +translate(string const& source) +{ + StaticData const& global = StaticData::Instance(); + + Sentence sentence; + istringstream ibuf(source+"\n"); + sentence.Read(ibuf,ifo); + + Manager manager(lineNumber, sentence, global.GetSearchAlgorithm()); + manager.ProcessSentence(); + + ostringstream obuf; + const Hypothesis* h = manager.GetBestHypothesis(); + obuf << h; + return obuf.str(); + +} + +int main(int argc, char* argv[]) +{ + Parameter params; + if (!params.LoadParam(argc,argv) || !StaticData::LoadDataStatic(¶ms, argv[0])) + exit(1); + + StaticData const& global = StaticData::Instance(); + global.SetVerboseLevel(0); + ifo = global.GetInputFactorOrder(); + + lineNumber = 0; // TODO: Include sentence request number here? + string source, target, alignment; + while (getline(cin,source)) + { + getline(cin,target); + getline(cin,alignment); + cout << "[S] " << source << endl; + cout << "[H] " << translate(source) << endl; + cout << "[T] " << target << endl; + Mmsapt* pdsa = reinterpret_cast<Mmsapt*>(PhraseDictionary::GetColl()[0]); + pdsa->add(source,target,alignment); + cout << "[X] " << translate(source) << endl; + cout << endl; + } + exit(0); +} + + + |