0

I'm using SWI-Prolog with the JPL library. I have a program written in Java that produces strings like these:

fact(1,2)
fact(2,3)
fact(1,3)

Then, there is a prolog file that needs this facts in the head of file. I do not want neither insert the code in the head of file, nor use a text file, but only java. Is there a solution for this?

user840718
  • 1,563
  • 6
  • 29
  • 54
  • easy way: call assert(fact(1,2)) on JPL interface – CapelliC Jun 19 '13 at 12:31
  • I've take a look a this post: http://osdir.com/ml/lang.swi-prolog.general/2006-09/msg00070.html Is this the solution? If yes, I can't understand why the keyword assert is a string. I have to use the java keyword assert, or as a simpley string to communicate with prolog? – user840718 Jun 19 '13 at 15:25
  • 1
    you have several choices. The simpler is Query(string q), that issues, well, a Query of text q to SWI-Prolog engine (like you entering on console). Then q = "assert(fact(1,2))" should do. – CapelliC Jun 19 '13 at 15:37

1 Answers1

1

If I'm reading this correctly, you need to write Strings into a Prolog file from Java?

Java can write into many files types including .txt, .word, and html. You can attempt to write to a Prolog file by using the extension name.

FileWriter exampleFileWriter = new FileWriter("exampleProlog.pl");

Just write the Strings, then close the file. There are many safer and better ways to writing to files in Java. Just look at this:

Fastest way to write to file?

http://www.javapractices.com/topic/TopicAction.do?Id=42

EDIT: This might be of help:

How use Prolog from Java?

Community
  • 1
  • 1
  • No no I wrote that I do not want this. I want to use Java to communicate the facts to the prolong. without writing to the head of file. – user840718 Jun 19 '13 at 09:26