File size: 1,139 Bytes
fd49381
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#pragma once

#include "moses/Syntax/BoundedPriorityContainer.h"
#include "moses/Syntax/PHyperedge.h"
#include "moses/Syntax/PVertex.h"
#include "moses/Syntax/SHyperedgeBundle.h"
#include "moses/Syntax/SHyperedgeBundleScorer.h"

#include "PHyperedgeToSHyperedgeBundle.h"
#include "PVertexToStackMap.h"

namespace Moses
{
namespace Syntax
{
namespace F2S
{

class RuleMatcherCallback
{
private:
  typedef BoundedPriorityContainer<SHyperedgeBundle> Container;

public:
  RuleMatcherCallback(const PVertexToStackMap &stackMap, std::size_t ruleLimit)
    : m_stackMap(stackMap)
    , m_container(ruleLimit) {}

  void operator()(const PHyperedge &hyperedge) {
    PHyperedgeToSHyperedgeBundle(hyperedge, m_stackMap, m_tmpBundle);
    float score = SHyperedgeBundleScorer::Score(m_tmpBundle);
    m_container.SwapIn(m_tmpBundle, score);
  }

  void ClearContainer() {
    m_container.LazyClear();
  }

  const Container &GetContainer() {
    return m_container;
  }

private:
  const PVertexToStackMap &m_stackMap;
  SHyperedgeBundle m_tmpBundle;
  BoundedPriorityContainer<SHyperedgeBundle> m_container;
};

}  // F2S
}  // Syntax
}  // Moses