Skip to main content

Knowledge Equations based Logic Engine, a forward chaining inference engine with Assertional Logic

Project description

KELE Inference Engine

English | 中文

Cola icon

License Build Python 3.13+ Docs PRs Welcome Commit Message


KELE is a forward-chaining inference engine based on Assertion Logic, implementing a subset of the logic.

It supports term-level facts, nested terms, equivalence axioms, and operators with functions, and integrates well with modern Python (3.13+). You can embed your tools through operator implementations (and embed KELE into your tools), while we leave the burden of wrapping/binding other languages to developers rather than users.

⚠️ Project status
We released the first alpha version on 12/31 and will move it to a beta release as soon as possible after the holiday. The engine will maintain backward compatibility for commonly used public classes and modules, while internal components are still evolving and under active development.

✨ Features

  • Term-level facts and reasoning: term-centric organization and inference, suited for equality knowledge
  • Equivalence axioms: convenient equivalence expressions with internal maintenance
  • Nested compound terms: operators can nest to build complex structures
  • Implement functions for operators: implement functions for operators (e.g., arithmetic, equation solving)

Implement functions for operators ≈ Prolog meta-predicates / ASP HEX external predicates (not identical semantics, similar usage).

🔍 Matching semantics

  • Loose matching: treat subsumption as "intersection" matching, without input/constraint distinction
  • Concept overlap check: returns whether there is a non-empty common concept set aligned
  • Mismatch handling: incompatible

🔧 Installation

Option A: PyPI (after release)

You can grab the latest built wheel from GitHub Actions or install a published release directly.

pip install kele

Option B: Build from source

Requirements: Python 3.13+; Rust toolchain (rustup); on Windows, MSVC (Visual Studio Build Tools).

git clone https://github.com/USTC-KnowledgeComputingLab/KELE
cd KELE
uv sync
uv run maturin develop --skip-install  # install rust and MSVC (Windows) beforehand

🚀 Quick start

Full example: examples/relationship_quick_start.py

uv run python examples/relationship_quick_start.py
# Output: grandparent relation inference result (forward-chaining demo)

🧩 Core syntax at a glance

Type Meaning Example/Hint
Concept Group of objects sharing something in common Person = Concept("Person")
Constant Object (belongs to concepts) alice = Constant("Alice", Person)
Variable Placeholder in rules/queries X = Variable("X")
Operator Map a tuple of objects into a single one parent(Person, Person) -> Bool
CompoundTerm Operator + arguments CompoundTerm(parent, [alice, bob])
Assertion “term = term” assertion Assertion(..., ...)
Formula Combine assertions with AND/OR/… Formula(A, "AND", B)
Rule body → head Rule(head=..., body=...)
QueryStructure Query input (premises + question) QueryStructure(premises=[...], question=[...])
InferenceEngine Engine core InferenceEngine(facts=[...], rules=[...])

examples/relationship_quick_start.py shows a family-relation inference example, illustrating how the pieces fit together:

  1. Define concepts (Concept) and operators (Operator), such as Person, parent, grandparent.
  2. Add initial facts (Assertion), e.g. “Bob is Alice’s parent”.
  3. Write rules (Rule + Formula), e.g. “if parent(X, Y) and parent(Y, Z), then grandparent(X, Z)”.
  4. Build a query (QueryStructure) and run InferenceEngine.

Example snippet (imports/details omitted; see examples/relationship_quick_start.py for a runnable version):

# 1. Define concepts and operators
Person = Concept("Person")
...

# 2. Add facts
alice = Constant("Alice", Person)
...

facts = [
    # parent(Alice, Bob) = True
    Assertion(CompoundTerm(parent, [alice, bob]), true_const),
    ...
]

# 3. Define rules + query
rules = [Rule(
    head=...,
    body=...,
)]

engine = InferenceEngine(facts=facts, rules=rules)
query = QueryStructure(premises=facts, question=[...])  # e.g., ask for grandparent(Alice, X)

print(engine.infer_query(query))

🧭 Documentation

  • Sphinx docs:

    • Read the Docs: WIP
    • Build locally: uv run sphinx-build -b html docs\source docs\build\html
  • Tutorial: https://msg-bq.github.io/

🧩 Custom registries

KELE exposes a top-level register hub so you can customize internal strategies (such as term/rule selectors) to fit domain-specific needs.

  • Built-in tasks: register.rule_selector and register.term_selector.
  • Each task registry supports register(name) as a decorator plus get(name) helpers.
  • Additional registries may be introduced in the future; today only rule/term selectors are supported.

🪝 Builtin hooks

BuiltinHook provides built-in hook points for inspection/debugging; enable them with the BuiltinHookEnabler switch. Other hook utilities (such as HookMixin and CallBack) are still under development.

