Skip to content

Commit

Permalink
Add: MeCab::load_with_userdicを追加 (#15)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Change: load_with_userdicのuserdicをOptionに

* Change: userdicがNoneだったときの処理を変更

* Update crates/open_jtalk/src/mecab/mod.rs

Co-authored-by: Ryo Yamashita <[email protected]>

---------

Co-authored-by: sevenc-nanashi <[email protected]>
Co-authored-by: Ryo Yamashita <[email protected]>
  • Loading branch information
3 people authored Jul 13, 2023
1 parent 290d0f6 commit a16714c
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions crates/open_jtalk-sys/src/generated/ios/aarch64/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions crates/open_jtalk-sys/src/generated/ios/x86_64/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions crates/open_jtalk-sys/src/generated/linux/aarch64/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions crates/open_jtalk-sys/src/generated/linux/x86_64/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions crates/open_jtalk-sys/src/generated/macos/aarch64/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions crates/open_jtalk-sys/src/generated/macos/x86_64/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions crates/open_jtalk-sys/src/generated/windows/x86/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions crates/open_jtalk/src/mecab/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit a16714c

Please sign in to comment.