Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 2+3 and pip #32

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Switch get_stanford from sh to python.
The entire script can be done with the Python
standard library, which is better than relying on
Unix programs.
Dylan Flaute committed Jul 3, 2018
commit 0aacba8b89def08b663c1492e1cf1387472548c9
47 changes: 47 additions & 0 deletions get_stanford_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env python
from __future__ import print_function

import os
import shutil
import zipfile

try:
from urllib.request import urlretrieve
except ImportError:
from urllib import urlretrieve


def main():
core_nlp = "stanford-corenlp-full-2015-12-09"
spice_lib = "pycocoevalcap/spice/lib"
jar = "stanford-corenlp-3.6.0{}.jar"

root_dir = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))

jar_file = os.path.join(root_dir, spice_lib, jar)
if os.path.exists(jar_file):
print("Found Stanford CoreNLP.")
else:
print("Downloading Stanford CoreNLP...")
core_nlp_zip = core_nlp + ".zip"
urlretrieve(
"http://nlp.stanford.edu/software/{}".format(core_nlp_zip),
core_nlp_zip)
print("Unzipping {}...".format(core_nlp_zip))
zip_ref = zipfile.ZipFile(core_nlp_zip, "r")
zip_ref.extractall(spice_lib)
zip_ref.close()
shutil.move(
os.path.join(spice_lib, core_nlp, jar.format("")),
spice_lib)
shutil.move(
os.path.join(spice_lib, core_nlp, jar.format("-models")),
spice_lib)
os.remove(core_nlp_zip)
shutil.rmtree(os.path.join(spice_lib, core_nlp))
print("Done.")


if __name__ == "__main__":
main()

21 changes: 1 addition & 20 deletions get_stanford_models.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
#!/usr/bin/env sh
# This script downloads the Stanford CoreNLP models.

CORENLP=stanford-corenlp-full-2015-12-09
SPICELIB=pycocoevalcap/spice/lib
JAR=stanford-corenlp-3.6.0

DIR="$( cd "$(dirname "$0")" ; pwd -P )"
cd $DIR

if [ -f $SPICELIB/$JAR.jar ]; then
echo "Found Stanford CoreNLP."
else
echo "Downloading..."
wget http://nlp.stanford.edu/software/$CORENLP.zip
echo "Unzipping..."
unzip $CORENLP.zip -d $SPICELIB/
mv $SPICELIB/$CORENLP/$JAR.jar $SPICELIB/
mv $SPICELIB/$CORENLP/$JAR-models.jar $SPICELIB/
rm -f $CORENLP.zip
rm -rf $SPICELIB/$CORENLP/
echo "Done."
fi
python get_stanford_models.py
15 changes: 2 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
@@ -2,22 +2,11 @@
import os
import subprocess
from setuptools import setup, find_packages
import get_stanford_models

bash_command = "./get_stanford_models.sh"

curdir = os.path.dirname(os.path.realpath(__file__))
spicedir = os.path.join(curdir, "spice", "lib")
stanford_fmt = os.path.join(spicedir, "stanford-corenlp-3.6.0%s.jar")
base_jar = stanford_fmt % ""
model_jar = stanford_fmt % "-models"
# if os.path.exists(base_jar):
# os.remove(base_jar)
# if os.path.exists(model_jar):
# os.remove(model_jar)

if subprocess.call(bash_command, cwd=curdir) != 0:
print("Stanford Jars could not be obtained and built. Do you have zip?")
sys.exit(1)
get_stanford_models.main()

setup(
name="pycocoevalcap",