def score_word(word): """ Simple heuristic scoring: - longer words slightly more important - punctuation emphasis """ score = len(word["text"]) * 0.1 if any(p in word["text"] for p in ["!", "?", "."]): score += 1 return score def detect_highlights(words, threshold=0.8): """ Groups words into highlight segments """ highlights = [] buffer = [] for w in words: if score_word(w) > threshold: buffer.append(w) else: if buffer: highlights.append(buffer) buffer = [] if buffer: highlights.append(buffer) return highlights