Download tests/test_02_ums.py from recommender-system/llmproccrs: direct link, hf CLI and curl.
- Browser
- Download file 2.3 kB
-
https://huggingface.co/recommender-system/llmproccrs/resolve/main/tests/test_02_ums.py
- Command line
-
hf download hf://recommender-system/llmproccrs/tests/test_02_ums.py
-
curl -L -o test_02_ums.py https://huggingface.co/recommender-system/llmproccrs/resolve/main/tests/test_02_ums.py
2.3 kB
| import sys | |
| import os | |
| import json | |
| # Fix import path | |
| sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) | |
| from modules.user_modeling.extractor import EntityExtractor | |
| from modules.user_modeling.query_relaxer import QueryRelaxer | |
| def test_ums(): | |
| print("\n" + "="*40) | |
| print("🧪 TESTING MODULE: USER MODELING (UMS)") | |
| print("="*40) | |
| # 1. Initialize | |
| try: | |
| extractor = EntityExtractor() | |
| relaxer = QueryRelaxer() | |
| print("✅ Initialization Success") | |
| except Exception as e: | |
| print(f"❌ Init Failed: {e}") | |
| return | |
| # Mock State Awal | |
| state = { | |
| "user_text": "", | |
| "collected_constraints": {}, # Memory kosong | |
| "entities": [], | |
| "relaxed_query": "" | |
| } | |
| # --- SKENARIO 1: Input Pertama --- | |
| print("\n--- [Scenario 1] User: 'Cari laptop gaming asus' ---") | |
| state["user_text"] = "Cari laptop gaming asus" | |
| state = extractor.run(state) | |
| # Validasi | |
| c = state["collected_constraints"] | |
| if "asus" in str(c).lower() and "laptop" in str(c).lower(): | |
| print("✅ Extraction OK") | |
| else: | |
| print("❌ Extraction Failed") | |
| print(f"Result: {c}") | |
| # --- SKENARIO 2: Input Kedua (Adding Context) --- | |
| print("\n--- [Scenario 2] User: 'Yang harganya 15 jutaan di Jakarta' ---") | |
| state["user_text"] = "Yang harganya 15 jutaan di Jakarta" | |
| state = extractor.run(state) | |
| # Validasi Merging (Harus ada laptop, asus, 15jt, jakarta) | |
| c = state["collected_constraints"] | |
| print(f"Merged Context: {json.dumps(c, indent=2)}") | |
| expected_keys = ["product", "brand", "price", "location"] | |
| # Cek apakah key yang diharapkan ada isinya | |
| matches = sum(1 for k in expected_keys if c.get(k)) | |
| if matches >= 3: # Minimal 3 info tertangkap | |
| print("✅ Merging Context OK") | |
| else: | |
| print("❌ Merging Context Failed") | |
| # --- SKENARIO 3: Query Relaxation --- | |
| print("\n--- [Scenario 3] Generating Semantic Query ---") | |
| state = relaxer.run(state) | |
| print(f"Final Query: {state['relaxed_query']}") | |
| if len(state['relaxed_query']) > 10: | |
| print("✅ Query Relaxation OK") | |
| else: | |
| print("❌ Query Relaxation Failed (Too short)") | |
| if __name__ == "__main__": | |
| test_ums() |