forked from DestyNova/pyswip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
124 additions
and
746 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
__pycache__ | ||
*.swp | ||
*.pyc | ||
.coverage | ||
*.BAC | ||
.pytest_cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
language: python | ||
python: | ||
- "3.4" | ||
- "3.5" | ||
- "3.6" | ||
- "nightly" | ||
- "pypy" | ||
sudo: required | ||
before_install: | ||
- sudo apt update && sudo apt install -y swi-prolog-nox | ||
install: | ||
- pip install test-requirements.txt coveralls | ||
script: | ||
- make cover | ||
after_success: | ||
- coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.PHONY: cover test test-all | ||
|
||
cover: | ||
py.test --cov=pyswip tests integration_tests | ||
|
||
test: | ||
py.test tests --verbose | ||
|
||
test-all: | ||
py.test tests integration_tests --verbose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,110 +1,79 @@ | ||
PySWIP README | ||
============= | ||
# PySWIP README | ||
|
||
:Version: | ||
0.2.3 | ||
## What's New? | ||
|
||
:Maintainer: | ||
Rodrigo Starr <[email protected]> | ||
* Updated | ||
|
||
:Author: | ||
Yuce Tekol <[email protected]> | ||
Rodrigo Starr <[email protected]> | ||
|
||
:Project Website: | ||
http://code.google.com/p/pyswip | ||
|
||
## Introduction | ||
|
||
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 | ||
PySWIP is a Python - SWI-Prolog bridge enabling to query [SWI-Prolog](http://www.swi-prolog.org) 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: | ||
------------- | ||
## 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). | ||
* Python 3.5 and higher. | ||
* SWI-Prolog 7.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 | ||
## Examples | ||
|
||
### Using Prolog | ||
|
||
```python | ||
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 | ||
``` | ||
|
||
### Foreign Functions | ||
|
||
```python | ||
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)")) | ||
``` | ||
|
||
### Pythonic interface (Experimental) | ||
|
||
```python | ||
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 | ||
------- | ||
## Install | ||
|
||
Please see ``INSTALL`` for detailed instructions. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.