FlexionGraph.cpp
1.45 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
#include "FlexionGraph.hpp"
FlexionGraph::FlexionGraph(int startNode)
: startNode(startNode) {
}
void FlexionGraph::addPath(const std::vector<InterpretedChunk>& path) {
for (const InterpretedChunk& chunk: path) {
if (&chunk == &(path.back())) {
Edge e = { chunk, -1 };
vector<Edge> v;
v.push_back(e);
this->graph.push_back(v);
// this->graph[node].push_back(e);
}
else if (&chunk == &(path.front())) {
Edge e = { chunk, (int) this->graph.size() };
this->graph[0].push_back(e);
}
else {
Edge e = { chunk, (int) this->graph.size() };
vector<Edge> v;
v.push_back(e);
this->graph.push_back(v);
}
}
}
void FlexionGraph::appendToResults(const Tagset& tagset, std::vector<MorphInterpretation>& results) {
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());
}
}
}