问题描述
有模块可以从 Python (pyswip) =to=> Prolog 调用,但是有没有办法从 Prolog =to=> Python 调用相反的方法?
我需要它,所以我可以从 Swi-Prolog 调用 Spacy-NLP 模块
找不到 Swi 是否支持 zeroMQ
解决方法
这是文件“c:\hello.py”中的示例python代码,它在命令行上提取参数q(可选)。它的结果被回显到标准输出流中。
import sys
def hello():
return 'hello world: ' + ','.join(sys.argv[1:])
if __name__ == '__main__':
print(hello())
这是文件“c:\hello.pl”中的 prolog 程序,它调用上述 python 代码作为一个进程:
do :-
process_create(path('python3.7'),['c:/hello.py',foo,bar],[stdout(pipe(In))]),%output stream named In
read_string(In,Len,X),%In=input stream to read_string/3
write(X),nl,halt.
激活这个 prolog/python 组合并将结果写入输出流
$ swipl -g do c:\hello.pl
hello world: foo,bar
这是否符合您的要求?