CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14
  1. #1
    Join Date
    Mar 2016
    Posts
    8

    pass parameters from java to prolog

    I have the code below using swi Prolog and I made a interface using jframe in netbeans.

    In this jframe I have textbox for answer and another textbox for grade.i want take answer from textbox and pass to start predicate in prolog to process answer. Can anyone tell me how I can do that? The only thing that I know is how to call predicate.
    start(Answer,Total_grade):-
    Question1 = "Define computer?",
    Word_list1 = ["software","operatingsystem"],
    Word_list2 = ["hardware","tools"],
    Msg = "Write your answers ",
    write(Question1),nl,
    write(Msg),nl,nl,
    read(Answer),
    string_lower(Answer,Low_answer),
    split_string(Low_answer," ,.()-_"," ,.()-_", Answer_in_list),
    find(Answer_in_list,Word_list1,Grade1),
    find(Answer_in_list,Word_list2,Grade2),
    Total_grade is Grade1 + Grade2,
    nl,write("Your grade is : "), write(Total_grade),nl.

  2. #2
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: pass parameters from java to prolog

    What is Prolog? Is it an external program? The Runtime/Process classes will interface with external programs.
    Norm

  3. #3
    Join Date
    Mar 2016
    Posts
    8

    Re: pass parameters from java to prolog

    Quote Originally Posted by Norm View Post
    What is Prolog? Is it an external program? The Runtime/Process classes will interface with external programs.
    Prolog is a general purpose logic programming language associated with artificial intelligence and computational linguistics.

  4. #4
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: pass parameters from java to prolog

    How is a prolog program executed? If by a command line, that commandline can be executed from java using the Runtime class's methods.
    Norm

  5. #5
    Join Date
    Mar 2016
    Posts
    8

    Re: pass parameters from java to prolog

    Quote Originally Posted by Norm View Post
    How is a prolog program executed? If by a command line, that commandline can be executed from java using the Runtime class's methods.
    yes it is executed by a command line. what are Runtime class's methods?

  6. #6
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: pass parameters from java to prolog

    Look at the API doc for the Runtime class to see its methods etc.
    http://docs.oracle.com/javase/8/docs/api/index.html
    Find Runtime in the list on the lower left, click on it and its doc will show in main window.
    Norm

  7. #7
    Join Date
    Mar 2016
    Posts
    8

    Re: pass parameters from java to prolog

    Quote Originally Posted by Norm View Post
    Look at the API doc for the Runtime class to see its methods etc.
    http://docs.oracle.com/javase/8/docs/api/index.html
    Find Runtime in the list on the lower left, click on it and its doc will show in main window.
    I read the methods.They are not benefit in this work because I use jpl to call process.i need to find out how to take answer from textbox and pass to prolog?

  8. #8
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: pass parameters from java to prolog

    how to take answer from textbox and pass to prolog?
    Is the textbox a java JTextField or JTextArea component shown in a java GUI?

    If not, how are you planning to use java for this problem?

    I have never heard of jpl. Is it part of java SE?
    Norm

  9. #9
    Join Date
    Mar 2016
    Posts
    8

    Re: pass parameters from java to prolog

    Quote Originally Posted by Norm View Post
    Is the textbox a java JTextField or JTextArea component shown in a java GUI?

    If not, how are you planning to use java for this problem?

    I have never heard of jpl. Is it part of java SE?
    yes,JTextArea component shown in a java GUI.
    jpl is library in java.like this import org.jpl7.*;

  10. #10
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: pass parameters from java to prolog

    Ok, please explain your problem now.
    Is this what you are trying to do:
    have a text area where the user can enter some data. The program can take that data and format a command line and call the prolog program with the Runtime class's methods and retrieve the response from prolog and display it in a text area.

    If you have a question about jpl, you should ask it on a jpl forum. jpl is not part of standard java.
    Norm

  11. #11
    Join Date
    Mar 2016
    Posts
    8

    Re: pass parameters from java to prolog

    Quote Originally Posted by Norm View Post
    Ok, please explain your problem now.
    Is this what you are trying to do:
    have a text area where the user can enter some data. The program can take that data and format a command line and call the prolog program with the Runtime class's methods and retrieve the response from prolog and display it in a text area.
    yes this is my problem.how to do this?

  12. #12
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: pass parameters from java to prolog

    how to do this?
    Something like this:
    When the user enters the data and presses a button, get the data, format it for the command line, use the Runtime class's methods to call prolog. Where does prolog put its results? If it writes it to the console, use the Process class's methods to read what was written to the console and put it in the text area for the user to see.
    Norm

  13. #13
    Join Date
    Mar 2016
    Posts
    8

    Re: pass parameters from java to prolog

    Quote Originally Posted by Norm View Post
    Something like this:
    When the user enters the data and presses a button, get the data, format it for the command line, use the Runtime class's methods to call prolog. Where does prolog put its results? If it writes it to the console, use the Process class's methods to read what was written to the console and put it in the text area for the user to see.
    what are exactly Runtime class's methods to call prolog and also to read what was written to the console and put it in the text area for the user to see?

  14. #14
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: pass parameters from java to prolog

    See the API doc for the Runtime class for a description of its methods.
    The exec method returns a Process class object that has methods for accessing what the called program writes to the console.
    Norm

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured