InflexionGraph.hpp
1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* File: FlexionGraph.hpp
* Author: mlenart
*
* Created on 18 listopad 2013, 15:03
*/
#ifndef FLEXIONGRAPH_HPP
#define FLEXIONGRAPH_HPP
#include <vector>
#include <set>
#include <utility>
#include "InterpretedChunk.hpp"
class InflexionGraph {
public:
InflexionGraph(): graph(), node2ChunkStartPtr(), onlyWeakPaths(true) {
}
struct Edge {
InterpretedChunk chunk;
unsigned long nextNode;
};
void addPath(const std::vector<InterpretedChunk>& path, bool weak);
// void getResults(const Tagset& tagset, const CharsetConverter& charsetConverter, std::vector<MorphInterpretation>& results);
const std::vector< std::vector<InflexionGraph::Edge> >& getTheGraph() {
minimizeGraph();
repairLastNodeNumbers();
return this->graph;
}
bool empty() const;
void clear();
// virtual ~FlexionGraph();
private:
typedef std::pair<const char*, int> PathElement;
typedef std::set<PathElement> Path;
void addStartEdge(const Edge& e);
void addMiddleEdge(unsigned int startNode, const Edge& e);
void minimizeGraph();
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);
void repairLastNodeNumbers();
void repairOrthShifts();
std::vector< std::vector<Edge> > graph;
std::vector< const char* > node2ChunkStartPtr;
bool onlyWeakPaths;
};
#endif /* FLEXIONGRAPH_HPP */