Skip to content

Flight-School/sentences

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sentences

sentences is a command-line utility that splits natural language text into sentences.

$ cat propositions.txt
All men are mortal. Socrates is a man. Therefore, Socrates is mortal.

$ sentences propositions.txt
All men are mortal.
Socrates is a man.
Therefore, Socrates is mortal.


For more information about natural language processing, check out Chapter 7 of the Flight School Guide to Swift Strings.


Requirements

  • macOS 10.13+

Installation

Install sentences with Homebrew using the following command:

$ brew install flight-school/formulae/sentences

Usage

Text can be read from either standard input or file arguments, and named entities are written to standard output on separate lines.

Reading from Piped Standard Input

$ echo "Designed by Apple in California. Assembled in China." | sentences
Designed by Apple in California. 
Assembled in China.

$ echo "床前明月光,疑是地上霜。举头望明月,低头思故乡。" | sentences
床前明月光,疑是地上霜。
举头望明月,低头思故乡。

Reading from Standard Input Interactively

$ sentences
Greetings from Cupertino, California! (This text is being typed into standard input.)
Greetings from Cupertino, California!
(This text is being typed into standard input.)

Reading from a File

$ head -n 1 think_different.txt
Here's to the crazy ones. The misfits. The rebels. The troublemakers.

$ sentences think_different.txt
Here's to the crazy ones.
The misfits.
The rebels.
The troublemakers.
The round pegs in the square holes.
The ones who see things differently.
They're not fond of rules.
And they have no respect for the status quo.
You can quote them, disagree with them, glorify or vilify them.
About the only thing you can't do is ignore them.
Because they change things.
They push the human race forward.
And while some may see them as the crazy ones, we see genius.
Because the people who are crazy enough to think they can change the world, are the ones who do.

Advanced Usage

sentences can be chained with Unix text processing commands, like cut, sort, uniq, comm, grep sed, and awk --- as well as its sibling tools, ner and pos.

Filtering Tags

$ sentences think_different.txt | head -n 1 | pos
ADVERB	Here
VERB	's
PREPOSITION	to
DETERMINER	the
ADJECTIVE	crazy
NOUN	ones

Additional Details

sentences uses NLTagger when available, falling back on NSLinguisticTagger for older versions of macOS.

License

MIT

Contact

Mattt (@mattt)

About

A command-line utility that splits natural language text into sentences.

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published