pub struct TripleExtractor { /* private fields */ }Expand description
Extracts subject–predicate–object triples from free text
Implementations§
Source§impl TripleExtractor
impl TripleExtractor
Sourcepub fn new(config: ExtractionConfig) -> Self
pub fn new(config: ExtractionConfig) -> Self
Create an extractor with no built-in patterns (only the supplied config).
Sourcepub fn with_defaults(config: ExtractionConfig) -> Self
pub fn with_defaults(config: ExtractionConfig) -> Self
Create an extractor pre-loaded with common English relation patterns.
Built-in patterns cover: is, has, works at, located in,
founded by, created by, known as, born in, part of.
Sourcepub fn add_pattern(&mut self, pattern: ExtractionPattern)
pub fn add_pattern(&mut self, pattern: ExtractionPattern)
Add a custom pattern to the extractor.
Sourcepub fn pattern_count(&self) -> usize
pub fn pattern_count(&self) -> usize
Returns the number of registered patterns.
Sourcepub fn extract(&self, text: &str) -> Vec<TextTriple>
pub fn extract(&self, text: &str) -> Vec<TextTriple>
Extract triples from text, splitting on sentence boundaries ('.', '!', '?').
Sourcepub fn extract_sentence(&self, sentence: &str) -> Vec<TextTriple>
pub fn extract_sentence(&self, sentence: &str) -> Vec<TextTriple>
Extract triples from a single sentence string.
Sourcepub fn normalize_predicate(predicate: &str) -> String
pub fn normalize_predicate(predicate: &str) -> String
Normalise a raw predicate string: lowercase, remove leading articles/stop words, collapse consecutive spaces, and trim.
Sourcepub fn confidence_for_pattern(
matched_words: usize,
total_pattern_words: usize,
) -> f64
pub fn confidence_for_pattern( matched_words: usize, total_pattern_words: usize, ) -> f64
Confidence based on how many predicate words were matched.
Returns matched_words / total_pattern_words, clamped to [0.0, 1.0].
Sourcepub fn to_knowledge_graph(
triples: &[TextTriple],
) -> Vec<(String, String, String)>
pub fn to_knowledge_graph( triples: &[TextTriple], ) -> Vec<(String, String, String)>
Convert a slice of TextTriples to plain (subject, predicate, object) tuples.
Auto Trait Implementations§
impl Freeze for TripleExtractor
impl RefUnwindSafe for TripleExtractor
impl Send for TripleExtractor
impl Sync for TripleExtractor
impl Unpin for TripleExtractor
impl UnsafeUnpin for TripleExtractor
impl UnwindSafe for TripleExtractor
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
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