How to suppress Stanford CoreNLP Redwood logging i

2019-08-30 09:44发布

问题:

The thread How to shutdown Stanford CoreNLP Redwood logging? supposedly resolved my question in Java. I would like to do the same in MATLAB, but the code(s) given in that thread doesn't work. Please suggest a complete solution, starting with what to import, setting properties, etc.

My code is the following:

import java.io.*;
import edu.stanford.nlp.tagger.maxent.MaxentTagger;

tagger = MaxentTagger('./english-left3words-distsim.tagger');

which logs on the command line:

Reading POS tagger model from ./english-left3words-distsim.tagger ... done [3.6 sec].

taken from CreateTagger.m in my package: https://github.com/jzsfvss/POSTaggerSML.

回答1:

I'm not very up on calling Java from MatLab, but I think it would work and remove the loading message to use instead the following (where the final false argument says to not print loading):

import edu.stanford.nlp.util.StringUtils;

...
tagger = MaxentTagger('./english-left3words-distsim.tagger', StringUtils.argsToProperties({'-model', './english-left3words-distsim.tagger'}), false);

If that doesn't work, perhaps the easiest thing would be to make an slf4j config file simplelogger.properties with the line:

org.slf4j.simpleLogger.log.edu.stanford.nlp.tagger.maxent.MaxentTagger=warn

and to make sure that file is on the Java classpath (presumably with a call to javaaddpath) so that the tagger component no longer prints INFO messages like the file loading.