【发布时间】:2012-05-03 18:37:41
【问题描述】:
resultList(UsersQuery):-
question(X,H),
write(H),
myintersection(H,UsersQuery,Match,TotalQuestionKeywords),
Percent is Match/TotalQuestionKeywords*100,
write('Question: '),
write(X),nl,write('Quality: '), write(Percent),write('%'),nl,
/* please look at this part
Percent>=50,
assert(listofQuestions(Percent,Question)),
write(Percent),write(Question),nl,
fail.
resultList(_).
我想填充一个名为“listofQuestions”的事实数据库。一切正常,但我断言的东西留在内存中。所以,如果我再次运行我的程序,我会在“问题列表”中添加相同的事实。
我只想拥有一组数据。
谢谢
【问题讨论】:
-
尝试使用 if-then-else 内置谓词
( listofQuestions(P,Q) -> true ; assert(listofQuestions(P,Q)) ) -
效果不错。但是每次我调用我的规则时,我想要的是一个全新的空白“问题列表”。只有当我重新启动 prolog 时才会发生这种情况。有什么帮助吗?