|
1
2
3
4
5
6
7
8
9
10
11
|
/*
* File: SegrulesFSA.hpp
* Author: mlenart
*
* Created on 12 marzec 2014, 17:52
*/
#ifndef SEGRULESFSA_HPP
#define SEGRULESFSA_HPP
#include <set>
|
|
12
|
#include <iostream>
|
|
13
14
15
|
#include "deserialization/deserializationUtils.hpp"
namespace morfeusz {
|
|
16
17
18
19
20
21
|
struct SegrulesState {
uint16_t offset;
bool accepting;
bool weak;
bool shiftOrthFromPrevious;
|
|
22
|
bool sink;
|
|
23
24
|
};
|
|
25
26
|
inline bool operator<(const SegrulesState& s1, const SegrulesState& s2) {
return s1.offset < s2.offset;
|
|
27
28
29
30
|
}
class SegrulesFSA {
public:
|
|
31
|
|
|
32
|
SegrulesFSA(const unsigned char* ptr) : initialState(), ptr(ptr), initialTransitions() {
|
|
33
|
SegrulesState state = {0, false, false, false, false};
|
|
34
|
initialState = state;
|
|
35
|
initialTransitions = createInitialTransitionsVector();
|
|
36
|
}
|
|
37
|
|
|
38
|
void proceedToNext(
|
|
39
|
const unsigned char segnum,
|
|
40
|
const SegrulesState& state,
|
|
41
42
|
bool atEndOfWord,
std::vector<SegrulesState>& res) const;
|
|
43
44
45
46
|
virtual ~SegrulesFSA() {
}
|
|
47
48
49
|
SegrulesState initialState;
private:
const unsigned char* ptr;
|
|
50
|
std::vector< std::vector<SegrulesState> > initialTransitions;
|
|
51
|
|
|
52
|
SegrulesState transition2State(const unsigned char* transitionPtr) const;
|
|
53
54
|
std::vector< std::vector<SegrulesState> > createInitialTransitionsVector();
|
|
55
56
57
58
59
60
61
62
63
64
65
|
void doProceedFromInitialState(
const unsigned char segnum,
bool atEndOfWord,
std::vector<SegrulesState>& res) const;
void doProceedFromNonInitialState(
const unsigned char segnum,
const SegrulesState& state,
bool atEndOfWord,
std::vector<SegrulesState>& res) const;
|
|
66
67
|
};
|
|
68
69
|
}
|
|
70
71
|
#endif /* SEGRULESFSA_HPP */
|