pub struct RelationExtractor { /* private fields */ }Expand description
Relation extraction module
Implementations§
Source§impl RelationExtractor
impl RelationExtractor
Sourcepub fn new(_config: &AiConfig) -> Result<Self>
pub fn new(_config: &AiConfig) -> Result<Self>
Create a new relation extractor backed by the built-in heuristic (rule-based) NER, relation classifier, and entity linker.
These heuristic backends are transparent, deterministic, and honest: they
do NOT emulate a trained ML model, they do not fabricate confidence scores
dressed up as model probabilities, and the entity linker does not invent
unverified knowledge-base URIs. Every relation they produce is tagged with
metadata["extraction_method"] = "heuristic-keyword-match" so downstream
consumers can distinguish heuristic output from a real model’s.
To use a real ML backend (BERT-NER, a trained relation classifier, a live
entity-linking service, etc.), construct real trait objects and pass them
to with_backends.
_config is currently unused by the heuristic backends (they have no
tunable model parameters); it is retained for API symmetry with the
backend-injecting constructor.
Sourcepub fn with_backends(
extraction_config: ExtractionConfig,
ner_model: Box<dyn NamedEntityRecognizer>,
relation_model: Box<dyn RelationClassifier>,
entity_linker: Box<dyn EntityLinker>,
) -> Self
pub fn with_backends( extraction_config: ExtractionConfig, ner_model: Box<dyn NamedEntityRecognizer>, relation_model: Box<dyn RelationClassifier>, entity_linker: Box<dyn EntityLinker>, ) -> Self
Create a relation extractor with caller-provided backends.
This is the path for wiring in a real NER model, relation classifier, and
entity linker. The extraction_config’s confidence_threshold is used to
filter extracted relations.
Sourcepub async fn extract_relations(
&self,
text: &str,
) -> Result<Vec<ExtractedRelation>>
pub async fn extract_relations( &self, text: &str, ) -> Result<Vec<ExtractedRelation>>
Extract relations from text
Sourcepub fn to_triples(&self, relations: &[ExtractedRelation]) -> Result<Vec<Triple>>
pub fn to_triples(&self, relations: &[ExtractedRelation]) -> Result<Vec<Triple>>
Convert extracted relations to RDF triples
Auto Trait Implementations§
impl !RefUnwindSafe for RelationExtractor
impl !UnwindSafe for RelationExtractor
impl Freeze for RelationExtractor
impl Send for RelationExtractor
impl Sync for RelationExtractor
impl Unpin for RelationExtractor
impl UnsafeUnpin for RelationExtractor
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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> 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 more