feat(export): 恢复旧导出引擎并加固换行与舍入、新增采纳来源溯源与项目目录排序
This commit is contained in:
@@ -674,3 +674,69 @@ def stats(con):
|
||||
return [dict(r) for r in con.execute(
|
||||
"SELECT suffix,original_name,n_shapes,n_nodes,extracted_at FROM classic_skel "
|
||||
"ORDER BY suffix, n_nodes DESC")]
|
||||
|
||||
|
||||
# ---------------- 形态银行(决策 274 补,2026-11-05 主人定)----------------
|
||||
# 「先盘查同后缀的大骨架的卡槽相似度,主要以卡槽为准」——本项目源件分层列集 vs
|
||||
# 候选件(同后缀的历史项目源件含最近审核项目+后台骨架库件)分层列集逐件打分,
|
||||
# 得分最多的件被采用,从它身上提取局部小骨架(行/块形态)。借形态不借条数:
|
||||
# 形态只当自增样板,输出条数按库数据走(266 自增口径);值一律来自库(259 不造数据)。
|
||||
|
||||
_FORM_TAGS = ("Norm", "LabourMaterialsEquipmentsMachinesElement", "NormAdjustmentList",
|
||||
"UnitPriceCalculationOfItem", "LabourMaterialsEquipmentsMachinesSummary")
|
||||
|
||||
|
||||
def _local_forms(blob, tags=None):
|
||||
"""一份同后缀原格式件 → 关键 tag 的最全局部形态 {tag: 串}。
|
||||
行=属性最多的自闭合行(Express 槽优先);Norm=属性最多+最长的完整块。
|
||||
认不出/没有该 tag → 该键缺席(fail-open=现状硬编码最小形态)。"""
|
||||
tags = list(tags or _FORM_TAGS)
|
||||
text = None
|
||||
try:
|
||||
z = zipfile.ZipFile(io.BytesIO(bytes(blob)))
|
||||
cands = [n for n in z.namelist()
|
||||
if n.lower() != "project.xml" and n.lower().endswith(".xml")]
|
||||
scored = []
|
||||
for n in cands:
|
||||
t = z.read(n).decode("utf-8", "replace")
|
||||
scored.append((t.count("<Norm"), len(t), t))
|
||||
if scored:
|
||||
text = max(scored)[2]
|
||||
except Exception:
|
||||
text = None
|
||||
if text is None:
|
||||
text = bytes(blob).decode("utf-8", "replace") # 裸 XML 族整件就是骨架
|
||||
out = {}
|
||||
for tag in tags:
|
||||
if tag == "Norm":
|
||||
blocks = re.findall(r'<Norm\b[^>]*?>.*?</Norm>', text, re.S)
|
||||
if not blocks:
|
||||
blocks = re.findall(r'<Norm\b[^>]*?/>', text)
|
||||
if blocks:
|
||||
out[tag] = max(blocks, key=lambda b: (len(re.findall(r'[A-Za-z]+="', b)), len(b)))
|
||||
continue
|
||||
rows = re.findall('<' + tag + r'\b[^>]*?/>', text)
|
||||
if not rows:
|
||||
m = re.search(r'<' + tag + r'\b[^>]*?>.*?</' + tag + '>', text, re.S)
|
||||
rows = [m.group(0)] if m else []
|
||||
if rows:
|
||||
out[tag] = max(rows, key=lambda r: (len(re.findall(r'[A-Za-z]+="', r)),
|
||||
' Express="' in r, len(r)))
|
||||
return out
|
||||
|
||||
|
||||
def local_form_bank(src_cols, candidates, tags=None):
|
||||
"""形态银行挑选:candidates=[(名, blob字节)](调用方保证**同后缀**),
|
||||
逐件 match_score(卡槽相似度)盘查,得分最多的件 → 它的局部小骨架。
|
||||
src_cols=本项目源件分层列集(layer_cols_of);无候选/全零分 → {}。"""
|
||||
best, best_s = None, -1.0
|
||||
for nm, blob in candidates or []:
|
||||
try:
|
||||
s = match_score(src_cols or {}, layer_cols_of(blob))
|
||||
except Exception:
|
||||
s = -1.0
|
||||
if s > best_s:
|
||||
best, best_s = blob, s
|
||||
if best is None or best_s <= 0:
|
||||
return {}
|
||||
return _local_forms(best, tags)
|
||||
|
||||
Reference in New Issue
Block a user