|
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>
|
|
12
13
|
#include <set>
#include <utility>
|
|
14
15
|
#include "InterpretedChunk.hpp"
|
|
16
17
|
namespace morfeusz {
|
|
18
19
20
21
|
/**
* This class build inflection graph (indexes the nodes, takes into account segments marked as "weak").
* Takes care to make the number of nodes as little as possible.
*/
|
|
22
|
class InflexionGraph {
|
|
23
|
public:
|
|
24
|
|
|
25
|
InflexionGraph(): graph(), node2ChunkStartPtr(), onlyWeakPaths(true) {
|
|
26
27
|
}
|
|
28
29
30
|
struct Edge {
InterpretedChunk chunk;
|
|
31
|
unsigned int nextNode;
|
|
32
|
};
|
|
33
34
35
36
37
38
39
|
/**
* Adds new path to the graph.
*
* @param path
* @param weak
*/
|
|
40
|
void addPath(const std::vector<InterpretedChunk>& path, bool weak);
|
|
41
42
43
|
// void getResults(const Tagset& tagset, const CharsetConverter& charsetConverter, std::vector<MorphInterpretation>& results);
|
|
44
45
46
47
48
|
/**
* Return current graph.
*
* @return
*/
|
|
49
|
const std::vector< std::vector<InflexionGraph::Edge> >& getTheGraph();
|
|
50
|
|
|
51
52
53
54
55
|
/**
* True iff the graph is empty.
*
* @return
*/
|
|
56
|
bool empty() const;
|
|
57
|
|
|
58
59
60
|
/**
* Clears the graph.
*/
|
|
61
|
void clear();
|
|
62
|
|
|
63
|
private:
|
|
64
65
66
67
|
typedef std::pair<const char*, int> PathElement;
typedef std::set<PathElement> Path;
|
|
68
69
70
71
72
|
/**
* Adds an edge that starts a chunk.
*
* @param e
*/
|
|
73
|
void addStartEdge(const Edge& e);
|
|
74
75
76
77
78
79
|
/**
* Adds non-starting edge.
* @param startNode
* @param e
*/
|
|
80
|
void addMiddleEdge(unsigned int startNode, const Edge& e);
|
|
81
|
|
|
82
83
84
|
/**
* Minimizes the graph so it contains as little number of nodes as possible.
*/
|
|
85
|
void minimizeGraph();
|
|
86
|
|
|
87
88
89
90
91
92
93
94
95
96
97
|
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);
|
|
98
|
|
|
99
|
void repairLastNodeNumbers();
|
|
100
101
|
void repairOrthShifts();
|
|
102
|
|
|
103
|
std::vector< std::vector<Edge> > graph;
|
|
104
|
std::vector< const char* > node2ChunkStartPtr;
|
|
105
|
bool onlyWeakPaths;
|
|
106
107
|
};
|
|
108
109
|
}
|
|
110
111
|
#endif /* FLEXIONGRAPH_HPP */
|