-
Notifications
You must be signed in to change notification settings - Fork 0
/
StaticMatcher.h
50 lines (44 loc) · 1.6 KB
/
StaticMatcher.h
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
#pragma once
#include "Base.h"
#include <map>
#include "trie.h"
class TStaticTemplateMatcher:public IMetaTemplateMatcher, private TTrie {
private:
weak_ptr<TTrieNode> moveto(weak_ptr<TTrieNode> node, char symbol);
weak_ptr<TTrieNode> suf_link_move(weak_ptr<TTrieNode> node);
weak_ptr<TTrieNode> hard_suf_link_move(weak_ptr<TTrieNode> node);
std::vector<size_t> template_lengths;
shared_ptr<TTrieNode> sink;
weak_ptr<TTrieNode> currentnode;
bool used;
void Handlesymbol(char ch, TMatchResults& ans, size_t &pos);
void AllowSameTemplates();
public:
TStaticTemplateMatcher();
size_t size() const;
TStringID AddTemplate(const std::string &templatestr) override;
TMatchResults MatchStream(ICharStream &stream) override;
friend class TDynamicTemplateMatcher;
friend class T2DSingleTemplateMatcher;
};
class TDynamicTemplateMatcher:public IMetaTemplateMatcher {
private:
std::vector<std::vector<TStaticTemplateMatcher>> Matchers;
std::vector<std::vector<size_t>> template_groups;
std::vector<string> templates;
TTrie CheckOnce;
public:
TDynamicTemplateMatcher();
TStringID AddTemplate(const std::string &templatestr) override;
TMatchResults MatchStream(ICharStream &stream) override;
};
class T2DSingleTemplateMatcher {
private:
TStaticTemplateMatcher Matcher;
size_t templatelength,templateheight,textlength, textheight;
void FindRowMatchSequence(const std::vector<size_t>& Matches, size_t columnnumber,
TMatchResults &Result,const std::vector<size_t>& equivalences);
public:
void AddTemplateTable(const std::vector<string> &templatetable);
TMatchResults MatchTable(const std::vector<string> &texttable);
};