简体   繁体   中英

How to call a python program from spring boot?

I am using implicit library in python to implement a recommendation system. The model is ready, but the problem is my application is java based(spring boot). Now I've the model, matrices and everything setup in python. Basically the model has a offline component, where i perform the data feeding and matrix factorization stuff. After that I've a python method which returns the recommendation for a user.

The offline component will run once in a month. For the whole month I need to store the factorized matrix in some place and whenever required I need to call my python method from REST endpoint, which will utilize the stored matrix and return some results.

So I've two questions.

1. My factorized matrix is a numpy.sparse_matrix. How can I store it, so that it will be reused again and again?
2. How do i invoke a python method in java endpoint which will utilize the methods from implicit library then do the calculation based on the matrix and return the result?

Any insight would be appreciated. Thanks in advance.

推荐的方法是在 REST 微服务中转换 Python 代码,然后在 Java 程序中使用它。

You can directly Runtime from java for the same.

String fetching = "python " + "c:\\<PythonFileName>.py \"" + songDetails + "\"";
String[] commandToExecute = new String[]{"cmd.exe", "/c", fetching};
Runtime.getRuntime().exec(commandToExecute);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM