Skip to main content

Inference Logic

https://img.shields.io/pypi/v/inference_logic.svg https://img.shields.io/travis/gecBurton/inference_logic.svg Documentation Status Updates

The goal of this project is to explore how to write a minimal set of features that allows a programmer to code declaratively in native Python.

The code is loosely based on Prolog, but rather than use the Prolog Term/functor structure it uses JSON-like dicts and tuples.

The success of this project is measured by the number of the 99 problems solved to keep the code focussed on delivering features and not bike-shedding

This code is experimental and incomplete. Do not use it in your work or school! If you wish to use a serious, well tested declarative tool in Python use the excellent pyDatalog.

tldr

from inference_logic import Variable, Rule, search

X, Y, Z, C, P = Variable.factory("X", "Y", "Z", "C", "P")

db = [
    dict(parent="Abe", child="Homer"),
    dict(parent="Homer", child="Lisa"),
    dict(parent="Homer", child="Bart"),
    dict(parent="Homer", child="Maggie"),
    Rule(dict(ancestor=X, descendant=Z), dict(parent=X, child=Z)),
    Rule(
        dict(ancestor=X, descendant=Z),
        dict(parent=X, child=Y),
        dict(ancestor=Y, descendant=Z),
    ),
]

query = dict(ancestor=P, descendant=C)
results = search(db, query)


assert next(results) == {C: "Lisa", P: "Abe"}
assert next(results) == {C: "Bart", P: "Abe"}
assert next(results) == {C: "Maggie", P: "Abe"}
assert next(results) == {C: "Homer", P: "Abe"}
assert next(results) == {C: "Lisa", P: "Homer"}
assert next(results) == {C: "Bart", P: "Homer"}
assert next(results) == {C: "Maggie", P: "Homer"}

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

This was originally inspired by py4fun some of this code here comes directly from this project.

Thank you to kclaurelie for helping to solve the fundamental problem that had been bugging me for months!

History

0.1.0 (2020-10-05)

  • First release on PyPI.

Release files for inference-logic 0.1.0

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

Source distribution (sdist)

Source distribution for inference-logic 0.1.0
File Size Uploaded
inference_logic-0.1.0.tar.gz 26.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for inference-logic 0.1.0
File Interpreter ABI Platform
inference_logic-0.1.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 36.0 kB

Release files / inference_logic-0.1.0.tar.gz

Download URL inference_logic-0.1.0.tar.gz
Size 26.6 kB
Tags Source
SHA-256 checksum
How to use checksums
241dfe7744c22ac133c4f517333ec8808c187eb1a1fe2073d825745d1dcf7280
BLAKE2b-256 checksum
How to use checksums
98c22f3680aa03a3f3bd58c3bb52ed3aae21ffb0b3db74adec476497e48f63c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

Release files / inference_logic-0.1.0-py2.py3-none-any.whl

Download URL inference_logic-0.1.0-py2.py3-none-any.whl
Size 9.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
e4432d2e8e832eff63d43db7883e23fd8da4360d4357bf8d8d6a8395075d857c
BLAKE2b-256 checksum
How to use checksums
c264b1c5ffac5ce9c3743a7d91bb0d7fdc4fd043e98b7c2fb69d7f8c1107fb8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

Release history Release notifications | RSS feed

This release

0.1.0 This release

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