pub struct JPreprocess { /* private fields */ }

Implementations§

source§

impl JPreprocess

source

pub fn from_config(config: JPreprocessConfig) -> JPreprocessResult<Self>

Loads the dictionary.

Example 1: Load from file
use jpreprocess::*;

 let config = JPreprocessConfig {
     dictionary: SystemDictionaryConfig::File(path),
     user_dictionary: None,
 };
let jpreprocess = JPreprocess::from_config(config)?;
Example 2: Load bundled dictionary (This requires a feature to be enabled)
use jpreprocess::{*, kind::*};

 let config = JPreprocessConfig {
     dictionary: SystemDictionaryConfig::Bundled(JPreprocessDictionaryKind::NaistJdic),
     user_dictionary: None,
 };
let jpreprocess = JPreprocess::from_config(config)?;
source

pub fn new( dictionary: Dictionary, user_dictionary: Option<UserDictionary> ) -> Self

Creates JPreprocess from dictionaries.

Note: new before v0.2.0 has moved to from_config

source

pub fn text_to_njd(&self, text: &str) -> JPreprocessResult<NJD>

Tokenize input text and return NJD.

Useful for customizing text processing.

use jpreprocess::*;
use jpreprocess_jpcommon::*;

let jpreprocess = JPreprocess::from_config(config)?;

let mut njd = jpreprocess.text_to_njd("日本語文を解析し、音声合成エンジンに渡せる形式に変換します.")?;
njd.preprocess();

// jpcommon utterance
let utterance = Utterance::from(njd.nodes.as_slice());

// Vec<([phoneme string], [context labels])>
let phoneme_vec = utterance_to_phoneme_vec(&utterance);

assert_eq!(&phoneme_vec[2].0, "i");
assert!(phoneme_vec[2].1.starts_with("/A:-3+1+7"));

// fullcontext label
let fullcontext = overwrapping_phonemes(phoneme_vec);

assert!(fullcontext[2].starts_with("sil^n-i+h=o"));
source

pub fn run_frontend(&self, text: &str) -> JPreprocessResult<Vec<String>>

Tokenize a text, preprocess, and return NJD converted to string.

The returned string does not match that of openjtalk. JPreprocess drops orig string and some of the CForm information, which is unnecessary to preprocessing.

If you need these infomation, please raise a feature request as an issue.

source

pub fn make_label(&self, njd_features: Vec<String>) -> Vec<String>

Generate jpcommon features from NJD features(returned by run_frontend).

source

pub fn extract_fullcontext(&self, text: &str) -> JPreprocessResult<Vec<String>>

Generate jpcommon features from a text.

This is not guaranteed to be same as calling run_frontend and make_label.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. 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 Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.