简体   繁体   中英

In python, how to add command to bash_profile?

My enviroment is Google Colab, which is in Python. I am trying to follow the instructions on this website.

https://github.com/abisee/cnn-dailymail

And it mentions to

Then add the following command to your bash_profile:

export CLASSPATH=/path/to/stanford-corenlp-full-2017-06-09/stanford-corenlp-3.8.0.jar

My best guess was to run using

!export CLASSPATH=/stanford-corenlp-full-2017-06-09/stanford-corenlp-3.8.0.jar

Which executed without any errors

But then the instructions say to

You can check if it's working by running

echo "Please tokenize this text." | java edu.stanford.nlp.process.PTBTokenizer

So I tried

!echo "Please tokenize this text." | java edu.stanford.nlp.process.PTBTokenizer

But then I got this error

Error: Could not find or load main class edu.stanford.nlp.process.PTBTokenizer
Caused by: java.lang.ClassNotFoundException: edu.stanford.nlp.process.PTBTokenizer

Edit:

I found instructions to install Java in colab

# Install Java
!apt-get install -y openjdk-8-jdk-headless -qq > /dev/null
os.environ["JAVA_HOME"] = "/usr/lib/jvm/java-8-openjdk-amd64"
!java -version

But

!echo "Please tokenize this text." | java edu.stanford.nlp.process.PTBTokenizer

Still gives the same error

I'd recommend not changing your .bash_profile as you're going to accumulate settings and junk.

Instead, java lets you specify CLASSPATH with the -cp option, which we can add to the Python script.

(You can also use java -cp /path/to/blahblah.jar etc to test it as their instructions recommend.)

Change this line in make_datafile.py to:

command = ['java', '-cp', '/path/to/blahblah.jar', 'edu.stanford.nlp.process.PTBTokenizer', 
           '-ioFileList', '-preserveLines', 'mapping.txt']

If you're still having trouble, make sure you have a valid jar!

List the contents with:

jar -tvf /path/to/blahblah.jar

You should see edu/stanford/nlp/process/PTBTokenizer.class listed, otherwise no amount of messing with the CLASSPATH will fix it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM