summaryrefslogtreecommitdiff
path: root/extractor/intersector.h
blob: 874ffc1b2ac8610a2a5edd94d80a9a37b4e6af09 (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
#ifndef _INTERSECTOR_H_
#define _INTERSECTOR_H_

#include <memory>
#include <tr1/unordered_map>
#include <vector>

#include <boost/functional/hash.hpp>

#include "binary_search_merger.h"
#include "linear_merger.h"

using namespace std;
using namespace tr1;

typedef boost::hash<vector<int> > vector_hash;
typedef unordered_map<vector<int>, vector<int>, vector_hash> Index;

class DataArray;
class MatchingComparator;
class Phrase;
class PhraseLocation;
class Precomputation;
class SuffixArray;
class Vocabulary;

class Intersector {
 public:
  Intersector(
      shared_ptr<Vocabulary> vocabulary,
      const Precomputation& precomputaiton,
      shared_ptr<SuffixArray> source_suffix_array,
      shared_ptr<MatchingComparator> comparator,
      bool use_baeza_yates);

  PhraseLocation Intersect(
      const Phrase& prefix, PhraseLocation& prefix_location,
      const Phrase& suffix, PhraseLocation& suffix_location,
      const Phrase& phrase);

 private:
  vector<int> Convert(const vector<int>& old_phrase,
      shared_ptr<DataArray> source_data_array);

  void ExtendPhraseLocation(const Phrase& phrase,
      PhraseLocation& phrase_location);

  shared_ptr<Vocabulary> vocabulary;
  shared_ptr<SuffixArray> suffix_array;
  shared_ptr<LinearMerger> linear_merger;
  shared_ptr<BinarySearchMerger> binary_search_merger;
  Index inverted_index;
  Index collocations;
  bool use_baeza_yates;
};

#endif