f0ma / pyswip3

This fork of PySWIP is a modifiaction to be able to use swi-prolog with python3 with full unicode support.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Disclaimers:

1 - JoaoFelipe
This is a fork from https://github.com/yuce/pyswip merged with https://github.com/f0ma/pyswip3
Its only purpose is to publish the most updated version at pypi (pyswip_alt)

2 - f0ma
This fork of PySWIP aims to full unicode/widechar support in python3 <-> swi-prolog communication
and not intended to save compatibility with python2.

This is not official python3 version of PySWIP, it is made just for fun.

All tests and examples have passed:
 - Python 3.4.0 / SWI-Prolog version 6.6.4 / Ubuntu 14.04 x86
 - Python 3.4.2 / SWI-Prolog version 7.2.3 / Window XP x86


3 - swenzel2
This fork of PySWIP is a modifiaction to be able to use swi-prolog with python3.
You are free to use but be aware that this is not meant to be an official python3 version or so...
The tests ran successfully on my machine (ubuntu 14.04 x64 with python 3.2.5 and 3.4.0).
However this doesn't mean there are no bugs anymore. I will try to maintain this fork but only for my personal use.
Issues are therefore not guaranteed to be considered and/or investigated by me.

Here is the original README:

PySWIP README
============

:Version: 
    0.2.3

:Maintainer:
    Rodrigo Starr <rodrigo.starr@gmail.com>

:Author:
    Yuce Tekol <yucetekol@gmail.com>
    Rodrigo Starr <rodrigo.starr@gmail.com>

:Project Website:
   http://code.google.com/p/pyswip
    

Introduction
------------

PySWIP is a 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.

Note that this version of PySWIP is slightly incompatible with 0.1.x versions.

Requirements:
-------------

* Python 2.3 and higher.
* ctypes 1.0 and higher.
* SWI-Prolog 5.6.x and higher (most probably other versions will also work).
* libpl as a shared library.
* Works on Linux and Win32, should work for all POSIX.

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 (*Note that interface is experimental.*)

Example (Pythonic interface):
-----------------------------

    from pyswip import Functor, Variable, Query

    assertz = Functor("assertz", 2)
    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

The core functionality of ``Prolog.query`` is based on Nathan Denny's public
domain prolog.py found at
http://www.ahsc.arizona.edu/~schcats/projects/docs/prolog-0.2.0.html

Install
-------

Please see ``INSTALL`` for detailed instructions.

About

This fork of PySWIP is a modifiaction to be able to use swi-prolog with python3 with full unicode support.

License:MIT License


Languages

Language:Python 96.8%Language:Prolog 3.0%Language:Batchfile 0.1%Language:Shell 0.1%