改进
This commit is contained in:
@@ -52,4 +52,4 @@ class Atom():
|
||||
|
||||
@staticmethod
|
||||
def placeholder():
|
||||
return (Electron.placeholder(), Nucleon.placeholder(), {})
|
||||
return (Electron.placeholder(), Nucleon.placeholder(), {})
|
@@ -5,7 +5,7 @@ import pathlib
|
||||
import toml
|
||||
import json
|
||||
|
||||
def loader_nucleon(path: pathlib.Path, fmt = "toml"):
|
||||
def load_nucleon(path: pathlib.Path, fmt = "toml"):
|
||||
with open(path, "r") as f:
|
||||
dictdata = dict()
|
||||
toml.load(f, dictdata) # type: ignore
|
||||
@@ -13,4 +13,14 @@ def loader_nucleon(path: pathlib.Path, fmt = "toml"):
|
||||
for item, attr in dictdata.items():
|
||||
if item == "__metadata__":
|
||||
continue
|
||||
lst.append(Nucleon(hasher.hash(item), attr))
|
||||
lst.append((Nucleon(hasher.hash(item), attr), dictdata["__metadata__"]["orbital"]))
|
||||
return lst
|
||||
|
||||
def load_electron(path: pathlib.Path, fmt = "json"):
|
||||
with open(path, "r") as f:
|
||||
dictdata = dict()
|
||||
json.load(f, dictdata) # type: ignore
|
||||
lst = list()
|
||||
for item, attr in dictdata.items():
|
||||
lst.append(Electron(hasher.hash(item), attr))
|
||||
return lst
|
@@ -1,29 +1,29 @@
|
||||
class Nucleon:
|
||||
"""原子核: 材料元数据"""
|
||||
|
||||
def __init__(self, ident: str, metadata: dict):
|
||||
def __init__(self, ident: str, payload: dict):
|
||||
"""初始化原子核 (记忆内容)
|
||||
|
||||
Args:
|
||||
ident: 唯一标识符
|
||||
metadata: 记忆内容信息
|
||||
payload: 记忆内容信息
|
||||
"""
|
||||
self.metadata = metadata
|
||||
self.payload = payload
|
||||
self.ident = ident
|
||||
|
||||
def __getitem__(self, key):
|
||||
if key == "ident":
|
||||
return self.ident
|
||||
if key in self.metadata:
|
||||
return self.metadata[key]
|
||||
if key in self.payload:
|
||||
return self.payload[key]
|
||||
else:
|
||||
raise KeyError(f"Key '{key}' not found in metadata.")
|
||||
raise KeyError(f"Key '{key}' not found in payload.")
|
||||
|
||||
def __iter__(self):
|
||||
yield from self.metadata.keys()
|
||||
yield from self.payload.keys()
|
||||
|
||||
def __len__(self):
|
||||
return len(self.metadata)
|
||||
return len(self.payload)
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.ident)
|
||||
|
Reference in New Issue
Block a user