Tue 27 Aug 00:14:56 CEST 2024
This commit is contained in:
parent
2c5d04c488
commit
4174155bad
44
test/test-logic.js
Normal file
44
test/test-logic.js
Normal file
|
@ -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).'))
|
Loading…
Reference in New Issue
Block a user