(user_profile: Optional[Dict[str, Any]])
| 2300 | |
| 2301 | def _daily_note_profile_terms(user_profile: Optional[Dict[str, Any]]) -> List[str]: |
| 2302 | profile = user_profile if isinstance(user_profile, dict) else {} |
| 2303 | terms: List[str] = [] |
| 2304 | |
| 2305 | def add_term(value: Any) -> None: |
| 2306 | text = _clean_text(value) |
| 2307 | if not text: |
| 2308 | return |
| 2309 | text = re.sub(r"^(preference|prefer|methodology)[_-]+", "", text, flags=re.IGNORECASE) |
| 2310 | text = text.replace("_", " ").strip() |
| 2311 | if len(text) >= 2 and text.lower() not in {term.lower() for term in terms}: |
| 2312 | terms.append(text) |
| 2313 | |
| 2314 | def add_weighted_keys(mapping: Any) -> None: |
| 2315 | if not isinstance(mapping, dict): |
| 2316 | return |
| 2317 | weighted = [] |
| 2318 | for key, value in mapping.items(): |
| 2319 | try: |
| 2320 | weight = float(value) |
| 2321 | except (TypeError, ValueError): |
| 2322 | weight = 0.0 |
| 2323 | weighted.append((str(key), weight)) |
| 2324 | for key, _weight in sorted(weighted, key=lambda item: item[1], reverse=True): |
| 2325 | add_term(key) |
| 2326 | |
| 2327 | add_weighted_keys(profile.get("core_directions")) |
| 2328 | add_weighted_keys(profile.get("topic_weights")) |
| 2329 | |
| 2330 | preferences = profile.get("methodology_preferences") or {} |
| 2331 | if isinstance(preferences, dict): |
| 2332 | for key, value in preferences.items(): |
| 2333 | if value: |
| 2334 | add_term(key) |
| 2335 | if isinstance(value, str): |
| 2336 | add_term(value) |
| 2337 | elif isinstance(value, (list, tuple, set)): |
| 2338 | for item in value: |
| 2339 | add_term(item) |
| 2340 | |
| 2341 | must_read = profile.get("must_read") or {} |
| 2342 | if isinstance(must_read, dict): |
| 2343 | for keyword in must_read.get("keywords") or []: |
| 2344 | add_term(keyword) |
| 2345 | |
| 2346 | return terms |
| 2347 | |
| 2348 | |
| 2349 | def _term_matches_daily_note_section(term: str, section_text: str) -> bool: |
| 2350 | normalized_term = _clean_text(term).replace("_", " ").replace("-", " ").lower() |
no test coverage detected