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+
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.
Reading from Piped Standard Input
$ echo "Tim Cook is the CEO of Apple." | ner PERSON Tim Cook ORGANIZATION Apple
Reading from Standard Input Interactively
$ ner Greetings from Cupertino, California! (This text is being typed into standard input.) PLACE Cupertino PLACE California
Reading from a File
$ 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
Reading from Multiple Files
$ 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
$ 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 (
ORGANIZATION), followed by a tab (
\t), followed by the token: