Struct Node

Source
pub struct Node {
Show 16 fields pub surface: String, pub feature: String, pub id: u32, pub length: u16, pub rlength: u16, pub rcattr: u16, pub lcattr: u16, pub posid: u16, pub char_type: u8, pub stat: u8, pub isbest: bool, pub alpha: f32, pub beta: f32, pub prob: f32, pub wcost: i16, pub cost: c_long, /* private fields */
}

Fields§

§surface: String§feature: String§id: u32§length: u16§rlength: u16§rcattr: u16§lcattr: u16§posid: u16§char_type: u8§stat: u8§isbest: bool§alpha: f32§beta: f32§prob: f32§wcost: i16§cost: c_long

Implementations§

Source§

impl Node

Source

pub fn iter_prev(self) -> NodeIter

Source

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

Source

pub fn iter_next(self) -> NodeIter

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}
More examples
Hide additional examples
examples/multithreaded.rs (line 27)
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}
Source

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

Source

pub fn iter_enext(self) -> NodeIter

Examples found in repository?
examples/multithreaded.rs (line 69)
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}
Source

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

Source

pub fn iter_bnext(self) -> NodeIter

Examples found in repository?
examples/multithreaded.rs (line 63)
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}
Source

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

Trait Implementations§

Source§

impl Clone for Node

Source§

fn clone(&self) -> Node

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for Node

§

impl RefUnwindSafe for Node

§

impl !Send for Node

§

impl !Sync for Node

§

impl Unpin for Node

§

impl UnwindSafe for Node

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.