1
我是Prolog的新手,我正在编写一个小程序,它会给出一个DCG的随机句子。Prolog - DCG - 随机语句
我以前的想法是用findall/3来列出所有可能的句子,然后使用random_member/2。
它的工作了一小会儿,直到语法越来越大,我开始变得因为递归的堆栈错误...
我当时以为的另一种方式:在给定的做出所有可能的方面一会儿,申请random_member获得下一个学期,递归调用这个相同的功能,直到我得到空的列表...
但我怎样才能得到一个不完整的谓词的所有可能的答案集?我怎样才能得到它在集?
的信息,我的DCG看起来是这样的:
s --> pronoun(X), verb(X), location.
pronoun(1) --> [i].
pronoun(2) --> [you].
verb(1) --> [am].
verb(2) --> [are].
location --> [here].
location --> [there].
我的解决方案(其中列表是已经连接在一起的术语列表)的想法:
createRandomSentence(List) :-
setof(H, s([List|[H|_]], []), Set),
random_member(Pick, Set),
append(List, [Pick], List2)
<recursive call (haven't figured out this one either yet)>
...
提前致谢! :)
我不知道这是可能的!非常感谢 ! – Clung 2013-04-28 22:07:49