Skip to content

NERtwork is a collection of scripts to help you create a network graph of co-occurring named entities using open source tools. This is done by using Stanford Named Entity Recognizer to identify named entities in the documents, then using NetworkX to create a bipartite projected network and exporting the node and edge lists for use in network vis…

License

Notifications You must be signed in to change notification settings

brandontlocke/NERtwork

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 

Repository files navigation

Batch script for Named Entity Recognition

This is a single command-line script that will call the Stanford Named Entity Recognizer on each text file in a folder, count unique entities, and print the results into a spreadsheet.

The final spreadsheet (called entities.csv) will have the text filename, the entity recognized, the type of entity (organization, location, person), and the number of times that entity occurred as that type** within the document.

**It's possible for the same word to be tagged as more than one type of entity within a document.

Requirements

This script only works on text (.txt) files, but it will work on as many text files as you'd like without any further interaction on your part.

You will need to download Stanford Named Entity Recognizer

Folder Setup

As is, the script will run Stanford NER on every text (.txt) file within a folder. This expects that the NER folder (as of this writing, the stanford-ner-2018-02-27 folder), all of the text files, and the batchner.sh script are all within the same folder. (Note: you do not have to change the names of the .txt files—the filenames below are just for demonstration)

├──🗂 project folder
|   ├──🗂 stanford-ner-2018-02-27
|   └──batchner.sh [or batchner-win.sh on Windows]
|   └──file1.txt
|   └──file2.txt
|   └──file3.txt
|   └──file4.txt
|   └──file5.txt
|   └──file6.txt
|   └──etc.

If you're familiar with shell scripting and file navigation, you can fairly easily restructure this.

Running the Script

Mac OS X

Once all of your files are properly arranged as above:

  1. Open Terminal
  2. Navigate to the folder containing these files (using $ cd) [if you have a folder 'project' on the Desktop, type (without the $) $ cd Desktop/project.]
  3. Type $ sh batchner.sh This will take a bit to run (4-5 files will likely take about a minute), but will print all of the results into a file in the same folder called entities.csv

Windows

Download and install Cygwin. Once your files are arranged as above:

  1. Open Cygwin
  2. Navigate to the folder containing these files (using $ cd) [if you have a folder 'project' on the Desktop, type (without the $) $ cd /cygdrive/c/Users/YOUR-USERNAME/Desktop/project.]
  3. Type $ sh batchner-win.sh This will take a bit to run (4-5 files will likely take about a minute), but will print all of the results into a file in the same folder called entities.csv

Notes

As new versions of Stanford NER come out, the filepath will change and will need to be updated

About

NERtwork is a collection of scripts to help you create a network graph of co-occurring named entities using open source tools. This is done by using Stanford Named Entity Recognizer to identify named entities in the documents, then using NetworkX to create a bipartite projected network and exporting the node and edge lists for use in network vis…

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published