(parsed_pdf: Optional[Dict[str, Any]])
| 3212 | |
| 3213 | def _build_pdf_chunks(parsed_pdf: Optional[Dict[str, Any]]) -> List[Dict[str, Any]]: |
| 3214 | if not isinstance(parsed_pdf, dict): |
| 3215 | return [] |
| 3216 | |
| 3217 | chunks: List[Dict[str, Any]] = [] |
| 3218 | abstract = _clean_text(parsed_pdf.get("abstract")) |
| 3219 | if abstract: |
| 3220 | chunks.extend(_chunk_text_with_overlap(abstract, "abstract")) |
| 3221 | |
| 3222 | sections = parsed_pdf.get("sections") or {} |
| 3223 | if isinstance(sections, dict): |
| 3224 | preferred_order = [ |
| 3225 | "introduction", |
| 3226 | "background", |
| 3227 | "method", |
| 3228 | "approach", |
| 3229 | "model", |
| 3230 | "results", |
| 3231 | "experiments", |
| 3232 | "evaluation", |
| 3233 | "discussion", |
| 3234 | "limitations", |
| 3235 | "conclusion", |
| 3236 | ] |
| 3237 | ordered_keys = preferred_order + [key for key in sections.keys() if key not in preferred_order] |
| 3238 | for section_name in ordered_keys: |
| 3239 | section_text = _clean_text(sections.get(section_name)) |
| 3240 | if section_text: |
| 3241 | chunks.extend(_chunk_text_with_overlap(section_text, section_name)) |
| 3242 | |
| 3243 | if not chunks: |
| 3244 | full_text = _clean_text(parsed_pdf.get("full_text")) |
| 3245 | if full_text: |
| 3246 | chunks.extend(_chunk_text_with_overlap(full_text, "full_text")) |
| 3247 | |
| 3248 | deduped: List[Dict[str, Any]] = [] |
| 3249 | seen_texts = set() |
| 3250 | for chunk in chunks: |
| 3251 | key = chunk["text"].casefold() |
| 3252 | if key in seen_texts: |
| 3253 | continue |
| 3254 | seen_texts.add(key) |
| 3255 | deduped.append(chunk) |
| 3256 | return deduped |
| 3257 | |
| 3258 | |
| 3259 | def _collect_evidence_sentences( |
| 3260 | evidence: Dict[str, Any], |
no test coverage detected