Welcome to mirror list, hosted at ThFree Co, Russian Federation.

sim-pe.cc « UG « TranslationModel « moses - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 58a70cab4290551f18829fa2553ac3a7b7a47ede (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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(&params, 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);
}