pub struct Tagger { /* private fields */ }
Expand description
形態素解析を行う
Implementations§
Source§impl Tagger
impl Tagger
Sourcepub fn new(data_dir: &Path) -> Result<Tagger>
pub fn new(data_dir: &Path) -> Result<Tagger>
Examples found in repository?
More examples
examples/parse.rs (line 8)
6fn main() {
7 let dic_dir = PathBuf::from(env::var("IGO_DIC").unwrap_or("data/ipadic".to_string()));
8 let tagger = Tagger::new(dic_dir.as_path()).unwrap();
9 let text = "すもももももも\u{1F351}もものうち";
10
11 let results = tagger.parse(text);
12 for ref m in &results {
13 println!("{}\t{}", m.surface, m.feature);
14 }
15 println!("EOS");
16
17 for ref m in results {
18 println!("{:?}", m);
19 }
20}
Sourcepub fn load_from_dir(dir: &mut dyn DirLike) -> Result<Tagger>
pub fn load_from_dir(dir: &mut dyn DirLike) -> Result<Tagger>
zip等にアーカイブしたバイナリ辞書を読み込んで、形態素解析器のインスタンスを作成する
WebAssembly等、ファイルシステムに直接アクセスできない環境向け
§Arguments
dir
- アーカイブファイルのイメージ
Sourcepub fn parse<'a, 'b>(&'a self, text: &'b str) -> Vec<Morpheme<'a, 'b>>
pub fn parse<'a, 'b>(&'a self, text: &'b str) -> Vec<Morpheme<'a, 'b>>
Examples found in repository?
examples/parse.rs (line 11)
6fn main() {
7 let dic_dir = PathBuf::from(env::var("IGO_DIC").unwrap_or("data/ipadic".to_string()));
8 let tagger = Tagger::new(dic_dir.as_path()).unwrap();
9 let text = "すもももももも\u{1F351}もものうち";
10
11 let results = tagger.parse(text);
12 for ref m in &results {
13 println!("{}\t{}", m.surface, m.feature);
14 }
15 println!("EOS");
16
17 for ref m in results {
18 println!("{:?}", m);
19 }
20}
More examples
examples/file_bench.rs (line 32)
15fn main() {
16 let repeat: usize = env::args().nth(1)
17 .and_then(|s| s.parse().ok()).unwrap_or(1000);
18 let input_path = env::args().nth(2)
19 .unwrap_or("data/text1.txt".to_string());
20
21 println!("input file path: {}", input_path);
22 let reader = BufReader::new(File::open(input_path).unwrap());
23 let lines: Vec<_> = reader.lines().map(|l| l.unwrap()).collect();
24
25 let tagger = setup_tagger();
26 let start_time = Instant::now();
27
28 println!("start {} iter", repeat);
29
30 for _ in 0..repeat {
31 for line in &lines {
32 tagger.parse(line);
33 }
34 }
35
36 let elapsed = start_time.elapsed();
37 let ms = (((elapsed.as_secs() as f64) * 1000.0)
38 + ((elapsed.subsec_nanos() as f64) / 1_000_000.0)) / (repeat as f64);
39 println!("elapsed: {} ms/iter", ms);
40}
Auto Trait Implementations§
impl Freeze for Tagger
impl RefUnwindSafe for Tagger
impl Send for Tagger
impl Sync for Tagger
impl Unpin for Tagger
impl UnwindSafe for Tagger
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more