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.
- macOS 10.13+
Install sentences
with Homebrew using the following command:
$ brew install flight-school/formulae/sentences
Text can be read from either standard input or file arguments, and named entities are written to standard output on separate lines.
$ echo "Designed by Apple in California. Assembled in China." | sentences
Designed by Apple in California.
Assembled in China.
$ echo "床前明月光,疑是地上霜。举头望明月,低头思故乡。" | sentences
床前明月光,疑是地上霜。
举头望明月,低头思故乡。
$ 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.)
$ 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.
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
.
$ sentences think_different.txt | head -n 1 | pos
ADVERB Here
VERB 's
PREPOSITION to
DETERMINER the
ADJECTIVE crazy
NOUN ones
sentences
uses
NLTagger
when available,
falling back on
NSLinguisticTagger
for older versions of macOS.
MIT
Mattt (@mattt)