Search code examples
javastanford-nlpslf4jjena

Stanford POS tagger doesn't work with SLF4J in classpath


I'm using the Stanford POS tagger 3.7.0 in a Java project that also uses the Jena RDF API. Jena requires slf4j-api-1.7.12.jar and slf4j-log4j12-1.7.12.jar, but when trying to call the POS tagger having those jars in the classpath I get the following error:

Exception in thread "main" java.lang.ExceptionInInitializerError
    at edu.stanford.nlp.util.logging.Redwood$ConsoleHandler.out(Redwood.java:920)
    at edu.stanford.nlp.util.logging.RedwoodConfiguration.<init>(RedwoodConfiguration.java:28)
    at edu.stanford.nlp.util.logging.RedwoodConfiguration.empty(RedwoodConfiguration.java:385)
    at util.Splitter.split(Splitter.java:58)
    at core.Main.main(Main.java:23)
Caused by: java.lang.IllegalStateException: Could not find SLF4J in your classpath
    at edu.stanford.nlp.util.logging.RedwoodConfiguration$Handlers.lambda$static$530(RedwoodConfiguration.java:190)
    at edu.stanford.nlp.util.logging.RedwoodConfiguration$Handlers$7.buildChain(RedwoodConfiguration.java:309)
    at edu.stanford.nlp.util.logging.RedwoodConfiguration$Handlers$7.apply(RedwoodConfiguration.java:318)
    at edu.stanford.nlp.util.logging.RedwoodConfiguration.lambda$handlers$535(RedwoodConfiguration.java:363)
    at edu.stanford.nlp.util.logging.RedwoodConfiguration.apply(RedwoodConfiguration.java:41)
    at edu.stanford.nlp.util.logging.Redwood.<clinit>(Redwood.java:609)
    ... 5 more
Caused by: edu.stanford.nlp.util.MetaClass$ClassCreationException: java.lang.ClassNotFoundException: edu.stanford.nlp.util.logging.SLF4JHandler
    at edu.stanford.nlp.util.MetaClass.createFactory(MetaClass.java:364)
    at edu.stanford.nlp.util.MetaClass.createInstance(MetaClass.java:381)
    at edu.stanford.nlp.util.logging.RedwoodConfiguration$Handlers.lambda$static$530(RedwoodConfiguration.java:186)
    ... 10 more
Caused by: java.lang.ClassNotFoundException: edu.stanford.nlp.util.logging.SLF4JHandler
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at edu.stanford.nlp.util.MetaClass$ClassFactory.construct(MetaClass.java:135)
    at edu.stanford.nlp.util.MetaClass$ClassFactory.<init>(MetaClass.java:202)
    at edu.stanford.nlp.util.MetaClass$ClassFactory.<init>(MetaClass.java:69)
    at edu.stanford.nlp.util.MetaClass.createFactory(MetaClass.java:360)
    ... 12 more

I've seen that people that had a similar problem solved it by removing SLF4J from the classpath. In fact, when I remove the jars the POS tagger works fine, but then Jena stops working.

Is there a way to keep SLF4J in the classpath and still get the POS tagger to work?


Solution

  • I think the best solution is to just use the full Stanford CoreNLP 3.7.0 release which won't have this issue but will have all the POS tagging functionality.

    The full download is available here:

    http://stanfordnlp.github.io/CoreNLP/download.html

    This issue should be resolved in the standalone distributions for Stanford CoreNLP 3.8.0 which we'll try to release in the early summer.