MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / direction_remove

Function direction_remove

scripts/drift_engine.py:1124–1175  ·  view source on GitHub ↗

绉婚櫎鏃ф柟鍚戯細绉婚櫎鏉冮噸浣庝簬闃堝€肩殑琛伴€€鏍稿績鏂瑰悜

(
    profile: Dict[str, Any],
    params: Dict[str, Any],
    selected_papers: Optional[List[Dict]] = None,
    date: Optional[str] = None,
)

Source from the content-addressed store, hash-verified

1122
1123def direction_remove(
1124 profile: Dict[str, Any],
1125 params: Dict[str, Any],
1126 selected_papers: Optional[List[Dict]] = None,
1127 date: Optional[str] = None,
1128) -> Tuple[Dict[str, Any], Dict[str, Any]]:
1129 """
1130 绉婚櫎鏃ф柟鍚戯細绉婚櫎鏉冮噸浣庝簬闃堝€肩殑琛伴€€鏍稿績鏂瑰悜
1131 """
1132 updated = copy.deepcopy(profile)
1133 core_directions = updated.get("core_directions", {})
1134
1135 weight_threshold = params.get("weight_threshold", 0.3)
1136 max_remove_count = params.get("max_remove_count", 2)
1137
1138 old_directions = list(core_directions.keys())
1139
1140 # 鎵惧嚭鏉冮噸浣庝簬闃堝€肩殑鏂瑰悜
1141 low_weight_directions = [
1142 (k, v) for k, v in core_directions.items() if v < weight_threshold
1143 ]
1144
1145 # 鎸夋潈閲嶆帓搴忥紝绉婚櫎鏈€浣庣殑
1146 low_weight_directions.sort(key=lambda x: x[1])
1147 to_remove = [k for k, v in low_weight_directions[:max_remove_count]]
1148
1149 # 绉婚櫎鏂瑰悜
1150 for direction in to_remove:
1151 del core_directions[direction]
1152
1153 # 褰掍竴鍖?
1154 if params.get("renormalize", True) and core_directions:
1155 max_score = max(core_directions.values())
1156 if max_score > 0:
1157 for k in core_directions:
1158 core_directions[k] = min(1.0, core_directions[k] / max_score)
1159
1160 updated["core_directions"] = core_directions
1161 updated["topic_weights"] = copy.deepcopy(core_directions)
1162
1163 # 鏇存柊 drift_state
1164 updated["drift_state"] = _update_drift_state(profile, date, score_delta=0.2)
1165
1166 drift_event = {
1167 "method": "direction_remove",
1168 "directions_before": old_directions,
1169 "directions_removed": to_remove,
1170 "directions_after": list(core_directions.keys()),
1171 "reason": f"weight < {weight_threshold}",
1172 }
1173
1174 return updated, drift_event
1175
1176
1177# ==================== 杈呭姪鍑芥暟 ====================
1178

Callers

nothing calls this directly

Calls 2

_update_drift_stateFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected