LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
LangDetectorCore.cpp
Go to the documentation of this file.
1//
2// Created by tderouet on 24/05/22.
3//
4
5#include "LangDetectorCore.h"
6
9 public:
10 fasttext::FastText ftext;
11 };
12
16
18 delete m_d;
19 }
20
21 /*
22 * Detect the language of the text.
23 */
24
25 std::string LangDetectorCore::detectLang(const std::string& text) const {
26 std::string lang;
27 std::vector<std::pair<fasttext::real, std::string>> prediction;
28 std::stringstream ioss(text + std::string("\n"));
29 m_d->ftext.predictLine(ioss, prediction, 1, 0);
30 lang = prediction.front().second;
31 return lang;
32 }
33 /*
34 * Remove the "__label__" part of the language label.
35 */
36 std::string LangDetectorCore::labelToPrintable(const std:: string &label) {
37 return label.substr(9, std::string::npos);
38 }
39
40 void LangDetectorCore::loadModel(const std::string& modelPath) {
41 m_d->ftext.loadModel(modelPath);
42 }
43}
static std::string labelToPrintable(const std::string &label)
std::string detectLang(const std::string &text) const