Skip to main content

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

Project description

KELE Inference Engine

English | 中文

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)
  • Built-in hook enabler: enable built-in hooks for inspection/debugging via BuiltinHookEnabler

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.

🗺️ 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.1a2.tar.gz (189.7 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.1a2-cp314-cp314-win_amd64.whl (323.8 kB view details)

Uploaded CPython 3.14Windows x86-64

kele-0.0.1a2-cp314-cp314-win32.whl (315.9 kB view details)

Uploaded CPython 3.14Windows x86

kele-0.0.1a2-cp314-cp314-musllinux_1_2_x86_64.whl (540.9 kB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ x86-64

kele-0.0.1a2-cp314-cp314-musllinux_1_2_aarch64.whl (524.0 kB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ ARM64

kele-0.0.1a2-cp314-cp314-manylinux_2_28_x86_64.whl (470.8 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64

kele-0.0.1a2-cp314-cp314-manylinux_2_28_aarch64.whl (458.9 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ ARM64

kele-0.0.1a2-cp314-cp314-macosx_11_0_arm64.whl (427.6 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

kele-0.0.1a2-cp313-cp313-win_amd64.whl (316.9 kB view details)

Uploaded CPython 3.13Windows x86-64

kele-0.0.1a2-cp313-cp313-win32.whl (309.6 kB view details)

Uploaded CPython 3.13Windows x86

kele-0.0.1a2-cp313-cp313-musllinux_1_2_x86_64.whl (541.4 kB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

kele-0.0.1a2-cp313-cp313-musllinux_1_2_aarch64.whl (523.9 kB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ ARM64

kele-0.0.1a2-cp313-cp313-manylinux_2_28_x86_64.whl (471.5 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

kele-0.0.1a2-cp313-cp313-manylinux_2_28_aarch64.whl (458.6 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

kele-0.0.1a2-cp313-cp313-macosx_11_0_arm64.whl (428.4 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: kele-0.0.1a2.tar.gz
  • Upload date:
  • Size: 189.7 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.1a2.tar.gz
Algorithm Hash digest
SHA256 3e2acf8094338b7953ba2e24962890fdadc89f02afe569783cc05298759b9088
MD5 570abc1267161e34a4fdc78079d4c8fe
BLAKE2b-256 404f0623ecb2ee2107b73fe0eb1b8411026500503d29834b7608db9599513ec2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kele-0.0.1a2-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 323.8 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.1a2-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 338d9545867200586b637040f08d119f47fbf7e98210d4d2ef7b75bad1680a7e
MD5 e84297a778c32bbdc668a05eb1c3f935
BLAKE2b-256 d9dc4177e60a122f446c9ff9ee38bd1efe0defe6160a0067929a383b7149f332

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kele-0.0.1a2-cp314-cp314-win32.whl
  • Upload date:
  • Size: 315.9 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.1a2-cp314-cp314-win32.whl
Algorithm Hash digest
SHA256 9a21646e9623b4929eefb2d58a180c3a86ac0be8426ca32731d0ed21d6b536af
MD5 6714a21f6c4794e7d49fc310045c69cd
BLAKE2b-256 2eb4038a6ee69bb76bbc26075021b78ab9b9d09d17c26f216e6b046a5f03fddf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kele-0.0.1a2-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 0e6e22c5debec58710e6607a1e89f2f8b756421e5d0f06f21e2c8e60e0a5dbbd
MD5 cf74e8350a45faea9ae856d7b6fef263
BLAKE2b-256 a76bb8cb2a310d3188fc10211ae7572a0778169f79d5aaf2c93af6801925ab4d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kele-0.0.1a2-cp314-cp314-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 724b1d8a7f8ed1f7182b393f5ed646aad2f1c6f4a7b303d0cf81263f601de970
MD5 6f1cf4e337f8ab40e2328d0b52e708f5
BLAKE2b-256 316a95548ceec654064f0474a08016379e564eb409478787d8525c0c14dc71fa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kele-0.0.1a2-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1ea0a0db5bdc875e806f9371bc2c04f37a30074f0c5ca457f6e9e033b229dc90
MD5 94b8cab9eed60d276c8aa55f2a3c3472
BLAKE2b-256 6053b06d13094b467b1c9d8d477deaa5aa6e93607b0211f8fff50f9be3cd6051

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kele-0.0.1a2-cp314-cp314-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 4471fb47a52afe57b13f9268d3ac7b895cf6801f833f3c5b6090edc63482fcc4
MD5 d6f6100e640ae7c47e4b563888db8168
BLAKE2b-256 e05a61e24f119190f91e8b9d56406731ac0c40ccfc740d58ed72a73245947995

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kele-0.0.1a2-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 dd409b3cfa94189b6ec565cb1b47af2d5978078b83c876b54ada523290635890
MD5 cf95862c7e8e15df0db0408f5daa9729
BLAKE2b-256 939d56ae8df85d990ae66c32046fd862823470dd7a110392e4b1c0b73b8f7730

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kele-0.0.1a2-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 316.9 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.1a2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 e7a90c32e3651c3a47c7f14c54e5a4d01c6fbde6dcd8065fdec921fb32a00849
MD5 756194b921417d57b5d5929bf12f2a79
BLAKE2b-256 b66dc47f8577ebf2318d13bc19790a34975f2a02a24d8eda8a71b18d4dbf5aef

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kele-0.0.1a2-cp313-cp313-win32.whl
  • Upload date:
  • Size: 309.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.1a2-cp313-cp313-win32.whl
Algorithm Hash digest
SHA256 d72fda68cea93c78b47474e6bc540451b00077d93954880bee6f4e0bac0a0d7d
MD5 aaf4c9ec9212abecb1ce4c00e578c2db
BLAKE2b-256 d1edf1a3fc16bb5af929ae37e89be4b7182d91f84d5da126ba75796f71270674

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kele-0.0.1a2-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 4d8ab92b268cbcb2bacfe8e4452ea8a216f6be94ff1268db05352aafc324b251
MD5 93678541c0383857d4211c8d81240760
BLAKE2b-256 d101079a1799711c0064a4c12d4ad42c521e0ae536127284f60741b3d8c22e67

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kele-0.0.1a2-cp313-cp313-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 fa564393ffaff97110ac5753278ef7393aea46a6a9d6e6bcf85921e9f3085a38
MD5 201de4d2c8155ed2806b639d6031189c
BLAKE2b-256 955cb7554ce23b29f80d2a2d5e79ae727c482362ed758f5741ca4d848aaa8550

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kele-0.0.1a2-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 494ab97e36e5652da8c71c45b1368b459b79ec99db2b8846c5fc38243a08cb2e
MD5 7bd653191e5468bd0e2369f1404e12b9
BLAKE2b-256 152fa5677f5d405a0db9e5ea79d0a0a902e515c6fd71738053661eac65dbdc6d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kele-0.0.1a2-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a4ebd7f19de986eec2ddcd1fba356febd685fec6cf394d26eab6c1e50ad2d265
MD5 29547b068cd2f2945c726125acd59048
BLAKE2b-256 f05b6b71ec29778d37242494cca5b39f6add78b7e716dff989536e303b8f9c01

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kele-0.0.1a2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a4ba8e9320718e86998b783638e5eaa822ddf8ea3e51e8e1db77b6f0f81b3a16
MD5 33ca9edcdbdbaa2f6f49dc9cc8c700a2
BLAKE2b-256 6b7e7a92d9e41a466761d46ba69466d458e90b1646a19adab391e9294fae1290

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