-2

What I want to do is, I have a semantic parser written in Java, and this semantic parser will output one-liner code in Python (string). And I want to make this consecutively. Methods I searched are runtime.exec or Jython where I can run the entire script. But I want to write code line by line and see the result after each line.

So let's say my Java program returned "import pandas." Then it will run that line in python. And then user makes another input and Java returned "pandas.read.csv('somefile.csv')". Then based on my previous call "import pandas", I will run the next line of code in Python script. I want to do this consecutively, since my semantic parser makes a one-liner code in Python based on the user input.

Ideally I would have Java program run Python interpreter and feed each code one by one and see the reuslt. But I'm not entirely sure if this is a feasible way to do this. Obvious solution would be to add line by line in a Python script and just run the entire script. But this would waste a lot of time. So if there is any good way to do this, please share with me. Thank you.

1 Answers1

0

The jep project uses JNI to embed a python interpreter within the java process. The eval method of the Jep class is specifically intended to allow you to run python line by line.

bsteffen
  • 371
  • 2
  • 9