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=[...])
ConflictRule Constraint expressed by leaving the head empty ConflictRule(body=..., name="no_x")

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

Conflict rules (:- body. style)

ConflictRule models a constraint whose head is omitted (empty) and is compiled internally to a reserved violate_* rule.

When any conflict rule is satisfied:

  • inference terminates with InferenceStatus.CONFLICT_DETECTED
  • EngineRunResult.conflict_reason contains phase/rule/evidence details

Runnable example:

uv run python examples/conflict_quick_start.py
  • 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.1b2.tar.gz (215.3 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.1b2-cp314-cp314-win_amd64.whl (346.9 kB view details)

Uploaded CPython 3.14Windows x86-64

kele-0.0.1b2-cp314-cp314-win32.whl (339.4 kB view details)

Uploaded CPython 3.14Windows x86

kele-0.0.1b2-cp314-cp314-musllinux_1_2_x86_64.whl (563.9 kB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ x86-64

kele-0.0.1b2-cp314-cp314-musllinux_1_2_aarch64.whl (546.4 kB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ ARM64

kele-0.0.1b2-cp314-cp314-manylinux_2_28_x86_64.whl (492.6 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64

kele-0.0.1b2-cp314-cp314-manylinux_2_28_aarch64.whl (480.6 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ ARM64

kele-0.0.1b2-cp314-cp314-macosx_11_0_arm64.whl (449.8 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

kele-0.0.1b2-cp313-cp313-win_amd64.whl (339.3 kB view details)

Uploaded CPython 3.13Windows x86-64

kele-0.0.1b2-cp313-cp313-win32.whl (333.0 kB view details)

Uploaded CPython 3.13Windows x86

kele-0.0.1b2-cp313-cp313-musllinux_1_2_x86_64.whl (563.0 kB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

kele-0.0.1b2-cp313-cp313-musllinux_1_2_aarch64.whl (546.6 kB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ ARM64

kele-0.0.1b2-cp313-cp313-manylinux_2_28_x86_64.whl (491.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

kele-0.0.1b2-cp313-cp313-manylinux_2_28_aarch64.whl (481.2 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

kele-0.0.1b2-cp313-cp313-macosx_11_0_arm64.whl (449.8 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: kele-0.0.1b2.tar.gz
  • Upload date:
  • Size: 215.3 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.1b2.tar.gz
Algorithm Hash digest
SHA256 04fca1ed842710b4b03bec8898296c57409aca67263134c6d5facfb7b1b0e86d
MD5 655b621888e4e4b450ac4ba0f04451de
BLAKE2b-256 76ecc135be2fb8ba3e5acc0c0d3d872aa0a9f453c300d62c0a231d474f4b2831

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kele-0.0.1b2-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 346.9 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.1b2-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 fb45a11c96012275b4388f2746bf4c280b087389b8699dd4e071e802f08bdad2
MD5 6fefcff88a02c6d7868654a358728e81
BLAKE2b-256 a5a0cfeb4fbd6dc499078fc93680d72eaf0f2a98fabd48396f6a75f01d6bd8f1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kele-0.0.1b2-cp314-cp314-win32.whl
  • Upload date:
  • Size: 339.4 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.1b2-cp314-cp314-win32.whl
Algorithm Hash digest
SHA256 c6844914a8a53abf4896a94bba43bb8ed8b97c98c78b542dda59c7161633896d
MD5 08c2c30b1f71a19b8b2ce75bc08df894
BLAKE2b-256 ddb3dcf083a81efb9e9d05cc342e963283f7416afa5b14408940cd23e409bd17

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kele-0.0.1b2-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 49b0900db14eb51fcf240a86a7547def9391d6dbaa4eb456985fbe8505cde731
MD5 82b9f5e7f5216235eb18fa3c35cde9af
BLAKE2b-256 b1e1dfcdd32bc8f1f9ab44b8cef939c4742903f179e1ab74157872c859fa7cca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kele-0.0.1b2-cp314-cp314-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 5cc441ba8f7253877e9271db347761c8142b649cd7064f70e64e6c94cd3700f3
MD5 539f9e7ee4a9a8a7c45d5f92f91e68c9
BLAKE2b-256 d7d92a41a53c54e8b0b955e9dd6bfdc530a7de6f31baea28781b7b15c9b3a4ce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kele-0.0.1b2-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 eaffe7d843c82bde83360cde6e3fd50949dc8f31089df24da2ce0ac56b039bdf
MD5 f4ba4433c4f1a3ca1f794dfc14f8cc7e
BLAKE2b-256 483e91668afdf519e3d611cedad84ba84e27c6805211d0ca6489c7fce22e2a46

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kele-0.0.1b2-cp314-cp314-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f6b923ad08efdc8cea29e40884eed45a34fd3ad05266765d9c61ea5339507f03
MD5 6cfc2df12f46b2b29949f19cfb70a4c1
BLAKE2b-256 5b85435390b324f0d83b229ec532c36747d1a7498de4e9ff1c16cdb1a1827c1f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kele-0.0.1b2-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 349e75fe034f31033a9a002ddbd1d5e939a74161f75593d1bcd3dcae2465d768
MD5 80b8fcf93b574afb956b9757bb8d991e
BLAKE2b-256 e2180afbc757fe8984b818b7299e96905a5b738f182b6c3e89b48617b7b5756a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kele-0.0.1b2-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 339.3 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.1b2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 1dd415020ac080769094c4aa69de3fab5cac55c3fa701bbc7ea51c7132e97d5f
MD5 7366771fe1c237ea257180f6f6f6ddef
BLAKE2b-256 d4ca62888888177809e53f405c6aab0740cf72c86b813647254ed78b67ee13d4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kele-0.0.1b2-cp313-cp313-win32.whl
  • Upload date:
  • Size: 333.0 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.1b2-cp313-cp313-win32.whl
Algorithm Hash digest
SHA256 48076c23f3a7324fd57f04c999719a39b5be6828d14defa767107e57ee414ff2
MD5 d6ebcbb2126b404d428d7f518ef680e5
BLAKE2b-256 642c54ce3c0a75127bcdd6fb0e836d4b71303ae53da0fbc6ff2852c6070fe0c1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kele-0.0.1b2-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 965f92cacff0df7d60544a35d792ffb12e4df00bb688d5458793e6c36c0a6d72
MD5 cb24bc154c61463d5481751ad2726a48
BLAKE2b-256 faa731edbaa77cf99e189064f3c4d6d10a74a98e846c2fb73920c340e8686c64

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kele-0.0.1b2-cp313-cp313-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 18cb6efaaef5795aa8d4d7242470fcfc9e2f1767c17f152723d6ae332d7d8e42
MD5 ea2fadff1a24f0bf85edad8000cbb802
BLAKE2b-256 3967ad57df53e665f94a800dfec211d7b79fe2f99fb3bd9b2bf2d18105112b4f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kele-0.0.1b2-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 359dc382b40d384c5c47b07d7de0b98869cb1f570d03a362c6cc52389b752aec
MD5 945582a0eba477a9ca789846ae8c2a22
BLAKE2b-256 1c31e6481fd88870aac8ba26f5832721c8bac127bbf9b7339dc82af33115c9e8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kele-0.0.1b2-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 3a8417b4eca829267e34ecec7c51759677641b6830c5489935a989ca6cfbc8b4
MD5 e90208515e96bc020b487cebf5898642
BLAKE2b-256 bcb44a37740c29c3a5d02bed5b8a848604b67ed32d7c0c2384c36d03b6f8bf4d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kele-0.0.1b2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b03d9f0a9137dff483c631ae9415a0bddf14d56193055648f4c04db05f4cff70
MD5 fbde9c130d1a87fbdf1de9d236081834
BLAKE2b-256 d6391cfb7122f01686630a4e6ffa8ea758a6b40f9f8aceb3eb1780398755fb54

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