thelinhbkhn2014 / VnCoreNLP_Wrapper

Apache License 2.0
25 stars 5 forks source link

Error when use with flask and other application sensitive with working dir #7

Closed chessgenius closed 1 year ago

chessgenius commented 2 years ago

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.

hoangnv735 commented 2 years 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);
    }
datquocnguyen commented 1 year ago

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.

thelinhbkhn2014 commented 1 year ago

I also updated the py_vncorenlp newest version (0.1.4). Thank you for your contribution!