Struct harper_core::Document
source · pub struct Document { /* private fields */ }
Expand description
A document containing some amount of lexed and parsed English text. This is
Implementations§
source§impl Document
impl Document
sourcepub fn new(
text: &str,
parser: &mut impl Parser,
dictionary: &impl Dictionary,
) -> Self
pub fn new( text: &str, parser: &mut impl Parser, dictionary: &impl Dictionary, ) -> Self
Lexes and parses text to produce a document using a provided language parser and dictionary.
sourcepub fn new_curated(text: &str, parser: &mut impl Parser) -> Self
pub fn new_curated(text: &str, parser: &mut impl Parser) -> Self
Lexes and parses text to produce a document using a provided language parser and the included curated dictionary.
sourcepub fn new_from_vec(
source: Lrc<Vec<char>>,
parser: &mut impl Parser,
dictionary: &impl Dictionary,
) -> Self
pub fn new_from_vec( source: Lrc<Vec<char>>, parser: &mut impl Parser, dictionary: &impl Dictionary, ) -> Self
Lexes and parses text to produce a document using a provided language parser and dictionary.
sourcepub fn new_plain_english_curated(text: &str) -> Self
pub fn new_plain_english_curated(text: &str) -> Self
Parse text to produce a document using the built-in PlainEnglish
parser and curated dictionary.
sourcepub fn new_plain_english(text: &str, dictionary: &impl Dictionary) -> Self
pub fn new_plain_english(text: &str, dictionary: &impl Dictionary) -> Self
Parse text to produce a document using the built-in PlainEnglish
parser and a provided dictionary.
sourcepub fn new_markdown_curated(text: &str) -> Self
pub fn new_markdown_curated(text: &str) -> Self
Parse text to produce a document using the built-in Markdown
parser
and curated dictionary.
sourcepub fn new_markdown(text: &str, dictionary: &impl Dictionary) -> Self
pub fn new_markdown(text: &str, dictionary: &impl Dictionary) -> Self
Parse text to produce a document using the built-in PlainEnglish
parser and the curated dictionary.
pub fn get_token_at_char_index(&self, char_index: usize) -> Option<Token>
sourcepub fn get_token(&self, index: usize) -> Option<Token>
pub fn get_token(&self, index: usize) -> Option<Token>
Defensively attempt to grab a specific token.
sourcepub fn tokens(&self) -> impl Iterator<Item = Token> + '_
pub fn tokens(&self) -> impl Iterator<Item = Token> + '_
Get an iterator over all the tokens contained in the document.
sourcepub fn fat_tokens(&self) -> impl Iterator<Item = FatToken> + '_
pub fn fat_tokens(&self) -> impl Iterator<Item = FatToken> + '_
Get an iterator over all the tokens contained in the document.
sourcepub fn chunks(&self) -> impl Iterator<Item = &[Token]> + '_
pub fn chunks(&self) -> impl Iterator<Item = &[Token]> + '_
Iterate over chunks.
For example, the following sentence contains two chunks separated by a comma:
Here is an example, it is short.
sourcepub fn sentences(&self) -> impl Iterator<Item = &[Token]> + '_
pub fn sentences(&self) -> impl Iterator<Item = &[Token]> + '_
Get an iterator over token slices that represent the individual sentences in a document.
pub fn get_span_content(&self, span: Span) -> &[char]
pub fn get_span_content_str(&self, span: Span) -> String
pub fn get_full_string(&self) -> String
pub fn get_full_content(&self) -> &[char]
Trait Implementations§
source§impl TokenStringExt for Document
impl TokenStringExt for Document
fn first_word(&self) -> Option<Token>
fn last_word(&self) -> Option<Token>
fn iter_word_indices(&self) -> impl Iterator<Item = usize> + '_
fn iter_words(&self) -> impl Iterator<Item = Token> + '_
fn first_space(&self) -> Option<Token>
fn last_space(&self) -> Option<Token>
fn iter_space_indices(&self) -> impl Iterator<Item = usize> + '_
fn iter_spaces(&self) -> impl Iterator<Item = Token> + '_
fn first_apostrophe(&self) -> Option<Token>
fn last_apostrophe(&self) -> Option<Token>
fn iter_apostrophe_indices(&self) -> impl Iterator<Item = usize> + '_
fn iter_apostrophes(&self) -> impl Iterator<Item = Token> + '_
fn first_pipe(&self) -> Option<Token>
fn last_pipe(&self) -> Option<Token>
fn iter_pipe_indices(&self) -> impl Iterator<Item = usize> + '_
fn iter_pipes(&self) -> impl Iterator<Item = Token> + '_
fn first_quote(&self) -> Option<Token>
fn last_quote(&self) -> Option<Token>
fn iter_quote_indices(&self) -> impl Iterator<Item = usize> + '_
fn iter_quotes(&self) -> impl Iterator<Item = Token> + '_
fn first_number(&self) -> Option<Token>
fn last_number(&self) -> Option<Token>
fn iter_number_indices(&self) -> impl Iterator<Item = usize> + '_
fn iter_numbers(&self) -> impl Iterator<Item = Token> + '_
fn first_at(&self) -> Option<Token>
fn last_at(&self) -> Option<Token>
fn iter_at_indices(&self) -> impl Iterator<Item = usize> + '_
fn iter_ats(&self) -> impl Iterator<Item = Token> + '_
fn first_sentence_word(&self) -> Option<Token>
fn first_non_whitespace(&self) -> Option<Token>
source§fn span(&self) -> Option<Span>
fn span(&self) -> Option<Span>
fn iter_linking_verb_indices(&self) -> impl Iterator<Item = usize> + '_
fn iter_linking_verbs(&self) -> impl Iterator<Item = Token> + '_
Auto Trait Implementations§
impl Freeze for Document
impl RefUnwindSafe for Document
impl !Send for Document
impl !Sync for Document
impl Unpin for Document
impl UnwindSafe for Document
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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