#define _JNI_INT64_TO_INT #include "JniUtils.hpp" #include static auto gClsTokenInfo = jni::DataClassDefinition() .template property<&kiwi::TokenInfo::str>("form") .template property<&kiwi::TokenInfo::position>("position") .template property<&kiwi::TokenInfo::wordPosition>("wordPosition") .template property<&kiwi::TokenInfo::sentPosition>("sentPosition") .template property<&kiwi::TokenInfo::lineNumber>("lineNumber") .template property<&kiwi::TokenInfo::length>("length") .template property<&kiwi::TokenInfo::tag>("tag") .template property<&kiwi::TokenInfo::senseId>("senseId") .template property<&kiwi::TokenInfo::score>("score") .template property<&kiwi::TokenInfo::typoCost>("typoCost") .template property<&kiwi::TokenInfo::typoFormId>("typoFormId") .template property<&kiwi::TokenInfo::pairedToken>("pairedToken") .template property<&kiwi::TokenInfo::subSentPosition>("subSentPosition"); static auto gClsTokenResult = jni::DataClassDefinition() .template property<&kiwi::TokenResult::first>("tokens") .template property<&kiwi::TokenResult::second>("score"); namespace jni { template<> struct ValueBuilder : public ValueBuilder { using CppType = kiwi::BuildOption; using JniType = jint; CppType fromJava(JNIEnv* env, JniType v) { return (CppType)v; } JniType toJava(JNIEnv* env, CppType v) { return (JniType)v; } }; template<> struct ValueBuilder : public ValueBuilder { using CppType = kiwi::Match; using JniType = jint; CppType fromJava(JNIEnv* env, JniType v) { return (CppType)v; } JniType toJava(JNIEnv* env, CppType v) { return (JniType)v; } }; template<> struct ValueBuilder : public ValueBuilder { using CppType = kiwi::POSTag; using JniType = jbyte; CppType fromJava(JNIEnv* env, JniType v) { return (CppType)v; } JniType toJava(JNIEnv* env, CppType v) { return (JniType)v; } }; template<> struct JClassName { static constexpr auto value = std::string_view{ "kr/pe/bab2min/Kiwi$TokenResult" }; }; template<> struct JClassName { static constexpr auto value = std::string_view{ "kr/pe/bab2min/Kiwi$Token" }; }; template<> struct ValueBuilder : public ValueBuilder { }; template<> struct ValueBuilder : public ValueBuilder { }; } class JKiwi : public kiwi::Kiwi, jni::JObject { public: static constexpr std::string_view className = "kr/pe/bab2min/Kiwi"; using kiwi::Kiwi::Kiwi; JKiwi(Kiwi&& inst) : Kiwi{ std::move(inst) } {} auto analyze(const std::u16string& text, uint64_t topN, kiwi::Match matchOption) const { return Kiwi::analyze(text, topN, matchOption); } }; class JKiwiBuilder : public kiwi::KiwiBuilder, jni::JObject { public: static constexpr std::string_view className = "kr/pe/bab2min/KiwiBuilder"; using kiwi::KiwiBuilder::KiwiBuilder; JKiwi build() const { return KiwiBuilder::build(); } }; jni::Module gModule{ JNI_VERSION_1_8 }; JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) { return gModule.load(vm, jni::define() .template ctor() .template method(&JKiwiBuilder::addWord)>("addWord") .template method(&JKiwiBuilder::addWord)>("addWord") .template method<&JKiwiBuilder::build>("build") .template method<&JKiwiBuilder::loadDictionary>("loadDictionary"), jni::define() .template method<&JKiwi::analyze>("analyze"), gClsTokenInfo, gClsTokenResult ); } JNIEXPORT void JNICALL JNI_OnUnload(JavaVM* vm, void* reserved) { gModule.unload(vm); }