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(_).
I want to populate a fact database named 'listofQuestions'. Everything works fine, but the stuffs that I am asserting stays in the memory. So, if I run my program again, I get the same bunch of facts added to the 'listofQuestions'.
I only want to have one set of data.
Thankyou
Maybe do retractall/1
before you rerun your program.
Make a separate predicate for assertion that checks if fact is not yet asserted:
assertThisFact(Fact):-
\+( Fact ),!, % \+ is a NOT operator.
assert(Fact).
assertThisFact(_).
来源:https://stackoverflow.com/questions/10437395/prolog-how-to-assert-make-a-database-only-once