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

TargetConstituentBoundariesRightAdjacentPhraseProperty.cpp « PP « moses - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 198ecfa38a9917554641c4f7bad560663cd3649c (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
#include "moses/PP/TargetConstituentBoundariesRightAdjacentPhraseProperty.h"
#include "moses/FactorCollection.h"
#include "moses/Util.h"
#include <iostream>
#include <queue>
#include <set>
#include <ostream>

namespace Moses
{

void TargetConstituentBoundariesRightAdjacentPhraseProperty::ProcessValue(const std::string &value)
{
  FactorCollection &factorCollection = FactorCollection::Instance();
  std::vector<std::string> tokens;
  Tokenize(tokens, value, " ");
  std::vector<std::string>::const_iterator tokenIter = tokens.begin();
  while (tokenIter != tokens.end()) {
    try {

      std::vector<std::string> constituents;
      Tokenize(constituents, *tokenIter, "<");
      ++tokenIter;
      float count = std::atof( tokenIter->c_str() );
      ++tokenIter;

      std::set<const Factor* > dedup;

      for ( std::vector<std::string>::iterator constituentIter = constituents.begin();
            constituentIter != constituents.end(); ++constituentIter ) {

        const Factor* constituentFactor = factorCollection.AddFactor(*constituentIter,false);

        std::pair< std::set<const Factor* >::iterator, bool > dedupIns =
          dedup.insert(constituentFactor);
        if ( dedupIns.second ) {

          std::pair< TargetConstituentBoundariesRightAdjacentCollection::iterator, bool > inserted =
            m_constituentsCollection.insert(std::make_pair(constituentFactor,count));
          if ( !inserted.second ) {
            (inserted.first)->second += count;
          }
        }
      }

    } catch (const std::exception &e) {
      UTIL_THROW2("TargetConstituentBoundariesRightAdjacentPhraseProperty: Read error. Flawed property?  " << value);
    }
  }
};

void TargetConstituentBoundariesRightAdjacentPhraseProperty::Print(std::ostream& out) const
{
  for ( TargetConstituentBoundariesRightAdjacentCollection::const_iterator it = m_constituentsCollection.begin();
        it != m_constituentsCollection.end(); ++it ) {
    if ( it != m_constituentsCollection.begin() ) {
      out << " ";
    }
    out << *(it->first) << " " << it->second;
  }
}

} // namespace Moses