-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.

2
  • You can do that easily with Jython jython.org/jythonbook/en/1.0/… Commented Mar 20, 2018 at 1:47
  • But it seems like Jython has some limitations in running pandas (jyni.org). Commented Mar 20, 2018 at 2:31

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.