Last active
February 1, 2023 21:53
-
-
Save troyane/c9355a3103ea08679baf to your computer and use it in GitHub Desktop.
Script to prepare Stanford NER to work with your Python and NLTK
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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? :)" |
Is #!/bin/bash a directory that I should have? Searching for it...
@renospec no it is the programm that will execute this file on unix systems. See: https://en.wikipedia.org/wiki/Shebang_(Unix)
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
@Shivakishore14 just ran across this as well. It's called StanfordNERTagger
in nltk 3.2.5.
how to run this on windows
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!