-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
77 lines (65 loc) · 2.4 KB
/
main.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// Created by 何召召 on 2021/9/18.
//
#include <string>
#include <iostream>
#include <langdetectpp/langdetectpp.h>
//#include <chrono>
#include <pybind11/pybind11.h>
using langdetectpp::Detector;
using langdetectpp::Language;
using namespace std;
//int language_det(string &text) {
// auto start = std::chrono::system_clock::now();
// auto detector = Detector::create();
// Language lang = detector->detect(text);
//// return langdetectpp::stringOfLanguage(lang);
// cout << langdetectpp::stringOfLanguage(lang) << std::endl;
// auto end = std::chrono::system_clock::now();
// std::chrono::duration<double> diff1 = end-start;
//// auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
// cout << "test1:" << diff1.count() << std::endl;
// lang = detector->detect(text);
// cout << langdetectpp::stringOfLanguage(lang) << std::endl;
// auto end2 = std::chrono::system_clock::now();
// std::chrono::duration<double> diff = end2-start;
// cout << "test2:" << diff.count() << std::endl;
//}
class LanguageDet {
public:
shared_ptr<Detector> m_detector;
LanguageDet() {
m_detector = Detector::create();
}
string language_det(const string &text) const {
// auto start = std::chrono::system_clock::now();
Language lang = this->m_detector->detect(text);
// cout << langdetectpp::stringOfLanguage(lang) << std::endl;
// auto end = std::chrono::system_clock::now();
// chrono::duration<double> diff1 = end - start;
// cout << "test1:" << diff1.count() << std::endl;
return langdetectpp::stringOfLanguage(lang);
}
};
#define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x)
namespace py = pybind11;
PYBIND11_MODULE(language_det, m) {
m.doc() = "this is a fastest c++ multi language detect function";
//m.def("language_det", &language_det, R"pbdoc(
// multi language function
// )pbdoc", py::arg("text"));
py::class_<LanguageDet>(m, "LanguageDet")
.def(py::init<>())
.def("language_det", &LanguageDet::language_det, R"pbdoc(
// multi language function
// )pbdoc", py::arg("text"));
// py::class_<Pet>(m, "Pet")
// .def(py::init<>())
// .def_readwrite("name", &Pet::name);
#ifdef VERSION_INFO
m.attr("__version__") = MACRO_STRINGIFY(VERSION_INFO);
#else
m.attr("__version__") = "dev";
#endif
}