mirror of https://github.com/M66B/FairEmail.git
cld3 binding
This commit is contained in:
parent
01328483f5
commit
77674b0730
|
@ -41,11 +41,23 @@ import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class TextHelper {
|
public class TextHelper {
|
||||||
|
static {
|
||||||
|
System.loadLibrary("fairemail");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static native String jni_language(byte[] octets);
|
||||||
|
|
||||||
static Locale detectLanguage(Context context, String text) {
|
static Locale detectLanguage(Context context, String text) {
|
||||||
// Why not ML kit? https://developers.google.com/ml-kit/terms
|
// Why not ML kit? https://developers.google.com/ml-kit/terms
|
||||||
if (TextUtils.isEmpty(text))
|
if (TextUtils.isEmpty(text))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
if (BuildConfig.DEBUG) {
|
||||||
|
// https://github.com/google/cld3
|
||||||
|
String lang = jni_language(text.getBytes());
|
||||||
|
return Locale.forLanguageTag(lang);
|
||||||
|
}
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q)
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <netinet/tcp.h>
|
#include <netinet/tcp.h>
|
||||||
|
|
||||||
#include "compact_enc_det/compact_enc_det.h"
|
#include "compact_enc_det/compact_enc_det.h"
|
||||||
|
#include "cld_3/src/nnet_language_identifier.h"
|
||||||
|
|
||||||
void log_android(int prio, const char *fmt, ...) {
|
void log_android(int prio, const char *fmt, ...) {
|
||||||
if (prio >= ANDROID_LOG_DEBUG) {
|
if (prio >= ANDROID_LOG_DEBUG) {
|
||||||
|
@ -57,6 +58,22 @@ Java_eu_faircode_email_CharsetHelper_jni_1detect(JNIEnv *env, jclass type, jbyte
|
||||||
(jboolean) is_reliable);
|
(jboolean) is_reliable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
JNIEXPORT jstring JNICALL
|
||||||
|
Java_eu_faircode_email_TextHelper_jni_1language(JNIEnv *env, jclass clazz, jbyteArray _octets) {
|
||||||
|
int len = env->GetArrayLength(_octets);
|
||||||
|
jbyte *octets = env->GetByteArrayElements(_octets, nullptr);
|
||||||
|
|
||||||
|
std::string text(reinterpret_cast<char const *>(octets), len);
|
||||||
|
|
||||||
|
chrome_lang_id::NNetLanguageIdentifier lang_id(0, 1000);
|
||||||
|
const chrome_lang_id::NNetLanguageIdentifier::Result result = lang_id.FindLanguage(text);
|
||||||
|
|
||||||
|
env->ReleaseByteArrayElements(_octets, octets, JNI_ABORT);
|
||||||
|
|
||||||
|
return env->NewStringUTF(result.language.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
JNIEXPORT jint JNICALL
|
JNIEXPORT jint JNICALL
|
||||||
Java_eu_faircode_email_EmailService_jni_1socket_1keep_1alive(
|
Java_eu_faircode_email_EmailService_jni_1socket_1keep_1alive(
|
||||||
|
|
Loading…
Reference in New Issue