I'm running the an embedded library [tuProlog (2p.jar)] Prolog Inference Engine in Android with custom logic bases which I can successfully query and display (some) of the results in an Android ListView.
What gets displayed is only the results from the inference engine itself, not ancillary commands like a Prolog 'write' statement which (by default) writes to STDOUT.
I need to capture the result of that 'write' printing to the STDOUT in an Android variable to display to the user. The general idea (which I'm not married to a ListView to implement) is to simulate the command line interaction which one would engage in if they ran a Java Based Prolog Interpreter terminal interface.
I'd like to stick to the realm of Knowledge Engineering rather than entering Systems Engineering in order to complete this project, so I would be grateful for any insights into this problem.
My research has lead me here as an avenue of further study, but the systems stuff quickly gets past my experience.
Big thanks in advance ....
After a good bit of my own research and further discussions w/the tuProlog developers I have a solution to this question I think is worth sharing w/this community...
The overall context of the issue is getting ANY Prolog implementation to work on 'properly' Android as a foundational architecture for more interesting Apps (Expert Systems, Game AI, and Natural Language Interfaces) later on down the line.
The big hurdle is that Prolog is a 'Console' based interpretative environment which prints to STDOUT, and while Android tolerates console printing activities, by default it routs ALL of that to /dev/null.
So there are two sets of problems to address: (1) Is there ANY Prolog portable to the Android Environment, and (2) How does one 'properly' handle the issue of capturing the console output when it's routed to /dev/null.
Addressing (1): We settled on tuProlog Site, who's official source can be found: Google Code Repository - tuProlog. They have engineered prolog to be embedded by a single JAR file particularly for Android. They were the only one we found who did it, and they are 'responsive' to developers. Their stuff is Open Source Java/Android and they have an Android Prolog App out with an update coming soon. Interrogating their code was invaluable to finding a proper solution.
Addressing (2): The links which added the most value to this research are these: Reading from PrintStream, Convert Java OutputStream to InputStream, and ultimately the most useful StreamWriter to OutputStream.
Specifically, what's needed to be done is:
Here's the Code:
Final Notes: tuProlog took into consideration the console printing problem and designed this particular implementation around it, using a combination of Listeners and Events to properly work around the capturing of Prolog "Write" commands as well as other.
The solving of Strict Prolog Queries is accomplished fairly easily by perusing the preferred methods established in their users guide ... developers can quickly gleam what they need from that.
It's the capturing of Prolog Engine functions like the Write, Spy and Error Events that are harder to nail down (I eventually consulted w/the developers). For that you'll need to interrogate their Android Implementation of CUIConsole (as opposed to their Console implementation of CUIConsole , which 'is' different).
In a nutshell the answer is this: (a) establish a Listener and then (b) prepare for the event to take place.
Here's the code:
End Note: For those interested in doing "Prolog on Android", I'd be very happy to make available any code I write or resource I have in order to help you along this process. Please don't hesitate to ask.