1

I'm trying to parse sentence with Malt Parser in NLTK. When I did raw_parse(sent) it gave an error with exit code 1. I executed java command on terminal and it gives class Not Found exception, I don't understand what is wrong now?

java -Xmx1024m -jar /usr/local/bin/malt.jar -w /home/abc/maltparser-1.7.2 -c engmalt.linear-1.7 -i /home/abc/maltparser-1.7.2/malt_input.conllrPZgwc -o /home/abc/maltparser-1.7.2/malt_output.conllDMSKpg -m parse Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Layout

Hanky Panky
  • 46,730
  • 8
  • 72
  • 95
gizgok
  • 7,303
  • 21
  • 79
  • 124
  • Note that the latest version of NLTK has this module patched up nicely, see http://stackoverflow.com/questions/33015326/maltparser-giving-error-in-nltk – alvas Oct 08 '15 at 15:10

1 Answers1

1

Your working directory is not correctly set. Log4j is a package used by Malt Parser (see: maltparser-1.7.2/lib/log4j.jar). Which is used for logging logically.

In order to run maltparser in NLTK, the working directory should be set to this folder (in your case: /home/abc/maltparser-1.7.2).

So, step one is getting the latest NLTK from git:

git clone https://github.com/nltk/nltk.git

Install NLTK:

sudo python setup.py install

To run Malt Parser using NLTK try this code example:

import os
import nltk

os.environ['MALTPARSERHOME']="/home/abc/maltparser-1.7.2"
verbose = False
maltParser = nltk.parse.malt.MaltParser(working_dir="/home/abc/maltparser-1.7.2", 
    mco="engmalt.linear-1.7",
    additional_java_args=['-Xmx512m'])
print(maltParser.raw_parse('This is a test sentence', verbose=verbose).tree().pprint())

As you may notice I'm using the pre-learned mco file (engmalt.linear-1.7), which can be downloaded from here: http://www.maltparser.org/mco/english_parser/engmalt.html

Move this mco file to: /home/abc/maltparser-1.7.2 directory.

Finally NLTK only except malt.jar. So create a copy (or rename):

cp maltparser-1.7.2.jar malt.jar

Which can still be located in your /home/abc/maltparser-1.7.2.jar directory.

Hopefully you'll get it running!

Melroy van den Berg
  • 2,697
  • 28
  • 31