Blame view

morfeusz/segrules/SegrulesFSA.hpp 1.67 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
24
};
Michał Lenart authored
25
26
inline bool operator<(const SegrulesState& s1, const SegrulesState& s2) {
    return s1.offset < s2.offset;
Michał Lenart authored
27
28
29
30
}

class SegrulesFSA {
public:
Michał Lenart authored
31
Michał Lenart authored
32
    SegrulesFSA(const unsigned char* ptr) : initialState(), ptr(ptr), initialTransitions() {
Michał Lenart authored
33
        SegrulesState state = {0, false, false, false, false};
Michał Lenart authored
34
        initialState = state;
Michał Lenart authored
35
        initialTransitions = createInitialTransitionsVector();
Michał Lenart authored
36
    }
Michał Lenart authored
37
Michał Lenart authored
38
    void proceedToNext(
Michał Lenart authored
39
            const unsigned char segnum,
Michał Lenart authored
40
            const SegrulesState& state,
Michał Lenart authored
41
42
            bool atEndOfWord,
            std::vector<SegrulesState>& res) const;
Michał Lenart authored
43
44
45
46

    virtual ~SegrulesFSA() {
    }
Michał Lenart authored
47
48
49
    SegrulesState initialState;
private:
    const unsigned char* ptr;
Michał Lenart authored
50
    std::vector< std::vector<SegrulesState> > initialTransitions;
Michał Lenart authored
51
Michał Lenart authored
52
    SegrulesState transition2State(const unsigned char* transitionPtr) const;
Michał Lenart authored
53
54

    std::vector< std::vector<SegrulesState> > createInitialTransitionsVector();
Michał Lenart authored
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;
Michał Lenart authored
66
67
};
Michał Lenart authored
68
69
}
Michał Lenart authored
70
71
#endif	/* SEGRULESFSA_HPP */