以句子形式输出 Prolog

Output in Sentence Form Prolog

我希望此输出为字符串格式。 怎么做到的?

我得到的输出:

[[[[a]|fat]|man],[[[[[was]|walking]|quickly],to],[[[[the]]|end],[of,[[[the]|long]|corridor]]]]]

预期输出:

a fat man was walking quickly to the end of the long corridor

您可以使用 flatten/2 and atomic_list_concat/3:

:- X = [[[[a]|fat]|man],[[[[[was]|walking]|quickly],to],[[[[the]]|end],[of,[[[the]|long]|corridor]]]]],
   flatten(X,Y),
   atomic_list_concat(Y,' ',Z).
X = [[[[a]|fat]|man], [[[[[was]|walking]|quickly], to], [[[[the]]|end], [of, [[...|...]|...]]]]],
Y = [a, fat, man, was, walking, quickly, to, the, end|...],
Z = 'a fat man was walking quickly to the end of the long corridor'.