FlexionGraph.cpp
2.21 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
#include <string>
#include "utils.hpp"
#include "FlexionGraph.hpp"
FlexionGraph::FlexionGraph(int startNode)
: startNode(startNode) {
}
static inline void debugPath(const std::vector<InterpretedChunk>& path) {
for (const InterpretedChunk& chunk: path) {
std::string text(chunk.chunk, chunk.chunkLength);
DEBUG(text);
DEBUG(chunk.chunkLength);
}
}
void FlexionGraph::addStartEdge(const Edge& e) {
if (this->graph.empty()) {
this->graph.push_back(vector<Edge>());
}
this->graph[0].push_back(e);
}
void FlexionGraph::addMiddleEdge(const Edge& e) {
this->graph.push_back(vector<Edge>(1, e));
}
void FlexionGraph::addPath(const std::vector<InterpretedChunk>& path) {
// debugPath(path);
for (const InterpretedChunk& chunk: path) {
if (&chunk == &(path.front())
&& &chunk == &(path.back())) {
Edge e = { chunk, -1 };
this->addStartEdge(e);
}
else if (&chunk == &(path.front())) {
Edge e = { chunk, (int) this->graph.size() + 1 };
this->addStartEdge(e);
}
else if (&chunk == &(path.back())) {
Edge e = { chunk, -1 };
this->addMiddleEdge(e);
}
else {
Edge e = { chunk, (int) this->graph.size() + 1 };
this->addMiddleEdge(e);
}
}
}
void FlexionGraph::minimizeGraph() {
if (this->graph.size() > 2) {
}
}
void FlexionGraph::appendToResults(const Tagset& tagset, std::vector<MorphInterpretation>& results) {
this->minimizeGraph();
int endNode = graph.size();
for (unsigned int i = 0; i < graph.size(); i++) {
vector<Edge>& edges = graph[i];
for (Edge& e: edges) {
int realStartNode = i + this->startNode;
int realEndNode = e.nextNode == -1 ? (endNode + this->startNode) : (i + e.nextNode);
string orth(e.chunk.chunk, e.chunk.chunkLength);
vector<MorphInterpretation> interps = e.chunk.interpsGroup.getRealInterps(orth, realStartNode, realEndNode, tagset);
results.insert(results.end(), interps.begin(), interps.end());
}
}
}
bool FlexionGraph::empty() const {
return this->graph.empty();
}