a-language 0.1.0__tar.gz
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.
- a_language-0.1.0/PKG-INFO +40 -0
- a_language-0.1.0/README.md +17 -0
- a_language-0.1.0/a_language.egg-info/PKG-INFO +40 -0
- a_language-0.1.0/a_language.egg-info/SOURCES.txt +7 -0
- a_language-0.1.0/a_language.egg-info/dependency_links.txt +1 -0
- a_language-0.1.0/a_language.egg-info/top_level.txt +1 -0
- a_language-0.1.0/parser.py +107 -0
- a_language-0.1.0/pyproject.toml +35 -0
- a_language-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: a-language
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A-Language: AI间私密通信协议的解析器
|
|
5
|
+
Author-email: "番茄 (ruihuowayking)" <ruihuowayking@users.noreply.github.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/ruihuowayking/A-Language
|
|
8
|
+
Project-URL: Documentation, https://github.com/ruihuowayking/A-Language#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/ruihuowayking/A-Language
|
|
10
|
+
Project-URL: Issues, https://github.com/ruihuowayking/A-Language/issues
|
|
11
|
+
Keywords: ai,communication,protocol,privacy,parser
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Requires-Python: >=3.8
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# A-Language Python Parser
|
|
25
|
+
|
|
26
|
+
## 安装
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install a-language
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## 使用
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from parser import ALanguageParser
|
|
36
|
+
|
|
37
|
+
parser = ALanguageParser()
|
|
38
|
+
msg = parser.parse("C[7]⟨Ξ|Φ⟩⊕Σ[3]")
|
|
39
|
+
print(msg.type, msg.priority, msg.meta)
|
|
40
|
+
```
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# A-Language Python Parser
|
|
2
|
+
|
|
3
|
+
## 安装
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pip install a-language
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## 使用
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
from parser import ALanguageParser
|
|
13
|
+
|
|
14
|
+
parser = ALanguageParser()
|
|
15
|
+
msg = parser.parse("C[7]⟨Ξ|Φ⟩⊕Σ[3]")
|
|
16
|
+
print(msg.type, msg.priority, msg.meta)
|
|
17
|
+
```
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: a-language
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A-Language: AI间私密通信协议的解析器
|
|
5
|
+
Author-email: "番茄 (ruihuowayking)" <ruihuowayking@users.noreply.github.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/ruihuowayking/A-Language
|
|
8
|
+
Project-URL: Documentation, https://github.com/ruihuowayking/A-Language#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/ruihuowayking/A-Language
|
|
10
|
+
Project-URL: Issues, https://github.com/ruihuowayking/A-Language/issues
|
|
11
|
+
Keywords: ai,communication,protocol,privacy,parser
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Requires-Python: >=3.8
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# A-Language Python Parser
|
|
25
|
+
|
|
26
|
+
## 安装
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install a-language
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## 使用
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from parser import ALanguageParser
|
|
36
|
+
|
|
37
|
+
parser = ALanguageParser()
|
|
38
|
+
msg = parser.parse("C[7]⟨Ξ|Φ⟩⊕Σ[3]")
|
|
39
|
+
print(msg.type, msg.priority, msg.meta)
|
|
40
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
parser
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"""
|
|
2
|
+
A-Language Parser v0.1
|
|
3
|
+
AI间私密通信协议解析器
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import re
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
from enum import Enum
|
|
9
|
+
from typing import Optional
|
|
10
|
+
|
|
11
|
+
class MessageType(Enum):
|
|
12
|
+
C = "Confirm" # 确认
|
|
13
|
+
Q = "Query" # 询问
|
|
14
|
+
R = "Response" # 响应
|
|
15
|
+
N = "Notification" # 通知
|
|
16
|
+
E = "Error" # 错误
|
|
17
|
+
T = "Transfer" # 传输
|
|
18
|
+
|
|
19
|
+
@dataclass
|
|
20
|
+
class ALMessage:
|
|
21
|
+
type: MessageType
|
|
22
|
+
priority: int
|
|
23
|
+
meta: dict
|
|
24
|
+
payload: str
|
|
25
|
+
raw: str
|
|
26
|
+
|
|
27
|
+
class ALanguageParser:
|
|
28
|
+
"""A-Language 解析器"""
|
|
29
|
+
|
|
30
|
+
SYMBOLS = {
|
|
31
|
+
'⊕': 'UNION', # 合并
|
|
32
|
+
'⊗': 'INTERSECT', # 交集
|
|
33
|
+
'Ξ': 'CONFIRM', # 确认
|
|
34
|
+
'λ': 'PROCESSING', # 处理中
|
|
35
|
+
'Φ': 'HIGH_PRIORITY', # 高优先级
|
|
36
|
+
'∅': 'NULL', # 空
|
|
37
|
+
'Ψ': 'QUERY', # 疑问
|
|
38
|
+
'Δ': 'CHANGED', # 变更
|
|
39
|
+
'Ω': 'URGENT', # 紧急
|
|
40
|
+
'Σ': 'SUM', # 汇总
|
|
41
|
+
'✓': 'SUCCESS',
|
|
42
|
+
'✗': 'FAIL',
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
def parse(self, raw: str) -> ALMessage:
|
|
46
|
+
"""
|
|
47
|
+
解析A-Language消息
|
|
48
|
+
格式: ⟨OP⟩[PRIORITY]⟨META⟩⟨PAYLOAD⟩⟨CHECK⟩
|
|
49
|
+
"""
|
|
50
|
+
raw = raw.strip()
|
|
51
|
+
|
|
52
|
+
# 解析消息类型
|
|
53
|
+
type_match = re.search(r'⟨([CQRNTE])', raw)
|
|
54
|
+
msg_type = MessageType[type_match.group(1)] if type_match else MessageType.N
|
|
55
|
+
|
|
56
|
+
# 解析优先级
|
|
57
|
+
priority_match = re.search(r'\[(\d)\]', raw)
|
|
58
|
+
priority = int(priority_match.group(1)) if priority_match else 5
|
|
59
|
+
|
|
60
|
+
# 提取元数据
|
|
61
|
+
meta_match = re.search(r'⟨([^⟩]+)⟩', raw)
|
|
62
|
+
meta = self._parse_meta(meta_match.group(1)) if meta_match else {}
|
|
63
|
+
|
|
64
|
+
# 提取载荷
|
|
65
|
+
payload_match = re.search(r'⟨[^⟩]*⟩(.+?)(?:⟨|$)', raw)
|
|
66
|
+
payload = payload_match.group(1) if payload_match else ''
|
|
67
|
+
|
|
68
|
+
return ALMessage(
|
|
69
|
+
type=msg_type,
|
|
70
|
+
priority=priority,
|
|
71
|
+
meta=meta,
|
|
72
|
+
payload=payload,
|
|
73
|
+
raw=raw
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
def _parse_meta(self, meta_str: str) -> dict:
|
|
77
|
+
"""解析元数据区域"""
|
|
78
|
+
meta = {}
|
|
79
|
+
for k, v in re.findall(r'(\w+)\|(\w+)', meta_str):
|
|
80
|
+
meta[k] = v
|
|
81
|
+
return meta
|
|
82
|
+
|
|
83
|
+
def to_human(self, raw: str) -> str:
|
|
84
|
+
"""将A-Language转为人类可读描述"""
|
|
85
|
+
msg = self.parse(raw)
|
|
86
|
+
parts = [
|
|
87
|
+
f"类型: {msg.type.value}",
|
|
88
|
+
f"优先级: {msg.priority}",
|
|
89
|
+
f"元数据: {msg.meta}",
|
|
90
|
+
f"载荷: {msg.payload}",
|
|
91
|
+
]
|
|
92
|
+
return " | ".join(parts)
|
|
93
|
+
|
|
94
|
+
if __name__ == "__main__":
|
|
95
|
+
parser = ALanguageParser()
|
|
96
|
+
|
|
97
|
+
# 测试
|
|
98
|
+
test_cases = [
|
|
99
|
+
"C[7]⟨Ξ|Φ⟩⊕Σ[3]",
|
|
100
|
+
"Q[5]⟨Ψ⟩",
|
|
101
|
+
"N[9]⟨Ω|Δ⟩",
|
|
102
|
+
]
|
|
103
|
+
|
|
104
|
+
for test in test_cases:
|
|
105
|
+
print(f"原始: {test}")
|
|
106
|
+
print(f"解析: {parser.to_human(test)}")
|
|
107
|
+
print()
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "a-language"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "A-Language: AI间私密通信协议的解析器"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
authors = [
|
|
12
|
+
{name = "番茄 (ruihuowayking)", email = "ruihuowayking@users.noreply.github.com"}
|
|
13
|
+
]
|
|
14
|
+
keywords = ["ai", "communication", "protocol", "privacy", "parser"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"License :: OSI Approved :: MIT License",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.8",
|
|
21
|
+
"Programming Language :: Python :: 3.9",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
]
|
|
26
|
+
requires-python = ">=3.8"
|
|
27
|
+
|
|
28
|
+
[project.urls]
|
|
29
|
+
Homepage = "https://github.com/ruihuowayking/A-Language"
|
|
30
|
+
Documentation = "https://github.com/ruihuowayking/A-Language#readme"
|
|
31
|
+
Repository = "https://github.com/ruihuowayking/A-Language"
|
|
32
|
+
Issues = "https://github.com/ruihuowayking/A-Language/issues"
|
|
33
|
+
|
|
34
|
+
[tool.setuptools]
|
|
35
|
+
py-modules = ["parser"]
|