Struct mecab::Tagger

source ·
pub struct Tagger { /* private fields */ }

Implementations§

source§

impl Tagger

source

pub fn new<T: Into<Vec<u8>>>(arg: T) -> Tagger

Examples found in repository?
examples/simple.rs (line 9)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
fn main() {
    let input = "太郎は次郎が持っている本を花子に渡した。";
    println!("INPUT: {}", input);

    let mut tagger = Tagger::new("");

    // gets tagged result as String
    let mut 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 i in 0..3 {
        if let Some(res) = tagger.next() {
            println!("{}:\n{}", i, res);
        }
    }

    // gets Node object
    for node in tagger.parse_to_node(input).iter_next() {
        match node.stat as i32 {
            mecab::MECAB_BOS_NODE => {
                print!("{} BOS ", node.id);
            }
            mecab::MECAB_EOS_NODE => {
                print!("{} EOS ", node.id);
            }
            _ => {
                print!("{} {} ", node.id, &(node.surface)[..(node.length as usize)]);
            }
        }

        println!("{} {} {} {} {} {} {} {} {} {} {} {} {}",
                 node.feature,
                 input.len() as isize - node.surface.len() as isize,
                 input.len() as isize - node.surface.len() as isize + node.length as isize,
                 node.rcattr,
                 node.lcattr,
                 node.posid,
                 node.char_type,
                 node.stat,
                 node.isbest,
                 node.alpha,
                 node.beta,
                 node.prob,
                 node.cost);
    }

    // dictionary info
    for dict in 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);
    }
}
source

pub fn get_last_error(&self) -> String

source

pub fn partial(&self) -> bool

source

pub fn set_partial(&self, partial: i32)

source

pub fn theta(&self) -> f32

source

pub fn set_theata(&self, theta: f32)

source

pub fn lattice_level(&self) -> i32

source

pub fn set_lattice_level(&self, level: i32)

source

pub fn all_morphs(&self) -> bool

source

pub fn set_all_morphs(&self, all_morphs: i32)

source

pub fn parse(&self, latice: &Lattice) -> bool

Examples found in repository?
examples/multithreaded.rs (line 23)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
fn main() {
    let input = "太郎は次郎が持っている本を花子に渡した。";

    // create model object
    let model = Arc::new(Model::new(""));

    let handle = std::thread::spawn(move || {
        // create tagger based on the model
        let tagger = model.create_tagger();

        // create lattice object per thread
        let mut lattice = model.create_lattice();

        // get tagged result as string
        lattice.set_sentence(input);

        // parse lattice
        tagger.parse(&lattice);
        println!("{}", lattice.to_string());

        // iterate over node objects
        for node in lattice.bos_node().iter_next() {
            match node.stat as i32 {
                mecab::MECAB_BOS_NODE => {
                    print!("{} BOS ", node.id);
                }
                mecab::MECAB_EOS_NODE => {
                    print!("{} EOS ", node.id);
                }
                _ => {
                    print!("{} {} ", node.id, &(node.surface)[..(node.length as usize)]);
                }
            }

            println!("{} {} {} {} {} {} {} {} {} {} {} {} {}",
                     node.feature,
                     input.len() as isize - node.surface.len() as isize,
                     input.len() as isize - node.surface.len() as isize + node.length as isize,
                     node.rcattr,
                     node.lcattr,
                     node.posid,
                     node.char_type,
                     node.stat,
                     node.isbest,
                     node.alpha,
                     node.beta,
                     node.prob,
                     node.cost);
        }

        // iterate over begin and end nodes
        let len = lattice.size();
        for i in 0..len + 1 {
            let b = lattice.begin_nodes(i);
            let e = lattice.end_nodes(i);

            if let Some(nodes) = b {
                for node in nodes.iter_bnext() {
                    println!("B[{}] {}\t{}", i, node.surface, node.feature);
                }
            }

            if let Some(nodes) = e {
                for node in nodes.iter_enext() {
                    println!("E[{}] {}\t{}", i, node.surface, node.feature);
                }
            }
        }

        // get N best results
        lattice.set_request_type(mecab::MECAB_NBEST);
        lattice.set_sentence(input);
        tagger.parse(&lattice);

        for i in 0..10 {
            println!("NBEST: {}", i);
            println!("{}", lattice.to_string());

            if !lattice.next() {
                break;
            }
        }

        // marginal probabilities
        lattice.remove_request_type(mecab::MECAB_NBEST);
        lattice.set_request_type(mecab::MECAB_MARGINAL_PROB);
        lattice.set_sentence(input);
        tagger.parse(&lattice);

        println!("{}", lattice.theta());

        for node in lattice.bos_node().iter_next() {
            println!("{}\t{}\t{}",
                     &(node.surface)[..(node.length as usize)],
                     node.feature,
                     node.prob);
        }

        // dictionary info
        for dict in model.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);
        }
    });

    handle.join().unwrap();
}
source

