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());

Gets a string without any annotation.

Returns

A reference to the string.

Examples

use vaporetto::Sentence;

let s = Sentence::from_raw("How are you?").unwrap();
assert_eq!("How are you?", s.to_raw_string());

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());

Generates a string with partial annotations.

Returns

A newly allocated string with partial annotations.

Examples

use vaporetto::Sentence;

let s = Sentence::from_tokenized("How are you ?").unwrap();
assert_eq!("H-o-w|a-r-e|y-o-u|?", &s.to_partial_annotation_string());

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 character type information.

Returns

A reference to the character type information.

Examples

use vaporetto::Sentence;

let s = Sentence::from_raw("A1あエ漢?").unwrap();
assert_eq!(&[b'R', b'D', b'H', b'T', b'K', b'O',], s.char_types());

Gets a reference to the boundary score information.

Returns

If the predictor inserted, the boundary score information is returned. Otherwise, None.

Gets a character position in the code point unit.

Returns

A position in the code point unit.

Errors

index must be a valid position.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.