- Notifications
You must be signed in to change notification settings - Fork9
Safe Rust bindings for mecab a part-of-speech and morphological analyzer library
License
tsurai/mecab-rs
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Safe Rust wrapper formecab a japanese language part-of-speech and morphological analyzer library.
The wrapper is almost identical to the C++ interface of mecab with the addition of various iterator for comfortable data access. It is build with the latest version of mecab v0.996.
Both Windows Rust versions (MSVC ABI and gcc toolchain) can just use theprebuilt 32bit library.Using mecab-rs with the Windows commandline is not recommended and can causeundefined behavior if you are not using the correct codepage and a font that supports japanese character.
CMake & 64bit library:
Thanks to@DoumanAsh for providing these files
Include this in your Cargo.toml to add mecab to your project:
[dependencies]mecab ="*"
externcrate mecab;use mecab::Tagger;fnmain(){let input ="太郎は次郎が持っている本を花子に渡した。";println!("INPUT: {}", input);letmut tagger =Tagger::new("");// gets tagged result as Stringletmut result = tagger.parse_str(input);println!("RESULT: {}", result);// gets N best results as String result = tagger.parse_nbest(3, input);println!("NBEST:\n{}", result);// gets N best in sequence tagger.parse_nbest_init(input);for iin0..3{ifletSome(res) = tagger.next(){println!("{}:\n{}", i, res);}}// gets Node objectfor nodein tagger.parse_to_node(input).iter_next(){match node.statasi32{ mecab::MECAB_BOS_NODE =>{print!("{} BOS ", node.id);}, mecab::MECAB_EOS_NODE =>{print!("{} EOS ", node.id);}, _ =>{print!("{} {} ", node.id,&(node.surface)[..(node.lengthasusize)]);}}println!("{} {} {} {} {} {} {} {} {} {} {} {} {}", node.feature, input.len()asisize - node.surface.len()asisize, input.len()asisize - node.surface.len()asisize + node.lengthasisize, node.rcattr, node.lcattr, node.posid, node.char_type, node.stat, node.isbest, node.alpha, node.beta, node.prob, node.cost);}// dictionary infofor dictin tagger.dictionary_info().iter(){println!("\nfilename: {}", dict.filename);println!("charset: {}", dict.charset);println!("size: {}", dict.size);println!("type: {}", dict.dict_type);println!("lsize: {}", dict.lsize);println!("rsize: {}", dict.rsize);println!("version: {}", dict.version);}}
See themultithreaded example
The MIT License (MIT)
Copyright (c) 2015-2016 Cristian Kubis
Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.
About
Safe Rust bindings for mecab a part-of-speech and morphological analyzer library
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.