pub struct PersonalTextRedactor { /* private fields */ }Expand description
Finds personal text: words an on-device DocumentReader reads that
adk_guardrail::PiiRedactor’s patterns match, and the values of labelled fields.
The reader’s words are joined per block with single spaces, PiiRedactor::find returns
byte ranges in that text (spec 3.7 X18), and every word a match touches is covered. A
labelled field — a block whose words start with one of the labels, such as Name or
Date of birth, with or without a colon — has every word after the label covered; when
the reader returns the label as a block of its own, the nearest block to its right on
the same line is the value and is covered whole. A block with no words is covered whole
when its text matches.
PersonalTextRedactor::pp_ocr (feature ocr) is the default reader: PP-OCRv6 from the
built-in manifest, loaded on first use.
§Example
use std::sync::Arc;
use adk_vision::{PersonalTextRedactor, RedactionClass, Redactor};
let redactor = PersonalTextRedactor::new(reader).with_labelled_fields(["Name", "Date of birth"]);
assert_eq!(redactor.class(), RedactionClass::personal_text());Implementations§
Source§impl PersonalTextRedactor
impl PersonalTextRedactor
Sourcepub fn new(reader: Arc<dyn DocumentReader>) -> Self
pub fn new(reader: Arc<dyn DocumentReader>) -> Self
Covers the words reader reads that PiiRedactor::new()’s patterns match.
Sourcepub fn pp_ocr(fetcher: ModelFetcher, size: PpOcrV6Size) -> Self
pub fn pp_ocr(fetcher: ModelFetcher, size: PpOcrV6Size) -> Self
Covers the words PP-OCRv6 of size reads that PiiRedactor::new()’s patterns match:
the built-in pp-ocrv6-{size}-det and -rec manifests, fetched through fetcher
and verified against their SHA-256 on the redactor’s first use (feature ocr).
Nothing loads here. When the weights cannot be had — HF_HUB_OFFLINE with an empty
cache, a digest mismatch — find fails, and the egress gate refuses the release.
§Example
use std::sync::Arc;
use adk_vision::{
FetchConfig, InMemoryAcceptanceStore, ModelFetcher, PERSONAL_FIELD_LABELS,
PersonalTextRedactor, PpOcrV6Size, RedactionClass, Redactor,
};
let fetcher =
ModelFetcher::new(FetchConfig::from_env(), Arc::new(InMemoryAcceptanceStore::new()));
let redactor = PersonalTextRedactor::pp_ocr(fetcher, PpOcrV6Size::Small)
.with_labelled_fields(PERSONAL_FIELD_LABELS.iter().copied());
assert_eq!(redactor.class(), RedactionClass::personal_text());Sourcepub fn with_pii(self, pii: PiiRedactor) -> Self
pub fn with_pii(self, pii: PiiRedactor) -> Self
Matches with pii’s patterns instead.
Sourcepub fn with_labelled_fields(
self,
labels: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn with_labelled_fields( self, labels: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Also covers the value of every field labelled with one of labels, such as Name.
Trait Implementations§
Source§impl Debug for PersonalTextRedactor
impl Debug for PersonalTextRedactor
Source§impl Redactor for PersonalTextRedactor
impl Redactor for PersonalTextRedactor
Source§fn class(&self) -> RedactionClass
fn class(&self) -> RedactionClass
Source§fn find<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
cx: &'life1 VisionCx,
image: &'life2 SentImage,
) -> Pin<Box<dyn Future<Output = Result<Vec<BBox>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn find<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
cx: &'life1 VisionCx,
image: &'life2 SentImage,
) -> Pin<Box<dyn Future<Output = Result<Vec<BBox>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
image’s pixels.Source§fn find_classified<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
cx: &'life1 VisionCx,
image: &'life2 SentImage,
) -> Pin<Box<dyn Future<Output = Result<Vec<(RedactionClass, BBox)>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn find_classified<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
cx: &'life1 VisionCx,
image: &'life2 SentImage,
) -> Pin<Box<dyn Future<Output = Result<Vec<(RedactionClass, BBox)>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
find as
class. A faces redactor names the whole-person boxes it falls back to
RedactionClass::people, so a card says which faces were covered as the whole
person. The receipt counts every box under class. Read moreAuto Trait Implementations§
impl !Freeze for PersonalTextRedactor
impl !RefUnwindSafe for PersonalTextRedactor
impl !UnwindSafe for PersonalTextRedactor
impl Forget for PersonalTextRedactor
impl Move for PersonalTextRedactor
impl Send for PersonalTextRedactorwhere
RawVecInner: Send,
OnceCell<Arc<dyn DocumentReader>>: Send,
BoxRaw<dyn Fn() -> Pin<Box<dyn Future<Output = Result<Arc<dyn DocumentReader>, VisionError>> + Send>> + Sync + Send>: Send,
Arc<RegexI>: Send,
BoxRaw<Pool<Cache, Box<dyn Fn() -> Cache + Sync + RefUnwindSafe + Send + UnwindSafe>>>: Send,
Arc<str>: Send,
impl Sync for PersonalTextRedactorwhere
RawVecInner: Sync,
OnceCell<Arc<dyn DocumentReader>>: Sync,
BoxRaw<dyn Fn() -> Pin<Box<dyn Future<Output = Result<Arc<dyn DocumentReader>, VisionError>> + Send>> + Sync + Send>: Sync,
Arc<RegexI>: Sync,
BoxRaw<Pool<Cache, Box<dyn Fn() -> Cache + Sync + RefUnwindSafe + Send + UnwindSafe>>>: Sync,
Arc<str>: Sync,
impl Unpin for PersonalTextRedactorwhere
*const u8 is !null: Unpin,
Align1<u8>: Unpin,
Arc<dyn DocumentReader>: Unpin,
Align4<u32>: Unpin,
*const Waiter is !null: Unpin,
Align8<usize>: Unpin,
Box<dyn Fn() -> Pin<Box<dyn Future<Output = Result<Arc<dyn DocumentReader>, VisionError>> + Send>> + Sync + Send>: Unpin,
Arc<RegexI>: Unpin,
Box<Pool<Cache, Box<dyn Fn() -> Cache + Sync + RefUnwindSafe + Send + UnwindSafe>>>: Unpin,
Arc<str>: Unpin,
impl UnsafeUnpin for PersonalTextRedactorwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
Align1<u8>: UnsafeUnpin,
*const ArcInner<dyn DocumentReader> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn DocumentReader>>: UnsafeUnpin,
PhantomData<Mutex<Waitlist>>: UnsafeUnpin,
*const Waiter is !null: UnsafeUnpin,
Align8<usize>: UnsafeUnpin,
*const dyn Fn() -> Pin<Box<dyn Future<Output = Result<Arc<dyn DocumentReader>, VisionError>> + Send>> + Sync + Send is !null: UnsafeUnpin,
PhantomData<dyn Fn() -> Pin<Box<dyn Future<Output = Result<Arc<dyn DocumentReader>, VisionError>> + Send>> + Sync + Send>: UnsafeUnpin,
PhantomData<(PiiType, Regex)>: UnsafeUnpin,
PhantomData<Vec<String>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for T
impl<T> Downcast for T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
impl<T> MaybeSend for Twhere
T: Send,
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.