在 Prolog 中测试。如何 运行 单元测试来检查我的输出文件是否与我的文本文件匹配?

Test in Prolog. How to run a unit test that checks if my output file matches the my text file?

我正在使用 prolog (swipl) 实现自然语言生成器。

我有一个 .txt 测试文件,其中包含我应该能够以这种格式生成的一些短语:

[goal,identify,type_object,animal,object,cat,event,ran away,when,[last,mont],where,[]]
[which,cats,ran away,last,month,?]

[goal,identify,type_object,animal,object,dog,event,ran,when,[last,mont],where,[]]
[which,dogs,ran away,last,year,?]

等等...

我如何使用 plunit(或其他东西?)来检查我的测试文件的所有元素是否都在我的输出文件中返回 true/false?

read/1 可能是您要找的:

假设我定义一个事实p/1:

p([a,b,c]).

然后我可以从标准输入中读取一个术语并进行比较(以 |: 开头的行表示为 SWI Prolog 的用户输入,您的实现可能有所不同):

?- read(X), p(X).
|: [a,b,c].

X = [a, b, c].

?- read(X), p(X).
|: [].

false.