Blame view

morfeusz/InflexionGraph.hpp 1.63 KB
Michał Lenart authored
1
2
3
4
5
6
7
8
9
10
11
/* 
 * File:   FlexionGraph.hpp
 * Author: mlenart
 *
 * Created on 18 listopad 2013, 15:03
 */

#ifndef FLEXIONGRAPH_HPP
#define	FLEXIONGRAPH_HPP

#include <vector>
Michał Lenart authored
12
13
#include <set>
#include <utility>
Michał Lenart authored
14
15
#include "InterpretedChunk.hpp"
Michał Lenart authored
16
class InflexionGraph {
Michał Lenart authored
17
public:
Michał Lenart authored
18
Michał Lenart authored
19
    InflexionGraph(): graph(), node2ChunkStartPtr(), onlyWeakPaths(true) {
Michał Lenart authored
20
21

    }
Michał Lenart authored
22
23
24

    struct Edge {
        InterpretedChunk chunk;
Michał Lenart authored
25
        unsigned int nextNode;
Michał Lenart authored
26
27
    };
Michał Lenart authored
28
    void addPath(const std::vector<InterpretedChunk>& path, bool weak);
Michał Lenart authored
29
30
31

    //    void getResults(const Tagset& tagset, const CharsetConverter& charsetConverter, std::vector<MorphInterpretation>& results);
Michał Lenart authored
32
    std::vector< std::vector<InflexionGraph::Edge> >& getTheGraph() {
Michał Lenart authored
33
        minimizeGraph();
Michał Lenart authored
34
        repairLastNodeNumbers();
Michał Lenart authored
35
36
37
        return this->graph;
    }
Michał Lenart authored
38
    bool empty() const;
Michał Lenart authored
39
40
41


    //    virtual ~FlexionGraph();
Michał Lenart authored
42
private:
Michał Lenart authored
43
44
45
46

    typedef std::pair<const char*, int> PathElement;
    typedef std::set<PathElement> Path;
Michał Lenart authored
47
    void addStartEdge(const Edge& e);
Michał Lenart authored
48
Michał Lenart authored
49
    void addMiddleEdge(unsigned int startNode, const Edge& e);
Michał Lenart authored
50
Michał Lenart authored
51
    void minimizeGraph();
Michał Lenart authored
52
53
54
55
56
57
58
59
60
61
62
63

    bool canMergeNodes(unsigned int node1, unsigned int node2);

    void doMergeNodes(unsigned int node1, unsigned int node2);

    bool tryToMergeTwoNodes();

    std::set<Path> getPossiblePaths(unsigned int node);

    void redirectEdges(unsigned int fromNode, unsigned int toNode);

    void doRemoveNode(unsigned int node);
Michał Lenart authored
64
Michał Lenart authored
65
    void repairLastNodeNumbers();
Michał Lenart authored
66
67

    void repairOrthShifts();
Michał Lenart authored
68
Michał Lenart authored
69
    std::vector< std::vector<Edge> > graph;
Michał Lenart authored
70
    std::vector< const char* > node2ChunkStartPtr;
Michał Lenart authored
71
    bool onlyWeakPaths;
Michał Lenart authored
72
73
74
75
};

#endif	/* FLEXIONGRAPH_HPP */