My favorites | Sign in
Project Logo
             
Show all Featured wiki pages:
Authors ChangeLog Examples FAQ INSTALL
People details
Project owners:
  yucetekol

(Current version: 0.2.2)


Announcement: Developers Wanted

Do you use PySWIP? Do you wish it was more robust, more functional, in short it was better? Here's the chance for you...

I can't find the time to maintain PySWIP anymore, so if anyone there would like to assume that responsibility, I'll be handing over the project to him/her.

You'll need the following skills:

... And of course a love of Free/Open Source Software...

Being a maintainer, you'll have the following responsibilities:

I want the project hosted at Google Code until I believe I've found the right person, so you'll need a Google account.

If you think you're the right person to carry PySWIP forward, please contact me at yucetekol AT gmail DOT com. Thank you.


PySWIP is a GPL'd Python - SWI-Prolog bridge enabling to query SWI-Prolog in your Python programs. It features an (incomplete) SWI-Prolog foreign language interface, a utility class that makes it easy querying with Prolog and also a Pythonic interface.

Since PySWIP uses SWI-Prolog as a shared library and ctypes to access it, it doesn't require compilation to be installed.

Requirements

Example (Using Prolog)

>>> from pyswip import Prolog
>>> prolog = Prolog()
>>> prolog.assertz("father(michael,john)")
>>> prolog.assertz("father(michael,gina)")
>>> list(prolog.query("father(michael,X)"))
[{'X': 'john'}, {'X': 'gina'}]
>>> for soln in prolog.query("father(X,Y)"):
...     print soln["X"], "is the father of", soln["Y"]
...
michael is the father of john
michael is the father of gina

Since version 0.1.3 of PySWIP, it is possible to register a Python function as a Prolog predicate through SWI-Prolog's foreign language interface.

Example (Foreign Functions)

from pyswip import Prolog, registerForeign

def hello(t):
    print "Hello,", t
hello.arity = 1

registerForeign(hello)

prolog = Prolog()
prolog.assertz("father(michael,john)")
prolog.assertz("father(michael,gina)")    
list(prolog.query("father(michael,X), hello(X)"))

Outputs:

Hello, john
Hello, gina

Since version 0.2, PySWIP contains a 'Pythonic' interface which allows writing predicates in pure Python.

Example (Pythonic interface)

from pyswip import Functor, Variable, Query, call

assertz = Functor("assertz", 1)
father = Functor("father", 2)

call(assertz(father("michael","john")))
call(assertz(father("michael","gina")))

X = Variable()
q = Query(father("michael",X))
while q.nextSolution():
    print "Hello,", X.value
q.closeQuery()

Outputs:

Hello, john
Hello, gina

If you want to contribute to PySWIP's development or just ask questions you can join Google PySWIP Group.

PySWIP is being developed by Yuce Tekol, you can email me at: yucetekol [AT] gmail [DOT] com. Please see Authors for a full list of contributors.









Hosted by Google Code