pub struct LanguageDetectorBuilder { /* private fields */ }
Expand description

This struct configures and creates an instance of LanguageDetector.

Implementations§

source§

impl LanguageDetectorBuilder

source

pub fn from_all_languages() -> Self

Creates and returns an instance of LanguageDetectorBuilder with all built-in languages.

source

pub fn from_all_spoken_languages() -> Self

Creates and returns an instance of LanguageDetectorBuilder with all built-in spoken languages.

source

pub fn from_all_languages_with_arabic_script() -> Self

Creates and returns an instance of LanguageDetectorBuilder with all built-in languages supporting the Arabic script.

source

pub fn from_all_languages_with_cyrillic_script() -> Self

Creates and returns an instance of LanguageDetectorBuilder with all built-in languages supporting the Cyrillic script.

source

pub fn from_all_languages_with_devanagari_script() -> Self

Creates and returns an instance of LanguageDetectorBuilder with all built-in languages supporting the Devanagari script.

source

pub fn from_all_languages_with_latin_script() -> Self

Creates and returns an instance of LanguageDetectorBuilder with all built-in languages supporting the Latin script.

source

pub fn from_all_languages_without(languages: &[Language]) -> Self

Creates and returns an instance of LanguageDetectorBuilder with all built-in languages except those specified in languages.

⚠ Panics if less than two languages are used to build the LanguageDetector.

source

pub fn from_languages(languages: &[Language]) -> Self

Creates and returns an instance of LanguageDetectorBuilder with the specified languages.

⚠ Panics if less than two languages are specified.

source

pub fn from_iso_codes_639_1(iso_codes: &[IsoCode639_1]) -> Self

Creates and returns an instance of LanguageDetectorBuilder with the languages specified by the respective ISO 639-1 codes.

⚠ Panics if less than two iso_codes are specified.

source

pub fn from_iso_codes_639_3(iso_codes: &[IsoCode639_3]) -> Self

Creates and returns an instance of LanguageDetectorBuilder with the languages specified by the respective ISO 639-3 codes.

⚠ Panics if less than two iso_codes are specified.

source

pub fn with_minimum_relative_distance(&mut self, distance: f64) -> &mut Self

Sets the desired value for the minimum relative distance measure.

By default, Lingua returns the most likely language for a given input text. However, there are certain words that are spelled the same in more than one language. The word prologue, for instance, is both a valid English and French word. Lingua would output either English or French which might be wrong in the given context. For cases like that, it is possible to specify a minimum relative distance that the logarithmized and summed up probabilities for each possible language have to satisfy.

Be aware that the distance between the language probabilities is dependent on the length of the input text. The longer the input text, the larger the distance between the languages. So if you want to classify very short text phrases, do not set the minimum relative distance too high. Otherwise you will get most results returned as None which is the return value for cases where language detection is not reliably possible.

⚠ Panics if distance is smaller than 0.0 or greater than 0.99.

source

pub fn with_preloaded_language_models(&mut self) -> &mut Self

Configures LanguageDetectorBuilder to preload all language models when creating the instance of LanguageDetector.

By default, Lingua uses lazy-loading to load only those language models on demand which are considered relevant by the rule-based filter engine. For web services, for instance, it is rather beneficial to preload all language models into memory to avoid unexpected latency while waiting for the service response. This method allows to switch between these two loading modes.

source

pub fn with_low_accuracy_mode(&mut self) -> &mut Self

Disables the high accuracy mode in order to save memory and increase performance.

By default, Lingua’s high detection accuracy comes at the cost of loading large language models into memory which might not be feasible for systems running low on resources.

This method disables the high accuracy mode so that only a small subset of language models is loaded into memory. The downside of this approach is that detection accuracy for short texts consisting of less than 120 characters will drop significantly. However, detection accuracy for texts which are longer than 120 characters will remain mostly unaffected.

source

pub fn build(&mut self) -> LanguageDetector

Creates and returns the configured instance of LanguageDetector.

Trait Implementations§

source§

impl Clone for LanguageDetectorBuilder

source§

fn clone(&self) -> LanguageDetectorBuilder

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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 T
where 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where 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 T
where 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.