fix: 改进代码
This commit is contained in:
@@ -1,11 +1,7 @@
|
||||
from heurams.services.logger import get_logger
|
||||
|
||||
from .base import BaseAlgorithm
|
||||
from .sm2 import SM2Algorithm
|
||||
from .sm15m import SM15MAlgorithm
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
__all__ = [
|
||||
"SM2Algorithm",
|
||||
"BaseAlgorithm",
|
||||
@@ -17,5 +13,3 @@ algorithms = {
|
||||
"SM-15M": SM15MAlgorithm,
|
||||
"Base": BaseAlgorithm,
|
||||
}
|
||||
|
||||
logger.debug("算法模块初始化完成, 注册的算法: %s", list(algorithms.keys()))
|
||||
|
||||
@@ -6,8 +6,6 @@ Evaluator 模块 - 生成评估模块
|
||||
|
||||
from heurams.services.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
from .base import BaseEvaluator
|
||||
from .cloze import ClozePuzzle
|
||||
from .mcq import MCQPuzzle
|
||||
@@ -26,38 +24,3 @@ puzzles = {
|
||||
"recognition": RecognitionPuzzle,
|
||||
"base": BaseEvaluator,
|
||||
}
|
||||
|
||||
|
||||
@staticmethod
|
||||
def create_by_dict(config_dict: dict) -> BaseEvaluator:
|
||||
"""
|
||||
根据配置字典创建谜题
|
||||
|
||||
Args:
|
||||
config_dict: 配置字典, 包含谜题类型和参数
|
||||
|
||||
Returns:
|
||||
BasePuzzle: 谜题实例
|
||||
|
||||
Raises:
|
||||
ValueError: 当配置无效时抛出
|
||||
"""
|
||||
logger.debug(
|
||||
"puzzles.create_by_dict: config_dict keys=%s", list(config_dict.keys())
|
||||
)
|
||||
puzzle_type = config_dict.get("type")
|
||||
|
||||
if puzzle_type == "cloze":
|
||||
return puzzles["cloze"](
|
||||
text=config_dict["text"],
|
||||
min_denominator=config_dict.get("min_denominator", 7),
|
||||
)
|
||||
elif puzzle_type == "mcq":
|
||||
return puzzles["mcq"](
|
||||
mapping=config_dict["mapping"],
|
||||
jammer=config_dict.get("jammer", []),
|
||||
max_riddles_num=config_dict.get("max_riddles_num", 2),
|
||||
prefix=config_dict.get("prefix", ""),
|
||||
)
|
||||
else:
|
||||
raise ValueError(f"未知的谜题类型: {puzzle_type}")
|
||||
|
||||
@@ -1,4 +1,21 @@
|
||||
from .atom import Atom
|
||||
from .electron import Electron
|
||||
from .nucleon import Nucleon
|
||||
#from .orbital import Orbital
|
||||
from .placeholders import (
|
||||
AtomPlaceholder,
|
||||
NucleonPlaceholder,
|
||||
ElectronPlaceholder,
|
||||
orbital_placeholder,
|
||||
)
|
||||
|
||||
# from .orbital import Orbital
|
||||
|
||||
__all__ = [
|
||||
"Atom",
|
||||
"Electron",
|
||||
"Nucleon",
|
||||
"AtomPlaceholder",
|
||||
"NucleonPlaceholder",
|
||||
"ElectronPlaceholder",
|
||||
"orbital_placeholder",
|
||||
]
|
||||
|
||||
@@ -13,9 +13,11 @@ class Nucleon:
|
||||
|
||||
def __init__(self, ident, payload, common):
|
||||
self.ident = ident
|
||||
env = {"payload": payload,
|
||||
"default": config_var.get()['puzzles'],
|
||||
"nucleon": (payload | common)}
|
||||
env = {
|
||||
"payload": payload,
|
||||
"default": config_var.get()["puzzles"],
|
||||
"nucleon": (payload | common),
|
||||
}
|
||||
self.evalizer = Evalizer(environment=env)
|
||||
self.data: dict = self.evalizer(deepcopy((payload | common))) # type: ignore
|
||||
|
||||
|
||||
@@ -5,8 +5,4 @@ from .phaser import Phaser
|
||||
from .procession import Procession
|
||||
from .states import PhaserState, ProcessionState
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
__all__ = ["PhaserState", "ProcessionState", "Procession", "Fission", "Phaser"]
|
||||
|
||||
logger.debug("反应堆模块已加载")
|
||||
|
||||
@@ -20,7 +20,7 @@ class Fission:
|
||||
phase_state.value if isinstance(phase_state, PhaserState) else phase_state
|
||||
)
|
||||
|
||||
self.orbital_schedule = atom.registry['orbital']["phases"][phase_value] # type: ignore
|
||||
self.orbital_schedule = atom.registry["orbital"]["phases"][phase_value] # type: ignore
|
||||
self.orbital_puzzles = atom.registry["nucleon"]["puzzles"]
|
||||
|
||||
self.puzzles = list()
|
||||
@@ -34,7 +34,6 @@ class Fission:
|
||||
{
|
||||
"puzzle": puz.puzzles[self.orbital_puzzles[item]["__origin__"]],
|
||||
"alia": item,
|
||||
"finished": 0,
|
||||
}
|
||||
)
|
||||
possibility -= 1
|
||||
@@ -44,7 +43,6 @@ class Fission:
|
||||
{
|
||||
"puzzle": puz.puzzles[self.orbital_puzzles[item]["__origin__"]],
|
||||
"alia": item,
|
||||
"finished": 0,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -53,7 +51,7 @@ class Fission:
|
||||
def get_puzzles(self):
|
||||
return self.puzzles
|
||||
|
||||
def get_current_puzzle(self, forward = 0):
|
||||
def get_current_puzzle(self, forward=0):
|
||||
if forward:
|
||||
if len(self.puzzles) <= self.cursor + 1:
|
||||
return 0
|
||||
@@ -61,10 +59,9 @@ class Fission:
|
||||
return self.puzzles[self.cursor]
|
||||
else:
|
||||
return self.puzzles[self.cursor]
|
||||
|
||||
|
||||
def check_passed(self):
|
||||
for i in self.puzzles:
|
||||
if i["finished"] == 0:
|
||||
return 0
|
||||
return 1
|
||||
return 1
|
||||
|
||||
@@ -130,12 +130,13 @@ class Phaser(Machine):
|
||||
def __repr__(self):
|
||||
from heurams.services.textproc import truncate
|
||||
from tabulate import tabulate as tabu
|
||||
|
||||
lst = [
|
||||
{
|
||||
"Type": "Phaser",
|
||||
"State": self.state,
|
||||
"Processions": list(map(lambda f: (f.name_), self.processions)),
|
||||
"Current Procession": "None" if not self.current_procession() else self.current_procession().name_, # type: ignore
|
||||
"Current Procession": "None" if not self.current_procession() else self.current_procession().name_, # type: ignore
|
||||
},
|
||||
]
|
||||
return str(tabu(lst, headers="keys")) + '\n'
|
||||
return str(tabu(lst, headers="keys")) + "\n"
|
||||
|
||||
@@ -63,8 +63,7 @@ class Procession(Machine):
|
||||
logger.debug("Procession 进入 FINISHED 状态")
|
||||
|
||||
def forward(self, step=1):
|
||||
"""将记忆原子指针向前移动并依情况更新原子(返回 1)或完成队列(返回 0)
|
||||
"""
|
||||
"""将记忆原子指针向前移动并依情况更新原子(返回 1)或完成队列(返回 0)"""
|
||||
logger.debug("Procession.forward: step=%d, 当前 cursor=%d", step, self.cursor)
|
||||
self.cursor += step
|
||||
if self.cursor >= len(self.queue):
|
||||
@@ -84,8 +83,7 @@ class Procession(Machine):
|
||||
return 0
|
||||
|
||||
def append(self, atom=None):
|
||||
"""追加(回忆失败的)原子(默认为当前原子)到队列末端
|
||||
"""
|
||||
"""追加(回忆失败的)原子(默认为当前原子)到队列末端"""
|
||||
if atom is None:
|
||||
atom = self.current_atom
|
||||
logger.debug("Procession.append: atom=%s", atom.ident if atom else "None")
|
||||
@@ -118,10 +116,11 @@ class Procession(Machine):
|
||||
return empty
|
||||
|
||||
def get_fission(self):
|
||||
return Fission(atom=self.current_atom, phase_state=self.phase) # type: ignore
|
||||
return Fission(atom=self.current_atom, phase_state=self.phase) # type: ignore
|
||||
|
||||
def __repr__(self):
|
||||
from heurams.services.textproc import truncate
|
||||
|
||||
dic = [
|
||||
{
|
||||
"Type": "Procession",
|
||||
@@ -129,7 +128,7 @@ class Procession(Machine):
|
||||
"State": self.state,
|
||||
"Progress": f"{self.cursor + 1} / {len(self.queue)}",
|
||||
"Queue": list(map(lambda f: truncate(f.ident), self.queue)),
|
||||
"Current Atom": self.current_atom.ident, # type: ignore
|
||||
"Current Atom": self.current_atom.ident, # type: ignore
|
||||
}
|
||||
]
|
||||
return str(tabu(dic, headers="keys")) + '\n'
|
||||
return str(tabu(dic, headers="keys")) + "\n"
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
from .repo import *
|
||||
from .repo import Repo, RepoManifest
|
||||
|
||||
__all__ = ["Repo", "RepoManifest"]
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
from ...utils.lict import Lict
|
||||
|
||||
|
||||
def merge(x: Lict, y: Lict):
|
||||
return Lict(list(x.values()) + list(y.values()))
|
||||
Reference in New Issue
Block a user