Closed chessgenius closed 1 year ago
I am not the authors, but I have tried some workaround to avoid changing the working directory. Then I finally realized that the Java code of VnCoreNLP loads models by related path. So I guess working directory alteration is inevitable now. Below is the Java code from VnCoreNLP
public class WordSegmenter {
private Node root;
private static WordSegmenter wordSegmenter = null;
public final static Logger LOGGER = Logger.getLogger(WordSegmenter.class);
public WordSegmenter()
throws IOException {
LOGGER.info("Loading Word Segmentation model");
String modelPath = System.getProperty("user.dir") + "/models/wordsegmenter/wordsegmenter.rdr";
if (!new File(modelPath).exists())
throw new IOException("WordSegmenter: " + modelPath + " is not found!");
this.constructTreeFromRulesFile(modelPath);
}
I made some minor changes to VnCoreNLP, to avoid using System.getProperty("user.dir")
. See: https://github.com/vncorenlp/VnCoreNLP/commit/62bbc58fe5d113c898eae112656be97dcf50b3a0
You thus might want to use the latest py_vncorenlp
version 0.1.4.
I also updated the py_vncorenlp newest version (0.1.4). Thank you for your contribution!
Dear authors,
If this app use with flask or any other application with sensitive with working dir, it will appear errors, because you use os.chdir in init and annotate_file function.
Just use os.path.realpath to get absolute path from relative path and avoid using os.chdir and using os.path.join to deal with joining directory instead of using your custom functions.
Thanks.