englisp 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- englisp/__init__.py +96 -0
- englisp/canonicalizer.py +1242 -0
- englisp/compiler.py +895 -0
- englisp/graph_db.py +283 -0
- englisp/interpreter.py +850 -0
- englisp/loader.py +406 -0
- englisp/minimizer.py +380 -0
- englisp/ontology.py +100 -0
- englisp/parser.py +764 -0
- englisp/xbar.py +94 -0
- englisp-1.0.0.dist-info/METADATA +366 -0
- englisp-1.0.0.dist-info/RECORD +14 -0
- englisp-1.0.0.dist-info/WHEEL +5 -0
- englisp-1.0.0.dist-info/top_level.txt +1 -0
englisp/__init__.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Copyright (c) 2026 Russell Shen. All rights reserved.
|
|
2
|
+
#
|
|
3
|
+
# This source code is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives
|
|
4
|
+
# 4.0 International (CC BY-NC-ND 4.0) license.
|
|
5
|
+
#
|
|
6
|
+
# Commercial use, proprietary use, or use in closed-source or revenue-generating projects
|
|
7
|
+
# is strictly prohibited under this license.
|
|
8
|
+
#
|
|
9
|
+
# For commercial licensing inquiries, please contact:
|
|
10
|
+
# Russell Shen (russellshen7@gmail.com)
|
|
11
|
+
#
|
|
12
|
+
# Licensing terms, scope, and compensation are subject to separate negotiation.
|
|
13
|
+
#
|
|
14
|
+
# Reference the footer section of any of the 4 .md files (README.md, SPECIFICATION.md,
|
|
15
|
+
# USE_CASES.md, LEXICAL_STRATEGIES.md) in the project's root directory for full licensing details.
|
|
16
|
+
#
|
|
17
|
+
# I am the sole original creator of the EngLISP project (around August 2025), and did not rely on
|
|
18
|
+
# the resources of any academic institution or private individual to develop it.
|
|
19
|
+
|
|
20
|
+
from englisp.xbar import XBarNode
|
|
21
|
+
from englisp.parser import parse, generate, detect_language
|
|
22
|
+
from englisp.canonicalizer import xbar_to_sexpr, sexpr_to_xbar, sexpr_to_string, parse_sexpr
|
|
23
|
+
from englisp.minimizer import minimize_sexpr, expand_sexpr
|
|
24
|
+
|
|
25
|
+
__version__ = "1.0.0"
|
|
26
|
+
|
|
27
|
+
# --- The 8 Top-Level API Functions for Python Developers ---
|
|
28
|
+
|
|
29
|
+
def nl_to_xbar(text: str, lang: str = "auto") -> XBarNode:
|
|
30
|
+
"""
|
|
31
|
+
Stage 1 -> Stage 2: Parses a natural language sentence into an X-bar tree.
|
|
32
|
+
If lang is "auto", the language is automatically detected (English or French).
|
|
33
|
+
"""
|
|
34
|
+
if lang == "auto":
|
|
35
|
+
lang = detect_language(text)
|
|
36
|
+
return parse(text, lang=lang)
|
|
37
|
+
|
|
38
|
+
def xbar_to_nl(node: XBarNode, lang: str = "en") -> str:
|
|
39
|
+
"""
|
|
40
|
+
Stage 2 -> Stage 1: Synthesizes a natural language sentence from an X-bar tree.
|
|
41
|
+
"""
|
|
42
|
+
return generate(node, lang=lang)
|
|
43
|
+
|
|
44
|
+
def xbar_to_englisp(node: XBarNode, lang: str = "en") -> list:
|
|
45
|
+
"""
|
|
46
|
+
Stage 2 -> Stage 3: Translates an X-bar tree into a canonical rotated EngLISP S-expression list.
|
|
47
|
+
"""
|
|
48
|
+
return xbar_to_sexpr(node, lang=lang)
|
|
49
|
+
|
|
50
|
+
def englisp_to_xbar(sexpr: list, lang: str = "en") -> XBarNode:
|
|
51
|
+
"""
|
|
52
|
+
Stage 3 -> Stage 2: Reconstructs an X-bar tree from a rotated EngLISP S-expression list.
|
|
53
|
+
"""
|
|
54
|
+
return sexpr_to_xbar(sexpr, lang=lang)
|
|
55
|
+
|
|
56
|
+
def englisp_to_minimalist(sexpr: list) -> list:
|
|
57
|
+
"""
|
|
58
|
+
Stage 3 -> Stage 4: Compresses a canonical EngLISP S-expression list into MinimaLIST form.
|
|
59
|
+
"""
|
|
60
|
+
return minimize_sexpr(sexpr)
|
|
61
|
+
|
|
62
|
+
def minimalist_to_englisp(sexpr: list) -> list:
|
|
63
|
+
"""
|
|
64
|
+
Stage 4 -> Stage 3: Expands a MinimaLIST S-expression list back into a full canonical EngLISP S-expression list.
|
|
65
|
+
"""
|
|
66
|
+
return expand_sexpr(sexpr)
|
|
67
|
+
|
|
68
|
+
# --- The 2 "All the Way" Functions ---
|
|
69
|
+
|
|
70
|
+
def nl_to_minimalist(text: str, lang: str = "auto") -> list:
|
|
71
|
+
"""
|
|
72
|
+
Stage 1 -> Stage 4: Transforms natural language directly to a MinimaLIST S-expression list.
|
|
73
|
+
"""
|
|
74
|
+
if lang == "auto":
|
|
75
|
+
lang = detect_language(text)
|
|
76
|
+
xbar = nl_to_xbar(text, lang=lang)
|
|
77
|
+
englisp = xbar_to_englisp(xbar, lang=lang)
|
|
78
|
+
return englisp_to_minimalist(englisp)
|
|
79
|
+
|
|
80
|
+
def minimalist_to_nl(sexpr: list, lang: str = "en") -> str:
|
|
81
|
+
"""
|
|
82
|
+
Stage 4 -> Stage 1: Expands a MinimaLIST S-expression list and synthesizes it back into natural language.
|
|
83
|
+
"""
|
|
84
|
+
englisp = minimalist_to_englisp(sexpr)
|
|
85
|
+
xbar = englisp_to_xbar(englisp, lang=lang)
|
|
86
|
+
return xbar_to_nl(xbar, lang=lang)
|
|
87
|
+
|
|
88
|
+
# --- S-expression string serialization/parsing helpers ---
|
|
89
|
+
|
|
90
|
+
def to_string(sexpr: list) -> str:
|
|
91
|
+
"""Serializes an S-expression list to its canonical string representation (with DAG backreferences if shared)."""
|
|
92
|
+
return sexpr_to_string(sexpr)
|
|
93
|
+
|
|
94
|
+
def from_string(s: str) -> list:
|
|
95
|
+
"""Parses a Lisp-style S-expression string (handling DAG reference notation) into a list structure."""
|
|
96
|
+
return parse_sexpr(s)
|