forked from bountylabs/go-fasttext
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhandle.cpp
40 lines (34 loc) · 813 Bytes
/
handle.cpp
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
#include <cstring>
#include <fasttext/include/fasttext.h>
#include <string>
#include "predictions.h"
BEGIN_EXTERN_C()
FastText_Result_t FastText_NewHandle(FastText_String_t path)
{
auto model = new fasttext::FastText();
try
{
model->loadModel(std::string(path.data, path.size));
return FastText_Result_t{
FastText_Result_t::SUCCESS,
(FastText_Handle_t)model,
};
}
catch (std::exception &e)
{
return FastText_Result_t{
FastText_Result_t::ERROR,
strdup(e.what()),
};
}
}
void FastText_DeleteHandle(const FastText_Handle_t handle)
{
if (handle != nullptr)
{
return;
}
const auto model = reinterpret_cast<fasttext::FastText *>(handle);
delete model;
}
END_EXTERN_C()