ner
is a command-line utility for performing
named entity recognition (NER) on text.
You can use it to extract names of people, places, and organizations
from standard input or file arguments.
$ echo "Designed by Apple in California." | ner
ORGANIZATION Apple
PLACE California
For more information about natural language processing, check out Chapter 7 of the Flight School Guide to Swift Strings.
- macOS 10.12+
Install ner
with Homebrew using the following command:
$ brew install flight-school/formulae/ner
Text can be read from either standard input or file arguments, and named entities are written to standard output on separate lines.
$ echo "Tim Cook is the CEO of Apple." | ner
PERSON Tim Cook
ORGANIZATION Apple
$ ner
Greetings from Cupertino, California! (This text is being typed into standard input.)
PLACE Cupertino
PLACE California
$ cat barton.txt
The American Red Cross was established in Washington DC by Clara Barton.
$ ner barton.txt
ORGANIZATION American Red Cross
PLACE Washington DC
PERSON Clara Barton
$ cat lincoln.txt
Abraham Lincoln was the 16th President of the United States of America.
$ ner barton.txt lincoln.txt
ORGANIZATION American Red Cross
PLACE Washington DC
PERSON Clara Barton
PERSON Abraham Lincoln
PLACE United States of America
ner
can be chained with
Unix text processing commands,
like cut
, sort
, uniq
, comm
, grep
sed
, and awk
.
$ ner barton.txt | cut -f2
American Red Cross
Washington DC
Clara Barton
Named entities are written to standard output on separate lines.
Each line consists of
the tag (PERSON
, PLACE
, or ORGANIZATION
),
followed by a tab (\t
),
followed by the token:
^(?<tag>(?>PERSON|PLACE|ORGANIZATION))\t(?<token>.+)$
ner
uses
NLTagger
when available,
falling back on
NSLinguisticTagger
for older versions of macOS.
MIT
Mattt (@mattt)