P-028 Mitigation: split keyword matching — match_keyword_exact for kw100, match_keyword for kwctx
TEIL 1 — booster.py: - Split _keyword_to_rooms into _kw100_to_rooms + _kwctx_to_rooms - keywords_100 matched via match_keyword_exact (no fuzzy/stemming, hyphen-insensitive) - keywords_context matched via match_keyword (fuzzy/stemming preserved) - _build_mapping() builds both mappings separately - boost() uses separate matchers per keyword type - _count_unique_matches() checks both mappings with respective matchers - _record_matches() now takes only matched_kw100 (context keywords never tracked) - cleanup_orphaned_rooms() rebuilds both mappings TEIL 2 — room-map.json (data, not in git): - Removed 39 space-variant dual keywords (e.g. 'presence engine' removed, 'presence-engine' kept). No longer needed since match_keyword_exact is hyphen-insensitive. - Backup: .bak-pre-curation-20260805 Tests: 35/35 passed (pytest -k booster)
This commit is contained in:
+15
-13
@@ -553,7 +553,7 @@ class TestBoosterCleanup:
|
||||
|
||||
def test_cleanup_rebuilds_mapping(self, booster: KeywordBooster) -> None:
|
||||
"""cleanup_orphaned_rooms() baut das Mapping aus der aktuellen RoomMap neu."""
|
||||
before = len(booster._keyword_to_rooms)
|
||||
before = len(booster._kw100_to_rooms) + len(booster._kwctx_to_rooms)
|
||||
|
||||
# Entferne room_b aus der RoomMap (simuliert GC)
|
||||
del booster._room_map._rooms["room_b"]
|
||||
@@ -564,16 +564,17 @@ class TestBoosterCleanup:
|
||||
# Mapping sollte kleiner sein (room_b's unique keywords sind weg)
|
||||
assert after < before
|
||||
|
||||
# "bat" war unique für room_b → sollte nicht mehr im Mapping sein
|
||||
assert "bat" not in booster._keyword_to_rooms
|
||||
# "bat" war unique für room_b (kw100) → sollte nicht mehr im Mapping sein
|
||||
assert "bat" not in booster._kw100_to_rooms
|
||||
assert "bat" not in booster._kwctx_to_rooms
|
||||
|
||||
# "plugin" war unique für room_a → sollte noch da sein
|
||||
assert "plugin" in booster._keyword_to_rooms
|
||||
assert booster._keyword_to_rooms["plugin"] == {"room_a"}
|
||||
# "plugin" war unique für room_a (kwctx) → sollte noch da sein
|
||||
assert "plugin" in booster._kwctx_to_rooms
|
||||
assert booster._kwctx_to_rooms["plugin"] == {"room_a"}
|
||||
|
||||
def test_cleanup_no_orphans_returns_same_count(self, booster: KeywordBooster) -> None:
|
||||
"""Keine orphaned Räume → Mapping bleibt gleich groß."""
|
||||
before = len(booster._keyword_to_rooms)
|
||||
before = len(booster._kw100_to_rooms) + len(booster._kwctx_to_rooms)
|
||||
after = booster.cleanup_orphaned_rooms({"room_a", "room_b", "room_catchall"})
|
||||
assert after == before
|
||||
|
||||
@@ -585,7 +586,8 @@ class TestBoosterCleanup:
|
||||
# room_catchall bleibt (catch_all=True, wird von _build_mapping ignoriert)
|
||||
after = booster.cleanup_orphaned_rooms({"room_catchall"})
|
||||
assert after == 0
|
||||
assert len(booster._keyword_to_rooms) == 0
|
||||
assert len(booster._kw100_to_rooms) == 0
|
||||
assert len(booster._kwctx_to_rooms) == 0
|
||||
|
||||
def test_cleanup_then_boost_still_works(self, booster: KeywordBooster) -> None:
|
||||
"""Nach Cleanup: Boost funktioniert korrekt mit bereinigtem Mapping."""
|
||||
@@ -683,8 +685,8 @@ class TestV82A3BoosterDemotion:
|
||||
old_date = (datetime.now() - timedelta(days=91)).isoformat()
|
||||
booster._room_map.set_keyword_last_matched("room_a", "rocketchat", old_date)
|
||||
|
||||
# Vorher: "rocketchat" ist im Mapping
|
||||
assert "rocketchat" in booster._keyword_to_rooms
|
||||
# Vorher: "rocketchat" ist im kw100-Mapping
|
||||
assert "rocketchat" in booster._kw100_to_rooms
|
||||
|
||||
demoted = booster.demote_stale_keywords(max_age_days=90)
|
||||
assert demoted >= 1
|
||||
@@ -695,7 +697,7 @@ class TestV82A3BoosterDemotion:
|
||||
assert "rocketchat" in entry.keywords_context
|
||||
|
||||
# Mapping wurde neu gebaut → "rocketchat" ist jetzt als context-Keyword im Mapping
|
||||
assert "rocketchat" in booster._keyword_to_rooms
|
||||
assert "rocketchat" in booster._kwctx_to_rooms
|
||||
|
||||
def test_demote_no_stale_returns_zero(self, booster: KeywordBooster) -> None:
|
||||
"""Keine stale Keywords → demote_stale_keywords() gibt 0 zurück."""
|
||||
@@ -715,8 +717,8 @@ class TestV82A3BoosterDemotion:
|
||||
assert demoted == 2
|
||||
|
||||
# Beide Keywords sind jetzt im Mapping (als context)
|
||||
assert "rocketchat" in booster._keyword_to_rooms
|
||||
assert "ddp" in booster._keyword_to_rooms
|
||||
assert "rocketchat" in booster._kwctx_to_rooms
|
||||
assert "ddp" in booster._kwctx_to_rooms
|
||||
|
||||
def test_demote_then_boost_still_works(self, booster: KeywordBooster) -> None:
|
||||
"""Nach Demotion: boost() funktioniert korrekt mit neuem Mapping."""
|
||||
|
||||
Reference in New Issue
Block a user