-
-
Notifications
You must be signed in to change notification settings - Fork 492
/
Copy pathLanguageIdentification.cpp
35 lines (28 loc) · 1.01 KB
/
LanguageIdentification.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
#include "pch.h"
#include "LanguageIdentification.h"
#if __has_include("LanguageIdentification.g.cpp")
#include "LanguageIdentification.g.cpp"
#endif
#include "StringUtils.h"
#include "lang_id/fb_model/lang-id-from-fb.h"
#include "lang_id/lang-id.h"
namespace winrt::Telegram::Native::implementation
{
std::mutex LanguageIdentification::s_criticalSection;
std::unique_ptr<libtextclassifier3::mobile::lang_id::LangId> LanguageIdentification::s_langid{ nullptr };
LangId* LanguageIdentification::Current()
{
std::lock_guard const guard(s_criticalSection);
if (s_langid == nullptr)
{
s_langid = libtextclassifier3::mobile::lang_id::GetLangIdFromFlatbufferFile("Assets\\langid_model.smfb.jpg");
}
return s_langid.get();
}
hstring LanguageIdentification::IdentifyLanguage(hstring text)
{
auto unmanaged = winrt::to_string(text);
auto language = Current()->FindLanguage(unmanaged);
return winrt::to_hstring(language);
}
}