Mute Stanford coreNLP logging

天大地大妈咪最大 提交于 2019-12-02 06:20:42

问题


First of all, Java is not my usual language, so I'm quite basic at it. I need to use it for this particular project, so please be patient, and if I have omitted any relevant information, please ask for it, I will be happy to provide it.

I have been able to implement coreNLP, and, seemingly, have it working right, but is generating lots of messages like:

ene 20, 2017 10:38:42 AM edu.stanford.nlp.process.PTBLexer next
ADVERTENCIA: Untokenizable: 【 (U+3010, decimal: 12304)

After some research (documentation, google, other threads here), I think (sorry, I don't know how I can tell for sure) coreNLP is finding the slf4j-api.jar in my classpath, and logging through it.

Which properties of the JVM can I use to set logging level of the messages that will be printed out?

Also, in which .properties file I could set them? (I already have a commons-logging.properties, a simplelog.properties and a StanfordCoreNLP.properties in my project's resource folder to set properties for other packages).


回答1:


Om’s answer is good, but two other possibly useful approaches:

  • If it is just these warnings from the tokenizer that are annoying you, you can (in code or in StanfordCoreNLP.properties) set a property so they disappear: props.setProperty("tokenize.options", "untokenizable=NoneKeep");.
  • If slf4j is on the classpath, then, by default, our own Redwoods logger will indeed log through slf4j. So, you can also set the logging level using slf4j.



回答2:


If I understand your problem, you want to disable all StanfordNLP logging message while the program is executing.

You can disable the logging message. Redwood logging framework is used as logging framework in Stanford NLP. First, clear the Redwood's default configuration(to display log message) then create StanfordNLP pipeline.

import edu.stanford.nlp.util.logging.RedwoodConfiguration;
RedwoodConfiguration.current().clear().apply();
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

Hope it helps.




回答3:


In accordance with Christopher Manning's suggestion, I followed this link How to configure slf4j-simple

I created a file src/simplelogger.properties with the line org.slf4j.simpleLogger.defaultLogLevel=warn.




回答4:


I am able to solve it by setting a blank output stream to system error stream.

System.setErr(new PrintStream(new BlankOutputStream())); // set blank error stream
// ... Add annotators ...
System.setErr(System.err); // Reset to default

Accompanying class is

public class BlankOutputStream extends OutputStream {

    @Override
    public void write(int b) throws IOException {
        // Do nothing
    }

}


来源:https://stackoverflow.com/questions/41761099/mute-stanford-corenlp-logging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!