2

我正在尝试编写一个程序,将序言句翻译成正式的英语句子。这是我的代码:

sentence --> [if],[the], first_phrase, second_phrase.
first_phrase -->  predicate, det , assertion, det, noun.
second_phrase --> [then],[the], predicate, det , noun.
assertion --> noun, [and], [the], predicate.
det --> [are].
det --> [is].



noun --> [flat].
noun --> [webbed].
noun -->[waterfowl].
predicate --> [feet].
predicate --> [bill].
predicate -->[order].


sentence(S1,S3) :- first_phrase(S1,S2), second_phrase(S2,S3).
first_phrase(S1,S3) :- second_phrase(S1,S2), noun(S2,S3).
second_phrase(S1,S3) :- assertion(S1,S2), first_phrase(S2,S3).
det([is|X], X).
det([are|X], X).

此代码的输出如下所示:X = [if, the, feet, are, flat, and, the, feet, are|...] 所以它缺少一些单词,它应该显示如下内容:如果脚有蹼,账单是平的,那么订单是水禽。

为了得到这个结果,我应该添加或修复什么?

4

1 回答 1

0

将此代码添加到您的源代码文件中:

remove_max_depth:-
    current_prolog_flag(toplevel_print_options,Options),
    select(max_depth(_), Options, NOptions)->
    set_prolog_flag(toplevel_print_options, NOptions); true.

:-remove_max_depth.

过程remove_max_depth将删除对在顶层显示的最大项目数的约束,并且指令:-remove_max_depth.将在您查阅文件时执行该过程。

于 2012-12-18T18:01:32.190 回答