Function Repository Resource:

SentenceCount

Source Notebook

Count the number of sentences in a string of text

Contributed by: Peter Cullen Burbery

ResourceFunction["SentenceCount"][str]

count the number of sentences in the string of text str.

Details

ResourceFunction["SentenceCount"] reproduces a common feature of word processing software.

Examples

Basic Examples

Count the number of sentences in the largest Wikipedia article, the Wikipedia article for the United States:

In[1]:=
ResourceFunction["SentenceCount"][WikipediaData["United States"]]
Out[1]=

Count the number of sentences in Hamlet:

In[2]:=
ResourceFunction["SentenceCount"][ExampleData[{"Text", "Hamlet"}]]
Out[2]=

Make a dataset of the number of sentences in example data texts and sort in descending order:

In[3]:=
Dataset[ReverseSort[
  AssociationMap[ResourceFunction["SentenceCount"][ExampleData[#]] &][
   ExampleData["Text"]]], DatasetTheme -> "Business", MaxItems -> 7]
Out[3]=

Publisher

Peter Burbery

Version History

  • 1.0.0 – 07 June 2023

Related Resources

License Information