prologterms - a python library for constructing prolog terms
Example:
from prologterms import TermGenerator, PrologRenderer, Var
X = Var('X')
P = TermGenerator()
term = P.member(X, [1, 2, 3])
r = PrologRenderer()
print(r.render(term))
writes:
member(X, [1, 2, 3])
All prolog escaping conventions are handled automatically.
See the Jupyter notebook
Rules
The “<=” operator in python is overloaded to mean the same as prolog “:-”. This means a rule object can be created as follows:
P.ancestor(X,Y) <= (P.parent(X,Z), P.ancestor(Z,Y))
This can be done more explicitly using a Rule constructor:
from prologterms import TermGenerator, PrologRenderer, Var, Rule
X = Var('X')
Y = Var('Y')
Z = Var('Z')
P = TermGenerator()
rule = Rule(P.ancestor(X,Y), (P.parent(X,Z), P.ancestor(Z,Y))
Usage
This module is of little use by itself. It is intended to be used to generate prolog programs that can be fed into a prolog execution engine.
write prolog programs and queries to a file, and load these using an engine like swi-prolog
through web services, e.g. via pengines
Pengines
[Note: requires latest pengines which may not be on pypi]
One of the intended applications is pengines
from pengines.Builder import PengineBuilder
from pengines.Pengine import Pengine
from prologterms import TermGenerator, PrologRenderer, Program, Var
P = TermGenerator()
X = Var('X')
Y = Var('Y')
Z = Var('Z')
R = PrologRenderer()
p = Program(
P.ancestor(X,Y) <= (P.parent(X,Z), P.ancestor(Z,Y)),
P.ancestor(X,Y) <= P.parent(X,Y),
P.parent('a','b'),
P.parent('b','c'),
P.parent('c','d')
)
q = P.ancestor(X,Y)
factory = PengineBuilder(urlserver="http://localhost:4242",
srctext=R.render(p),
ask=R.render(q))
pengine = Pengine(builder=factory, debug=True)
while pengine.currentQuery.hasMore:
pengine.doNext(pengine.currentQuery)
for p in pengine.currentQuery.availProofs:
print('{} <- {}'.format(p[X.name], p[Y.name]))
Release files for prologterms 0.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| prologterms-0.0.6.tar.gz | 3.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| prologterms-0.0.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.9 kB
Release files / prologterms-0.0.6.tar.gz
| Download URL | prologterms-0.0.6.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c63cfc291ccfa3e2eeea89eed93bc7fc0214a1f2d748a200de0a5fdd90e0426a
|
|
BLAKE2b-256 checksum How to use checksums |
1e997783b44e82a5a7943222ec57fd75dd9dc38b14c72949e2619a3ee231abad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.4.2 requests/2.19.1 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.7.1
|
Release files / prologterms-0.0.6-py3-none-any.whl
| Download URL | prologterms-0.0.6-py3-none-any.whl |
|---|---|
| Size | 4.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9b8f6272dcae5a0a9257daa41cd455d5b060147486cea36623f91a3226a656e9
|
|
BLAKE2b-256 checksum How to use checksums |
e766cd1904c6268b0f9146e0e3c25ca4993ef52a5077e8d30f9a604c90610c4d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.4.2 requests/2.19.1 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.7.1
|