Skip to main content

This is a module for interfacing python with the Prolog Pengines knowledge base.

API

Create a basic run pengine server script, and run it with swipl.

:- use_module(library(http/thread_httpd)).
:- use_module(library(http/http_dispatch)).
:- use_module(library(pengines)).

server(Port) :- http_server(http_dispatch, [port(Port)]).

:- server(4242).

Initialize a basic PengineBuilder

from pengines.Builder import PengineBuilder
from pengines.Pengine import Pengine

pengine_builder = PengineBuilder(urlserver="http://localhost:4242")

Create the pengine querying object.

pengine = Pengine(builder=pengine_builder)
pengine.create()

Make your query – note the lack of ending period – Pengine performs the query like ‘ask(member(X, [1,2,3], [])).’

query = "member(X, [1,2,3])"
pengine.ask(query)
print(pengine.currentQuery.availProofs)

Iterate through the proofs like this:

while pengine.currentQuery.hasMore:
    pengine.doNext(pengine.currentQuery)
    print(pengine.currentQuery.availProofs)

prologterms library

The python library prologterms aims to make it easier to construct prolog programs and query terms from within python.

For an example of how to use prologterms in conjunction with pengines, see:

https://pypi.org/project/prologterms/

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 pengines 0.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pengines 0.1.8
File Size Uploaded
pengines-0.1.8.tar.gz 8.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pengines 0.1.8
File Interpreter ABI Platform
pengines-0.1.8-py3-none-any.whl Python 3 none any Details

Total release size: 17.4 kB

Release files / pengines-0.1.8.tar.gz

Download URL pengines-0.1.8.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5325205eaa538f0c02ec886ff5bfd031949e141d0459479817173ec99a6c9d95
BLAKE2b-256 checksum
How to use checksums
74a3fd7e21f2d00d6eb6f6a6e932f6479149ce01265f125b203942cdfcac9089
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 / pengines-0.1.8-py3-none-any.whl

Download URL pengines-0.1.8-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
35ea10b7d2c77757b2a97160298c5d28b4145b00635005647afecdbf5a47763b
BLAKE2b-256 checksum
How to use checksums
bcdefab4d98642b805839e7d7779780a1c567db61f1a0f8829686b55e1d265f8
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 history Release notifications | RSS feed

This release

0.1.8 This release

2 release files

0.1.7

2 release files

0.1.5

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page