ResultsManager.cpp
1.4 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
/*
* File: ResultsManager.cpp
* Author: mlenart
*
* Created on 24 czerwiec 2014, 17:09
*/
#include "ResultsManager.hpp"
#include "morfeusz2.h"
namespace morfeusz {
static const int initialSize = 1024;
ResultsManager::ResultsManager()
: results(new InterpMorf[initialSize]()),
resultsArraySize(initialSize) {
}
ResultsManager::~ResultsManager() {
delete results;
}
InterpMorf* ResultsManager::convertResults(const std::vector<MorphInterpretation>& res) {
if (res.size() + 1 > resultsArraySize) {
reserve(res.size() + 1);
}
for (unsigned int i = 0; i < res.size(); i++) {
results[i] = convertOneResult(res[i]);
}
results[res.size()].p = -1;
}
void ResultsManager::reserve(size_t size) {
while (resultsArraySize <= size) {
resultsArraySize *= 2;
}
delete results;
results = new InterpMorf[resultsArraySize];
}
InterpMorf ResultsManager::convertOneResult(const MorphInterpretation& res) {
InterpMorf convertedRes;
convertedRes.p = res.getStartNode();
convertedRes.k = res.getEndNode();
convertedRes.forma = const_cast<char*>(res.getOrth().c_str());
convertedRes.haslo = const_cast<char*>(res.getLemma().c_str());
convertedRes.interp = const_cast<char*>(res.getTag().c_str());
return convertedRes;
}
}