39 lines
1008 B
Python
39 lines
1008 B
Python
"""
|
|
FILE: app/core/graph/graph_weights.py
|
|
DESCRIPTION: Definition der Basisgewichte und Berechnung der Kanteneffektivität.
|
|
"""
|
|
from typing import Dict
|
|
|
|
# Basisgewichte je Edge-Typ (WP-04a Config)
|
|
EDGE_BASE_WEIGHTS: Dict[str, float] = {
|
|
# Struktur
|
|
"belongs_to": 0.10,
|
|
"next": 0.06,
|
|
"prev": 0.06,
|
|
"backlink": 0.04,
|
|
"references_at": 0.08,
|
|
|
|
# Wissen
|
|
"references": 0.20,
|
|
"depends_on": 0.18,
|
|
"related_to": 0.15,
|
|
"similar_to": 0.12,
|
|
}
|
|
|
|
def calculate_edge_weight(pl: Dict) -> float:
|
|
"""Berechnet das effektive Edge-Gewicht aus kind + confidence."""
|
|
kind = pl.get("kind", "edge")
|
|
base = EDGE_BASE_WEIGHTS.get(kind, 0.0)
|
|
|
|
conf_raw = pl.get("confidence", None)
|
|
try:
|
|
conf = float(conf_raw) if conf_raw is not None else None
|
|
except Exception:
|
|
conf = None
|
|
|
|
if conf is None:
|
|
return base
|
|
|
|
# Clamp confidence 0.0 - 1.0
|
|
conf = max(0.0, min(1.0, conf))
|
|
return base * conf |