Reputation: 2407
I am using swi-prolog in my python program. It is taking input query from user and creating asserts for it. I have kept this part as gearman worker (like server socket) which keep listening for input query.
1st query - program generates x numbers of asserts
2nd query - program generates y numbers of asserts, now program considers (x+y) asserts while processing the query.
and so on.
Is that any way to flush asserts after each query execution? Here is code snippet of process.pro:
Here linkage takes asserts and question is for input query.
question(REND, RULE):-
linkage(LINK, LEND, REND_NEW),
(
(
rule_first_question(LINK, REND_NEW) ->
nb_getval(rule, RULE_NEW),
nb_getval(rend, REND)
; nb_linkval(rule, ''), nb_getval(rule, RULE)
)
;
(
rule_third_question(LINK, REND_NEW) ->
nb_getval(link, LINK_NEW),
nb_getval(rule, RULE_NEW)
; nb_linkval(rule, ''), nb_getval(rule, RULE)
)
;
(
rule_four_question(LINK, REND_NEW) ->
nb_getval(link, LINK_NEW),
nb_getval(rule, RULE_NEW)
; nb_linkval(rule, ''), nb_getval(rule, RULE)
)
).
Upvotes: 1
Views: 159
Reputation: 41
I’m assuming that by ‘flush’ you mean ‘forget’.
retractall/1 is what you desire.
Example :
?- assert(bottoms_on_fire(all_english_men)).
true.
?- assert(bottoms_on_fire(all_scottish_men)).
true.
?- bottoms_on_fire(all_english_men).
true.
?- retractall(bottoms_on_fire(_)).
true.
%note- use of the anonymous variable to unify with all such facts
?- bottoms_on_fire(all_english_men).
false.
Upvotes: 0
Reputation: 5407
Yeah, retract can help you to remove the facts from databse.
for p in self.prolog_question_identify.query("retract(linkage(_,_,_)),fail"):
print
in linkage you can give which ever value you want to flush out.
Upvotes: 1