Conversation
There was a problem hiding this comment.
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.tsandmain.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) |
There was a problem hiding this comment.
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.
| 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) |
| tmpdir = tempfile.TemporaryDirectory(prefix="ddss-") | ||
| path = pathlib.Path(tmpdir.name) / "ddss.db" | ||
| addr = f"sqlite+aiosqlite:///{path.as_posix()}" | ||
| file_name = sys.argv[1] |
There was a problem hiding this comment.
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.
| 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)) |
There was a problem hiding this comment.
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.
| 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)) |
| 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) |
There was a problem hiding this comment.
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.
| 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) |
| for task in pending: | ||
| try: | ||
| await task | ||
| except asyncio.CancelledError: |
There was a problem hiding this comment.
'except' clause does nothing but pass and there is no explanatory comment.
| await task | ||
| except asyncio.CancelledError: | ||
| pass | ||
| except asyncio.CancelledError: |
There was a problem hiding this comment.
'except' clause does nothing but pass and there is no explanatory comment.
| except asyncio.CancelledError: | |
| except asyncio.CancelledError: | |
| # Intentionally ignore cancellation here so that the engine is always | |
| # disposed in the finally block below. |
a828618 to
107ccb7
Compare
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.
No description provided.