Struct vaporetto::Sentence [−][src]
pub struct Sentence { /* fields omitted */ }
Expand description
Sentence with boundary annotations.
Implementations
Creates a new Sentence
from a given string.
Arguments
text
- A raw string without any annotation.
Returns
A new Sentence
.
Errors
If the given text
is empty, an error variant will be returned.
Examples
use vaporetto::Sentence;
let s = Sentence::from_raw("How are you?");
assert!(s.is_ok());
let s = Sentence::from_raw("");
assert!(s.is_err());
Creates a new Sentence
from a tokenized string.
Arguments
tokenized_text
- A tokenized string containing whitespaces for word boundaries.
Returns
A new Sentence
.
Errors
This function will return an error variant when:
tokenized_text
is empty.tokenized_text
starts/ends with a whitespace.tokenized_text
contains consecutive whitespaces.
Examples
use vaporetto::Sentence;
let s = Sentence::from_tokenized("How are you?");
assert!(s.is_ok());
let s = Sentence::from_tokenized("How are you?");
assert!(s.is_err());
Generates a string with whitespaces for word boundaries.
Returns
A newly allocated string containing whitespaces for word boundaries.
Errors
If the sentence contains unknown boundary, an error variant will be returned.
Examples
use vaporetto::Sentence;
let s = Sentence::from_tokenized("How are you?").unwrap();
assert_eq!("How are you?", s.to_tokenized_string().unwrap());
Generates a vector of words.
Returns
A newly allocated vector of words.
Errors
If the sentence contains unknown boundaries, an error variant will be returned.
Examples
use vaporetto::Sentence;
let s = Sentence::from_tokenized("How are you ?").unwrap();
assert_eq!(vec![
"How".to_string(),
"are".to_string(),
"you".to_string(),
"?".to_string(),
], s.to_tokenized_vec().unwrap());
Creates a new Sentence
from a string with partial annotations.
Arguments
labeled_text
- A string with partial annotations.
Returns
A new Sentence
.
Errors
This function will return an error variant when:
labeled_text
is empty.- The length of
lsbeled_text
is even numbers. labeled_text
contains invalid boundary characters.
Examples
use vaporetto::Sentence;
let s = Sentence::from_partial_annotation("g-o-o-d|i-d e-a");
assert!(s.is_ok());
let s = Sentence::from_partial_annotation("b-a-d/i-d-e-a");
assert!(s.is_err());
Gets a reference to the boundary information.
Returns
A reference to the boundary information.
Examples
use vaporetto::{BoundaryType, Sentence};
let s = Sentence::from_partial_annotation("a|b-c d").unwrap();
assert_eq!(&[
BoundaryType::WordBoundary,
BoundaryType::NotWordBoundary,
BoundaryType::Unknown,
], s.boundaries());
Gets a mutable reference to the boundary information.
Returns
A mutable reference to the boundary information.
Gets a reference to the boundary score information.
Returns
If the predictor inserted, the boundary score information is returned. Otherwise, None.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Sentence
impl UnwindSafe for Sentence
Blanket Implementations
Mutably borrows from an owned value. Read more