pub fn parse_str<T: Into<Vec<u8>>>(&self, input: T) -> String

Examples found in repository?
examples/simple.rs (line 12)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
fn main() {
    let input = "太郎は次郎が持っている本を花子に渡した。";
    println!("INPUT: {}", input);

    let mut tagger = Tagger::new("");

    // gets tagged result as String
    let mut 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 i in 0..3 {
        if let Some(res) = tagger.next() {
            println!("{}:\n{}", i, res);
        }
    }

    // gets Node object
    for node in tagger.parse_to_node(input).iter_next() {
        match node.stat as i32 {
            mecab::MECAB_BOS_NODE => {
                print!("{} BOS ", node.id);
            }
            mecab::MECAB_EOS_NODE => {
                print!("{} EOS ", node.id);
            }
            _ => {
                print!("{} {} ", node.id, &(node.surface)[..(node.length as usize)]);
            }
        }

        println!("{} {} {} {} {} {} {} {} {} {} {} {} {}",
                 node.feature,
                 input.len() as isize - node.surface.len() as isize,
                 input.len() as isize - node.surface.len() as isize + node.length as isize,
                 node.rcattr,
                 node.lcattr,
                 node.posid,
                 node.char_type,
                 node.stat,
                 node.isbest,
                 node.alpha,
                 node.beta,
                 node.prob,
                 node.cost);
    }

    // dictionary info
    for dict in 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);
    }
}
source

pub fn parse_to_node<T: Into<Vec<u8>>>(&mut self, input: T) -> Node

Examples found in repository?
examples/simple.rs (line 28)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
fn main() {
    let input = "太郎は次郎が持っている本を花子に渡した。";
    println!("INPUT: {}", input);

    let mut tagger = Tagger::new("");

    // gets tagged result as String
    let mut 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 i in 0..3 {
        if let Some(res) = tagger.next() {
            println!("{}:\n{}", i, res);
        }
    }

    // gets Node object
    for node in tagger.parse_to_node(input).iter_next() {
        match node.stat as i32 {
            mecab::MECAB_BOS_NODE => {
                print!("{} BOS ", node.id);
            }
            mecab::MECAB_EOS_NODE => {
                print!("{} EOS ", node.id);
            }
            _ => {
                print!("{} {} ", node.id, &(node.surface)[..(node.length as usize)]);
            }
        }

        println!("{} {} {} {} {} {} {} {} {} {} {} {} {}",
                 node.feature,
                 input.len() as isize - node.surface.len() as isize,
                 input.len() as isize - node.surface.len() as isize + node.length as isize,
                 node.rcattr,
                 node.lcattr,
                 node.posid,
                 node.char_type,
                 node.stat,
                 node.isbest,
                 node.alpha,
                 node.beta,
                 node.prob,
                 node.cost);
    }

    // dictionary info
    for dict in 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);
    }
}
source

pub fn parse_nbest<T: Into<Vec<u8>>>(&self, n: usize, input: T) -> String

Examples found in repository?
examples/simple.rs (line 16)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
fn main() {
    let input = "太郎は次郎が持っている本を花子に渡した。";
    println!("INPUT: {}", input);

    let mut tagger = Tagger::new("");

    // gets tagged result as String
    let mut 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 i in 0..3 {
        if let Some(res) = tagger.next() {
            println!("{}:\n{}", i, res);
        }
    }

    // gets Node object
    for node in tagger.parse_to_node(input).iter_next() {
        match node.stat as i32 {
            mecab::MECAB_BOS_NODE => {
                print!("{} BOS ", node.id);
            }
            mecab::MECAB_EOS_NODE => {
                print!("{} EOS ", node.id);
            }
            _ => {
                print!("{} {} ", node.id, &(node.surface)[..(node.length as usize)]);
            }
        }

        println!("{} {} {} {} {} {} {} {} {} {} {} {} {}",
                 node.feature,
                 input.len() as isize - node.surface.len() as isize,
                 input.len() as isize - node.surface.len() as isize + node.length as isize,
                 node.rcattr,
                 node.lcattr,
                 node.posid,
                 node.char_type,
                 node.stat,
                 node.isbest,
                 node.alpha,
                 node.beta,
                 node.prob,
                 node.cost);
    }

    // dictionary info
    for dict in 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);
    }
}
source

