fix(jats): preserve structured abstract sections and fix nested list parent - #4172
Open
ceberam wants to merge 2 commits into
Open
fix(jats): preserve structured abstract sections and fix nested list parent#4172ceberam wants to merge 2 commits into
ceberam wants to merge 2 commits into
Conversation
Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com>
Nested <list> elements inside a <list-item> were walked with the ListItem itself as the docling parent, causing add_list_item() to receive a non-list-group parent and emit a DeprecationWarning while silently creating a list group on the fly. Fix by explicitly creating the GroupLabel.LIST group before recursing into the nested list. Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com>
Contributor
|
✅ DCO Check Passed Thanks @ceberam, all your commits are properly signed off. 🎉 |
Contributor
Merge Protections🔴 1 of 2 protections blocking · waiting on 👀 reviews
🔴 Require two reviewer for test updatesWaiting for
This rule is failing.When test data is updated, we require two reviewers
Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
8 tasks
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR addresses two gaps in the JATS backend. In particular, it addressed a gap not fully covered by #3584 and documented on #3584 (comment)
Structured abstracts: JATS articles commonly use a structured abstract — an
<abstract>element whose content is split into named<sec>children (e.g. Background, Results, Conclusion). The previous implementation collected all section text into a singleTextItem, prepending each section title inline as"Title: text…". This lost the document structure that JATS explicitly encodes. Each<sec>inside an<abstract>is now emitted as a dedicated section heading (DocItemLabel.SECTION_HEADER) with its paragraph(s) as separateTextItemchildren beneath it. Plain (un-sectioned) abstracts are unaffected.Nested list parent: Nested
<list>elements inside a<list-item>were walked with theListItemitself as the docling parent, causingadd_list_item()to receive a non-list-group parent. This triggered aDeprecationWarningfrom docling-core and a silent on-the-fly group creation. The list group is now created explicitly before recursing into the nested list.Changes
docling/backend/xml/jats_backend.pyAbstractSectionTypedDict(title,paragraphs) to represent a parsed abstract sub-section.AbstractTypedDictwith asections: list[AbstractSection]field alongside the existingcontentfield (which is retained for plain paragraph-only abstracts)._parse_abstract_section()to return anAbstractSectioninstead of a flat string._parse_abstract()to separate<sec>children (→sections) from bare<p>children (→content)._add_abstract()to emit each section asdoc.add_heading(level=hlevel+2)with individualdoc.add_text()calls underneath, falling back to the original single-TextItempath for plain abstracts.GroupLabel.LISTgroup under theListItembefore walking a nested<list>, so that childlist-itemelements always receive a proper list-group parent.tests/test_backend_jats.pytest_jats_structured_abstract_sections_are_preservedto assert the new structure (sub-headings present, flat"Title: text"format absent) and to verify theDoclingDocumentitem labels directly.tests/data/jats/sources/pmc2231364.nxmltests/data/jats/groundtruth/pmc2231364.nxml.*Behaviour before and after
Structured abstract
Before — all sections collapsed into one
TextItem:## Abstract Background: Environmental modulation… Results: To provide… Conclusion: The comparative…After — each section is a separate heading with its own paragraph:
Nested lists
Before —
ListItempassed directly as parent to nested list walk, triggering:After — a
GroupLabel.LISTgroup is created explicitly under theListItembefore recursing, matching the required parent contract.Testing
All 40 JATS tests pass with
-W error::DeprecationWarning. The new fixture is picked up automatically bytest_e2e_jats_conversions.Checklist: