|
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
|
bool failed;
|
|
24
|
|
|
25
|
SegrulesState() : offset(0), accepting(false), weak(false), shiftOrthFromPrevious(false), sink(true), failed(true) {}
|
|
26
27
|
};
|
|
28
29
|
inline bool operator<(const SegrulesState& s1, const SegrulesState& s2) {
return s1.offset < s2.offset;
|
|
30
31
32
33
|
}
class SegrulesFSA {
public:
|
|
34
|
|
|
35
|
SegrulesFSA(const unsigned char* ptr) : initialState(), ptr(ptr), initialTransitions() {
|
|
36
37
38
39
40
41
|
SegrulesState state;
state.accepting = false;
state.weak = false;
state.shiftOrthFromPrevious = false;
state.sink = false;
state.failed = false;
|
|
42
|
initialState = state;
|
|
43
|
initialTransitions = createInitialTransitionsVector();
|
|
44
|
}
|
|
45
|
|
|
46
|
void proceedToNext(
|
|
47
|
const unsigned char segnum,
|
|
48
|
const SegrulesState& state,
|
|
49
50
|
bool atEndOfWord,
SegrulesState& resState) const;
|
|
51
52
53
54
|
virtual ~SegrulesFSA() {
}
|
|
55
56
57
|
SegrulesState initialState;
private:
const unsigned char* ptr;
|
|
58
|
std::vector< SegrulesState > initialTransitions;
|
|
59
|
|
|
60
|
SegrulesState transition2State(const unsigned char* transitionPtr) const;
|
|
61
|
|
|
62
|
std::vector< SegrulesState > createInitialTransitionsVector();
|
|
63
|
|
|
64
|
void doProceedFromInitialState(
|
|
65
|
const unsigned char segnum,
|
|
66
67
|
bool atEndOfWord,
SegrulesState& resState) const;
|
|
68
|
|
|
69
|
void doProceedFromNonInitialState(
|
|
70
71
|
const unsigned char segnum,
const SegrulesState& state,
|
|
72
73
|
bool atEndOfWord,
SegrulesState& resState) const;
|
|
74
75
|
};
|
|
76
77
|
}
|
|
78
79
|
#endif /* SEGRULESFSA_HPP */
|