Skip to content

Add examples from KELE.#58

Open
hzhangxyz wants to merge 1 commit intomainfrom
dev/kele
Open

Add examples from KELE.#58
hzhangxyz wants to merge 1 commit intomainfrom
dev/kele

Conversation

@hzhangxyz
Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings January 15, 2026 19:42
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds example files from KELE to demonstrate the DDSS (Distributed Deductive System Sorts) capabilities. The PR includes runner scripts in both TypeScript and Python, along with multiple domain-specific language (DSP) example files covering relationship reasoning, arithmetic operations, and complex geometry problems.

Changes:

  • Added example runner scripts (main.ts and main.py) that load DSP files and execute deductive reasoning
  • Added 14 DSP example files demonstrating various reasoning tasks (relationships, arithmetic, and geometry)

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
examples/main.ts TypeScript runner that loads DSP files, executes reasoning engines, and handles arithmetic operations
examples/main.py Python runner with equivalent functionality to the TypeScript version
examples/relationship_quick_start.dsp Simple family relationship example demonstrating grandparent inference
examples/relationship.dsp Extended family relationship example with uncle/sibling rules
examples/arithmetic_example.dsp Arithmetic reasoning example demonstrating sum operations
examples/geometry_for_wo_tool_complex_1.dsp Complex geometry reasoning problem (97 lines)
examples/geometry_for_wo_tool_complex_2.dsp Complex geometry reasoning problem (45 lines)
examples/geometry_for_wo_tool_complex_3.dsp Complex geometry reasoning problem (78 lines)
examples/geometry_for_wo_tool_complex_4.dsp Complex geometry reasoning problem (37 lines)
examples/geometry_for_wo_tool_complex_5.dsp Complex geometry reasoning problem (30 lines)
examples/geometry_for_wo_tool_complex_6.dsp Complex geometry reasoning problem (35 lines)
examples/geometry_for_wo_tool_complex_7.dsp Complex geometry reasoning problem (35 lines)
examples/geometry_for_wo_tool_complex_8.dsp Complex geometry reasoning problem (29 lines)
examples/geometry_for_wo_tool_complex_9.dsp Complex geometry reasoning problem (86 lines)
examples/geometry_for_wo_tool_complex_10.dsp Complex geometry reasoning problem (68 lines)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Degree(`P1, `P2, `P3) == Degree(`P1, `P4, `P3) => Cyclic(`P1, `P4, `P3, `P2)

// R9: OE=OI & OI=OJ & OT=OJ & OS=OI => E,I,J,T 共圆
Length(`P1, `P2) == Length(`P1, `P3), Length(`P1, `P3) == Length(`P1, `P4), Length(`P1, `P5) == Length(`P1, `P4), Length(`P1, `P6) == Length(`P1, `P3) => Cyclic(`P2, `P3, `P5, `P5)
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conclusion has a duplicate variable P5 in Cyclic(P2, P3, P5, P5). Based on the premise conditions and comparison with similar rules (R1 at line 31), this should likely be Cyclic(P2, P3, P5, P4) or another appropriate variable representing the fourth point. The duplicate P5 will cause incorrect cyclic inference.

Suggested change
Length(`P1, `P2) == Length(`P1, `P3), Length(`P1, `P3) == Length(`P1, `P4), Length(`P1, `P5) == Length(`P1, `P4), Length(`P1, `P6) == Length(`P1, `P3) => Cyclic(`P2, `P3, `P5, `P5)
Length(`P1, `P2) == Length(`P1, `P3), Length(`P1, `P3) == Length(`P1, `P4), Length(`P1, `P5) == Length(`P1, `P4), Length(`P1, `P6) == Length(`P1, `P3) => Cyclic(`P2, `P3, `P4, `P5)

Copilot uses AI. Check for mistakes.
tmpdir = tempfile.TemporaryDirectory(prefix="ddss-")
path = pathlib.Path(tmpdir.name) / "ddss.db"
addr = f"sqlite+aiosqlite:///{path.as_posix()}"
file_name = sys.argv[1]
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing input validation for command-line arguments. The Python implementation does not check if a file name argument is provided before accessing sys.argv[1], which will raise an IndexError if no argument is given. The TypeScript version at line 230 properly validates this condition and provides a user-friendly error message. Consider adding a check similar to the TypeScript implementation.

