Struct TextFilter

Source
pub struct TextFilter {
    min_length: usize,
    skip_links: bool,
    skip_code_blocks: bool,
    custom_filters: Vec<Regex>,
    number_pattern: Regex,
    url_pattern: Regex,
    email_pattern: Regex,
    code_pattern: Regex,
    skip_words: HashSet<String>,
}
Expand description

文本过滤器

Fields§

§min_length: usize

最小文本长度

§skip_links: bool

跳过链接文本

§skip_code_blocks: bool

跳过代码块

§custom_filters: Vec<Regex>

自定义过滤规则

§number_pattern: Regex

数字模式正则

§url_pattern: Regex

URL模式正则

§email_pattern: Regex

邮箱模式正则

§code_pattern: Regex

代码模式正则

§skip_words: HashSet<String>

常见的不需要翻译的词汇

Implementations§

Source§

impl TextFilter

Source

pub fn new(config: &TranslationConfig) -> Self

创建新的文本过滤器

Source

pub fn should_translate(&self, text: &str) -> bool

判断文本是否应该翻译

Source

pub fn analyze_text(&self, text: &str) -> TextAnalysis

分析文本的可翻译性

Source

fn is_version_like(&self, text: &str) -> bool

检查是否类似版本号

Source

fn is_html_entity(&self, text: &str) -> bool

检查是否为HTML实体

Source

fn calculate_confidence(&self, text: &str) -> f32

计算翻译置信度

Source

fn detect_language_hint(&self, text: &str) -> LanguageHint

检测语言提示

Source

fn get_skip_reasons(&self, text: &str) -> Vec<String>

获取跳过原因

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,