0

i'm trying to use Tau-Prolog integration with javascript via this script:

<!-- index.html -->
<script type="text/javascript" src="tau-prolog.js"></script>
<script>
  var TEN_THOUSAND = 10000;
            
  function buttonClick() {
    var question = document.getElementById("question-area").value;

    if (question == "")
      return;

    ask(question);
  }

  function ask(question) {
    var session = pl.create(TEN_THOUSAND);
                
    var program = document.getElementById("program").value;
                
    session.consult(program, {
      success: function () {
        session.query(question, {
          success: function (question) {
            session.answer({
              success: function (answer) {
                console.log(answer);
              },
              error: function (err) {
                console.log("ERROR SHOWING THE ANSWER");
                console.log(err);
              },
              fail: function () {
                console.log("Query failed.");
              },
              limit: function () {
                console.log("Limit excedeed");
              },
            });
          },
          error: function (err) {
            console.log("ERROR QUERYING THE PROGRAM");
            console.log(err);
          },
        });
      },
      error: function (err) {
        console.log("ERROR PARSING THE PROGRAM");
        console.log(err);
      },
    });
  } 
</script>

The prolog program linked to this script is this:

bot(KB, Question, Answer) :-
  ask(KB, Question, Answer).

ask(KB, Question, Answer) :-
  question(SQ, Question, []),
  SQ = action(Action, Modifiers1),
  member(action(Action, Modifiers2), KB),
  subset(Modifiers1, Modifiers2),
  sentence(SQ, Answer, []).

//other predicates

The problem i'm having is that everytime i try to query the bot/3 predicate i get the exception uncaught exception: error(existence_error(procedure, bot/3, top_level/0)).

I tried running the program on SWI-Prolog, and it works just fine. I tried to use more simple programs, such as:

member(H, [H | _]).
member(X, [_ | R]) :-
  member(X, R).

and it worked.

I'm not using the tau-prolog node.js extension. Can anyone help? Thanks in advance.

false
  • 10,264
  • 13
  • 101
  • 209

0 Answers0