wowool-sdk-cpp 3.6.1__cp313-cp313-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- wowool/native/core/wowool_sdk.cpp +655 -0
- wowool/package/lib/_wowool_plugin.cp313-win_amd64.pyd +0 -0
- wowool/package/lib/_wowool_sdk.cp313-win_amd64.pyd +0 -0
- wowool/package/lib/afst++.exe +0 -0
- wowool/package/lib/concrt140.dll +0 -0
- wowool/package/lib/icudt77.dll +0 -0
- wowool/package/lib/icuuc77.dll +0 -0
- wowool/package/lib/msvcp140.dll +0 -0
- wowool/package/lib/msvcp140_1.dll +0 -0
- wowool/package/lib/msvcp140_2.dll +0 -0
- wowool/package/lib/msvcp140_atomic_wait.dll +0 -0
- wowool/package/lib/msvcp140_codecvt_ids.dll +0 -0
- wowool/package/lib/vcruntime140.dll +0 -0
- wowool/package/lib/vcruntime140_1.dll +0 -0
- wowool/package/lib/woc++.exe +0 -0
- wowool/package/lib/wow++.exe +0 -0
- wowool/package/lib/wowool.dll +0 -0
- wowool/package/lib/wowool_plugin.py +22 -0
- wowool/package/lib/wowool_sdk.py +36 -0
- wowool/plugin/wowool_plugin.cpp +1432 -0
- wowool/plugin/wowool_plugin.hpp +157 -0
- wowool_sdk_cpp-3.6.1.dist-info/METADATA +33 -0
- wowool_sdk_cpp-3.6.1.dist-info/RECORD +25 -0
- wowool_sdk_cpp-3.6.1.dist-info/WHEEL +5 -0
- wowool_sdk_cpp-3.6.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,655 @@
|
|
|
1
|
+
//////////////////////////////////////
|
|
2
|
+
// Warning Do not move this headers.
|
|
3
|
+
// Otherwise MSVC can not compile the stuff
|
|
4
|
+
/////////////////////////////////////////////////////////////////
|
|
5
|
+
#define WITH_THREAD
|
|
6
|
+
#include "wowool/analyzer/analyzer.hpp"
|
|
7
|
+
#include "wowool/analyzer/options.hpp"
|
|
8
|
+
#include "wowool/common/exception.hpp"
|
|
9
|
+
#include "wowool/common/logging.hpp"
|
|
10
|
+
#include "wowool/common/options.hpp"
|
|
11
|
+
#include "wowool/common/version.hpp"
|
|
12
|
+
#include "wowool/domain/domain.hpp"
|
|
13
|
+
#include "wowool/engine/engine.hpp"
|
|
14
|
+
#include "wowool/filter/filter.hpp"
|
|
15
|
+
#include "wowool/language_identifier/language_identifier.hpp"
|
|
16
|
+
#include <Python.h>
|
|
17
|
+
#include <iostream>
|
|
18
|
+
#include <mutex>
|
|
19
|
+
#include <pybind11/functional.h>
|
|
20
|
+
#include <pybind11/pybind11.h>
|
|
21
|
+
#include <pybind11/stl.h>
|
|
22
|
+
#include <string>
|
|
23
|
+
#include <thread>
|
|
24
|
+
#include <variant>
|
|
25
|
+
#include <vector>
|
|
26
|
+
#if !defined(WIN32)
|
|
27
|
+
#include <signal.h>
|
|
28
|
+
#else
|
|
29
|
+
#include <thread>
|
|
30
|
+
#include <windows.h>
|
|
31
|
+
#endif
|
|
32
|
+
namespace py = pybind11;
|
|
33
|
+
|
|
34
|
+
//#define DEBUG_WOW_THREADS
|
|
35
|
+
|
|
36
|
+
#define TIR_WLOG_COMPILER 0x1000
|
|
37
|
+
|
|
38
|
+
std::mutex global_python_mutex;
|
|
39
|
+
#define PYTHON_LOCK std::lock_guard<std::mutex> guard(global_python_mutex);
|
|
40
|
+
|
|
41
|
+
bool get_environment_bool(std::string const &env_id, bool default_value)
|
|
42
|
+
{
|
|
43
|
+
char const *value_ptr = std::getenv(env_id.c_str());
|
|
44
|
+
if (value_ptr)
|
|
45
|
+
{
|
|
46
|
+
std::string value(value_ptr);
|
|
47
|
+
return value == "true" || value == "True";
|
|
48
|
+
}
|
|
49
|
+
return default_value;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
bool lock_gil = get_environment_bool("WOWOOL_LOCK_GIL", false);
|
|
53
|
+
|
|
54
|
+
namespace detail {
|
|
55
|
+
struct DoNotExecFirstTime {
|
|
56
|
+
mutable bool initial = true;
|
|
57
|
+
|
|
58
|
+
template <typename Functor> void operator()(Functor functor) const {
|
|
59
|
+
if (!initial) {
|
|
60
|
+
functor();
|
|
61
|
+
} else
|
|
62
|
+
initial = false;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
void reset() { initial = true; }
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
} // namespace detail
|
|
69
|
+
|
|
70
|
+
std::ostream &print_string_map(std::ostream &out,
|
|
71
|
+
wowool::common::Options const &options) {
|
|
72
|
+
for (auto const &option : options) {
|
|
73
|
+
out << option.first << ":" << option.second << ",";
|
|
74
|
+
}
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
namespace tir {
|
|
79
|
+
namespace pywowool {
|
|
80
|
+
|
|
81
|
+
class exception_t : public std::exception {
|
|
82
|
+
private:
|
|
83
|
+
std::string message;
|
|
84
|
+
std::string extraData;
|
|
85
|
+
|
|
86
|
+
public:
|
|
87
|
+
exception_t(std::string message_, std::string extraData_)
|
|
88
|
+
: message(message_), extraData(extraData_) {}
|
|
89
|
+
// TODO: declare this nothrow
|
|
90
|
+
~exception_t() throw() {}
|
|
91
|
+
const char *what() const throw() { return message.c_str(); }
|
|
92
|
+
std::string getMessage() { return message; }
|
|
93
|
+
std::string getExtraData() { return extraData; }
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
class exception_json_t : public std::exception {
|
|
97
|
+
private:
|
|
98
|
+
std::string json_data;
|
|
99
|
+
|
|
100
|
+
public:
|
|
101
|
+
exception_json_t(std::string json_data_) : json_data(json_data_) {}
|
|
102
|
+
// TODO: declare this nothrow
|
|
103
|
+
~exception_json_t() throw() {}
|
|
104
|
+
const char *what() const throw() { return json_data.c_str(); }
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
void translate(exception_json_t const &e) {
|
|
108
|
+
PyErr_SetString(PyExc_RuntimeError, e.what());
|
|
109
|
+
}
|
|
110
|
+
void translate(exception_t const &e) {
|
|
111
|
+
PyErr_SetString(PyExc_RuntimeError, e.what());
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
wowool::common::Options convert_py_2_api_options(py::dict const &kwargs) {
|
|
115
|
+
wowool::common::Options options;
|
|
116
|
+
for (auto const &item : kwargs) {
|
|
117
|
+
options.emplace(py::str(item.first), py::str(item.second));
|
|
118
|
+
}
|
|
119
|
+
return options;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
std::string convert_filterset(wowool::filter::Filter const &filterset) {
|
|
123
|
+
return filterset.info();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
py::dict convert_options_2_py(wowool::common::Options const &options) {
|
|
127
|
+
py::dict kwargs;
|
|
128
|
+
for (auto const &item : options) {
|
|
129
|
+
kwargs[py::str(item.first)] = py::str(item.second);
|
|
130
|
+
}
|
|
131
|
+
return kwargs;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// self.options["pytryoshka"] = "true"
|
|
135
|
+
|
|
136
|
+
static wowool::common::Options global_shared_engine_options = {
|
|
137
|
+
{std::string("language"), std::string("auto")},
|
|
138
|
+
// { std::string("verbose") , std::string("trace") },
|
|
139
|
+
{std::string("pytryoshka"), std::string("true")}};
|
|
140
|
+
|
|
141
|
+
static std::shared_ptr<wowool::engine::Engine>
|
|
142
|
+
global_shared_engine; //( global_shared_engine_options );
|
|
143
|
+
|
|
144
|
+
wowool::engine::Engine &get_default_engine(wowool::common::Options &options) {
|
|
145
|
+
PYTHON_LOCK
|
|
146
|
+
|
|
147
|
+
if (!global_shared_engine) {
|
|
148
|
+
wowool::engine::Engine *global_wowool_engine =
|
|
149
|
+
new wowool::engine::Engine(options);
|
|
150
|
+
// std::cout << " !!!!!!!!!!!!!! Creating Global Engine" <<
|
|
151
|
+
// global_wowool_engine << std::endl;
|
|
152
|
+
global_shared_engine.reset(global_wowool_engine);
|
|
153
|
+
}
|
|
154
|
+
return *global_shared_engine;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
class engine_t : public wowool::engine::Engine {
|
|
158
|
+
public:
|
|
159
|
+
// typedef wowool::EngineInterface type;
|
|
160
|
+
|
|
161
|
+
typedef wowool::engine::Engine type;
|
|
162
|
+
|
|
163
|
+
// using wowool::engine::Engine::Engine;
|
|
164
|
+
|
|
165
|
+
// engine_t(wowool::engine::Engine const &&base)
|
|
166
|
+
// : wowool::engine::Engine(std::move(base))
|
|
167
|
+
// {
|
|
168
|
+
// std::cout << "PLUGIN wowool::engine::Engine(wowool::engine::Engine const
|
|
169
|
+
// &&base)" << this << std::endl;
|
|
170
|
+
// }
|
|
171
|
+
|
|
172
|
+
// engine_t(wowool::engine::Engine const &&base, py::dict const &kwarg)
|
|
173
|
+
// : wowool::engine::Engine(tir::pywowool::convert_py_2_api_options(kwarg))
|
|
174
|
+
// {
|
|
175
|
+
// std::cout << "PLUGIN wowool::engine::Engine(wowool::engine::Engine const
|
|
176
|
+
// &&base, py::dict const &kwarg)" << this << std::endl;
|
|
177
|
+
// }
|
|
178
|
+
|
|
179
|
+
// we need this one to be able to create multi_process objects.
|
|
180
|
+
engine_t(py::dict const &kwarg)
|
|
181
|
+
: wowool::engine::Engine(tir::pywowool::convert_py_2_api_options(kwarg)) {
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
class lid_t : public wowool::language_identifier::LanguageIdentifier {
|
|
186
|
+
public:
|
|
187
|
+
typedef wowool::language_identifier::LanguageIdentifier type;
|
|
188
|
+
|
|
189
|
+
using wowool::language_identifier::LanguageIdentifier::LanguageIdentifier;
|
|
190
|
+
|
|
191
|
+
lid_t(wowool::language_identifier::LanguageIdentifier const &&base)
|
|
192
|
+
: wowool::language_identifier::LanguageIdentifier(std::move(base)) {}
|
|
193
|
+
|
|
194
|
+
lid_t(wowool::analyzer::Engine const &engine, py::dict const &kwarg)
|
|
195
|
+
: wowool::language_identifier::LanguageIdentifier(
|
|
196
|
+
engine, tir::pywowool::convert_py_2_api_options(kwarg)) {}
|
|
197
|
+
|
|
198
|
+
lid_t(py::dict const &kwarg)
|
|
199
|
+
: wowool::language_identifier::LanguageIdentifier(
|
|
200
|
+
tir::pywowool::get_default_engine(global_shared_engine_options),
|
|
201
|
+
tir::pywowool::convert_py_2_api_options(kwarg)) {}
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
class domain_t : public wowool::domain::Domain {
|
|
205
|
+
public:
|
|
206
|
+
typedef wowool::domain::Domain type;
|
|
207
|
+
|
|
208
|
+
using wowool::domain::Domain::Domain;
|
|
209
|
+
|
|
210
|
+
domain_t(wowool::domain::Domain const &&base)
|
|
211
|
+
: wowool::domain::Domain(std::move(base)) {}
|
|
212
|
+
|
|
213
|
+
domain_t(wowool::analyzer::Engine const &engine,
|
|
214
|
+
std::string const domain_descriptor, py::dict const &kwarg)
|
|
215
|
+
: wowool::domain::Domain(engine, domain_descriptor,
|
|
216
|
+
tir::pywowool::convert_py_2_api_options(kwarg)) {
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// we need this one to be able to create multi_process objects.
|
|
220
|
+
domain_t(py::dict const &kwarg)
|
|
221
|
+
: wowool::domain::Domain(
|
|
222
|
+
tir::pywowool::get_default_engine(global_shared_engine_options),
|
|
223
|
+
kwarg["name"].cast<std::string>(),
|
|
224
|
+
tir::pywowool::convert_py_2_api_options(kwarg)) {}
|
|
225
|
+
|
|
226
|
+
// wowool::analyzer::Results process(wowool::analyzer::Results const document)
|
|
227
|
+
// {
|
|
228
|
+
// char *p = 0;
|
|
229
|
+
// *p = 0;
|
|
230
|
+
// std::cout << "PLUGIN domain_t::process" << std::endl;
|
|
231
|
+
// // py::gil_scoped_release release; // Release the GIL
|
|
232
|
+
// return (*static_cast<wowool::domain::Domain const *>(this))(document);
|
|
233
|
+
// };
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
wowool::filter::FilterCollection
|
|
237
|
+
string2filterset(std::string const &filter_str) {
|
|
238
|
+
auto filter_vector = wowool::common::split(filter_str, ',');
|
|
239
|
+
return wowool::filter::FilterCollection(filter_vector.begin(),
|
|
240
|
+
filter_vector.end());
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
class filter_t : public wowool::filter::Filter {
|
|
244
|
+
public:
|
|
245
|
+
typedef wowool::filter::Filter type;
|
|
246
|
+
|
|
247
|
+
using wowool::filter::Filter::Filter;
|
|
248
|
+
|
|
249
|
+
filter_t(wowool::filter::Filter const &&base)
|
|
250
|
+
: wowool::filter::Filter(std::move(base)) {}
|
|
251
|
+
|
|
252
|
+
filter_t(wowool::filter::FilterCollection const &filterset)
|
|
253
|
+
: wowool::filter::Filter(filterset), _filterset(filterset) {}
|
|
254
|
+
|
|
255
|
+
filter_t(std::string const filterset)
|
|
256
|
+
: wowool::filter::Filter(filterset),
|
|
257
|
+
_filterset(string2filterset(filterset)) {}
|
|
258
|
+
|
|
259
|
+
wowool::filter::FilterCollection const _filterset;
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
class results_t : public wowool::analyzer::Results {
|
|
263
|
+
public:
|
|
264
|
+
typedef wowool::analyzer::Results type;
|
|
265
|
+
|
|
266
|
+
using wowool::analyzer::Results::Results;
|
|
267
|
+
|
|
268
|
+
results_t(wowool::analyzer::Results const &&base)
|
|
269
|
+
: wowool::analyzer::Results(std::move(base)) {}
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
class analyzer_t : public wowool::analyzer::Analyzer {
|
|
273
|
+
public:
|
|
274
|
+
typedef wowool::analyzer::Analyzer type;
|
|
275
|
+
py::dict _kwargs;
|
|
276
|
+
|
|
277
|
+
using wowool::analyzer::Analyzer::Analyzer;
|
|
278
|
+
using wowool::analyzer::Analyzer::operator();
|
|
279
|
+
|
|
280
|
+
analyzer_t(wowool::analyzer::Analyzer const &&base)
|
|
281
|
+
: wowool::analyzer::Analyzer(std::move(base)) {}
|
|
282
|
+
|
|
283
|
+
analyzer_t(wowool::analyzer::Engine const &engine, py::dict const &kwarg)
|
|
284
|
+
: wowool::analyzer::Analyzer(
|
|
285
|
+
engine, tir::pywowool::convert_py_2_api_options(kwarg)),
|
|
286
|
+
_kwargs(kwarg) {}
|
|
287
|
+
|
|
288
|
+
std::string
|
|
289
|
+
process_return_string(std::string const &document,
|
|
290
|
+
wowool::common::Options const &json_options) {
|
|
291
|
+
std::string ret_val;
|
|
292
|
+
// std::cout << "options:" ; print_string_map(std::cout , json_options);
|
|
293
|
+
// std::cout << std::endl;
|
|
294
|
+
auto results = (*this)(document, json_options);
|
|
295
|
+
return results.to_json();
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
std::string pipeline_expand(std::string const &pipeline,
|
|
300
|
+
std::string const &paths_str, bool file_access,
|
|
301
|
+
bool allow_dev_versions,
|
|
302
|
+
std::string const &pipeline_language) {
|
|
303
|
+
try {
|
|
304
|
+
std::vector<std::string> paths = wowool::common::split(paths_str, ',');
|
|
305
|
+
return wowool::engine::expand_pipeline(
|
|
306
|
+
pipeline, paths, file_access, allow_dev_versions, pipeline_language);
|
|
307
|
+
} catch (wowool::common::JsonException const &ex) {
|
|
308
|
+
throw exception_json_t(ex.what());
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
std::string pipeline_parse(std::string const &pipeline) {
|
|
313
|
+
try {
|
|
314
|
+
return wowool::engine::parse_pipeline(pipeline);
|
|
315
|
+
} catch (wowool::common::JsonException const &ex) {
|
|
316
|
+
throw exception_json_t(ex.what());
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
bool is_valid_version_format(std::string const &version) {
|
|
321
|
+
return wowool::common::is_valid_version_format(version);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
std::string get_domain_info(std::string const domains_str) {
|
|
325
|
+
std::vector<std::string> all_groups;
|
|
326
|
+
std::vector<std::string> domains = wowool::common::split(domains_str, ',');
|
|
327
|
+
std::stringstream json;
|
|
328
|
+
try {
|
|
329
|
+
for (auto const &domain_descriptor : domains) {
|
|
330
|
+
std::vector<std::string> groups;
|
|
331
|
+
std::string domain = domain_descriptor;
|
|
332
|
+
wowool::domain::get_domain_concepts(domain, groups);
|
|
333
|
+
std::copy(groups.begin(), groups.end(), std::back_inserter(all_groups));
|
|
334
|
+
}
|
|
335
|
+
} catch (std::exception const &ex) {
|
|
336
|
+
throw exception_t(ex.what(), "");
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
if (!all_groups.empty()) {
|
|
340
|
+
json << "[";
|
|
341
|
+
detail::DoNotExecFirstTime dneft;
|
|
342
|
+
for (auto const &concept : all_groups) {
|
|
343
|
+
if (concept.empty())
|
|
344
|
+
continue;
|
|
345
|
+
|
|
346
|
+
dneft([&json]() { json << ","; });
|
|
347
|
+
json << "\"" << concept << "\"";
|
|
348
|
+
}
|
|
349
|
+
json << "]";
|
|
350
|
+
return json.str();
|
|
351
|
+
} else {
|
|
352
|
+
json << "[]";
|
|
353
|
+
}
|
|
354
|
+
return json.str();
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
void print_log_message(unsigned short id, char const *msg) {
|
|
358
|
+
std::cout << msg << std::endl;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
std::string compile_domain(std::string const domain_descriptor,
|
|
362
|
+
py::dict const &kwargs) {
|
|
363
|
+
try {
|
|
364
|
+
auto options = convert_py_2_api_options(kwargs);
|
|
365
|
+
return wowool::domain::compile_domain(options);
|
|
366
|
+
} catch (wowool::common::Exception &ex) {
|
|
367
|
+
throw exception_t(ex.what(), "");
|
|
368
|
+
} catch (std::exception const &e) {
|
|
369
|
+
throw exception_t(e.what(), "");
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
struct options_t {
|
|
374
|
+
static const std::string language;
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
const std::string options_t::language = wowool::analyzer::option::language;
|
|
378
|
+
|
|
379
|
+
auto __exit__callback = []() {
|
|
380
|
+
PYTHON_LOCK
|
|
381
|
+
global_shared_engine.reset();
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
struct PyLog {
|
|
385
|
+
std::function<void(unsigned short, const char *)> logit;
|
|
386
|
+
|
|
387
|
+
PyLog(std::function<void(unsigned short, const char *)> logit_)
|
|
388
|
+
: logit(logit_) {}
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
std::function<void(int, std::string)> pylogit;
|
|
392
|
+
|
|
393
|
+
void global_logger_fn(unsigned short id, const char *msg) {
|
|
394
|
+
if (pylogit) {
|
|
395
|
+
pylogit(id, std::string(msg));
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
void add_logger(unsigned short id, std::string level,
|
|
400
|
+
const std::function<void(int, std::string)> logit) {
|
|
401
|
+
pylogit = logit;
|
|
402
|
+
wowool::logging::add_logger(id, level, global_logger_fn);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
void unset_logger() { pylogit = nullptr; }
|
|
406
|
+
|
|
407
|
+
} // namespace pywowool
|
|
408
|
+
} // namespace tir
|
|
409
|
+
|
|
410
|
+
// clang-format off
|
|
411
|
+
|
|
412
|
+
std::variant<py::none, py::object> make_py_range(plugin_Annotation * concept_internal_ptr)
|
|
413
|
+
{
|
|
414
|
+
if (concept_internal_ptr == 0)
|
|
415
|
+
{
|
|
416
|
+
return py::none();
|
|
417
|
+
}
|
|
418
|
+
py::module plugin = py::module::import("wowool.package.lib.wowool_plugin");
|
|
419
|
+
auto annotation_range = plugin.attr("annotation_range");
|
|
420
|
+
return annotation_range(concept_internal_ptr);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
PYBIND11_MODULE(_wowool_sdk, m)
|
|
424
|
+
{
|
|
425
|
+
|
|
426
|
+
m.add_object("_cleanup", py::capsule(tir::pywowool::__exit__callback));
|
|
427
|
+
m.def("get_domain_info", tir::pywowool::get_domain_info);
|
|
428
|
+
m.def("pipeline_expand", tir::pywowool::pipeline_expand);
|
|
429
|
+
m.def("pipeline_parse", tir::pywowool::pipeline_parse);
|
|
430
|
+
m.def("is_valid_version_format", tir::pywowool::is_valid_version_format);
|
|
431
|
+
m.def("compile_domain", tir::pywowool::compile_domain);
|
|
432
|
+
m.def("add_logger", tir::pywowool::add_logger);
|
|
433
|
+
m.def("unset_logger", tir::pywowool::unset_logger);
|
|
434
|
+
|
|
435
|
+
py::register_exception<tir::pywowool::exception_t>(m, "TirException");
|
|
436
|
+
py::register_exception<tir::pywowool::exception_json_t>(m, "TirJsonException");
|
|
437
|
+
|
|
438
|
+
//------------------------------------------------------------------------------------------
|
|
439
|
+
// Engine Object
|
|
440
|
+
//------------------------------------------------------------------------------------------
|
|
441
|
+
py::class_<wowool::engine::Engine, tir::pywowool::engine_t>(m, "engine")
|
|
442
|
+
.def(py::init([](py::dict const& kwargs) {
|
|
443
|
+
wowool::engine::Engine * engine = new wowool::engine::Engine(tir::pywowool::convert_py_2_api_options(kwargs));
|
|
444
|
+
return engine;
|
|
445
|
+
}))
|
|
446
|
+
.def("property", [](wowool::engine::Engine const& self, std::string const& prop) {
|
|
447
|
+
return wowool::engine::get_engine_property(&self, prop.c_str());
|
|
448
|
+
})
|
|
449
|
+
.def("purge", [](wowool::engine::Engine& self, std::string const& purge_descriptor) {
|
|
450
|
+
return self.purge(purge_descriptor);
|
|
451
|
+
})
|
|
452
|
+
.def("info", [](wowool::engine::Engine& self) {
|
|
453
|
+
return self.info();
|
|
454
|
+
})
|
|
455
|
+
.def("languages", [](wowool::engine::Engine& self) {
|
|
456
|
+
return self.languages();
|
|
457
|
+
})
|
|
458
|
+
.def("release_domain", [](wowool::engine::Engine& self, std::string const& domain_descriptor) {
|
|
459
|
+
return self.release_domain(domain_descriptor);
|
|
460
|
+
})
|
|
461
|
+
.def("__getstate__", [](wowool::engine::Engine const& self) {
|
|
462
|
+
py::dict kwargs = tir::pywowool::convert_options_2_py(self.options);
|
|
463
|
+
return kwargs;
|
|
464
|
+
})
|
|
465
|
+
.def("__setstate__", [](py::object self, py::dict kwargs) {
|
|
466
|
+
// std::cout << "PLUGIN __setstate__ wowool::engine::Engine(py::dict const& kwargs)" << std::endl;
|
|
467
|
+
auto& p = self.cast<tir::pywowool::engine_t&>();
|
|
468
|
+
new (&p) tir::pywowool::engine_t(kwargs);
|
|
469
|
+
})
|
|
470
|
+
;
|
|
471
|
+
|
|
472
|
+
//------------------------------------------------------------------------------------------
|
|
473
|
+
// Language Identification
|
|
474
|
+
//------------------------------------------------------------------------------------------
|
|
475
|
+
py::class_<wowool::language_identifier::LanguageIdentifier, tir::pywowool::lid_t>(m, "lid")
|
|
476
|
+
.def(py::init([](tir::pywowool::engine_t const& eng, py::dict const& kwargs) {
|
|
477
|
+
return new wowool::language_identifier::LanguageIdentifier(eng, tir::pywowool::convert_py_2_api_options(kwargs));
|
|
478
|
+
}))
|
|
479
|
+
.def("language_identification_section", [](wowool::language_identifier::LanguageIdentifier const& self, std::string const& doc) {
|
|
480
|
+
return self.language_identification_section(doc);
|
|
481
|
+
})
|
|
482
|
+
.def("language_identification", [](wowool::language_identifier::LanguageIdentifier const& self, std::string const& doc) {
|
|
483
|
+
return self.language_identification(doc);
|
|
484
|
+
})
|
|
485
|
+
.def("__getstate__", [](wowool::language_identifier::LanguageIdentifier const& self) {
|
|
486
|
+
py::dict kwargs = tir::pywowool::convert_options_2_py(self.options);
|
|
487
|
+
return kwargs;
|
|
488
|
+
})
|
|
489
|
+
.def("__setstate__", [](py::object self, py::dict kwargs) {
|
|
490
|
+
auto& p = self.cast<tir::pywowool::lid_t&>();
|
|
491
|
+
new (&p) tir::pywowool::lid_t(kwargs);
|
|
492
|
+
})
|
|
493
|
+
;
|
|
494
|
+
|
|
495
|
+
//------------------------------------------------------------------------------------------
|
|
496
|
+
// Results object
|
|
497
|
+
//------------------------------------------------------------------------------------------
|
|
498
|
+
py::class_<wowool::analyzer::Results, tir::pywowool::results_t>(m, "results")
|
|
499
|
+
.def("to_json", [](wowool::analyzer::Results const& self) {
|
|
500
|
+
return self.to_json();
|
|
501
|
+
})
|
|
502
|
+
.def("metadata", [](wowool::analyzer::Results const& self) {
|
|
503
|
+
return self.metadata();
|
|
504
|
+
})
|
|
505
|
+
.def("internal_annotations", [](wowool::analyzer::Results const& self) {
|
|
506
|
+
return self.internal_annotations();
|
|
507
|
+
})
|
|
508
|
+
.def("language", [](wowool::analyzer::Results const& self) {
|
|
509
|
+
return self.language();
|
|
510
|
+
})
|
|
511
|
+
.def("id", [](wowool::analyzer::Results const& self) {
|
|
512
|
+
return self.id();
|
|
513
|
+
})
|
|
514
|
+
.def("get_concept" , [&](wowool::analyzer::Results const& self, unsigned int begin_offset, unsigned int end_offset, std::string const & uri , bool unicode_offsets )
|
|
515
|
+
-> std::variant<py::none, py::object>
|
|
516
|
+
{
|
|
517
|
+
plugin_Annotation * concept_internal_ptr = const_cast<wowool::analyzer::Results &>(self).get_concept(begin_offset,end_offset,uri,unicode_offsets);
|
|
518
|
+
return make_py_range(concept_internal_ptr);
|
|
519
|
+
})
|
|
520
|
+
.def("add_concept" , [&](wowool::analyzer::Results const& self, unsigned int begin_offset, unsigned int end_offset, std::string const & uri , bool unicode_offsets )
|
|
521
|
+
-> std::variant<py::none, py::object>
|
|
522
|
+
{
|
|
523
|
+
plugin_Annotation * concept_internal_ptr = const_cast<wowool::analyzer::Results &>(self).add_concept(begin_offset,end_offset,uri,unicode_offsets);
|
|
524
|
+
return make_py_range(concept_internal_ptr);
|
|
525
|
+
})
|
|
526
|
+
.def("remove_pos" , [&](wowool::analyzer::Results const& self, unsigned int begin_offset, unsigned int end_offset, std::string const & pos , bool unicode_offsets )
|
|
527
|
+
{
|
|
528
|
+
const_cast<wowool::analyzer::Results &>(self).remove_pos(begin_offset,end_offset,pos,unicode_offsets);
|
|
529
|
+
})
|
|
530
|
+
.def("get_byte_offset" , [&](wowool::analyzer::Results const& self, unsigned int begin_offset)
|
|
531
|
+
{
|
|
532
|
+
return const_cast<wowool::analyzer::Results &>(self).get_byte_offset(begin_offset);
|
|
533
|
+
})
|
|
534
|
+
|
|
535
|
+
;
|
|
536
|
+
|
|
537
|
+
using namespace pybind11::literals;
|
|
538
|
+
|
|
539
|
+
//------------------------------------------------------------------------------------------
|
|
540
|
+
// Domain Object
|
|
541
|
+
//------------------------------------------------------------------------------------------
|
|
542
|
+
py::class_<wowool::domain::Domain, tir::pywowool::domain_t>(m, "domain")
|
|
543
|
+
|
|
544
|
+
.def(py::init([](tir::pywowool::engine_t const& eng, std::string const filename, py::dict const& kwargs) {
|
|
545
|
+
return new wowool::domain::Domain(eng, filename, tir::pywowool::convert_py_2_api_options(kwargs));
|
|
546
|
+
}))
|
|
547
|
+
.def("info", [](wowool::domain::Domain const& self) {
|
|
548
|
+
return self.info();
|
|
549
|
+
})
|
|
550
|
+
.def("filename", [](wowool::domain::Domain const& self) {
|
|
551
|
+
return self.filename();
|
|
552
|
+
})
|
|
553
|
+
.def("process", [](wowool::domain::Domain const& self, wowool::analyzer::Results const& document) {
|
|
554
|
+
if (lock_gil)
|
|
555
|
+
{
|
|
556
|
+
return self(document);
|
|
557
|
+
}
|
|
558
|
+
py::gil_scoped_release release; // Release the GIL
|
|
559
|
+
return self(document);
|
|
560
|
+
})
|
|
561
|
+
.def("__getstate__", [](wowool::domain::Domain const& self) {
|
|
562
|
+
py::dict kwargs = tir::pywowool::convert_options_2_py(self.options);
|
|
563
|
+
return kwargs;
|
|
564
|
+
})
|
|
565
|
+
.def("__setstate__", [](py::object self, py::dict kwargs) {
|
|
566
|
+
assert(kwargs.find("name") != kwargs.end());
|
|
567
|
+
auto& p = self.cast<tir::pywowool::domain_t&>();
|
|
568
|
+
new (&p) tir::pywowool::domain_t(kwargs);
|
|
569
|
+
})
|
|
570
|
+
;
|
|
571
|
+
|
|
572
|
+
//------------------------------------------------------------------------------------------
|
|
573
|
+
// Analyzer
|
|
574
|
+
//------------------------------------------------------------------------------------------
|
|
575
|
+
py::class_<wowool::analyzer::Analyzer, tir::pywowool::analyzer_t>(m, "analyzer")
|
|
576
|
+
.def(py::init([](tir::pywowool::engine_t const& eng, py::dict const& kwargs) {
|
|
577
|
+
return new wowool::analyzer::Analyzer(eng, tir::pywowool::convert_py_2_api_options(kwargs));
|
|
578
|
+
}))
|
|
579
|
+
.def("process", [](wowool::analyzer::Analyzer const& self, std::string const& doc, py::dict const& kwargs) {
|
|
580
|
+
auto options = tir::pywowool::convert_py_2_api_options(kwargs);
|
|
581
|
+
if (lock_gil)
|
|
582
|
+
{
|
|
583
|
+
return self.process(doc, options).to_json();
|
|
584
|
+
}
|
|
585
|
+
return self.process(doc, options).to_json();
|
|
586
|
+
},
|
|
587
|
+
"Process a given input and return a JSON string."
|
|
588
|
+
"\n\nEXAMPLE"
|
|
589
|
+
"\n\twith wowool() as mc:"
|
|
590
|
+
"\n\t\toptions['language']='english'"
|
|
591
|
+
"\n\t\tresult_data = mc.process( input_text , options )",
|
|
592
|
+
"doc"_a, "options"_a)
|
|
593
|
+
.def("process_results", [](wowool::analyzer::Analyzer const& self, std::string const& text, py::dict const& kwargs) {
|
|
594
|
+
auto options = tir::pywowool::convert_py_2_api_options(kwargs);
|
|
595
|
+
if (lock_gil)
|
|
596
|
+
{
|
|
597
|
+
return new wowool::analyzer::Results(self.process(text, options));
|
|
598
|
+
}
|
|
599
|
+
py::gil_scoped_release release; // Release the GIL
|
|
600
|
+
return new wowool::analyzer::Results(self.process(text, options));
|
|
601
|
+
},
|
|
602
|
+
"Process a given input and return a JSON string."
|
|
603
|
+
"\n\nEXAMPLE"
|
|
604
|
+
"\n\twith wowool() as mc:"
|
|
605
|
+
"\n\t\toptions['language']='english'"
|
|
606
|
+
"\n\t\tresult_data = mc.process_results( input_text , options )",
|
|
607
|
+
"doc"_a, "options"_a)
|
|
608
|
+
.def("process_document", [](wowool::analyzer::Analyzer const& self, wowool::analyzer::Results const text, py::dict const& kwargs) {
|
|
609
|
+
if (lock_gil)
|
|
610
|
+
{
|
|
611
|
+
return new wowool::analyzer::Results(self.process_results(text));
|
|
612
|
+
}
|
|
613
|
+
// py::gil_scoped_release release; // Release the GIL
|
|
614
|
+
return new wowool::analyzer::Results(self.process_results(text));
|
|
615
|
+
})
|
|
616
|
+
.def("filename", [](wowool::analyzer::Analyzer const& self) {
|
|
617
|
+
return self.filename();
|
|
618
|
+
})
|
|
619
|
+
.def("__getstate__", [](wowool::analyzer::Analyzer const& self) {
|
|
620
|
+
py::dict kwargs = tir::pywowool::convert_options_2_py(self.options);
|
|
621
|
+
return kwargs;
|
|
622
|
+
})
|
|
623
|
+
.def("__setstate__", [](py::object self, py::dict kwargs) {
|
|
624
|
+
auto& p = self.cast<tir::pywowool::analyzer_t&>();
|
|
625
|
+
|
|
626
|
+
new (&p) tir::pywowool::analyzer_t(tir::pywowool::get_default_engine(tir::pywowool::global_shared_engine_options) , kwargs);
|
|
627
|
+
})
|
|
628
|
+
;
|
|
629
|
+
|
|
630
|
+
//------------------------------------------------------------------------------------------
|
|
631
|
+
// Filter object
|
|
632
|
+
//------------------------------------------------------------------------------------------
|
|
633
|
+
py::class_<wowool::filter::Filter, tir::pywowool::filter_t>(m, "filter")
|
|
634
|
+
.def(py::init([](wowool::filter::FilterCollection const& filter_set) {
|
|
635
|
+
return new wowool::filter::Filter(filter_set);
|
|
636
|
+
}))
|
|
637
|
+
.def(py::init([](py::str filter_set) {
|
|
638
|
+
return new wowool::filter::Filter(filter_set);
|
|
639
|
+
}))
|
|
640
|
+
.def("process", [](wowool::filter::Filter const& self, wowool::analyzer::Results const& document) {
|
|
641
|
+
return self(document);
|
|
642
|
+
})
|
|
643
|
+
.def("info", [](wowool::filter::Filter const& self) {
|
|
644
|
+
return self.info();
|
|
645
|
+
})
|
|
646
|
+
.def("__getstate__", [](wowool::filter::Filter const& self) {
|
|
647
|
+
py::str filter_set = tir::pywowool::convert_filterset(self);
|
|
648
|
+
return filter_set;
|
|
649
|
+
})
|
|
650
|
+
.def("__setstate__", [](py::object self, py::str filter_set) {
|
|
651
|
+
auto& p = self.cast<tir::pywowool::filter_t&>();
|
|
652
|
+
new (&p) tir::pywowool::filter_t( filter_set );
|
|
653
|
+
})
|
|
654
|
+
;
|
|
655
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|