Skip to main content

A simple python library for generating prolog terms

Project description

|PyPI|

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

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]))




Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prologterms-0.0.3.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

prologterms-0.0.3-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file prologterms-0.0.3.tar.gz.

File metadata

File hashes

Hashes for prologterms-0.0.3.tar.gz
Algorithm Hash digest
SHA256 e8dcd377635578abf7d1e3834b58a4ebce156237bb90566e11057e9bf56b0e79
MD5 c2b540c6fd7446f18bb5fd09caec7d48
BLAKE2b-256 52e1cba9f8e95861147d7d0b9aaab5dbcf63cb3e2ab9929040bea15da9d0141f

See more details on using hashes here.

Provenance

File details

Details for the file prologterms-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for prologterms-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1529bbcaedcd316ee0486897cab2a501cf97176f735a2a5629e2368d43628840
MD5 7e960e4c0333d7db530a04604c6ca300
BLAKE2b-256 11b1b0378008e0e5645121b16913c049616c2254baf0d4bfa32d085544055223

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page