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

InputType.cpp « moses2 - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: af5b61ff9391950297f1ebfe33c7ed500819f64b (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
 * InputType.cpp
 *
 *  Created on: 14 Dec 2015
 *      Author: hieu
 */

#include "InputType.h"
#include "System.h"
#include <iostream>

using namespace std;

namespace Moses2
{
//////////////////////////////////////////////////////////////////////////////
InputType::XMLOption::XMLOption(MemPool &pool, const std::string &nodeName, size_t vStartPos)
  :startPos(vStartPos)
  ,prob(0)
  ,m_entity(NULL)
{
  m_nodeName = pool.Allocate<char>(nodeName.size() + 1);
  strcpy(m_nodeName, nodeName.c_str());
}

void InputType::XMLOption::SetTranslation(MemPool &pool, const std::string &val)
{
  m_translation = pool.Allocate<char>(val.size() + 1);
  strcpy(m_translation, val.c_str());
}

void InputType::XMLOption::SetEntity(MemPool &pool, const std::string &val)
{
  m_entity = pool.Allocate<char>(val.size() + 1);
  strcpy(m_entity, val.c_str());
}

std::string InputType::XMLOption::Debug(const System &system) const
{
  std::stringstream out;
  out << "[" << startPos << "," << phraseSize << "]="
      << m_nodeName << ","
      << m_translation << ","
      << prob;
  if (m_entity) {
    out << "," << m_entity;
  }
  return out.str();
}

//////////////////////////////////////////////////////////////////////////////

InputType::InputType(MemPool &pool)
  :m_reorderingConstraint(pool)
  ,m_xmlOptions(pool)
  ,m_xmlCoverageMap(pool)
{
}

InputType::~InputType()
{
  // TODO Auto-generated destructor stub
}

void InputType::Init(const System &system, size_t size, int max_distortion)
{
  m_reorderingConstraint.InitializeWalls(size, max_distortion);

  if (system.options.input.xml_policy != XmlPassThrough) {
    m_xmlCoverageMap.assign(size, false);
  }
}

void InputType::AddXMLOption(const System &system, const XMLOption *xmlOption)
{
  m_xmlOptions.push_back(xmlOption);

  if (system.options.input.xml_policy != XmlPassThrough) {
    for(size_t j = xmlOption->startPos; j < xmlOption->startPos + xmlOption->phraseSize; ++j) {
      m_xmlCoverageMap[j]=true;
    }
  }
}

bool InputType::XmlOverlap(size_t startPos, size_t endPos) const
{
  for (size_t pos = startPos; pos <=  endPos ; pos++) {
    if (pos < m_xmlCoverageMap.size() && m_xmlCoverageMap[pos]) {
      return true;
    }
  }
  return false;
}

std::string InputType::Debug(const System &system) const
{
  cerr << "InputType::Debug" << endl;
}

} /* namespace Moses2 */