Skip to main content

declarative programming on json-like objects in Python

Project description

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.

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

inference_logic-0.1.0.tar.gz (26.6 kB view details)

Uploaded Source

Built Distribution

inference_logic-0.1.0-py2.py3-none-any.whl (9.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file inference_logic-0.1.0.tar.gz.

File metadata

  • Download URL: inference_logic-0.1.0.tar.gz
  • Upload date:
  • Size: 26.6 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for inference_logic-0.1.0.tar.gz
Algorithm Hash digest
SHA256 241dfe7744c22ac133c4f517333ec8808c187eb1a1fe2073d825745d1dcf7280
MD5 841e35a3f35e99d54e64a7da68cc49dd
BLAKE2b-256 98c22f3680aa03a3f3bd58c3bb52ed3aae21ffb0b3db74adec476497e48f63c6

See more details on using hashes here.

File details

Details for the file inference_logic-0.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: inference_logic-0.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using 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

File hashes

Hashes for inference_logic-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e4432d2e8e832eff63d43db7883e23fd8da4360d4357bf8d8d6a8395075d857c
MD5 33f0fc6bcc18939f2057c698bca4dbc0
BLAKE2b-256 c264b1c5ffac5ce9c3743a7d91bb0d7fdc4fd043e98b7c2fb69d7f8c1107fb8d

See more details on using hashes here.

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