Spaces:
Runtime error
Runtime error
| """Reference ingest body cleanup — strip photo captions and RICS NOTE blocks.""" | |
| from __future__ import annotations | |
| from backend.core.reference_chunker import ( | |
| _clean_reference_body, | |
| build_reference_chunks, | |
| split_into_section_paragraphs, | |
| ) | |
| def test_clean_reference_body_strips_photos_and_notes() -> None: | |
| raw = ( | |
| "NOTE 2: You will need to submit a Building Regulations application.\n" | |
| "The mortar bedding and pointing to the ridge tiles is deteriorating.\n" | |
| "Photo - 5 Main roof hip pitched style\n" | |
| "Photo - 6 Front roof slope. Note the slipped tiles.\n" | |
| "There is some moss and lichen growth on the roof.\n" | |
| ) | |
| cleaned = _clean_reference_body(raw) | |
| assert "NOTE 2" not in cleaned | |
| assert "Photo -" not in cleaned | |
| assert "mortar bedding" in cleaned | |
| assert "moss and lichen" in cleaned | |
| def test_split_into_section_paragraphs_deduplicates_table_stub() -> None: | |
| text = ( | |
| "D2 Roof coverings\n" | |
| "Element no. Element name\n" | |
| "D2 Roof coverings\n" | |
| "The pitched roof covering comprises natural slate tiles laid to timber rafters.\n" | |
| "Photo - 1 Main roof\n" | |
| ) | |
| tagged = split_into_section_paragraphs(text, {"D2"}) | |
| assert len(tagged) == 1 | |
| sid, _idx, body = tagged[0] | |
| assert sid == "D2" | |
| assert "slate tiles" in body | |
| assert "Element no" not in body | |
| assert "Photo -" not in body | |
| def test_build_reference_chunks_applies_cleanup() -> None: | |
| text = ( | |
| "F4 Heating\n" | |
| "NOTE 1: Generic procedural guidance only.\n" | |
| "The boiler is a condensing unit installed in 2019.\n" | |
| "Photo - 3 Boiler cupboard\n" | |
| ) | |
| chunks = build_reference_chunks(text, source_filename="past.pdf", valid_section_ids={"F4"}) | |
| assert len(chunks) == 1 | |
| assert "condensing unit" in chunks[0].text | |
| assert "NOTE 1" not in chunks[0].text | |
| assert "Photo -" not in chunks[0].text | |