pub fn with_config(config: TokenizerConfig) -> LinderaResult<Tokenizer> {
        let dictionary = match config.dict_type {
            DictionaryType::LocalDictionary => match config.dict_path.clone() {
                Some(path) => lindera_dictionary::load_dictionary(path)
                    .map_err(|e| LinderaErrorKind::DictionaryNotFound.with_error(e))?,
                None => {
                    return Err(LinderaErrorKind::DictionaryNotFound
                        .with_error(anyhow::anyhow!("dictionary path is not set.")));
                }
            },
            #[cfg(feature = "ipadic")]
            DictionaryType::Ipadic => lindera_ipadic::load_dictionary()
                .map_err(|e| LinderaErrorKind::DictionaryNotFound.with_error(e))?,
            #[cfg(feature = "unidic")]
            DictionaryType::Unidic => lindera_unidic::load_dictionary()
                .map_err(|e| LinderaErrorKind::DictionaryNotFound.with_error(e))?,
            #[cfg(feature = "ko-dic")]
            DictionaryType::Kodic => lindera_ko_dic::load_dictionary()
                .map_err(|e| LinderaErrorKind::DictionaryNotFound.with_error(e))?,
            #[cfg(feature = "cc-cedict")]
            DictionaryType::Cedict => lindera_cc_cedict::load_dictionary()
                .map_err(|e| LinderaErrorKind::DictionaryNotFound.with_error(e))?,
        };

        let user_dictionary = match config.user_dict_path {
            Some(path) => Some(build_user_dict(
                config.dict_type,
                path,
                config.user_dict_type,
            )?),
            None => None,
        };

        let tokenizer = Tokenizer {
            dictionary,
            user_dictionary,
            mode: config.mode,
        };

        Ok(tokenizer)
    }
/// Creates a new instance with the config
///
/// # Arguments
///
/// * `config`: settings of Tokenizer
///
/// returns: Result<Tokenizer, LinderaError>
///
Creates a new instance with the config
Creates a new instance with the config
pub fn with_config(config: TokenizerConfig) -> LinderaResult<Tokenizer> {
        let dictionary = match config.dict_type {
            DictionaryType::LocalDictionary => match config.dict_path.clone() {
                Some(path) => lindera_dictionary::load_dictionary(path)
                    .map_err(|e| LinderaErrorKind::DictionaryNotFound.with_error(e))?,
                None => {
                    return Err(LinderaErrorKind::DictionaryNotFound
                        .with_error(anyhow::anyhow!("dictionary path is not set.")));
                }
            },
            #[cfg(feature = "ipadic")]
            DictionaryType::Ipadic => lindera_ipadic::load_dictionary()
                .map_err(|e| LinderaErrorKind::DictionaryNotFound.with_error(e))?,
            #[cfg(feature = "unidic")]
            DictionaryType::Unidic => lindera_unidic::load_dictionary()
                .map_err(|e| LinderaErrorKind::DictionaryNotFound.with_error(e))?,
            #[cfg(feature = "ko-dic")]
            DictionaryType::Kodic => lindera_ko_dic::load_dictionary()
                .map_err(|e| LinderaErrorKind::DictionaryNotFound.with_error(e))?,
            #[cfg(feature = "cc-cedict")]
            DictionaryType::Cedict => lindera_cc_cedict::load_dictionary()
                .map_err(|e| LinderaErrorKind::DictionaryNotFound.with_error(e))?,
        };
        let user_dictionary = match config.user_dict_path {
            Some(path) => Some(build_user_dict(
                config.dict_type,
                path,
                config.user_dict_type,
            )?),
            None => None,
        };
        let tokenizer = Tokenizer {
            dictionary,
            user_dictionary,
            mode: config.mode,
        };
        Ok(tokenizer)
    }
pub fn with_config ( config : TokenizerConfig ) -> LinderaResult < Tokenizer > { let dictionary = match config . dict_type { DictionaryType :: LocalDictionary => match config . dict_path . clone ( ) { Some ( path ) => lindera_dictionary :: load_dictionary ( path ) . map_err ( | e | LinderaErrorKind :: DictionaryNotFound . with_error ( e ) ) ? , None => { return Err ( LinderaErrorKind :: DictionaryNotFound . with_error ( anyhow :: anyhow ! ( " " ) ) ) ; } } , # [ cfg ( feature " " ) ] DictionaryType :: Ipadic => lindera_ipadic :: load_dictionary ( ) . map_err ( | e | LinderaErrorKind :: DictionaryNotFound . with_error ( e ) ) ? , # [ cfg ( feature " " ) ] DictionaryType :: Unidic => lindera_unidic :: load_dictionary ( ) . map_err ( | e | LinderaErrorKind :: DictionaryNotFound . with_error ( e ) ) ? , # [ cfg ( feature " " ) ] DictionaryType :: Kodic => lindera_ko_dic :: load_dictionary ( ) . map_err ( | e | LinderaErrorKind :: DictionaryNotFound . with_error ( e ) ) ? , # [ cfg ( feature " " ) ] DictionaryType :: Cedict => lindera_cc_cedict :: load_dictionary ( ) . map_err ( | e | LinderaErrorKind :: DictionaryNotFound . with_error ( e ) ) ? , } ; let user_dictionary = match config . user_dict_path { Some ( path ) => Some ( build_user_dict ( config . dict_type , path , config . user_dict_type , ) ? ) , None => None , } ; let tokenizer = Tokenizer { dictionary , user_dictionary , mode : config . mode , } ; Ok ( tokenizer ) }
Creates a new instance with the config
Creates a new instance with the config
config
TokenizerConfig
config
TokenizerConfig