1

I have a expert system written in prolog that gives me problems when I run it from a java interface. The problems are related to the comunication of the output. I tried Streams but (only with this project) they don't work fine, the application apparently freezes at the time of writing the txt file, i do something like this :

myFunction(CurPlace, Place) :-
open('text.txt',write,Stream), nl(Stream),
write(Stream,'You cant go from '), write(Stream,CurPlace), write(Stream,' to '), write(Stream,Place), nl(Stream),close(Stream),
fail.

At the end of the writing i read the txt with java, with all my old systems this method worked fine, but with this, maybe for the inference or for the recursive calls, something goes wrong(java-side, because if I run it directly from swiprolog all goes fine)! So I decided to use jpl_get and call, but I'm new at this. I need some help! In my interface I have a jtextarea that print all the output from the prolog system. I call it "jTextAreaOUTPUT", this component is in my java class Interface.

My project folders are (in windows): "main_folder" then inside I have (like all the eclipse project) src,bin... I placed the prolog system pl file in the main_folder so the path to the interface.java is : src/mypackage/interface.java How can i print my example message "Start Message" in my jtextarea ? I tryed this :

start:- jpl_get( 'src.mypackage.interface', jTextAreaOUTPUT, X),
        jpl_call(X,append,['Start Message\n']).

...and in my Java application i call the query in this way :

public static void CallQuery(String t2){
        Query q2 = new Query(t2);
        try{
        q2.hasSolution();
        } catch (Exception e) {
    }

}

t2 is "start" when i call it from the main()! So when i run it, the system give me the "ClassNotFoundException"!

Question 1)Can someone give me a good example that does what I want ?

Question 2)What is the role of the variable X in jpl get and call ?

Question 3)If i want to print a variable how can I do that ?

  • pass the *fullpath* to open/3 – CapelliC Sep 18 '15 at 08:59
  • I tried that. The file is created but is empty (when i run from java, instead from swipl works fine and the content is not empty ) ! – Esmeralda90 Sep 18 '15 at 09:09
  • why do you use fail at the end of the rule ? – CapelliC Sep 18 '15 at 09:12
  • Nevermind that specific function. I pick the first one scrolling my old project. The problem is related in my opinion to the fact that i should split the threads ( java and prolog ) in this particular project. Maybe due to the inference engine and the recursive calls the file ( running it from java ) waits too long and doesn't end the file in time ! – Esmeralda90 Sep 18 '15 at 09:21
  • playing with threads sounds really complex... all calls should be synced automatically – CapelliC Sep 18 '15 at 09:25
  • So what should I do ? I need i way to redirect the value of a variable, avoiding in write() or write(stream) directly on my jtextArea. There is a way ? – Esmeralda90 Sep 18 '15 at 09:29
  • `jpl_get(+Object, +Field, -Value)` - I guess - should be useless here. Instead, I would try `jpl_call(jTextAreaOUTPUT,append,['Start Message\n']).` – CapelliC Sep 18 '15 at 09:47
  • If i put instead of jtextareaoutput a simple function java with a systemout that print a message, doesn't work. doesn't recognise the jpl_call/3 – Esmeralda90 Sep 18 '15 at 09:58
  • then, jTextAreaOUTPUT is not an actual Java object, I guess – CapelliC Sep 18 '15 at 10:10
  • No is a component :/ should I create an object and save in this object the value every time then put the object(converted to string) in the text area? – Esmeralda90 Sep 20 '15 at 09:40
  • I would see if it's possible to get the object from the component – CapelliC Sep 20 '15 at 10:05

0 Answers0