Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7158203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:01:25+00:00 2026-05-28T13:01:25+00:00

I’m running the an embedded library [tuProlog (2p.jar)] Prolog Inference Engine in Android with

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:01:26+00:00Added an answer on May 28, 2026 at 1:01 pm

    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:

    • Create a ByteArrayOutputStream object to capture the Binary Data
      from the process of printing to the Console (System.out).
    • Create PrintStream object (using the ByteArrayOutputStream) in
      which to set the System.setOut (which governs where the console output [System.out.println] goes to)
    • Reroute the System Output
    • Capture the desired console print output to a string variable
    • Add that string (in the case of this Android project) to a row of a listview
    • Notify that Listview the Data has changed
    • Reset the ByteArrayOutputStream object (to avoid concatenation)

    Here’s the Code:

       // OutPutStream I/O Experimental Stuff
       PrintStream orgStream   = System.out;
    
       // ByteArray Sub Experimental Stuff
       ByteArrayOutputStream baos = new ByteArrayOutputStream();
       PrintStream psout = new PrintStream(baos, Boolean.TRUE); // Using autoFlush
    
    
       // Instantiate an instance of the Prolog Engine. 
       //Do this only once because it's VERY expensive.
       Prolog engine;
    
    
        // ReRouting Print Streams 
        // (Inside method we need to capture console output)
        System.setOut(orgStream);           // Set the System Output Stream  
    
    
        String myResult = baos.toString();      // returns the actual text 
        myChatListItems.add(myResult);          // Add Text to New ListView Row  
        chatBotAdapter.notifyDataSetChanged();  // notify the Adapter to Refresh
        baos.reset();                           // Reset the ByteArrayOutputStream
    
          System.setOut(orgStream);  // RESET the System Output Stream 
    

    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:

        // Establish Prolog engine and it's appropriate listeners
        // [Warning, Output, and Spy] 
        engine = new Prolog();
        engine.addWarningListener(this);
        engine.addOutputListener(this);
        engine.addSpyListener(this); 
    
    //// PROLOG CONSOLE OUTPUT MECHANISMS *******************************
    
    @Override
    public void onSpy(SpyEvent e) {
        Log.d(TAG, "** LG'd onSpy => SpyEvent Occured ** " );
        System.out.println("** onSpy => SpyEvent Occured ** \n ");
        myChatListItems.add( e.getMsg() );
        chatBotAdapter.notifyDataSetChanged();
    
    }
    
    
    @Override
    public void onOutput(OutputEvent e) {
        Log.d(TAG, "** LG'd: onOutput => OutputEvent Occured ** " );
        System.out.println("** onOutput => OutputEvent Occured ** \n ");
        myChatListItems.add( e.getMsg() );
        chatBotAdapter.notifyDataSetChanged();
    
    }
    
    
    @Override
    public void onWarning(WarningEvent e) {
        Log.d(TAG, "** LG'd: onWarning => WarningEvent Occured ** " );
        System.out.println("** onWarning => WarningEvent Occured ** \n ");
        myChatListItems.add( e.getMsg() );
        chatBotAdapter.notifyDataSetChanged();
    
    }
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am currently running into a problem where an element is coming back from
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.