🗺️ Roadmap

WIP

🤝 Contributing

Issues/PRs welcome! Please read CONTRIBUTING.md, and consider enabling ruff, mypy, and pydoclint (via flake8). Ruff's DOC rules are powered by pydoclint.

If you have any questions about using the engine—including usage, syntax/semantics, or theoretical foundations—please open an issue or contact us.

🪪 License

This project uses the BSD 3-Clause license. See LICENSE.

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

kele-0.0.1b1.tar.gz (205.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

kele-0.0.1b1-cp314-cp314-win_amd64.whl (334.7 kB view details)

Uploaded CPython 3.14Windows x86-64

kele-0.0.1b1-cp314-cp314-win32.whl (327.1 kB view details)

Uploaded CPython 3.14Windows x86

kele-0.0.1b1-cp314-cp314-musllinux_1_2_x86_64.whl (552.1 kB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ x86-64

kele-0.0.1b1-cp314-cp314-musllinux_1_2_aarch64.whl (534.2 kB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ ARM64

kele-0.0.1b1-cp314-cp314-manylinux_2_28_x86_64.whl (480.3 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64

kele-0.0.1b1-cp314-cp314-manylinux_2_28_aarch64.whl (468.5 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ ARM64

kele-0.0.1b1-cp314-cp314-macosx_11_0_arm64.whl (437.8 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

kele-0.0.1b1-cp313-cp313-win_amd64.whl (327.1 kB view details)

Uploaded CPython 3.13Windows x86-64

kele-0.0.1b1-cp313-cp313-win32.whl (320.6 kB view details)

Uploaded CPython 3.13Windows x86

kele-0.0.1b1-cp313-cp313-musllinux_1_2_x86_64.whl (550.9 kB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

kele-0.0.1b1-cp313-cp313-musllinux_1_2_aarch64.whl (534.6 kB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ ARM64

kele-0.0.1b1-cp313-cp313-manylinux_2_28_x86_64.whl (479.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

kele-0.0.1b1-cp313-cp313-manylinux_2_28_aarch64.whl (469.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

kele-0.0.1b1-cp313-cp313-macosx_11_0_arm64.whl (437.8 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

File details

Details for the file kele-0.0.1b1.tar.gz.

File metadata

  • Download URL: kele-0.0.1b1.tar.gz
  • Upload date:
  • Size: 205.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kele-0.0.1b1.tar.gz
Algorithm Hash digest
SHA256 3a6709e41bb21b46fa2d5734a83791113b5ea6d119c2bbd3a87ae7ff89e0a2d1
MD5 282b9ec25334e66fc37fba70df54373a
BLAKE2b-256 942deacef76eac91e57b784e61517064d8c8eae88dff885619580e36545e0a37

See more details on using hashes here.

File details

Details for the file kele-0.0.1b1-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: kele-0.0.1b1-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 334.7 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kele-0.0.1b1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 5182a337276f6972bb94cd50ad8cb3be3e880ff95af7f242add1b34dd7d135b8
MD5 65e7493cc8c17ad9e9e8867afb8b6232
BLAKE2b-256 eb652b65242f36582e5971364ed1ed3105ab744275aa2792c8ccc540c177062e

See more details on using hashes here.

File details

Details for the file kele-0.0.1b1-cp314-cp314-win32.whl.

File metadata

  • Download URL: kele-0.0.1b1-cp314-cp314-win32.whl
  • Upload date:
  • Size: 327.1 kB
  • Tags: CPython 3.14, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kele-0.0.1b1-cp314-cp314-win32.whl
Algorithm Hash digest
SHA256 427579385d6bb8b1f9f73977fea6c83bb76545550ba72c76710f1cb51433e0c9
MD5 f818cf743f4c6e5e2f54623ea21ffe94
BLAKE2b-256 4b0c79d21122a71b4ef029cf9b1368558b06977d8c3129df28c40de3fa8ab179

See more details on using hashes here.

File details

Details for the file kele-0.0.1b1-cp314-cp314-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for kele-0.0.1b1-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 633271a3c991f00aa2416d4bbe4ede9247c741b1d79e3a9575966e30f99c3e7e
MD5 ab98848e6de6c0ba1843e5e8cd9ec06f
BLAKE2b-256 85df308890f169289e9fd729ff3ecb667de4086a2246ffca0c43c5164322da25

See more details on using hashes here.

File details

Details for the file kele-0.0.1b1-cp314-cp314-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for kele-0.0.1b1-cp314-cp314-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 38e192fc7d77d8769353f0501783ca882e7f7a2ca9512920b04b5c96e069f3e5
MD5 609b599fe62ba8f9bb58fc2d05a6d66b
BLAKE2b-256 252b801cb9e2c23da26a2fb28e14d5ec8ff1b060bd186f8c55bda2b0926910e5

See more details on using hashes here.

File details

Details for the file kele-0.0.1b1-cp314-cp314-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for kele-0.0.1b1-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 481013c123ceb47846fe0e0bc91006ff0f5a56da5ebb2839b774cd32ad924f4f
MD5 8c7e3d9678b3fd493b12d547d9bcff6b
BLAKE2b-256 97f666f75dfe51d2e45b4b71abda1d727d3dda1552df2f8b7306541c2c725302

See more details on using hashes here.

File details

Details for the file kele-0.0.1b1-cp314-cp314-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for kele-0.0.1b1-cp314-cp314-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 4fdb3217351240e8ed978f1fa16da008fec65678b50922b0ccd675b456b02358
MD5 714c98d848ff62aa901203594fe23fe6
BLAKE2b-256 c2f04ab26d9e41e357fb70642ebdf2e3607342593e9b1344dbd5687e20c0740e

See more details on using hashes here.

File details

Details for the file kele-0.0.1b1-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kele-0.0.1b1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f456cfe8c7b5ec70239aa974f57a339e94db1bb22554bd6ec507f37b20144152
MD5 8d2ccd7afdaae91b1d25a4e56b060f8c
BLAKE2b-256 7f6f44e59aeff4133abedbe8011949a7b90a7bb99883b1f85cb7bf97ee224f23

See more details on using hashes here.

File details

Details for the file kele-0.0.1b1-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: kele-0.0.1b1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 327.1 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kele-0.0.1b1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 b9159ea9645dfc97c986679fab34f9601b79f2a9a1898d9033640f42b63c251d
MD5 6d4d3447d025607e8787e31cf2ce665c
BLAKE2b-256 e379de2c7ea1ad5ac7103a47c6b1401ea954694a9219eec68e9efae8faace0ec

See more details on using hashes here.

File details

Details for the file kele-0.0.1b1-cp313-cp313-win32.whl.

File metadata

  • Download URL: kele-0.0.1b1-cp313-cp313-win32.whl
  • Upload date:
  • Size: 320.6 kB
  • Tags: CPython 3.13, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kele-0.0.1b1-cp313-cp313-win32.whl
Algorithm Hash digest
SHA256 7dd04b7456633cd33de8735ba0bc43516ec0895cbf34451f05cda47f216d1044
MD5 1be1b0951d379ccbd9f3c0e777a1733b
BLAKE2b-256 516bab0e33b263647d012f1dbe3e053e840ac8ad350e6d3db8b8428dffab96ac

See more details on using hashes here.

File details

Details for the file kele-0.0.1b1-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for kele-0.0.1b1-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 df361d4955c5c429711eb76f47e8b4663dbe13974fda6451492a87571aedf08d
MD5 b0e08786ee10d93a98b88f1a1ca15df3
BLAKE2b-256 5c8967c739c5d9a614e446a32427712835b15639d4f3f8e9afe78c691d5d7da7

See more details on using hashes here.

File details

Details for the file kele-0.0.1b1-cp313-cp313-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for kele-0.0.1b1-cp313-cp313-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 83e92420712f6eb457d94d0588e592419d34df9a1a2801ff3f36d473eb949ab0
MD5 3f8ecdbc54e20e90bde7380a1388c07a
BLAKE2b-256 9ea793ec0c1caa1bee6738cb0e521beaa90da369baf8b61d643651d43a90d6d1

See more details on using hashes here.

File details

Details for the file kele-0.0.1b1-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for kele-0.0.1b1-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ef70267dd5e860520def71756d328b5055f4ac6db0990a1f9642ef1af5ed13ae
MD5 605eee1b59c4cab939e6a194848a515c
BLAKE2b-256 368bb778ffdb1be5d39cf895c0524ddfd36b46486242be20019678fc44924299

See more details on using hashes here.

File details

Details for the file kele-0.0.1b1-cp313-cp313-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for kele-0.0.1b1-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 c1374b1b8f09f39a84cce97b199f54a87b0c0bf8d6ae8be0d9c06ac4d2f84fb6
MD5 e8db0fab1c7a52dafa559a1ddac571e3
BLAKE2b-256 0f919a37dcb5e496bb44b8b854ddfdbbb26bb44c78afd0be99327a26d08814f5

See more details on using hashes here.

File details

Details for the file kele-0.0.1b1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kele-0.0.1b1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d750ba261922ca02db573fc53252cf5bc23c89cbe02dd0546a17063a6896fab8
MD5 5dcccbeff6f6f94243ad09f93071f5c3
BLAKE2b-256 b568669666e91c4947b0a02e301c74a273f46c7ddab9ce5c1e520b6f36c13a43

See more details on using hashes here.

Supported by

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