Copilot uses AI. Check for mistakes.
Comment on lines +192 to +196
tmpdir = tempfile.TemporaryDirectory(prefix="ddss-")
path = pathlib.Path(tmpdir.name) / "ddss.db"
addr = f"sqlite+aiosqlite:///{path.as_posix()}"
file_name = sys.argv[1]
asyncio.run(run(addr, file_name))
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The temporary directory created is not properly managed. The TemporaryDirectory object should be used as a context manager or explicitly cleaned up to ensure the temporary directory is removed after execution. Consider using with tempfile.TemporaryDirectory(prefix="ddss-") as tmpdir: to ensure proper cleanup.

Suggested change
tmpdir = tempfile.TemporaryDirectory(prefix="ddss-")
path = pathlib.Path(tmpdir.name) / "ddss.db"
addr = f"sqlite+aiosqlite:///{path.as_posix()}"
file_name = sys.argv[1]
asyncio.run(run(addr, file_name))
with tempfile.TemporaryDirectory(prefix="ddss-") as tmpdir:
path = pathlib.Path(tmpdir) / "ddss.db"
addr = f"sqlite+aiosqlite:///{path.as_posix()}"
file_name = sys.argv[1]
asyncio.run(run(addr, file_name))

Copilot uses AI. Check for mistakes.
Comment on lines +144 to +159
for line in open(file_name, "rt", encoding="utf-8"):
data = line.strip()
if data == "":
continue
if data.startswith("//"):
continue

try:
ds = parse(data)
except Exception as e:
print(f"error: {e}")
continue

await insert_or_ignore(sess, Facts, ds)
if idea := str_rule_get_str_idea(ds):
await insert_or_ignore(sess, Ideas, idea)
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File handle is not properly closed. The file should be opened using a context manager (with open(...)) to ensure it is properly closed even if an exception occurs during processing.

Suggested change
for line in open(file_name, "rt", encoding="utf-8"):
data = line.strip()
if data == "":
continue
if data.startswith("//"):
continue
try:
ds = parse(data)
except Exception as e:
print(f"error: {e}")
continue
await insert_or_ignore(sess, Facts, ds)
if idea := str_rule_get_str_idea(ds):
await insert_or_ignore(sess, Ideas, idea)
with open(file_name, "rt", encoding="utf-8") as f:
for line in f:
data = line.strip()
if data == "":
continue
if data.startswith("//"):
continue
try:
ds = parse(data)
except Exception as e:
print(f"error: {e}")
continue
await insert_or_ignore(sess, Facts, ds)
if idea := str_rule_get_str_idea(ds):
await insert_or_ignore(sess, Ideas, idea)

Copilot uses AI. Check for mistakes.
for task in pending:
try:
await task
except asyncio.CancelledError:
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'except' clause does nothing but pass and there is no explanatory comment.

Copilot uses AI. Check for mistakes.
await task
except asyncio.CancelledError:
pass
except asyncio.CancelledError:
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'except' clause does nothing but pass and there is no explanatory comment.

Suggested change
except asyncio.CancelledError:
except asyncio.CancelledError:
# Intentionally ignore cancellation here so that the engine is always
# disposed in the finally block below.

Copilot uses AI. Check for mistakes.
@hzhangxyz hzhangxyz force-pushed the dev/kele branch 5 times, most recently from a828618 to 107ccb7 Compare March 12, 2026 11:22
feat: add relationship examples and main execution script

feat: add arithmetic example and support in main.py

Update the new interface.

Cancel pending tasks.

Update arithmetic structure to support typed literals.

Refactor arithmetic with helper functions for better structure extraction.

Support +, -, *, / and Int/Float types in arithmetic.

Sync arithmetic support and loop optimizations to examples.

Add a geometry example

Add TypeScript implementation of arithmetic example.

refactor: update examples main calls to match new signatures

feat: add complex geometry examples 1-10 (excluding 8)

Update engine name to chain.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants