Skip to content

Commit 4ff1099

Browse files
authored
Merge pull request #10 from ian-andrich/cjm-fixes
Prep for next release
2 parents ef16307 + 2dd0934 commit 4ff1099

File tree

8 files changed

+132
-49
lines changed

8 files changed

+132
-49
lines changed

CHANGES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## v0.2.0
2+
3+
* Various refactoring, see https://github.com/ian-andrich/PythonPengines/pull/5
4+
5+
## v0.1.4 : More fat fingering.
6+
## v0.1.3 : Fat fingered some pypi code.
7+
## v0.1.2 : Added repo to pypi under the name PythonPengines

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
test:
2+
pytest tests/srctest_test.py
3+
4+
# TODO: manually increment version in setup.py, run . bump.sh, then this
5+
release: cleandist
6+
python setup.py sdist bdist_wheel bdist_egg
7+
twine upload dist/*
8+
9+
cleandist:
10+
rm dist/* || true

README.md

Lines changed: 0 additions & 48 deletions
This file was deleted.

README.rst

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
Python Pengines
2+
===============
3+
4+
This is a module for interfacing python with the Prolog Pengines
5+
knowledge base.
6+
7+
API
8+
---
9+
10+
Create a basic run pengine server script, and run it with swipl.
11+
12+
::
13+
14+
:- use_module(library(http/thread_httpd)).
15+
:- use_module(library(http/http_dispatch)).
16+
:- use_module(library(pengines)).
17+
18+
server(Port) :- http_server(http_dispatch, [port(Port)]).
19+
20+
:- server(4242).
21+
22+
Initialize a basic PengineBuilder
23+
24+
::
25+
26+
from pengines.Builder import PengineBuilder
27+
from pengines.Pengine import Pengine
28+
29+
pengine_builder = PengineBuilder(urlserver="http://localhost:4242")
30+
31+
Create the pengine querying object.
32+
33+
::
34+
35+
pengine = Pengine(builder=pengine_builder)
36+
pengine.create()
37+
38+
Make your query -- note the lack of ending period -- Pengine performs
39+
the query like 'ask(member(X, [1,2,3], [])).'
40+
41+
::
42+
43+
query = "member(X, [1,2,3])"
44+
pengine.ask(query)
45+
print(pengine.currentQuery.availProofs)
46+
47+
Iterate through the proofs like this:
48+
49+
::
50+
51+
while pengine.currentQuery.hasMore:
52+
pengine.doNext(pengine.currentQuery)
53+
print(pengine.currentQuery.availProofs)
54+
55+
prologterms library
56+
-------------------
57+
58+
The python library prologterms aims to make it easier to construct
59+
prolog programs and query terms from within python.
60+
61+
For an example of how to use prologterms in conjunction with pengines,
62+
see:
63+
64+
https://pypi.org/project/prologterms/
65+
66+
::
67+
68+
from pengines.Builder import PengineBuilder
69+
from pengines.Pengine import Pengine
70+
from prologterms import TermGenerator, PrologRenderer, Program, Var
71+
72+
P = TermGenerator()
73+
X = Var('X')
74+
Y = Var('Y')
75+
Z = Var('Z')
76+
R = PrologRenderer()
77+
78+
p = Program(
79+
P.ancestor(X,Y) <= (P.parent(X,Z), P.ancestor(Z,Y)),
80+
P.ancestor(X,Y) <= P.parent(X,Y),
81+
P.parent('a','b'),
82+
P.parent('b','c'),
83+
P.parent('c','d')
84+
)
85+
86+
q = P.ancestor(X,Y)
87+
88+
factory = PengineBuilder(urlserver="http://localhost:4242",
89+
srctext=R.render(p),
90+
ask=R.render(q))
91+
pengine = Pengine(builder=factory, debug=True)
92+
while pengine.currentQuery.hasMore:
93+
pengine.doNext(pengine.currentQuery)
94+
for p in pengine.currentQuery.availProofs:
95+
print('{} <- {}'.format(p[X.name], p[Y.name]))

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
pytest>=0.0
2+
requests>=0.0

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
setup(
33
name = "pengines",
44
packages = ["pengines"],
5-
version = "0.1.4",
5+
version = "0.1.5",
66
description = "A simple python library for interacting with SWI-Prologs Pengines",
77
author = "Ian Andrich",
88
author_email = "iandrich87+github@gmail.com",

tests/server.pl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
:- use_module(library(http/thread_httpd)).
2+
:- use_module(library(http/http_dispatch)).
3+
:- use_module(library(pengines)).
4+
5+
server(Port) :- http_server(http_dispatch, [port(Port)]).
6+
7+
:- server(4242),T is 10**10,sleep(T).

tests/srctest_test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1+
"""
2+
Assumes a bare-bones pengines service running on 4242
3+
4+
You can use this:
5+
6+
docker run -p 4242:9083 -e PORT=9083 --name sparqlprog cmungall/sparqlprog
7+
8+
"""
19
from pengines.Builder import PengineBuilder
210
from pengines.Pengine import Pengine
311

412
def test_src():
13+
"""
14+
15+
"""
516
src = "foo(a).\nfoo(b).\nfoo(c)."
617
q = "foo(X)"
718
factory = PengineBuilder(urlserver="http://localhost:4242", destroy=False, srctext=src, ask=q)

0 commit comments

Comments
 (0)