pub fn parse_nbest_init<T: Into<Vec<u8>>>(&mut self, input: T) -> bool

Examples found in repository?
examples/simple.rs (line 20)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
fn main() {
    let input = "太郎は次郎が持っている本を花子に渡した。";
    println!("INPUT: {}", input);

    let mut tagger = Tagger::new("");

    // gets tagged result as String
    let mut 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 i in 0..3 {
        if let Some(res) = tagger.next() {
            println!("{}:\n{}", i, res);
        }
    }

    // gets Node object
    for node in tagger.parse_to_node(input).iter_next() {
        match node.stat as i32 {
            mecab::MECAB_BOS_NODE => {
                print!("{} BOS ", node.id);
            }
            mecab::MECAB_EOS_NODE => {
                print!("{} EOS ", node.id);
            }
            _ => {
                print!("{} {} ", node.id, &(node.surface)[..(node.length as usize)]);
            }
        }

        println!("{} {} {} {} {} {} {} {} {} {} {} {} {}",
                 node.feature,
                 input.len() as isize - node.surface.len() as isize,
                 input.len() as isize - node.surface.len() as isize + node.length as isize,
                 node.rcattr,
                 node.lcattr,
                 node.posid,
                 node.char_type,
                 node.stat,
                 node.isbest,
                 node.alpha,
                 node.beta,
                 node.prob,
                 node.cost);
    }

    // dictionary info
    for dict in 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);
    }
}
source

pub fn next(&self) -> Option<String>

Examples found in repository?
examples/simple.rs (line 22)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
fn main() {
    let input = "太郎は次郎が持っている本を花子に渡した。";
    println!("INPUT: {}", input);

    let mut tagger = Tagger::new("");

    // gets tagged result as String
    let mut 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 i in 0..3 {
        if let Some(res) = tagger.next() {
            println!("{}:\n{}", i, res);
        }
    }

    // gets Node object
    for node in tagger.parse_to_node(input).iter_next() {
        match node.stat as i32 {
            mecab::MECAB_BOS_NODE => {
                print!("{} BOS ", node.id);
            }
            mecab::MECAB_EOS_NODE => {
                print!("{} EOS ", node.id);
            }
            _ => {
                print!("{} {} ", node.id, &(node.surface)[..(node.length as usize)]);
            }
        }

        println!("{} {} {} {} {} {} {} {} {} {} {} {} {}",
                 node.feature,
                 input.len() as isize - node.surface.len() as isize,
                 input.len() as isize - node.surface.len() as isize + node.length as isize,
                 node.rcattr,
                 node.lcattr,
                 node.posid,
                 node.char_type,
                 node.stat,
                 node.isbest,
                 node.alpha,
                 node.beta,
                 node.prob,
                 node.cost);
    }

    // dictionary info
    for dict in 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);
    }
}
source

pub fn next_node(&self) -> Option<Node>

source

pub fn format_node(&self, node: Node) -> String

source

pub fn dictionary_info(&self) -> DictionaryInfo

Examples found in repository?
examples/simple.rs (line 58)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
fn main() {
    let input = "太郎は次郎が持っている本を花子に渡した。";
    println!("INPUT: {}", input);

    let mut tagger = Tagger::new("");

    // gets tagged result as String
    let mut 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 i in 0..3 {
        if let Some(res) = tagger.next() {
            println!("{}:\n{}", i, res);
        }
    }

    // gets Node object
    for node in tagger.parse_to_node(input).iter_next() {
        match node.stat as i32 {
            mecab::MECAB_BOS_NODE => {
                print!("{} BOS ", node.id);
            }
            mecab::MECAB_EOS_NODE => {
                print!("{} EOS ", node.id);
            }
            _ => {
                print!("{} {} ", node.id, &(node.surface)[..(node.length as usize)]);
            }
        }

        println!("{} {} {} {} {} {} {} {} {} {} {} {} {}",
                 node.feature,
                 input.len() as isize - node.surface.len() as isize,
                 input.len() as isize - node.surface.len() as isize + node.length as isize,
                 node.rcattr,
                 node.lcattr,
                 node.posid,
                 node.char_type,
                 node.stat,
                 node.isbest,
                 node.alpha,
                 node.beta,
                 node.prob,
                 node.cost);
    }

    // dictionary info
    for dict in 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);
    }
}

Trait Implementations§

source§

impl Drop for Tagger

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.