From 4174155bade79f7ce66908db5b0dc2ab52dae4ef Mon Sep 17 00:00:00 2001 From: sbosse Date: Tue, 27 Aug 2024 00:15:05 +0200 Subject: [PATCH] Tue 27 Aug 00:14:56 CEST 2024 --- test/test-logic.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 test/test-logic.js diff --git a/test/test-logic.js b/test/test-logic.js new file mode 100644 index 0000000..8f9185e --- /dev/null +++ b/test/test-logic.js @@ -0,0 +1,44 @@ +var session = logic.create(null , function (msg) { + console.log(msg); +}); + +var db = [ +'event(music).', +'event(theatre).', +'event(poetry).', +'event(stage).', +'event(guided_tour).', +'music(ev0001).', +'music(ev0002).', +'theatre(ev0003).', +'ort(ev0001,bremen).', +'ort(ev0003,bremen).', +'ort(ev0002,hamburg).', +'event_in(Ort,X) :- (music(X);theatre(X)),ort(X,Ort).', +] +var t0=time(); +var parsed=session.consult(db.join('\n')); +print('consult',time()-t0,'ms'); +print(parsed); +function answer(query) { + parsed=session.query(query); + print(parsed); + var result,results=[],error; + do { + session.answer(function (_result) { + result=_result; + if (result) { + var output=result.toString(); + if (output.contains('throw(error')) { + return error=result.args[0].args; + } + if (output=='{}') output='true'; + else output=output.replace(/{|}/g,'').replace(/\//,' = '); + results.push(output); + } + }); + } while (result); + return results; +} +print(answer('event(X).')) +print(answer('event_in(bremen,X).'))