0

I'm working in Java with the NetBeans IDE. I've downloaded the Stanford CoreNLP from their website and have no idea how to 'get it to work' in my Java project. I would like to be able to get this demo code working:

import java.io.FileReader;
import java.io.IOException;
import java.util.List;

import edu.stanford.nlp.ling.CoreLabel;
import edu.stanford.nlp.ling.HasWord;
import edu.stanford.nlp.process.CoreLabelTokenFactory;
import edu.stanford.nlp.process.DocumentPreprocessor;
import edu.stanford.nlp.process.PTBTokenizer;

public class TokenizerDemo {

  public static void main(String[] args) throws IOException {
    for (String arg : args) {
      // option #1: By sentence.
      DocumentPreprocessor dp = new DocumentPreprocessor(arg);
      for (List sentence : dp) {
        System.out.println(sentence);
      }
      // option #2: By token
      PTBTokenizer ptbt = new PTBTokenizer(new FileReader(arg),
              new CoreLabelTokenFactory(), "");
      for (CoreLabel label; ptbt.hasNext(); ) {
        label = ptbt.next();
        System.out.println(label);
      }
    }
  }
}

But I have no idea how to achieve this. Off the bat, my import statements produce errors (can't find ___ package) Can someone provide step by step instructions for how to get this code to work?

Tilo
  • 3,255
  • 26
  • 31
Sam Jones
  • 43
  • 5

1 Answers1

1

When you downloaded Stanford CoreNLP it came with a file stanford-corenlp-<VERSION>.jar and a stanford-corenlp-<VERSION>-models.jar that you should put on the classpath.

This answer tells you how to do that with NetBeans: How to setup classpath in Netbeans?

Community
  • 1
  • 1
Tilo
  • 3,255
  • 26
  • 31