Struct Tagger

Source
pub struct Tagger { /* private fields */ }
Expand description

形態素解析を行う

Implementations§

Source§

impl Tagger

Source

pub fn new(data_dir: &Path) -> Result<Tagger>

バイナリ辞書を読み込んで、形態素解析器のインスタンスを作成する

§Arguments
  • data_dir - バイナリ辞書があるディレクトリ
Examples found in repository?
examples/file_bench.rs (line 12)
10fn setup_tagger() -> Tagger {
11    let dic_dir = PathBuf::from("data/ipadic");
12    Tagger::new(&dic_dir).unwrap()
13}
More examples
Hide additional 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}
Source

pub fn load_from_dir(dir: &mut dyn DirLike) -> Result<Tagger>

zip等にアーカイブしたバイナリ辞書を読み込んで、形態素解析器のインスタンスを作成する

WebAssembly等、ファイルシステムに直接アクセスできない環境向け

§Arguments
  • dir - アーカイブファイルのイメージ
Source

pub fn parse<'a, 'b>(&'a self, text: &'b str) -> Vec<Morpheme<'a, 'b>>

形態素解析を行う

§Arguments
  • text - 解析対象テキスト
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
Hide additional 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}
Source

pub fn wakati(&self, text: &str) -> Vec<String>

分かち書きを行う

§Arguments
  • text - 分かち書きされるテキスト

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.