Skip to main content

推理引擎

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)

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/

🗺️ Roadmap

WIP

🤝 Contributing

Issues/PRs welcome! Please read CONTRIBUTING.md, and consider enabling ruff and mypy.

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.1a1.tar.gz (181.4 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.1a1-cp314-cp314-win_amd64.whl (316.9 kB view details)

Uploaded CPython 3.14Windows x86-64

kele-0.0.1a1-cp314-cp314-win32.whl (309.1 kB view details)

Uploaded CPython 3.14Windows x86

kele-0.0.1a1-cp314-cp314-musllinux_1_2_x86_64.whl (534.1 kB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ x86-64

kele-0.0.1a1-cp314-cp314-musllinux_1_2_aarch64.whl (517.1 kB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ ARM64

kele-0.0.1a1-cp314-cp314-manylinux_2_28_x86_64.whl (464.0 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64

kele-0.0.1a1-cp314-cp314-manylinux_2_28_aarch64.whl (452.0 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ ARM64

kele-0.0.1a1-cp314-cp314-macosx_11_0_arm64.whl (420.8 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

kele-0.0.1a1-cp313-cp313-win_amd64.whl (310.0 kB view details)

Uploaded CPython 3.13Windows x86-64

kele-0.0.1a1-cp313-cp313-win32.whl (302.7 kB view details)

Uploaded CPython 3.13Windows x86

kele-0.0.1a1-cp313-cp313-musllinux_1_2_x86_64.whl (534.5 kB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

kele-0.0.1a1-cp313-cp313-musllinux_1_2_aarch64.whl (517.0 kB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ ARM64

kele-0.0.1a1-cp313-cp313-manylinux_2_28_x86_64.whl (464.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

kele-0.0.1a1-cp313-cp313-manylinux_2_28_aarch64.whl (451.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

kele-0.0.1a1-cp313-cp313-macosx_11_0_arm64.whl (421.5 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: kele-0.0.1a1.tar.gz
  • Upload date:
  • Size: 181.4 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.1a1.tar.gz
Algorithm Hash digest
SHA256 1c37c773b2df30b6714704834657e76715c68bdb48e46e341d998487af77fe4e
MD5 92b35564524e811e4c678d323892544d
BLAKE2b-256 b18002aa005929a37b06eaaee63db8c2a82f22e6c565260a6e88a454010ec68a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kele-0.0.1a1-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 316.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.1a1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 5a42c810903866d6c648bb1a44f4ec22c820660c62383b0969bdbf44f7c01eea
MD5 45abf244839cb87a8479f038d6aee08c
BLAKE2b-256 9f49def396c2bef4c04682f1ed969feda3f502626fa784534fd4b658f1548560

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kele-0.0.1a1-cp314-cp314-win32.whl
  • Upload date:
  • Size: 309.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.1a1-cp314-cp314-win32.whl
Algorithm Hash digest
SHA256 4d33d3dfafa45001eed872a0ee99f725efa54f0295cb7d15e40071578b187827
MD5 d9bf674b4cdb95ae24125a0058185227
BLAKE2b-256 f3a1f6c82a44b41772cd27ae4712cd6ca8a444a0f9fd760ce4e2ff662d16719d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kele-0.0.1a1-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2144b52de1f947a71bc724c4c17e5f1dd96bf1e295734d9291c9960f49cea650
MD5 979a415f974f1041ed67000ebe335af2
BLAKE2b-256 a4c532aa278767db94384b8d96a3062696da61e34476c1a36f3997c73cead6b0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kele-0.0.1a1-cp314-cp314-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 860a2565802c376b10fcb735786d497e77c4a98437d2ee1cea5cbfda34a549e4
MD5 778919b2455025dc4c61a9c3c1d2f04b
BLAKE2b-256 41f6f09723a870a717e5c50847e3a7f8947b8932260763f7464f9a67001abf9d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kele-0.0.1a1-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ef13e3b229232be6a572008d8377f464d6dcab9532cb9c2045c41e3a1cd6bf33
MD5 b66eb14805b07648f39c62eed124b4b0
BLAKE2b-256 c3e4f9da821c23a84d76bcbd75257effe64b5fc50bcb33b998e2ac8737baf752

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kele-0.0.1a1-cp314-cp314-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 91c0054abb51df35c061d4cbd4bcaa4a0f018cc607c52c96c5b6b45713c94d8f
MD5 fe67ab3fa2b6f4a82facfe1f018f66c4
BLAKE2b-256 c97a1fb187d5bcd88827cafa00b8d0c917b4e2a65bca5e808e5fd4147e072b27

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kele-0.0.1a1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ba2335426c3c60b5d9dbf94342f6b617fe325b7212f55af936a6c39ddd15998c
MD5 8f24513c890635efe662bf535723798d
BLAKE2b-256 cc6bde823b513617ee52641ac7d4ea2f0d3121744576987508c2f023f457aef8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kele-0.0.1a1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 310.0 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.1a1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 deca9199e4a74ea961515fde5e3544055458e71457ecbf9f6b6023a1a4b8c3c2
MD5 24764e1f21038422007f3ec19446f27c
BLAKE2b-256 b35919e74d2e2488fc3dde8517d35e8e265008adf8371e0f7aba51aea3f850be

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kele-0.0.1a1-cp313-cp313-win32.whl
  • Upload date:
  • Size: 302.7 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.1a1-cp313-cp313-win32.whl
Algorithm Hash digest
SHA256 5c6d0929c0ab176167d18e8b8943623a55bb82cd76900c6f86f382a79ff4add0
MD5 3450df0b6f6da9c8ba8c5eb1ef5b15f4
BLAKE2b-256 1a0024d15b83d7ee046ec4e90f14db894778a4292cabf1255776b1f2748d3bc0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kele-0.0.1a1-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1385071cd95f76de1ed3ff35bd9415ad3f63b2beda436b58789dde237c2d3d85
MD5 22747242061a8b677292f418113d4a66
BLAKE2b-256 0d2ee1d5e0de0c4f4e4e6a6c1909524fd9a90451b90c806c07d66da40a768076

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kele-0.0.1a1-cp313-cp313-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 db504f91f755143f6c92c5548bcf2e681d2d6470cdd899b141cf7de1db9d3191
MD5 76a908c3ce8753f3267ce2268374dee7
BLAKE2b-256 d3d8805a64e92544c741fffaa9ee86599770d726f942e8f405efa41ae599627a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kele-0.0.1a1-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 187f00307790306c1ef913961fe1b5ed95d988edb0679d76484046879b2816c3
MD5 e6e20950da7f67bac0202f607150802f
BLAKE2b-256 2cd81a8187de81a992a14917377e15cd7f075aff29d3c2fb63c5218c3fe04c17

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kele-0.0.1a1-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 0cce62c5a40d64e4e5ef7f27cf9a8f440eca5614b88fdc83d14998b97de9f9cd
MD5 7dcd04e16b3f763ead02d2389451c99f
BLAKE2b-256 5cd8d7f6b0b5633a017efb3df09b2a229e6a3c635ef5eb78f4ce605b2d867bf3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kele-0.0.1a1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2e800c3e3f2885af1242882c8f9620675b92db6efee3b691c601df8ce1df1662
MD5 23336aac87605e987978c9ce75df73e2
BLAKE2b-256 800e8a712617839fb8e889d45389f71d1247d08bb5451f379b99854d0ec12f35

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