mirror of
https://github.com/mii443/akaza.git
synced 2025-08-22 14:55:31 +00:00
Merge pull request #211 from akaza-im/inline-function
Inlining new_with_default_score
This commit is contained in:
@ -167,7 +167,7 @@ impl BigramWordViterbiEngineBuilder {
|
||||
MarisaSystemUnigramLM,
|
||||
MarisaSystemBigramLM,
|
||||
MarisaKanaKanjiDict,
|
||||
> = GraphBuilder::new_with_default_score(
|
||||
> = GraphBuilder::new(
|
||||
dict,
|
||||
single_term,
|
||||
user_data.clone(),
|
||||
|
@ -38,22 +38,6 @@ impl<U: SystemUnigramLM, B: SystemBigramLM, KD: KanaKanjiDict> GraphBuilder<U, B
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_with_default_score(
|
||||
system_kana_kanji_dict: KD,
|
||||
system_single_term_dict: KD,
|
||||
user_data: Arc<Mutex<UserData>>,
|
||||
system_unigram_lm: Rc<U>,
|
||||
system_bigram_lm: Rc<B>,
|
||||
) -> GraphBuilder<U, B, KD> {
|
||||
Self::new(
|
||||
system_kana_kanji_dict,
|
||||
system_single_term_dict,
|
||||
user_data,
|
||||
system_unigram_lm,
|
||||
system_bigram_lm,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn construct(&self, yomi: &str, words_ends_at: &SegmentationResult) -> LatticeGraph<U, B> {
|
||||
// このグラフのインデクスは単語の終了位置。
|
||||
let mut graph: BTreeMap<i32, Vec<WordNode>> = BTreeMap::new();
|
||||
@ -130,16 +114,17 @@ impl<U: SystemUnigramLM, B: SystemBigramLM, KD: KanaKanjiDict> GraphBuilder<U, B
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::kana_kanji::hashmap_vec::HashmapVecKanaKanjiDict;
|
||||
use crate::lm::system_bigram::MarisaSystemBigramLMBuilder;
|
||||
use crate::lm::system_unigram_lm::MarisaSystemUnigramLMBuilder;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_single_term() -> anyhow::Result<()> {
|
||||
let graph_builder = GraphBuilder::new_with_default_score(
|
||||
let graph_builder = GraphBuilder::new(
|
||||
HashmapVecKanaKanjiDict::new(HashMap::new()),
|
||||
HashmapVecKanaKanjiDict::new(HashMap::from([(
|
||||
"すし".to_string(),
|
||||
@ -175,7 +160,7 @@ mod tests {
|
||||
// ひらがな、カタカナのエントリーが自動的に入るようにする。
|
||||
#[test]
|
||||
fn test_default_terms() -> anyhow::Result<()> {
|
||||
let graph_builder = GraphBuilder::new_with_default_score(
|
||||
let graph_builder = GraphBuilder::new(
|
||||
HashmapVecKanaKanjiDict::new(HashMap::new()),
|
||||
HashmapVecKanaKanjiDict::new(HashMap::new()),
|
||||
Arc::new(Mutex::new(UserData::default())),
|
||||
@ -205,7 +190,7 @@ mod tests {
|
||||
// ひらがな、カタカナがすでにかな漢字辞書から提供されている場合でも、重複させない。
|
||||
#[test]
|
||||
fn test_default_terms_duplicated() -> anyhow::Result<()> {
|
||||
let graph_builder = GraphBuilder::new_with_default_score(
|
||||
let graph_builder = GraphBuilder::new(
|
||||
HashmapVecKanaKanjiDict::new(HashMap::from([(
|
||||
"す".to_string(),
|
||||
vec!["す".to_string(), "ス".to_string()],
|
||||
|
@ -1,11 +1,10 @@
|
||||
use std::collections::vec_deque::VecDeque;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::graph::candidate::Candidate;
|
||||
use anyhow::Context;
|
||||
|
||||
use log::trace;
|
||||
|
||||
use crate::graph::candidate::Candidate;
|
||||
use crate::graph::lattice_graph::LatticeGraph;
|
||||
use crate::graph::word_node::WordNode;
|
||||
use crate::lm::base::{SystemBigramLM, SystemUnigramLM};
|
||||
@ -165,7 +164,7 @@ mod tests {
|
||||
.set_default_edge_cost(20_f32)
|
||||
.build()?;
|
||||
let user_data = UserData::default();
|
||||
let graph_builder = GraphBuilder::new_with_default_score(
|
||||
let graph_builder = GraphBuilder::new(
|
||||
HashmapVecKanaKanjiDict::new(HashMap::new()),
|
||||
HashmapVecKanaKanjiDict::new(Default::default()),
|
||||
Arc::new(Mutex::new(user_data)),
|
||||
@ -219,7 +218,7 @@ mod tests {
|
||||
let mut user_data = UserData::default();
|
||||
// 私/わたし のスコアをガッと上げる。
|
||||
user_data.record_entries(&[Candidate::new("わたし", "私", 0_f32)]);
|
||||
let graph_builder = GraphBuilder::new_with_default_score(
|
||||
let graph_builder = GraphBuilder::new(
|
||||
HashmapVecKanaKanjiDict::new(dict),
|
||||
HashmapVecKanaKanjiDict::new(HashMap::new()),
|
||||
Arc::new(Mutex::new(user_data)),
|
||||
|
Reference in New Issue
Block a user