sudachi/plugin/oov/
mod.rsuse crate::analysis::created::CreatedWords;
use crate::analysis::Node;
use serde_json::Value;
use crate::config::Config;
use crate::dic::grammar::Grammar;
use crate::input_text::InputBuffer;
use crate::plugin::oov::mecab_oov::MeCabOovPlugin;
use crate::plugin::oov::regex_oov::RegexOovProvider;
use crate::plugin::oov::simple_oov::SimpleOovPlugin;
use crate::plugin::PluginCategory;
use crate::prelude::*;
pub mod mecab_oov;
pub mod regex_oov;
pub mod simple_oov;
pub trait OovProviderPlugin: Sync + Send {
fn set_up(
&mut self,
settings: &Value,
config: &Config,
grammar: &mut Grammar,
) -> SudachiResult<()>;
fn provide_oov(
&self,
input_text: &InputBuffer,
offset: usize,
other_words: CreatedWords,
result: &mut Vec<Node>,
) -> SudachiResult<usize>;
}
impl PluginCategory for dyn OovProviderPlugin {
type BoxType = Box<dyn OovProviderPlugin + Sync + Send>;
type InitFnType = unsafe fn() -> SudachiResult<Self::BoxType>;
fn configurations(cfg: &Config) -> &[Value] {
&cfg.oov_provider_plugins
}
fn bundled_impl(name: &str) -> Option<Self::BoxType> {
match name {
"SimpleOovPlugin" => Some(Box::<SimpleOovPlugin>::default()),
"MeCabOovPlugin" => Some(Box::<MeCabOovPlugin>::default()),
"RegexOovProvider" => Some(Box::<RegexOovProvider>::default()),
_ => None,
}
}
fn do_setup(
ptr: &mut Self::BoxType,
settings: &Value,
config: &Config,
grammar: &mut Grammar,
) -> SudachiResult<()> {
ptr.set_up(settings, config, grammar)
}
}