佩雷拉的Prolog操作员错误

时间:2017-12-04 13:12:02

标签: prolog nlp swi-prolog

在Ubuntu Linux中使用SWI Prolog 7.7.2,我试图运行“谈话” Pereira和Schieber的模块(附录A, http://www.mtome.com/Publications/PNLA/prolog-digital.pdf)。

复制后,粘贴到文本编辑器(Sublime),然后进行调整 换行符(大部分)匹配原始的,运行swipl,然后 ['talk.P'],我遇到了二十多个“语法错误:操作员 预期的“错误,例如(目录位置被[...]替换):

  

第15-20行:

main_loop :-
    write(’>> ’),       % prompt the user
    read_sent(Words),   % read a sentence
    talk(Words, Reply), % process it with TALK
    print_reply(Reply), % generate a printed reply
    main_loop.          % process more sentences
     

错误:[...] / talk.P:16:15:语法错误:操作员期望

     

---第38行:

talk(_Sentence, error(’too difficult’)).
     

错误:[...] / talk.P:38:25:语法错误:操作员期望

     

---第76-77行:

% Replying to some other type of sentence.
reply(_Type, _FreeVars, _Clause, error(’unknown type’)).
     

错误:[...] / talk.P:77:42:语法错误:操作员期望

     

---第87-91行:

print_reply(error(ErrorType)) :-
    write(’Error: "’), write(ErrorType), write(’."’), nl.

print_reply(asserted(Assertion)) :-
    write(’Asserted "’), write(Assertion), write(’."’), nl.
     

错误:[...] / talk.P:91:12:语法错误:操作员期望

---注意我也遇到了十个单例变量警告,但我不确定这是否会被证明是一个问题,例如:

  

---第59-60行:

reply(query, FreeVars,
    (answer(Answer):-Condition), Reply) :- Warning: [...]/talk.P:59:  Singleton variables:
     

[FreeVars,Condition,FreeVarsCondition]警告:[...] / talk.P:59:     分支中的单例变量:FreeVarsCondition

     

---第242-243行:

q(S => ‘answer(X)) -->
    whpron, vp(finite, XˆS, nogap).
     

警告:[...] / talk.P:242:单例变量:[S,X,XS]

启动并运行此模块需要做什么?

1 个答案:

答案 0 :(得分:1)

有几个问题。运算符值(100,500等)与标准运算符的旧值兼容,应该更高。此外,反向引用/反向标记(ASCII 96)在某些时候从符号变为引用字符。

我设法通过更改运算符来加载the files加载SWI prolog:

:- op(1000,xfy,&). 
:- op(1010,xfy,=>). 
:- op(200,fx,`).

并给出命令行参数--traditional(以引用符号而不是引号字符)。

$ swipl --traditional
Welcome to SWI-Prolog (threaded, 64 bits, version 7.4.2)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit http://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

?- [talk].
true.