From a16714ce16dec76fd0e3041a7acfa484921db3b5 Mon Sep 17 00:00:00 2001 From: Nanashi Date: Thu, 13 Jul 2023 10:57:24 +0900 Subject: [PATCH] =?UTF-8?q?Add:=20MeCab::load=5Fwith=5Fuserdic=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=20(#15)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Change: CmakeListのリポを変更 * Automated generate bindings for x86_64-unknown-linux-gnu * Automated generate bindings for aarch64-unknown-linux-gnu * Automated generate bindings for aarch64-linux-android * Automated generate bindings for x86_64-linux-android * Automated generate bindings for aarch64-apple-darwin * Automated generate bindings for aarch64-apple-ios-sim * Automated generate bindings for x86_64-apple-darwin * Automated generate bindings for x86_64-pc-windows-msvc * Automated generate bindings for aarch64-apple-ios * Automated generate bindings for x86_64-apple-ios * Automated generate bindings for i686-pc-windows-msvc * Add: load_with_userdicを追加 * Code: コードフォーマット * Update: リポジトリを更新 * Discard changes to crates/open_jtalk-sys/open_jtalk/CMakeLists.txt * Update crates/open_jtalk/src/mecab/mod.rs Co-authored-by: Ryo Yamashita * Change: load_with_userdicのuserdicをOptionに * Change: userdicがNoneだったときの処理を変更 * Update crates/open_jtalk/src/mecab/mod.rs Co-authored-by: Ryo Yamashita --------- Co-authored-by: sevenc-nanashi Co-authored-by: Ryo Yamashita --- .../src/generated/android/aarch64/bindings.rs | 7 +++++++ .../src/generated/android/x86_64/bindings.rs | 7 +++++++ .../src/generated/ios/aarch64/bindings.rs | 7 +++++++ .../src/generated/ios/x86_64/bindings.rs | 7 +++++++ .../src/generated/linux/aarch64/bindings.rs | 7 +++++++ .../src/generated/linux/x86_64/bindings.rs | 7 +++++++ .../src/generated/macos/aarch64/bindings.rs | 7 +++++++ .../src/generated/macos/x86_64/bindings.rs | 7 +++++++ .../src/generated/windows/x86/bindings.rs | 7 +++++++ .../src/generated/windows/x86_64/bindings.rs | 7 +++++++ crates/open_jtalk/src/mecab/mod.rs | 21 +++++++++++++++++++ 11 files changed, 91 insertions(+) diff --git a/crates/open_jtalk-sys/src/generated/android/aarch64/bindings.rs b/crates/open_jtalk-sys/src/generated/android/aarch64/bindings.rs index 61bc5cc..f0993c0 100644 --- a/crates/open_jtalk-sys/src/generated/android/aarch64/bindings.rs +++ b/crates/open_jtalk-sys/src/generated/android/aarch64/bindings.rs @@ -1697,6 +1697,13 @@ extern "C" { dicdir: *const ::std::os::raw::c_char, ) -> ::std::os::raw::c_int; } +extern "C" { + pub fn Mecab_load_with_userdic( + m: *mut Mecab, + dicdir: *const ::std::os::raw::c_char, + userdic: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} extern "C" { pub fn Mecab_analysis( m: *mut Mecab, diff --git a/crates/open_jtalk-sys/src/generated/android/x86_64/bindings.rs b/crates/open_jtalk-sys/src/generated/android/x86_64/bindings.rs index 61bc5cc..f0993c0 100644 --- a/crates/open_jtalk-sys/src/generated/android/x86_64/bindings.rs +++ b/crates/open_jtalk-sys/src/generated/android/x86_64/bindings.rs @@ -1697,6 +1697,13 @@ extern "C" { dicdir: *const ::std::os::raw::c_char, ) -> ::std::os::raw::c_int; } +extern "C" { + pub fn Mecab_load_with_userdic( + m: *mut Mecab, + dicdir: *const ::std::os::raw::c_char, + userdic: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} extern "C" { pub fn Mecab_analysis( m: *mut Mecab, diff --git a/crates/open_jtalk-sys/src/generated/ios/aarch64/bindings.rs b/crates/open_jtalk-sys/src/generated/ios/aarch64/bindings.rs index b937f38..3a570c4 100644 --- a/crates/open_jtalk-sys/src/generated/ios/aarch64/bindings.rs +++ b/crates/open_jtalk-sys/src/generated/ios/aarch64/bindings.rs @@ -2151,6 +2151,13 @@ extern "C" { dicdir: *const ::std::os::raw::c_char, ) -> ::std::os::raw::c_int; } +extern "C" { + pub fn Mecab_load_with_userdic( + m: *mut Mecab, + dicdir: *const ::std::os::raw::c_char, + userdic: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} extern "C" { pub fn Mecab_analysis( m: *mut Mecab, diff --git a/crates/open_jtalk-sys/src/generated/ios/x86_64/bindings.rs b/crates/open_jtalk-sys/src/generated/ios/x86_64/bindings.rs index b937f38..3a570c4 100644 --- a/crates/open_jtalk-sys/src/generated/ios/x86_64/bindings.rs +++ b/crates/open_jtalk-sys/src/generated/ios/x86_64/bindings.rs @@ -2151,6 +2151,13 @@ extern "C" { dicdir: *const ::std::os::raw::c_char, ) -> ::std::os::raw::c_int; } +extern "C" { + pub fn Mecab_load_with_userdic( + m: *mut Mecab, + dicdir: *const ::std::os::raw::c_char, + userdic: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} extern "C" { pub fn Mecab_analysis( m: *mut Mecab, diff --git a/crates/open_jtalk-sys/src/generated/linux/aarch64/bindings.rs b/crates/open_jtalk-sys/src/generated/linux/aarch64/bindings.rs index b297198..c90e99e 100644 --- a/crates/open_jtalk-sys/src/generated/linux/aarch64/bindings.rs +++ b/crates/open_jtalk-sys/src/generated/linux/aarch64/bindings.rs @@ -2249,6 +2249,13 @@ extern "C" { dicdir: *const ::std::os::raw::c_char, ) -> ::std::os::raw::c_int; } +extern "C" { + pub fn Mecab_load_with_userdic( + m: *mut Mecab, + dicdir: *const ::std::os::raw::c_char, + userdic: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} extern "C" { pub fn Mecab_analysis( m: *mut Mecab, diff --git a/crates/open_jtalk-sys/src/generated/linux/x86_64/bindings.rs b/crates/open_jtalk-sys/src/generated/linux/x86_64/bindings.rs index b297198..c90e99e 100644 --- a/crates/open_jtalk-sys/src/generated/linux/x86_64/bindings.rs +++ b/crates/open_jtalk-sys/src/generated/linux/x86_64/bindings.rs @@ -2249,6 +2249,13 @@ extern "C" { dicdir: *const ::std::os::raw::c_char, ) -> ::std::os::raw::c_int; } +extern "C" { + pub fn Mecab_load_with_userdic( + m: *mut Mecab, + dicdir: *const ::std::os::raw::c_char, + userdic: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} extern "C" { pub fn Mecab_analysis( m: *mut Mecab, diff --git a/crates/open_jtalk-sys/src/generated/macos/aarch64/bindings.rs b/crates/open_jtalk-sys/src/generated/macos/aarch64/bindings.rs index b937f38..3a570c4 100644 --- a/crates/open_jtalk-sys/src/generated/macos/aarch64/bindings.rs +++ b/crates/open_jtalk-sys/src/generated/macos/aarch64/bindings.rs @@ -2151,6 +2151,13 @@ extern "C" { dicdir: *const ::std::os::raw::c_char, ) -> ::std::os::raw::c_int; } +extern "C" { + pub fn Mecab_load_with_userdic( + m: *mut Mecab, + dicdir: *const ::std::os::raw::c_char, + userdic: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} extern "C" { pub fn Mecab_analysis( m: *mut Mecab, diff --git a/crates/open_jtalk-sys/src/generated/macos/x86_64/bindings.rs b/crates/open_jtalk-sys/src/generated/macos/x86_64/bindings.rs index b937f38..3a570c4 100644 --- a/crates/open_jtalk-sys/src/generated/macos/x86_64/bindings.rs +++ b/crates/open_jtalk-sys/src/generated/macos/x86_64/bindings.rs @@ -2151,6 +2151,13 @@ extern "C" { dicdir: *const ::std::os::raw::c_char, ) -> ::std::os::raw::c_int; } +extern "C" { + pub fn Mecab_load_with_userdic( + m: *mut Mecab, + dicdir: *const ::std::os::raw::c_char, + userdic: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} extern "C" { pub fn Mecab_analysis( m: *mut Mecab, diff --git a/crates/open_jtalk-sys/src/generated/windows/x86/bindings.rs b/crates/open_jtalk-sys/src/generated/windows/x86/bindings.rs index 478c077..fb07d2d 100644 --- a/crates/open_jtalk-sys/src/generated/windows/x86/bindings.rs +++ b/crates/open_jtalk-sys/src/generated/windows/x86/bindings.rs @@ -1725,6 +1725,13 @@ extern "C" { dicdir: *const ::std::os::raw::c_char, ) -> ::std::os::raw::c_int; } +extern "C" { + pub fn Mecab_load_with_userdic( + m: *mut Mecab, + dicdir: *const ::std::os::raw::c_char, + userdic: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} extern "C" { pub fn Mecab_analysis( m: *mut Mecab, diff --git a/crates/open_jtalk-sys/src/generated/windows/x86_64/bindings.rs b/crates/open_jtalk-sys/src/generated/windows/x86_64/bindings.rs index 98d0c85..eaa2c38 100644 --- a/crates/open_jtalk-sys/src/generated/windows/x86_64/bindings.rs +++ b/crates/open_jtalk-sys/src/generated/windows/x86_64/bindings.rs @@ -1725,6 +1725,13 @@ extern "C" { dicdir: *const ::std::os::raw::c_char, ) -> ::std::os::raw::c_int; } +extern "C" { + pub fn Mecab_load_with_userdic( + m: *mut Mecab, + dicdir: *const ::std::os::raw::c_char, + userdic: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} extern "C" { pub fn Mecab_analysis( m: *mut Mecab, diff --git a/crates/open_jtalk/src/mecab/mod.rs b/crates/open_jtalk/src/mecab/mod.rs index 2c45830..8847d91 100644 --- a/crates/open_jtalk/src/mecab/mod.rs +++ b/crates/open_jtalk/src/mecab/mod.rs @@ -47,6 +47,27 @@ impl Mecab { )) } } + + /// # Panics + /// + /// 次の場合にパニックする。 + /// + /// - `dic_dir`または`userdic`が`\0`を含む。 + /// - `dic_dir`または`userdic`がUTF-8の文字列ではない。 + pub fn load_with_userdic(&mut self, dic_dir: &Path, userdic: Option<&Path>) -> bool { + let dic_dir = CString::new(dic_dir.to_str().unwrap()).unwrap(); + let userdic = &userdic.map(|userdic| CString::new(userdic.to_str().unwrap()).unwrap()); + unsafe { + bool_number_to_bool(open_jtalk_sys::Mecab_load_with_userdic( + self.as_raw_ptr(), + dic_dir.as_ptr(), + match userdic { + Some(userdic) => userdic.as_ptr(), + None => std::ptr::null(), + }, + )) + } + } pub fn get_feature(&self) -> Option<&MecabFeature> { unsafe { let feature = open_jtalk_sys::Mecab_get_feature(self.as_raw_ptr());