pub struct Tagger { /* private fields */ }
Implementations§
Source§impl Tagger
impl Tagger
Sourcepub fn new<T: Into<Vec<u8>>>(arg: T) -> Tagger
pub fn new<T: Into<Vec<u8>>>(arg: T) -> Tagger
Examples found in repository?
examples/simple.rs (line 9)
5fn main() {
6 let input = "太郎は次郎が持っている本を花子に渡した。";
7 println!("INPUT: {}", input);
8
9 let mut tagger = Tagger::new("");
10
11 // gets tagged result as String
12 let mut result = tagger.parse_str(input);
13 println!("RESULT: {}", result);
14
15 // gets N best results as String
16 result = tagger.parse_nbest(3, input);
17 println!("NBEST:\n{}", result);
18
19 // gets N best in sequence
20 tagger.parse_nbest_init(input);
21 for i in 0..3 {
22 if let Some(res) = tagger.next() {
23 println!("{}:\n{}", i, res);
24 }
25 }
26
27 // gets Node object
28 for node in tagger.parse_to_node(input).iter_next() {
29 match node.stat as i32 {
30 mecab::MECAB_BOS_NODE => {
31 print!("{} BOS ", node.id);
32 }
33 mecab::MECAB_EOS_NODE => {
34 print!("{} EOS ", node.id);
35 }
36 _ => {
37 print!("{} {} ", node.id, &(node.surface)[..(node.length as usize)]);
38 }
39 }
40
41 println!("{} {} {} {} {} {} {} {} {} {} {} {} {}",
42 node.feature,
43 input.len() as isize - node.surface.len() as isize,
44 input.len() as isize - node.surface.len() as isize + node.length as isize,
45 node.rcattr,
46 node.lcattr,
47 node.posid,
48 node.char_type,
49 node.stat,
50 node.isbest,
51 node.alpha,
52 node.beta,
53 node.prob,
54 node.cost);
55 }
56
57 // dictionary info
58 for dict in tagger.dictionary_info().iter() {
59 println!("\nfilename: {}", dict.filename);
60 println!("charset: {}", dict.charset);
61 println!("size: {}", dict.size);
62 println!("type: {}", dict.dict_type);
63 println!("lsize: {}", dict.lsize);
64 println!("rsize: {}", dict.rsize);
65 println!("version: {}", dict.version);
66 }
67}
pub fn get_last_error(&self) -> String
pub fn partial(&self) -> bool
pub fn set_partial(&self, partial: i32)
pub fn theta(&self) -> f32
pub fn set_theata(&self, theta: f32)
pub fn lattice_level(&self) -> i32
pub fn set_lattice_level(&self, level: i32)
pub fn all_morphs(&self) -> bool
pub fn set_all_morphs(&self, all_morphs: i32)
Sourcepub fn parse(&self, latice: &Lattice) -> bool
pub fn parse(&self, latice: &Lattice) -> bool
Examples found in repository?
examples/multithreaded.rs (line 23)
6fn main() {
7 let input = "太郎は次郎が持っている本を花子に渡した。";
8
9 // create model object
10 let model = Arc::new(Model::new(""));
11
12 let handle = std::thread::spawn(move || {
13 // create tagger based on the model
14 let tagger = model.create_tagger();
15
16 // create lattice object per thread
17 let mut lattice = model.create_lattice();
18
19 // get tagged result as string
20 lattice.set_sentence(input);
21
22 // parse lattice
23 tagger.parse(&lattice);
24 println!("{}", lattice.to_string());
25
26 // iterate over node objects
27 for node in lattice.bos_node().iter_next() {
28 match node.stat as i32 {
29 mecab::MECAB_BOS_NODE => {
30 print!("{} BOS ", node.id);
31 }
32 mecab::MECAB_EOS_NODE => {
33 print!("{} EOS ", node.id);
34 }
35 _ => {
36 print!("{} {} ", node.id, &(node.surface)[..(node.length as usize)]);
37 }
38 }
39
40 println!("{} {} {} {} {} {} {} {} {} {} {} {} {}",
41 node.feature,
42 input.len() as isize - node.surface.len() as isize,
43 input.len() as isize - node.surface.len() as isize + node.length as isize,
44 node.rcattr,
45 node.lcattr,
46 node.posid,
47 node.char_type,
48 node.stat,
49 node.isbest,
50 node.alpha,
51 node.beta,
52 node.prob,
53 node.cost);
54 }
55
56 // iterate over begin and end nodes
57 let len = lattice.size();
58 for i in 0..len + 1 {
59 let b = lattice.begin_nodes(i);
60 let e = lattice.end_nodes(i);
61
62 if let Some(nodes) = b {
63 for node in nodes.iter_bnext() {
64 println!("B[{}] {}\t{}", i, node.surface, node.feature);
65 }
66 }
67
68 if let Some(nodes) = e {
69 for node in nodes.iter_enext() {
70 println!("E[{}] {}\t{}", i, node.surface, node.feature);
71 }
72 }
73 }
74
75 // get N best results
76 lattice.set_request_type(mecab::MECAB_NBEST);
77 lattice.set_sentence(input);
78 tagger.parse(&lattice);
79
80 for i in 0..10 {
81 println!("NBEST: {}", i);
82 println!("{}", lattice.to_string());
83
84 if !lattice.next() {
85 break;
86 }
87 }
88
89 // marginal probabilities
90 lattice.remove_request_type(mecab::MECAB_NBEST);
91 lattice.set_request_type(mecab::MECAB_MARGINAL_PROB);
92 lattice.set_sentence(input);
93 tagger.parse(&lattice);
94
95 println!("{}", lattice.theta());
96
97 for node in lattice.bos_node().iter_next() {
98 println!("{}\t{}\t{}",
99 &(node.surface)[..(node.length as usize)],
100 node.feature,
101 node.prob);
102 }
103
104 // dictionary info
105 for dict in model.dictionary_info().iter() {
106 println!("\nfilename: {}", dict.filename);
107 println!("charset: {}", dict.charset);
108 println!("size: {}", dict.size);
109 println!("type: {}", dict.dict_type);
110 println!("lsize: {}", dict.lsize);
111 println!("rsize: {}", dict.rsize);
112 println!("version: {}", dict.version);
113 }
114 });
115
116 handle.join().unwrap();
117}
Sourcepub fn parse_str<T: Into<Vec<u8>>>(&self, input: T) -> String
pub fn parse_str<T: Into<Vec<u8>>>(&self, input: T) -> String
Examples found in repository?
examples/simple.rs (line 12)
5fn main() {
6 let input = "太郎は次郎が持っている本を花子に渡した。";
7 println!("INPUT: {}", input);
8
9 let mut tagger = Tagger::new("");
10
11 // gets tagged result as String
12 let mut result = tagger.parse_str(input);
13 println!("RESULT: {}", result);
14
15 // gets N best results as String
16 result = tagger.parse_nbest(3, input);
17 println!("NBEST:\n{}", result);
18
19 // gets N best in sequence
20 tagger.parse_nbest_init(input);
21 for i in 0..3 {
22 if let Some(res) = tagger.next() {
23 println!("{}:\n{}", i, res);
24 }
25 }
26
27 // gets Node object
28 for node in tagger.parse_to_node(input).iter_next() {
29 match node.stat as i32 {
30 mecab::MECAB_BOS_NODE => {
31 print!("{} BOS ", node.id);
32 }
33 mecab::MECAB_EOS_NODE => {
34 print!("{} EOS ", node.id);
35 }
36 _ => {
37 print!("{} {} ", node.id, &(node.surface)[..(node.length as usize)]);
38 }
39 }
40
41 println!("{} {} {} {} {} {} {} {} {} {} {} {} {}",
42 node.feature,
43 input.len() as isize - node.surface.len() as isize,
44 input.len() as isize - node.surface.len() as isize + node.length as isize,
45 node.rcattr,
46 node.lcattr,
47 node.posid,
48 node.char_type,
49 node.stat,
50 node.isbest,
51 node.alpha,
52 node.beta,
53 node.prob,
54 node.cost);
55 }
56
57 // dictionary info
58 for dict in tagger.dictionary_info().iter() {
59 println!("\nfilename: {}", dict.filename);
60 println!("charset: {}", dict.charset);
61 println!("size: {}", dict.size);
62 println!("type: {}", dict.dict_type);
63 println!("lsize: {}", dict.lsize);
64 println!("rsize: {}", dict.rsize);
65 println!("version: {}", dict.version);
66 }
67}
Sourcepub fn parse_to_node<T: Into<Vec<u8>>>(&mut self, input: T) -> Node
pub fn parse_to_node<T: Into<Vec<u8>>>(&mut self, input: T) -> Node
Examples found in repository?
examples/simple.rs (line 28)
5fn main() {
6 let input = "太郎は次郎が持っている本を花子に渡した。";
7 println!("INPUT: {}", input);
8
9 let mut tagger = Tagger::new("");
10
11 // gets tagged result as String
12 let mut result = tagger.parse_str(input);
13 println!("RESULT: {}", result);
14
15 // gets N best results as String
16 result = tagger.parse_nbest(3, input);
17 println!("NBEST:\n{}", result);
18
19 // gets N best in sequence
20 tagger.parse_nbest_init(input);
21 for i in 0..3 {
22 if let Some(res) = tagger.next() {
23 println!("{}:\n{}", i, res);
24 }
25 }
26
27 // gets Node object
28 for node in tagger.parse_to_node(input).iter_next() {
29 match node.stat as i32 {
30 mecab::MECAB_BOS_NODE => {
31 print!("{} BOS ", node.id);
32 }
33 mecab::MECAB_EOS_NODE => {
34 print!("{} EOS ", node.id);
35 }
36 _ => {
37 print!("{} {} ", node.id, &(node.surface)[..(node.length as usize)]);
38 }
39 }
40
41 println!("{} {} {} {} {} {} {} {} {} {} {} {} {}",
42 node.feature,
43 input.len() as isize - node.surface.len() as isize,
44 input.len() as isize - node.surface.len() as isize + node.length as isize,
45 node.rcattr,
46 node.lcattr,
47 node.posid,
48 node.char_type,
49 node.stat,
50 node.isbest,
51 node.alpha,
52 node.beta,
53 node.prob,
54 node.cost);
55 }
56
57 // dictionary info
58 for dict in tagger.dictionary_info().iter() {
59 println!("\nfilename: {}", dict.filename);
60 println!("charset: {}", dict.charset);
61 println!("size: {}", dict.size);
62 println!("type: {}", dict.dict_type);
63 println!("lsize: {}", dict.lsize);
64 println!("rsize: {}", dict.rsize);
65 println!("version: {}", dict.version);
66 }
67}
Sourcepub fn parse_nbest<T: Into<Vec<u8>>>(&self, n: usize, input: T) -> String
pub fn parse_nbest<T: Into<Vec<u8>>>(&self, n: usize, input: T) -> String
Examples found in repository?
examples/simple.rs (line 16)
5fn main() {
6 let input = "太郎は次郎が持っている本を花子に渡した。";
7 println!("INPUT: {}", input);
8
9 let mut tagger = Tagger::new("");
10
11 // gets tagged result as String
12 let mut result = tagger.parse_str(input);
13 println!("RESULT: {}", result);
14
15 // gets N best results as String
16 result = tagger.parse_nbest(3, input);
17 println!("NBEST:\n{}", result);
18
19 // gets N best in sequence
20 tagger.parse_nbest_init(input);
21 for i in 0..3 {
22 if let Some(res) = tagger.next() {
23 println!("{}:\n{}", i, res);
24 }
25 }
26
27 // gets Node object
28 for node in tagger.parse_to_node(input).iter_next() {
29 match node.stat as i32 {
30 mecab::MECAB_BOS_NODE => {
31 print!("{} BOS ", node.id);
32 }
33 mecab::MECAB_EOS_NODE => {
34 print!("{} EOS ", node.id);
35 }
36 _ => {
37 print!("{} {} ", node.id, &(node.surface)[..(node.length as usize)]);
38 }
39 }
40
41 println!("{} {} {} {} {} {} {} {} {} {} {} {} {}",
42 node.feature,
43 input.len() as isize - node.surface.len() as isize,
44 input.len() as isize - node.surface.len() as isize + node.length as isize,
45 node.rcattr,
46 node.lcattr,
47 node.posid,
48 node.char_type,
49 node.stat,
50 node.isbest,
51 node.alpha,
52 node.beta,
53 node.prob,
54 node.cost);
55 }
56
57 // dictionary info
58 for dict in tagger.dictionary_info().iter() {
59 println!("\nfilename: {}", dict.filename);
60 println!("charset: {}", dict.charset);
61 println!("size: {}", dict.size);
62 println!("type: {}", dict.dict_type);
63 println!("lsize: {}", dict.lsize);
64 println!("rsize: {}", dict.rsize);
65 println!("version: {}", dict.version);
66 }
67}
Sourcepub fn parse_nbest_init<T: Into<Vec<u8>>>(&mut self, input: T) -> bool
pub fn parse_nbest_init<T: Into<Vec<u8>>>(&mut self, input: T) -> bool
Examples found in repository?
examples/simple.rs (line 20)
5fn main() {
6 let input = "太郎は次郎が持っている本を花子に渡した。";
7 println!("INPUT: {}", input);
8
9 let mut tagger = Tagger::new("");
10
11 // gets tagged result as String
12 let mut result = tagger.parse_str(input);
13 println!("RESULT: {}", result);
14
15 // gets N best results as String
16 result = tagger.parse_nbest(3, input);
17 println!("NBEST:\n{}", result);
18
19 // gets N best in sequence
20 tagger.parse_nbest_init(input);
21 for i in 0..3 {
22 if let Some(res) = tagger.next() {
23 println!("{}:\n{}", i, res);
24 }
25 }
26
27 // gets Node object
28 for node in tagger.parse_to_node(input).iter_next() {
29 match node.stat as i32 {
30 mecab::MECAB_BOS_NODE => {
31 print!("{} BOS ", node.id);
32 }
33 mecab::MECAB_EOS_NODE => {
34 print!("{} EOS ", node.id);
35 }
36 _ => {
37 print!("{} {} ", node.id, &(node.surface)[..(node.length as usize)]);
38 }
39 }
40
41 println!("{} {} {} {} {} {} {} {} {} {} {} {} {}",
42 node.feature,
43 input.len() as isize - node.surface.len() as isize,
44 input.len() as isize - node.surface.len() as isize + node.length as isize,
45 node.rcattr,
46 node.lcattr,
47 node.posid,
48 node.char_type,
49 node.stat,
50 node.isbest,
51 node.alpha,
52 node.beta,
53 node.prob,
54 node.cost);
55 }
56
57 // dictionary info
58 for dict in tagger.dictionary_info().iter() {
59 println!("\nfilename: {}", dict.filename);
60 println!("charset: {}", dict.charset);
61 println!("size: {}", dict.size);
62 println!("type: {}", dict.dict_type);
63 println!("lsize: {}", dict.lsize);
64 println!("rsize: {}", dict.rsize);
65 println!("version: {}", dict.version);
66 }
67}
Sourcepub fn next(&self) -> Option<String>
pub fn next(&self) -> Option<String>
Examples found in repository?
examples/simple.rs (line 22)
5fn main() {
6 let input = "太郎は次郎が持っている本を花子に渡した。";
7 println!("INPUT: {}", input);
8
9 let mut tagger = Tagger::new("");
10
11 // gets tagged result as String
12 let mut result = tagger.parse_str(input);
13 println!("RESULT: {}", result);
14
15 // gets N best results as String
16 result = tagger.parse_nbest(3, input);
17 println!("NBEST:\n{}", result);
18
19 // gets N best in sequence
20 tagger.parse_nbest_init(input);
21 for i in 0..3 {
22 if let Some(res) = tagger.next() {
23 println!("{}:\n{}", i, res);
24 }
25 }
26
27 // gets Node object
28 for node in tagger.parse_to_node(input).iter_next() {
29 match node.stat as i32 {
30 mecab::MECAB_BOS_NODE => {
31 print!("{} BOS ", node.id);
32 }
33 mecab::MECAB_EOS_NODE => {
34 print!("{} EOS ", node.id);
35 }
36 _ => {
37 print!("{} {} ", node.id, &(node.surface)[..(node.length as usize)]);
38 }
39 }
40
41 println!("{} {} {} {} {} {} {} {} {} {} {} {} {}",
42 node.feature,
43 input.len() as isize - node.surface.len() as isize,
44 input.len() as isize - node.surface.len() as isize + node.length as isize,
45 node.rcattr,
46 node.lcattr,
47 node.posid,
48 node.char_type,
49 node.stat,
50 node.isbest,
51 node.alpha,
52 node.beta,
53 node.prob,
54 node.cost);
55 }
56
57 // dictionary info
58 for dict in tagger.dictionary_info().iter() {
59 println!("\nfilename: {}", dict.filename);
60 println!("charset: {}", dict.charset);
61 println!("size: {}", dict.size);
62 println!("type: {}", dict.dict_type);
63 println!("lsize: {}", dict.lsize);
64 println!("rsize: {}", dict.rsize);
65 println!("version: {}", dict.version);
66 }
67}
pub fn next_node(&self) -> Option<Node>
pub fn format_node(&self, node: Node) -> String
Sourcepub fn dictionary_info(&self) -> DictionaryInfo
pub fn dictionary_info(&self) -> DictionaryInfo
Examples found in repository?
examples/simple.rs (line 58)
5fn main() {
6 let input = "太郎は次郎が持っている本を花子に渡した。";
7 println!("INPUT: {}", input);
8
9 let mut tagger = Tagger::new("");
10
11 // gets tagged result as String
12 let mut result = tagger.parse_str(input);
13 println!("RESULT: {}", result);
14
15 // gets N best results as String
16 result = tagger.parse_nbest(3, input);
17 println!("NBEST:\n{}", result);
18
19 // gets N best in sequence
20 tagger.parse_nbest_init(input);
21 for i in 0..3 {
22 if let Some(res) = tagger.next() {
23 println!("{}:\n{}", i, res);
24 }
25 }
26
27 // gets Node object
28 for node in tagger.parse_to_node(input).iter_next() {
29 match node.stat as i32 {
30 mecab::MECAB_BOS_NODE => {
31 print!("{} BOS ", node.id);
32 }
33 mecab::MECAB_EOS_NODE => {
34 print!("{} EOS ", node.id);
35 }
36 _ => {
37 print!("{} {} ", node.id, &(node.surface)[..(node.length as usize)]);
38 }
39 }
40
41 println!("{} {} {} {} {} {} {} {} {} {} {} {} {}",
42 node.feature,
43 input.len() as isize - node.surface.len() as isize,
44 input.len() as isize - node.surface.len() as isize + node.length as isize,
45 node.rcattr,
46 node.lcattr,
47 node.posid,
48 node.char_type,
49 node.stat,
50 node.isbest,
51 node.alpha,
52 node.beta,
53 node.prob,
54 node.cost);
55 }
56
57 // dictionary info
58 for dict in tagger.dictionary_info().iter() {
59 println!("\nfilename: {}", dict.filename);
60 println!("charset: {}", dict.charset);
61 println!("size: {}", dict.size);
62 println!("type: {}", dict.dict_type);
63 println!("lsize: {}", dict.lsize);
64 println!("rsize: {}", dict.rsize);
65 println!("version: {}", dict.version);
66 }
67}
Trait Implementations§
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