Skip to content

Improve docs for sentence segmentation #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 40 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,6 @@ pub trait UnicodeSegmentation {
/// ```
fn split_word_bound_indices<'a>(&'a self) -> UWordBoundIndices<'a>;

/// Returns an iterator over substrings of `self` separated on
/// [UAX#29 sentence boundaries](http://www.unicode.org/reports/tr29/#Sentence_Boundaries).
///
/// The concatenation of the substrings returned by this function is just the original string.
fn unicode_sentences<'a>(&'a self) -> UnicodeSentences<'a>;

/// Returns an iterator over substrings of `self` separated on
/// [UAX#29 sentence boundaries](http://www.unicode.org/reports/tr29/#Sentence_Boundaries).
///
Expand All @@ -192,10 +186,50 @@ pub trait UnicodeSegmentation {
/// [Alphabetic](http://unicode.org/reports/tr44/#Alphabetic)
/// property, or with
/// [General_Category=Number](http://unicode.org/reports/tr44/#General_Category_Values).
///
/// # Example
///
/// ```
/// # use self::unicode_segmentation::UnicodeSegmentation;
/// let uss = "Mr. Fox jumped. [...] The dog was too lazy.";
/// let us1 = uss.unicode_sentences().collect::<Vec<&str>>();
/// let b: &[_] = &["Mr. ", "Fox jumped. ", "The dog was too lazy."];
///
/// assert_eq!(&us1[..], b);
/// ```
fn unicode_sentences<'a>(&'a self) -> UnicodeSentences<'a>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add some text explaining what this function does?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid I don't understand. Do you mean I should expand on

Returns an iterator over substrings of self separated on
UAX#29 sentence boundaries.

Here, "sentences" are just those substrings which, after splitting on
UAX#29 sentence boundaries, contain any alphanumeric characters. That is, the
substring must contain at least one character with the
Alphabetic
property, or with
General_Category=Number.

above the example?

(I'm wondering whether the way the diff is rendered might be confusing you.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, sorry, this was absolutely diff rendering stuff 😄


/// Returns an iterator over substrings of `self` separated on
/// [UAX#29 sentence boundaries](http://www.unicode.org/reports/tr29/#Sentence_Boundaries).
///
/// The concatenation of the substrings returned by this function is just the original string.
///
/// # Example
///
/// ```
/// # use self::unicode_segmentation::UnicodeSegmentation;
/// let ssbs = "Mr. Fox jumped. [...] The dog was too lazy.";
/// let ssb1 = ssbs.split_sentence_bounds().collect::<Vec<&str>>();
/// let b: &[_] = &["Mr. ", "Fox jumped. ", "[...] ", "The dog was too lazy."];
///
/// assert_eq!(&ssb1[..], b);
/// ```
fn split_sentence_bounds<'a>(&'a self) -> USentenceBounds<'a>;

/// Returns an iterator over substrings of `self`, split on UAX#29 sentence boundaries,
/// and their offsets. See `split_sentence_bounds()` for more information.
///
/// # Example
///
/// ```
/// # use self::unicode_segmentation::UnicodeSegmentation;
/// let ssis = "Mr. Fox jumped. [...] The dog was too lazy.";
/// let ssi1 = ssis.split_sentence_bound_indices().collect::<Vec<(usize, &str)>>();
/// let b: &[_] = &[(0, "Mr. "), (4, "Fox jumped. "), (16, "[...] "),
/// (22, "The dog was too lazy.")];
///
/// assert_eq!(&ssi1[..], b);
/// ```
fn split_sentence_bound_indices<'a>(&'a self) -> USentenceBoundIndices<'a>;
}

Expand Down