feat: 完善 STEP 一级参数化编辑识别与关系式建模
This commit is contained in:
@@ -38,6 +38,17 @@ USER_PRIORITY_BUCKETS: tuple[tuple[int, str, str], ...] = (
|
||||
(90, "只读/诊断", "暂未稳定归类为可修改特征。"),
|
||||
)
|
||||
|
||||
EXTERNAL_RELATION_SCORE_WEIGHTS: dict[str, int] = {
|
||||
"coaxial": 8,
|
||||
"tangent": 5,
|
||||
"coplanar": 4,
|
||||
"parallel": 3,
|
||||
"perpendicular": 3,
|
||||
"parallel_axis": 3,
|
||||
}
|
||||
EXTERNAL_RELATION_SCORE_LIMIT = 18
|
||||
EXTERNAL_FEATURE_HINT_SCORE_LIMIT = 12
|
||||
|
||||
|
||||
def _text(value: object) -> str:
|
||||
return str(value or "").strip()
|
||||
@@ -50,6 +61,69 @@ def _float_or_none(value: object) -> float | None:
|
||||
return None
|
||||
|
||||
|
||||
def _int_or_zero(value: object) -> int:
|
||||
try:
|
||||
return int(value)
|
||||
except (TypeError, ValueError):
|
||||
return 0
|
||||
|
||||
|
||||
def _text_values(value: object) -> tuple[str, ...]:
|
||||
if value is None or value == "":
|
||||
return ()
|
||||
if isinstance(value, str):
|
||||
return (value.strip(),) if value.strip() else ()
|
||||
if isinstance(value, (list, tuple, set)):
|
||||
return tuple(str(item).strip() for item in value if str(item).strip())
|
||||
return ()
|
||||
|
||||
|
||||
def _relation_types_from_summary(value: object) -> tuple[str, ...]:
|
||||
text = _text(value)
|
||||
if not text:
|
||||
return ()
|
||||
result: list[str] = []
|
||||
for chunk in text.replace(";", ",").split(","):
|
||||
relation_type = chunk.split(":", 1)[0].strip()
|
||||
if relation_type:
|
||||
result.append(relation_type)
|
||||
return tuple(result)
|
||||
|
||||
|
||||
def external_relation_score_bonus(info: Mapping[str, object]) -> int:
|
||||
relation_types = _text_values(info.get("external_recognition_relation_types")) or _text_values(
|
||||
info.get("asitus_geometric_relation_types")
|
||||
)
|
||||
if not relation_types:
|
||||
relation_types = _relation_types_from_summary(
|
||||
info.get("external_recognition_relation_summary")
|
||||
or info.get("asitus_geometric_relation_summary")
|
||||
)
|
||||
relation_count = _int_or_zero(
|
||||
info.get("external_recognition_relation_count")
|
||||
or info.get("asitus_geometric_relation_count")
|
||||
)
|
||||
score = 0
|
||||
for relation_type in relation_types:
|
||||
score += EXTERNAL_RELATION_SCORE_WEIGHTS.get(relation_type, 1)
|
||||
if relation_count and not relation_types:
|
||||
score = min(relation_count * 2, EXTERNAL_RELATION_SCORE_LIMIT)
|
||||
score = max(0, min(score, EXTERNAL_RELATION_SCORE_LIMIT))
|
||||
hint_score = min(_int_or_zero(info.get("analysis_situs_feature_hint_score")), EXTERNAL_FEATURE_HINT_SCORE_LIMIT)
|
||||
return max(0, min(score + hint_score, EXTERNAL_RELATION_SCORE_LIMIT + EXTERNAL_FEATURE_HINT_SCORE_LIMIT))
|
||||
|
||||
|
||||
def _confidence_sort_rank(value: object) -> int:
|
||||
return {
|
||||
"high": 0,
|
||||
"medium": 1,
|
||||
"low": 2,
|
||||
"pending": 3,
|
||||
"unchecked": 3,
|
||||
"none": 4,
|
||||
}.get(_text(value), 5)
|
||||
|
||||
|
||||
def _is_effectively_full_cylinder(info: Mapping[str, object]) -> bool:
|
||||
if bool(info.get("is_full_cylinder")):
|
||||
return True
|
||||
@@ -146,7 +220,7 @@ def feature_recognition_priority_reason(info: Mapping[str, object]) -> str:
|
||||
return reason
|
||||
|
||||
|
||||
def feature_recognition_sort_key(info: Mapping[str, object]) -> tuple[int, int, int, int]:
|
||||
def feature_recognition_sort_key(info: Mapping[str, object]) -> tuple[int, int, int, int, int, int]:
|
||||
status_order = {"ready": 0, "candidate": 0, "caution": 1, "blocked": 2}
|
||||
risk_order = {"low": 0, "medium": 1, "high": 2, "blocked": 3}
|
||||
target_id = info.get("target_id", info.get("face_id", info.get("edge_id", -1)))
|
||||
@@ -158,5 +232,7 @@ def feature_recognition_sort_key(info: Mapping[str, object]) -> tuple[int, int,
|
||||
feature_recognition_priority(info),
|
||||
status_order.get(_text(info.get("status")), 9),
|
||||
risk_order.get(_text(info.get("risk")), 9),
|
||||
_confidence_sort_rank(info.get("confidence") or info.get("recognition_confidence")),
|
||||
-external_relation_score_bonus(info),
|
||||
numeric_target,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user