Skip to content

Instantly share code, notes, and snippets.

@troyane
Last active February 1, 2023 21:53
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save troyane/c9355a3103ea08679baf to your computer and use it in GitHub Desktop.
Save troyane/c9355a3103ea08679baf to your computer and use it in GitHub Desktop.
Script to prepare Stanford NER to work with your Python and NLTK
#!/bin/bash
mkdir my_project
cd my_project
echo " . . . Downloading file stanford-ner-2014-08-27.zip"
# NOTE: need to update link for further versions
wget http://nlp.stanford.edu/software/stanford-ner-2014-08-27.zip
echo " . . . Unpacking stanford-ner-2014-08-27.zip"
unzip stanford-ner-2014-08-27.zip
mkdir stanford-ner
cp stanford-ner-2014-08-27/stanford-ner.jar stanford-ner/stanford-ner.jar
cp stanford-ner-2014-08-27/classifiers/english.all.3class.distsim.crf.ser.gz stanford-ner/english.all.3class.distsim.crf.ser.gz
cp stanford-ner-2014-08-27/classifiers/english.all.3class.distsim.prop stanford-ner/english.all.3class.distsim.prop
echo " . . . Clearing all"
rm -rf stanford-ner-2014-08-27 stanford-ner-2014-08-27.zip
echo " . . . Preparing Python test file test_sner.py"
touch test_sner.py
# import Stanford NER for NLTK (avaaible from 2.0 ver)
echo "from nltk.tag.stanford import NERTagger" >> test_sner.py
# initialize SNER using copied files
echo "st = NERTagger('stanford-ner/english.all.3class.distsim.crf.ser.gz', 'stanford-ner/stanford-ner.jar')" >> test_sner.py
# add test to see weather it works
echo "print st.tag('You can call me Billiy Bubu and I live in Amsterdam.'.split())" >> test_sner.py
chmod +x test_sner.py
echo " . . . Executing Python test file test_sner.py"
python test_sner.py
echo " . . . Isn't it cool? :)"
@skywalker-lili
Copy link

Thanks!

@renospec
Copy link

Is #!/bin/bash a directory that I should have? Searching for it...

@ferdynator
Copy link

@renospec no it is the programm that will execute this file on unix systems. See: https://en.wikipedia.org/wiki/Shebang_(Unix)

@Shivakishore14
Copy link

I am unable to import NERTagger

File "test_sner.py", line 1, in <module>
    from nltk.tag.stanford import NERTagger
ImportError: cannot import name NERTagger

nltk version : 3.2.5

@georggrab
Copy link

@Shivakishore14 just ran across this as well. It's called StanfordNERTagger in nltk 3.2.5.

@bhargavAtgithub
Copy link

how to run this on windows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment