ResultsManager.cpp
1.52 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
/*
* File: ResultsManager.cpp
* Author: mlenart
*
* Created on 24 czerwiec 2014, 17:09
*/
#include "ResultsManager.hpp"
#include "morfeusz2.h"
#include <iostream>
using namespace std;
namespace morfeusz {
static const int initialSize = 1024;
ResultsManager::ResultsManager(const Morfeusz* morfeusz)
: morfeusz(morfeusz), 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;
return results;
}
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.startNode;
convertedRes.k = res.endNode;
convertedRes.forma = const_cast<char*>(res.orth.c_str());
convertedRes.haslo = const_cast<char*>(res.lemma.c_str());
convertedRes.interp = const_cast<char*>(morfeusz->getIdResolver().getTag(res.tagId).c_str());
return convertedRes;
}
}