pub struct Lattice { /* private fields */ }
Implementations§
source§impl Lattice
impl Lattice
pub fn new() -> Lattice
pub fn clear(&self)
pub fn is_available(&self) -> bool
sourcepub fn bos_node(&self) -> Node
pub fn bos_node(&self) -> Node
Examples found in repository?
examples/multithreaded.rs (line 27)
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();
}
pub fn eos_node(&self) -> Node
sourcepub fn begin_nodes(&self, pos: usize) -> Option<Node>
pub fn begin_nodes(&self, pos: usize) -> Option<Node>
Examples found in repository?
examples/multithreaded.rs (line 59)
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();
}
sourcepub fn end_nodes(&self, pos: usize) -> Option<Node>
pub fn end_nodes(&self, pos: usize) -> Option<Node>
Examples found in repository?
examples/multithreaded.rs (line 60)
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();
}
pub fn sentence(&self) -> String
sourcepub fn set_sentence<T: Into<Vec<u8>>>(&mut self, sentence: T)
pub fn set_sentence<T: Into<Vec<u8>>>(&mut self, sentence: T)
Examples found in repository?
examples/multithreaded.rs (line 20)
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();
}
sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
Examples found in repository?
examples/multithreaded.rs (line 57)
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();
}
pub fn z(&self) -> f64
pub fn set_z(&self, z: f64)
sourcepub fn theta(&self) -> f64
pub fn theta(&self) -> f64
Examples found in repository?
examples/multithreaded.rs (line 95)
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();
}
pub fn set_theta(&self, theta: f64)
sourcepub fn next(&self) -> bool
pub fn next(&self) -> bool
Examples found in repository?
examples/multithreaded.rs (line 84)
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();
}
pub fn request_type(&self) -> i32
pub fn has_request_type(&self, request_type: i32) -> bool
sourcepub fn set_request_type(&self, request_type: i32)
pub fn set_request_type(&self, request_type: i32)
Examples found in repository?
examples/multithreaded.rs (line 76)
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();
}
pub fn add_request_type(&self, request_type: i32)
sourcepub fn remove_request_type(&self, request_type: i32)
pub fn remove_request_type(&self, request_type: i32)
Examples found in repository?
examples/multithreaded.rs (line 90)
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();
}
sourcepub fn to_string(&self) -> String
pub fn to_string(&self) -> String
Examples found in repository?
examples/multithreaded.rs (line 24)
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();
}
pub fn enum_nbest_as_string(&self, n: i64) -> String
pub fn has_constraint(&self) -> bool
pub fn boundary_constraint(&self, pos: u64) -> i32
pub fn feature_constraint(&self, pos: u64) -> String
pub fn set_boundary_constraint(&self, pos: u64, boundary_type: i32)
pub fn set_feature_constraint<T: Into<Vec<u8>>>( &self, begin_pos: u64, end_pos: u64, feature: T )
pub fn set_result<T: Into<Vec<u8>>>(&self, result: T)
pub fn what(&self) -> String
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Lattice
impl !Send for Lattice
impl !Sync for Lattice
impl Unpin for Lattice
impl UnwindSafe for Lattice
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