Eclipse python prolog swi

1 篇文章 0 订阅
1 篇文章 0 订阅

1.eclipse-help-install new software-work with-add:

name:PDT

Repository  Location:http://sewiki.iai.uni-bonn.de/public-downloads/update-site-pdt/nightly/

一直next下去,安装好后重启eclipse。

eclipse-windows-preferences 应该出现一项PDT,点开后选择prolog processes,选择swi prolog,edit选择swipl.exe的路径(通常为swi路径下的swipl\bin\swipl.exe)。apply and close。至此eclipse下的prolog安装完成

2.安装ProDT(官方网址:http://prodevtools.sourceforge.net/index.html)

同上,work with 中的url地址为:http://prodevtools.sourceforge.net/updates/,选择ProDT下的所有组件,同上,安装完成后重启eclipse。配置:从菜单Window-> Preferences-> Prolog-> Interpreters中打开首选项对话框 ,然后按“添加...”按钮,选择swipl.exe的路径(通常为swi路径下的swipl\bin\swipl.exe)

(这一步好像没用上)

3.在python的环境里pip install pyswip(ubuntu:pip3 install pyswip)

4.选择Window-> Open perspective-> Other ...-> Prolog 。

例子:

test.pl:

:-module(test).

room(kitchen).
room(office).
room(hall). 
room('dining room').
room(cellar). 
 
door(office, hall).
door(office,kitchen).
door(kitchen, office).
door(hall, 'dining room').
door(kitchen, cellar).
door('dining room', kitchen).
 
location(desk, office).
location(apple,kitchen).
location(flashlight, desk). 
location('washing machine', cellar).
location(nani, 'washing machine').
location(broccoli, kitchen).
location(crackers, kitchen).
location(computer, office).

edible(apple).
edible(crackers).
tastes_yucky(broccoli).
here(kitchen).

consult后在PDTContextView会出现事实的调用结构:(PDTContextView在右上方的Quick Access中搜索添加)
is_in(X,Y):-edible(X),location(X,Y).
search_food(X):-location(Y,X),edible(Y).
search_food(X):-door(X,Z),search_food(Z).

testEx.py:

'''
-*- coding: utf-8 -*-
@author: user
'''
from pyswip import Prolog
from pyswip import *
from pyswip import Functor,Variable,Query

prolog = Prolog()
prolog.consult("test")
for solution in prolog.query("door(Y,kitchen)"):
    print(solution["Y"] +" has door to kitchen.")

运行结果:

5.Eclipse 中.pl需要右键open with .PL Editor后才可以consult.

划重点:以上所有的安装路径不要出现中文,包括swi这个软件,python不支持中文。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值