Blame view

morfeusz/segrules/SegrulesFSA.hpp 1.89 KB
Michał Lenart authored
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>
Michał Lenart authored
12
#include <iostream>
Michał Lenart authored
13
14
15
#include "deserialization/deserializationUtils.hpp"

namespace morfeusz {
Michał Lenart authored
16
17
18
19
20
21

struct SegrulesState {
    uint16_t offset;
    bool accepting;
    bool weak;
    bool shiftOrthFromPrevious;
Michał Lenart authored
22
    bool sink;
Michał Lenart authored
23
    bool failed;
Michał Lenart authored
24
Michał Lenart authored
25
    SegrulesState() : offset(0), accepting(false), weak(false), shiftOrthFromPrevious(false), sink(true), failed(true) {}
Michał Lenart authored
26
27
};
Michał Lenart authored
28
29
inline bool operator<(const SegrulesState& s1, const SegrulesState& s2) {
    return s1.offset < s2.offset;
Michał Lenart authored
30
31
32
33
}

class SegrulesFSA {
public:
Michał Lenart authored
34
Michał Lenart authored
35
    SegrulesFSA(const unsigned char* ptr) : initialState(), ptr(ptr), initialTransitions() {
Michał Lenart authored
36
37
38
39
40
41
        SegrulesState state;
        state.accepting = false;
        state.weak = false;
        state.shiftOrthFromPrevious = false;
        state.sink = false;
        state.failed = false;
Michał Lenart authored
42
        initialState = state;
Michał Lenart authored
43
        initialTransitions = createInitialTransitionsVector();
Michał Lenart authored
44
    }
Michał Lenart authored
45
Michał Lenart authored
46
    void proceedToNext(
Michał Lenart authored
47
            const unsigned char segnum,
Michał Lenart authored
48
            const SegrulesState& state,
Michał Lenart authored
49
50
            bool atEndOfWord,
            SegrulesState& resState) const;
Michał Lenart authored
51
52
53
54

    virtual ~SegrulesFSA() {
    }
Michał Lenart authored
55
56
57
    SegrulesState initialState;
private:
    const unsigned char* ptr;
Michał Lenart authored
58
    std::vector< SegrulesState > initialTransitions;
Michał Lenart authored
59
Michał Lenart authored
60
    SegrulesState transition2State(const unsigned char* transitionPtr) const;
Michał Lenart authored
61
Michał Lenart authored
62
    std::vector< SegrulesState > createInitialTransitionsVector();
Michał Lenart authored
63
Michał Lenart authored
64
    void doProceedFromInitialState(
Michał Lenart authored
65
            const unsigned char segnum,
Michał Lenart authored
66
67
            bool atEndOfWord,
            SegrulesState& resState) const;
Michał Lenart authored
68
Michał Lenart authored
69
    void doProceedFromNonInitialState(
Michał Lenart authored
70
71
            const unsigned char segnum,
            const SegrulesState& state,
Michał Lenart authored
72
73
            bool atEndOfWord,
            SegrulesState& resState) const;
Michał Lenart authored
74
75
};
Michał Lenart authored
76
77
}
Michał Lenart authored
78
79
#endif	/* SEGRULESFSA_HPP */