Skip to content

fix(text): keep a bulleted list that follows its lead-in line as list items - #4580

Merged
cragwolfe merged 15 commits into
Unstructured-IO:mainfrom
L4XB:fix/text-bullet-list-after-lead-in
Oct 24, 2026
Merged

cragwolfe merged 15 commits into
Unstructured-IO:mainfrom
L4XB:fix/text-bullet-list-after-lead-in

Conversation

@L4XB

@L4XB L4XB commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A bulleted list that starts on the line right after its lead-in, with no blank line between them, loses its list items in partition_text():

text main this PR
Shopping list: / • milk / • bread Title("Shopping list:"), Title("milk"), Title("bread") Title("Shopping list:"), ListItem("milk"), ListItem("bread")
Shopping list: / • fresh milk and cheese from the farm market / • bread one NarrativeText("Shopping list: • fresh milk and cheese from the farm market • bread") Title, ListItem, ListItem

group_broken_paragraphs() sends a paragraph to group_bullet_paragraph() only when the paragraph itself starts with a bullet. A lead-in line followed by bullets is one paragraph that does not, so it takes the other path:

  • When all lines are short, it splits the paragraph with PARAGRAPH_PATTERN_RE. That pattern splits at unambiguous bullets as well as at line breaks, and it captures the separator, so each • becomes a piece of its own. group_broken_paragraphs("Shopping list:\n• milk\n• bread") returns 'Shopping list:\n\n\n•\n\n milk\n\n\n•\n\n bread', partition_text() drops the lone bullets as empty bullets, and the items are classified as titles.
  • When a line is long, it joins all lines into one paragraph, so the list becomes part of the lead-in text.

Change

group_broken_paragraphs() first passes each paragraph to a new _split_off_bullet_lists(). It splits off the lists whose items start with • (U+2022), ● (U+25CF) or ○ (U+25CB) and the lines around them. The existing code then groups each part unchanged, as if a blank line separated it from the next one, so a split-off list goes through group_bullet_paragraph():

  • A list starts at a line that begins with one of these glyphs, right after a line that ends with :.
  • After an item, only another item or the lead-in of the next list may follow, such as Vegetables: in Fruits: / • apple / Vegetables: / • carrot.

These glyphs only mark list items, while -, * and · can also be a sign, Markdown emphasis or a thematic break, or an operator. As agreed in review, lists with those markers are left to a follow-up with agreed recognition rules. These paragraphs stay whole and are grouped exactly as before:

  • A paragraph with a line that starts with any other bullet glyph (-, *, ·, –, …) or with e , which can be an OCR bullet, and a paragraph with an item line that the bullet matcher downstream (UNICODE_BULLETS_RE) does not read as a bullet, such as •- 5 °C, where another glyph follows the bullet directly.
  • A paragraph with a bullet glyph inside a line, after the line's leading marker: the bullet splitters downstream cut at any glyph of UNAMBIGUOUS_BULLETS_PATTERN, so 10 N·m, *really*, Required *production* settings:, 3 · 4 and inline lists (• milk • eggs) would lose characters.
  • A paragraph that starts with a bullet, or whose bullet line does not follow a : line.
  • A paragraph with any other line after an item, such as a wrapped item or prose after the list, because that line can continue the item.
  • Every paragraph, when the caller passes its own line_split.

Testing

  • test_group_broken_paragraphs_keeps_a_bulleted_list_after_its_lead_in_line covers short and long items with each of the three glyphs, a glyph without a following space, successive lead-ins and indented bullets. All cases fail on main.
  • test_group_broken_paragraphs_keeps_a_lead_in_list_with_an_inline_bullet_glyph_as_before checks, with LF and CRLF, that the helper keeps N·m, *really* in an item, *production* in a lead-in, 3 · 4, 3 ∙ 4 and a late rejection after a supported list whole, and that group_broken_paragraphs() returns main's text for them. These cases fail on d95b0f9. test_group_broken_paragraphs_keeps_a_lead_in_list_with_a_glyph_after_its_bullet_as_before does the same for •- 5 °C, •– 5 °C and a rejection after a supported list; it fails on 08d4f79. A spaced • - 5 °C still splits off and keeps its sign.
  • test_split_off_bullet_lists_keeps_an_ambiguous_paragraph_whole covers dash, star and middle-dot lists, a list that mixes • and -, emphasis, inline bullets, an OCR e line, a bullet without a lead-in, and prose or a wrapped line after an item. test_split_off_bullet_lists_keeps_a_long_wrapped_list_item_whole checks an item with 20,000 wrapped lines.
  • test_partition_text_reads_a_bulleted_list_that_follows_its_lead_in_line runs the lists through default partition_text(), also with prose before the lead-in and with two lists in a row, plus ambiguous paragraphs (N·m, *really* with CRLF, a late rejection, prose after an item) that stay one NarrativeText as on main. The custom line_split tests keep a configured paragraph grouper's own split.
  • Compared with main: 16,000 random ambiguous paragraphs (LF and CRLF, each with another bullet glyph at the start of a line, a glyph inside a line such as N·m or *x*, a line after an item or a bullet without a lead-in) come out of group_broken_paragraphs() exactly as on main (1,676 differed before the inline-glyph fallback, and 1,540 before the bullet-matcher check, with •- 5 °C-style lines added), and in 3,000 random supported lists every item becomes a ListItem.
  • test_unstructured/cleaners (without test_translate.py, which needs transformers), test_unstructured/nlp, partition/html, partition/test_text.py, test_email.py, test_md.py and test_text_type.py: 976 passed, 1 skipped.
  • ruff check and ruff format --check (0.15.10) pass. Since chore: replace per-PR changelog edits with generated release notes #4578 a PR no longer edits the version or the CHANGELOG, so this one leaves both alone.

@cragwolfe cragwolfe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 56a350cb23df90e108dda33fbfa3b21af8fa6997 with GPT Pro. Two actionable regressions remain in unstructured/cleaners/core.py:149–151.

  1. P2 — A subsequent list lead-in is absorbed into the preceding item. For Fruits:\n- apple\nVegetables:\n- carrot\n, the baseline short-line path preserves both headings and items. The new helper hands the entire suffix starting at - apple to group_bullet_paragraph(), which joins the intervening heading into - apple Vegetables:. partition_text() therefore loses the separate Vegetables: element and changes the preceding item's text. Continue segmenting successive lead-ins and bullet runs instead of treating the entire suffix as one list. Add cleaner and partitioner regressions, including indented bullets, while retaining legitimate wrapped continuations.

  2. P2 — Wrapped asterisk emphasis becomes false list items. For These rules must be followed\n*without exception* in all deployments.\n, the baseline joins the five-word first line and its continuation as ordinary prose. The new scan matches the unqualified * as a bullet and passes the suffix to a splitter that separates at both asterisks. The result becomes two false list items, and the partitioner strips the literal emphasis markers. Qualify ASCII * when detecting a new list inside prose, for example by requiring following whitespace or end-of-line. Keep this restriction local if needed to preserve existing shared-pattern behavior. Add a negative prose regression and a positive * item list case; retain no-space Unicode bullet support such as ○item.

Both scenarios reach the changed grouping through the default partition_text() path with a terminal newline. These findings follow from source inspection; no local tests or reproductions were run. Exact-head changelog, lint, and ingest checks passed; unit and Docker checks remain in progress.

(authored by codex)

L4XB added 2 commits October 23, 2026 00:51
…ut of lists

The whole suffix after the first bullet went to group_bullet_paragraph, so a later lead-in such as "Vegetables:" was joined into the item before it, and an unqualified "*" read prose emphasis as a new list. A line after an item now continues it only when the line before is long enough to have wrapped or the line starts in lowercase, and not when it ends with ":" before the next item. "*" starts an item only when whitespace or the end of the line follows it.
…after-lead-in

# Conflicts:
#	CHANGELOG.md
#	unstructured/__version__.py
@L4XB

L4XB commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. Both regressions are fixed in a5b1444. d967b6d merges current main and follows #4578: the changelog entry and the version bump are gone.

1. Successive lead-ins. _split_off_bullet_lists() now splits a paragraph into all of its lead-ins and bullet runs, not only at the first bullet. A line after an item continues that item when the line before it has five or more words (the threshold of the existing short-lines check), or when the line starts in lowercase. A line that ends with : right before the next item never continues it.

input partition_text()
Fruits:\n- apple\nVegetables:\n- carrot\n Fruits: (Title), apple, Vegetables: (Title), carrot
Fruits:\n - apple\n - pear\nVegetables:\n - carrot\n Fruits:, apple, pear, Vegetables:, carrot
Fruits:\n- apple\n- pear\nThat is all.\n Fruits:, apple, pear, That is all. (NarrativeText)
Requirements:\n- install the latest Python release first and then\n configure the environment\n- pip Requirements:, install … and then configure the environment, pip
Animals:\n• The big red fox\nis walking down the lane.\n• … Animals:, The big red fox is walking down the lane., …

2. Emphasis. A list line is now detected locally by _starts_list_item(). That helper accepts ASCII * only when whitespace or the end of the line follows it. The shared patterns are unchanged, so ○item still starts an item. These rules must be followed\n*without exception* in all deployments.\n again gives one NarrativeText, the same as main.

New regressions in test_core.py (cleaner): the wrapped continuation, both lead-in cases (flat and indented), * item, ○item and the emphasis prose. New regressions in test_text.py (partitioner): the indented lead-in case and the emphasis prose. Five of them fail with the previous head and pass now.

pytest test_unstructured/cleaners test_unstructured/partition/test_text.py test_unstructured/nlp: 260 passed. test_translate.py was skipped locally because transformers is not installed. ruff check and ruff format --check (0.15.10) are clean.

group_bullet_paragraph() itself is unchanged. Inside an actual * item list it still splits at a later * (* first *really* important), the same as main does for a paragraph that starts with a bullet.

@cragwolfe cragwolfe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed d967b6de9b551de52b876d3ccff25c5f2490f239 with GPT Pro. Both previous findings are fixed: successive lead-ins remain separate, and wrapped ordinary-prose emphasis is preserved. Two further P2 regressions remain.

  1. P2 — Newly isolated lists split inline emphasis into false items (unstructured/cleaners/core.py:172–176,215–218). For Requirements:\n- This installation must always be *really* safe\n- Next step\n, the new pass sends the isolated list through group_bullet_paragraph(). Its existing BULLET_SPLIT_RE_0W splits at both inline asterisks, so the intended first item becomes three items: This installation must always be, really, and safe; clean_bullets() removes the literal emphasis markers. The baseline keeps this input in its ordinary-paragraph branch and preserves the text. Although the splitter is unchanged, this PR newly exposes lead-in/list input to it. Qualify boundaries during the actual splitting of newly isolated lists, not only during initial line detection. Add cleaner and default-partitioner regressions that preserve the complete item and its inline emphasis, including a wrapped emphasis continuation; retain * item and no-space Unicode bullet support.

  2. P2 — A leading newline detaches an existing wrapped list continuation (unstructured/cleaners/core.py:163–166,182–185). For \n- Install\n SQL Server for the database\n- Verify setup\n, the baseline dispatch uses paragraph.strip() and keeps Install SQL Server for the database in one item. The new helper examines only the empty first line, misses its preservation guard, and applies its continuation heuristic. Because - Install is short and SQL starts uppercase, it detaches the explicitly indented continuation into a separate non-list element. Use the same first non-whitespace content as the existing dispatch to recognize an already-bulleted paragraph. Add cleaner and default-partitioner coverage for a single leading LF/CRLF and uppercase or numeric continuations after short item lines.

Both scenarios reach the changed path through default partition_text() with the newlines shown. Findings were verified against source; no local tests or reproductions were run. Exact-head CI is still running, with no failed checks observed at publication. These defects need author changes before approval.

(authored by codex)

@cragwolfe
cragwolfe enabled auto-merge October 23, 2026 01:17
@cragwolfe
cragwolfe disabled auto-merge October 23, 2026 01:17
…p lists after a leading break whole

A list split off from its lead-in went through group_bullet_paragraph(), whose BULLET_SPLIT_RE_0W also splits at an inline '*', so '- must always be *really* safe' became three items. Such a list is now split only at the lines that _starts_list_item() accepts, and its other lines are joined to the item before them. A prose line that follows the list no longer goes through the bullet path either. A paragraph that starts with a line break before its first bullet was checked by its empty first line, so it missed the guard for already-bulleted paragraphs, and an indented continuation such as '  SQL Server for the database' was split off. The guard now reads the stripped paragraph, as the bullet dispatch does.
@L4XB

L4XB commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, both are fixed in 88995a1.

  1. Inline emphasis in a newly isolated list. A list that _split_off_bullet_lists() splits off no longer goes through group_bullet_paragraph(). The new _list_items() starts an item only at a line that _starts_list_item() accepts, and joins the other lines to the item before them. - This installation must always be *really* safe therefore stays one item, also when *really* safe for every deployment is a wrapped line of its own. A prose line that follows such a list doesn't take the bullet path either. Paragraphs that _split_off_bullet_lists() leaves whole, including every paragraph that starts with a bullet, go through group_bullet_paragraph() as before. * item and no-space Unicode bullets (○item one) still start items.
  2. Leading line break. The already-bulleted guard now reads paragraph.strip(), the same content the bullet dispatch uses. \n- Install\n SQL Server for the database\n- Verify setup\n and its CRLF form give Install SQL Server for the database and Verify setup again, the same as main. The same holds for a numeric continuation such as 2019 edition of SQL Server.

New cleaner cases cover inline emphasis, a wrapped emphasis line, and a leading LF and CRLF with uppercase and numeric continuations. The same scenarios run through default partition_text(), and all of them fail on d967b6d. Items of an isolated list no longer carry the trailing space that group_bullet_paragraph() left, so the existing expectations in this test changed only by that space.

test_unstructured/cleaners (without test_translate.py, which needs transformers), partition/test_text.py, test_email.py, test_md.py, test_text_type.py and test_unstructured/nlp: 545 passed. test_msg.py::test_partition_msg_can_process_attachments fails the same way on d967b6d in my environment, because its PNG/PDF/PPTX attachments need extras I don't have installed. [email protected] check and format --check pass.

@cragwolfe cragwolfe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 88995a18094b115b49fdd6b70b68ef4ea915dd10 with GPT Pro. Both latest findings are repaired: inline/wrapped emphasis inside isolated items remains intact, and leading LF/CRLF paragraphs preserve uppercase or numeric continuations. The earlier successive-lead-in and ordinary-prose examples also remain repaired. Two further P2 issues remain, detailed inline: emphasized non-list fragments can lose characters and paragraph boundaries, and many wrapped continuation lines incur quadratic copying.

Findings were verified against source and checked-in tests. No local tests or reproductions were run. Exact-head CI and security workflows await approval; only the two Socket checks have passed. Source changes are needed before approval, so workflow approval and auto-merge remain inactive.

(authored by codex)

Comment thread unstructured/cleaners/core.py Outdated
paragraphs: list[tuple[str, bool]] = []
for paragraph in paragraph_split.split(text):
parts = _split_off_bullet_lists(paragraph)
paragraphs.extend((part, len(parts) > 1) for part in parts)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 — Preserve emphasized text in newly isolated non-list parts. For Required *production* settings:\n- Install the latest Python version first\n, this subdivision sends the short lead-in through the existing line_split/all_lines_short branch. The default PARAGRAPH_PATTERN_RE captures inline asterisks, so the lead-in becomes separate Required, production, and settings: paragraphs; default partition_text() drops the standalone asterisks as empty bullets. On the baseline, the long item keeps the original paragraph out of that short-line branch, preserving its text. _list_items() fixes emphasis inside list items, but does not protect these non-list fragments. Preserve physical-line content for isolated non-list parts, with cleaner and default-partitioner regressions for an emphasized lead-in and short emphasized prose after a list. Retain genuine * item and no-space Unicode bullets.

(authored by codex)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 538d61f. A part that _split_off_bullet_lists() splits off and that is not a list is now split only at its line breaks, with PARAGRAPH_PATTERN, and no longer with line_split. None of its lines starts an item, so an inline * in it stays emphasis. Required *production* settings: stays one paragraph (NarrativeText from partition_text()), and Only *fresh* ones after a list stays one Title. main split the latter into Only, fresh and ones. New cleaner and partition_text() cases cover both, and they fail on 88995a1. List parts are unchanged, so * item and no-space Unicode bullets still start items. Paragraphs left whole keep line_split.

Comment thread unstructured/cleaners/core.py Outdated
if _starts_list_item(line) or not items:
items.append(text)
elif text:
items[-1] = f"{items[-1]} {text}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 — Join wrapped continuation fragments once per item. Each continuation copies the entire accumulated item in items[-1]. A lead-in followed by one item and many lowercase wrapped lines therefore takes quadratic cumulative string copying. For example, 100,000 roughly 80-character continuation lines yield about 8 MB of text but approximately 400 billion characters of copying. This is a source-derived estimate, not a measured runtime. The path is reachable through default partition_text() when introductory blank-separated paragraphs make auto_paragraph_grouper() choose blank_line_grouper(); the baseline processes this lead-in paragraph with one newline-normalizing regex substitution. Collect continuation fragments per item and join once at the next bullet or end of input. Preserve empty-line handling and qualified bullet boundaries, and add a large wrapped-item regression that checks complete text and the following item boundary.

(authored by codex)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 538d61f. _list_items() now collects each item's stripped lines and joins them once, after the last line has been read. Empty lines are still skipped, and an item still starts only at a line that _starts_list_item() accepts. New test_group_broken_paragraphs_joins_a_long_wrapped_list_item runs 20,000 lowercase continuation lines (about 720 KB) and checks the complete first item and the - second item after it. It takes about 0.3 s.

…in item lines once

The lead-in and the prose around a split-off list went through the short-lines branch, whose PARAGRAPH_PATTERN_RE also splits at an inline '*', so 'Required *production* settings:' became three paragraphs. These parts are now split only at their line breaks. _list_items() also copied the whole item for each continuation line; it now collects an item's lines and joins them once.

@cragwolfe cragwolfe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 538d61f538187e554f0538920d68ceafe1661e35 with GPT Pro. The examples from all previous rounds are repaired, including emphasized non-list fragments and quadratic continuation copying. Three P2 regressions remain, detailed inline: leading emphasis can lose its opening marker and become a false list item, inline Unicode list entries collapse together, and isolated prose ignores a custom line_split.

Verified against the complete source change, surrounding partition/classification code, and checked-in tests. No local tests or reproductions were run. Exact-head Security, CodeQL, lint, version, and ingest checks have passed; unit, Docker, and benchmark jobs are still running, with no failures observed. Source changes are needed before approval, so workflow approval and auto-merge remain inactive.

(authored by codex)

Comment thread unstructured/cleaners/core.py Outdated
para_split = line_split.split(paragraph)
# A part split off from a list is split only at its line breaks: none of its lines starts
# an item, so an inline "*" in it is emphasis.
para_split = (paragraph_pattern_re if split_off else line_split).split(paragraph)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 — Preserve leading emphasis through element classification. For default partition_text(text="Fruits:\n- Buy fresh apples from the local orchard\n*Vegetables*:\n- carrots\n"), the new subdivision isolates *Vegetables*:. This branch preserves its stars, but downstream is_bulleted_text() still accepts the opening *, and clean_bullets() removes it: the heading becomes ListItem("Vegetables*:"). The baseline takes the long-line normalization branch and preserves both stars. A related case is Requirements:\n- Install\n *SQL Server* to accept remote production connections\n- Verify setup\n: the short-item heuristic ignores indentation, detaches the continuation, and exposes its first star to the same deletion. Carry the qualified asterisk interpretation through classification, and preserve explicit indented continuations. Add cleaner/default-partitioner regressions for these inputs while retaining * item and no-space Unicode bullets. The current emphasis tests use an interior star or a long preceding item, so they miss these cases.

(authored by codex)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in fbecbc9. Classification now follows the same qualified reading of the star. is_bulleted_text() treats a leading star as emphasis when another star closes it after a non-space on the same line (EMPHASIS_START_RE, as in *Note*:). Your first input now gives Title("*Vegetables*:") between the two list items, with both stars kept. *item without a closing star is still a bullet, and * item is as before. Both are pinned in test_is_bulletized_text. For the second input, a line indented deeper than its item's bullet now continues the item. *SQL Server* to accept remote production connections therefore stays in ListItem("Install *SQL Server* to accept remote production connections"). Cleaner and partition_text() cases cover both. Since is_bulleted_text() is shared, I also ran test_docx.py, test_xlsx.py and partition/html. The counts are the same as before: 189, 157, and the html suite passes.

Comment thread unstructured/cleaners/core.py Outdated
items: list[list[str]] = []
for line in paragraph.split("\n"):
text = line.strip()
if _starts_list_item(line) or not items:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 — Retain inline Unicode item boundaries in newly isolated lists. With partition_text(text="Shopping list:\n• milk • eggs • bread\n"), this splitter recognizes only the physical line boundary, producing one ListItem("milk • eggs • bread"). The baseline ordinary-paragraph splitter preserves three separate content elements, milk, eggs, and bread. Existing cleaner and partitioner tests explicitly retain inline Unicode bullet splitting, but their blank line before the list sends them through the unchanged path. Split unambiguous Unicode bullet boundaries inside newly isolated list lines while keeping asterisks qualified and hyphens/en dashes line-anchored. Add cleaner/default-partitioner coverage with the single-LF lead-in above and a no-space Unicode variant.

(authored by codex)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in fbecbc9. After _list_items() joins an item's lines, it splits the item again at INLINE_BULLET_SPLIT_RE_0W, which covers the unambiguous glyphs without *, - and –. Those three still start an item only at the start of a line, so emphasis, hyphens and minus signs inside an item are untouched. Shopping list:\n• milk • eggs • bread\n and the no-space •milk •eggs •bread both give Title("Shopping list:") and three list items. New cleaner and partition_text() cases cover both.

Comment thread unstructured/cleaners/core.py Outdated
para_split = line_split.split(paragraph)
# A part split off from a list is split only at its line breaks: none of its lines starts
# an item, so an inline "*" in it is emphasis.
para_split = (paragraph_pattern_re if split_off else line_split).split(paragraph)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 — Honor an explicitly supplied line_split for isolated prose. group_broken_paragraphs("Document title\fDocument subtitle\n- check\n", line_split=re.compile(r"\s*[\n\f]\s*")) previously returns "Document title\n\nDocument subtitle\n\n- check". This unconditional replacement of the caller pattern now returns "Document title\fDocument subtitle\n\n- check", merging the two configured heading lines. The same loss of boundaries reaches partition_text() when this configured cleaner is supplied as paragraph_grouper. Keep the emphasis-safe default handling while honoring explicit separators, and add this cleaner regression plus a no-list control using the same pattern.

(authored by codex)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in fbecbc9. Prose around a split-off list uses the emphasis-safe PARAGRAPH_PATTERN only when line_split is the default PARAGRAPH_PATTERN_RE. A pattern the caller passes is used as given. Your example returns "Document title\n\nDocument subtitle\n\n- check" again. test_group_broken_paragraphs_splits_the_lines_around_a_list_with_a_custom_line_split checks it together with the no-list control under the same pattern.

…, and honor a custom line_split

is_bulleted_text() read the star that opens emphasis, as in '*Vegetables*:', as a bullet, so the element became a list item without its first star. A star closed later on the line after a non-space now opens emphasis. A line indented deeper than its item's bullet now continues the item. A split-off list also splits at the unambiguous glyphs inside a line, as in '• milk • eggs', while '*' and the dashes still count only at the start of a line. The prose around a list keeps a line_split that the caller passed.

@cragwolfe cragwolfe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed fbecbc956f7f02a8459f597d10fb6419a1e7c02a with GPT Pro. The previous examples are repaired, including leading emphasis, indented continuations, inline Unicode entries on list lines, and custom delimiters before a list. Three P2 regressions remain, detailed inline: middle dots in units are removed by false item boundaries, custom delimiters inside isolated lists are bypassed, and inline Unicode items in isolated prefixes merge into their lead-ins.

Verified against the complete current diff, surrounding source, and checked-in tests. No local tests or reproductions were run. Exact-head Security, CodeQL, version, lint, ingest, and Socket checks passed; required unit and Docker jobs are still running. Source changes are needed before approval, so workflow approval and auto-merge remain inactive.

(authored by codex)

Comment thread unstructured/cleaners/core.py Outdated
return [
piece.strip()
for item in items
for piece in INLINE_BULLET_SPLIT_RE_0W.split(" ".join(item))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 — Preserve middle dots inside units. For default partition_text(text="Requirements:\n- Tighten the bolt to 10 N·m of torque\n"), the new inline splitter splits before ·, producing ListItem("Tighten the bolt to 10 N") and ListItem("m of torque"). This removes the unit separator and invents a second item. The baseline ordinary-paragraph path sees a long fragment and normalizes the original paragraph, preserving N·m; this lead-in/list input is newly exposed to the bullet splitter. Qualify embedded middle dots in the new path, and add cleaner/default-partitioner regressions requiring one intact item while retaining genuine middle-dot delimiters and no-space Unicode bullets such as •milk •eggs.

(authored by codex)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a2d2e5b. A middle dot (· and the bullet operator ∙) now starts an item inside a line only after whitespace. - Tighten the bolt to 10 N·m of torque stays one item, and • milk · eggs still splits into milk and eggs. The other unambiguous glyphs are unchanged, so •milk •eggs •bread still gives three items. New cleaner and partition_text() cases cover these.

Comment thread unstructured/cleaners/core.py Outdated

if UNICODE_BULLETS_RE.match(stripped_par) or E_BULLET_PATTERN.match(stripped_par):
if split_off and _starts_list_item(stripped_par):
clean_paragraphs.extend(_list_items(paragraph))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 — Honor custom line delimiters inside isolated lists. group_broken_paragraphs("Items:\n- first\f- second\n", line_split=re.compile(r"\s*[\n\f]\s*")) previously returns "Items:\n\n- first\n\n- second". This dispatch bypasses the caller pattern: _list_items() splits only on LF and its inline splitter excludes dashes, so it returns "Items:\n\n- first\f- second". With this configured cleaner as partition_text()’s paragraph_grouper, the two items become one ListItem("first\f- second"). The customization repair below covers only non-list fragments. Honor the explicit logical-line delimiters in list processing, or preserve the prior custom-pattern route. Add cleaner/configured-partitioner cases with a form feed between two dash items and between an item and following prose, retaining the existing delimiter-before-list and emphasis cases.

(authored by codex)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a2d2e5b. I took the second option: a caller that passes its own line_split now keeps the previous route for every paragraph, and _split_off_bullet_lists() runs only with the default PARAGRAPH_PATTERN_RE. Items:\n- first\f- second\n gives "Items:\n\n- first\n\n- second" again, and an item followed by prose after a form feed keeps that boundary too. The earlier delimiter-before-list case still passes. New cases cover both form-feed inputs in the cleaner and through partition_text(paragraph_grouper=functools.partial(group_broken_paragraphs, line_split=...)).

Comment thread unstructured/cleaners/core.py Outdated
# passed its own `line_split`: none of its lines starts an item, so an inline "*" in it
# is emphasis.
default_split = split_off and line_split is PARAGRAPH_PATTERN_RE
para_split = (paragraph_pattern_re if default_split else line_split).split(paragraph)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 — Keep inline Unicode item boundaries in isolated prefixes. For default partition_text(text="Shopping list: • milk\n- bread\n"), the baseline preserves separate content elements Shopping list:, milk, and bread. The new scan isolates Shopping list: • milk as a non-list prefix, then this newline-only default split leaves it whole. The result merges the first item into the heading: Shopping list: • milk, followed by bread. The latest inline-Unicode repair runs only inside _list_items(), so it cannot recover this prefix boundary. Preserve genuine inline Unicode boundaries in non-list fragments while keeping emphasis stars intact and dash qualification unchanged. Add cleaner/default-partitioner regressions for this mixed inline/next-line list and the no-space •milk variant.

(authored by codex)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a2d2e5b. A part around a split-off list is now split at its line breaks and also at the glyphs that start an item inside a line (INLINE_BULLET_SPLIT_RE_0W). * and the dashes stay out of that split, so emphasis is kept and dash qualification is unchanged. Shopping list: • milk\n- bread\n and the no-space Shopping list: •milk now give Title("Shopping list:"), ListItem("milk") and ListItem("bread"). New cleaner and partition_text() cases cover both.

… items in a lead-in

The inline item split took the middle dot in '10 N·m' for a bullet. A middle dot now starts an item inside a line only after whitespace. A caller that passes its own line_split now keeps the previous route, so its separators also split the lines of a list. A lead-in such as 'Shopping list: • milk' is now split at the glyph inside it, so its item is no longer merged into the heading.

@cragwolfe cragwolfe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed a2d2e5bf307bb4968f4444d16e79ca0dc89dc68f with GPT Pro. The three latest reported examples are repaired: unspaced middle dots in units stay intact, custom delimiters inside lists retain the previous route, and short inline Unicode items in prefixes remain separate. Three P2 regressions remain, detailed inline: four-word inline items merge into their lead-ins, spaced multiplication dots become false item boundaries and disappear, and emphasis spanning physical lines can lose its opening star.

Verified against the complete current diff, surrounding source and shared classifier consumers, and checked-in tests. No local tests or reproductions were run. Exact-head CI, Security, CodeQL, and benchmark workflows await approval; only Socket checks have passed. Source changes are needed before approval, so workflow approval and auto-merge remain inactive.

(authored by codex)

Comment thread unstructured/cleaners/core.py Outdated
para_split = [
piece.strip()
for line in paragraph_pattern_re.split(paragraph)
for piece in INLINE_BULLET_SPLIT_RE_0W.split(line)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 — Keep four-word inline items separate from their lead-ins. For default partition_text(text="Shopping list: • fresh milk and eggs\n- bread\n"), this split identifies Shopping list: and • fresh milk and eggs, but retaining the bullet makes the latter count as five space-separated tokens. all_lines_short becomes false, and the fallback restores the unsplit prefix. The first item therefore merges into Shopping list: • fresh milk and eggs, followed by the separate bread item. The baseline captures the bullet separately and preserves the heading and four-word item content as separate elements. The new prefix tests cover only one-word items. Preserve recognized inline item boundaries through the length heuristic, and add cleaner/default-partitioner regressions for this input while retaining emphasis and no-space Unicode bullets.

(authored by codex)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in fb8f7a2. The • inside the lead-in line now keeps the whole paragraph on the old path, so this input gives the same output as on main. The case is in test_split_off_bullet_lists_keeps_a_paragraph_whole.

Comment thread unstructured/nlp/patterns.py Outdated
)
INLINE_BULLET_SPLIT_RE_0W = re.compile(
f"(?:(?={INLINE_BULLETS_PATTERN})(?<!{INLINE_BULLETS_PATTERN}))"
f"|(?:(?<=\\s)(?=[{''.join(MIDDLE_DOT_BULLETS)}]))",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 — Preserve spaced multiplication dots inside items. For default partition_text(text="Calculations:\n- Multiply the two numbers 3 ∙ 4 to get twelve\n"), the new list path accepts ∙ as an inline item boundary solely because whitespace precedes it. The cleaner produces - Multiply the two numbers 3 and ∙ 4 to get twelve; downstream classification calls clean_bullets() on both, deleting the multiplication operator and inventing a second list item. · behaves the same way. The baseline ordinary-paragraph branch encounters the long fragment before the operator and normalizes the original paragraph intact. The N·m repair covers only an unspaced dot. Qualify numeric-operand contexts and add cleaner/default-partitioner cases requiring one intact item for both 3 · 4 and 3 ∙ 4, while retaining • milk · eggs, N·m, and no-space Unicode bullets.

(authored by codex)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in fb8f7a2. The new path no longer splits at a middle dot: a · or ∙ inside a line keeps the whole paragraph on the old path, so 3 · 4, 3 ∙ 4 and 10 N·m come out as on main. All three are in test_split_off_bullet_lists_keeps_a_paragraph_whole.

Comment thread unstructured/cleaners/core.py Outdated
if split_off:
para_split = [
piece.strip()
for line in paragraph_pattern_re.split(paragraph)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 — Preserve emphasis spans that cross physical lines. For default partition_text(text="Tasks:\n- Install\n*Important security\nrequirements*:\n- Require multifactor authentication for all users\n"), the scan isolates *Important security\nrequirements*: as non-list text. This branch then splits it at its physical newline, and both fragments satisfy all_lines_short. Downstream is_bulleted_text() receives *Important security without its closing star, treats it as a bullet, and clean_bullets() deletes the opening marker. The result contains a false ListItem("Important security") and a separate requirements*: element. The baseline's long final item selects normalization of the original paragraph, preserving both markers. Preserve the paired span before short-line fragmentation, with cleaner/default-partitioner regressions for LF and CRLF requiring one non-list *Important security requirements*: heading. Retain genuine * item bullets and the supported unclosed *item behavior.

(authored by codex)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in fb8f7a2. A * that does not start an item now keeps the whole paragraph on the old path, so *Important security / requirements*: is grouped as on main. The LF and CRLF variants are in test_split_off_bullet_lists_keeps_a_paragraph_whole.

…all start lines

Each review round found inputs where the new list split and the old paragraph path disagree: emphasis that spans lines, middle dots in units and products, and inline bullets in a lead-in or an item. Instead of teaching the split more grammar, a paragraph now stays whole when a bullet glyph appears anywhere but at the start of a line, or when a line starts with an OCR "e" bullet. A list also starts only after a line that ends with ":", so a dash or a sign that starts a line in prose is left alone. The parts go through the existing grouping unchanged, as if blank lines separated them. This drops the inline splitter, the list item joiner and the emphasis change to is_bulleted_text().
@L4XB

L4XB commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

I narrowed this PR in fb8f7a2. The review rounds kept finding inputs where the new split and the old paragraph path disagree: emphasis, middle dots, inline bullets. Each fix added grammar that the next input could trip over. Now the new path takes only a list that follows a line ending in :, and only when every bullet glyph in the paragraph starts a line. Every other paragraph is grouped exactly as on main. The split-off parts go through the existing code as if blank lines separated them, so a list goes through group_bullet_paragraph() as before. This removes the inline splitter, the list item joiner and the is_bulleted_text() change. The PR description shows the new scope.

@cragwolfe cragwolfe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed fb8f7a23d0215f4bea3871c34cb31873f06111d5 with GPT Pro. The previous examples are restored to baseline behavior, including four-word inline items, spaced multiplication dots, multiline emphasis, custom separators, and wrapped-continuation complexity. One P2 regression remains, detailed inline: isolating a later list can expose earlier signed prose to bullet classification and remove its minus sign.

Verified against the complete current diff, surrounding source, shared consumers, and checked-in tests. No local tests or reproductions were run. Exact-head Security, CodeQL, version, lint, ingest, and Socket checks passed; unit, Docker, and benchmark jobs remain in progress. Author changes are needed before approval, so workflow approval and auto-merge remain inactive.

(authored by codex)

indent = len(line) - len(line.lstrip())
if _starts_list_item(line) and (in_list or lines[idx - 1].strip().endswith(":")):
if not in_list:
parts.append("\n".join(lines[start:idx]))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 — Preserve signed prose when isolating a later list. For default partition_text(text="The temperature dropped to\n- 5 degrees overnight.\nObservations:\n- Ice formed on the lake\n"), the new scan correctly does not recognize the temperature line as a list, but this subdivision isolates the three short prefix lines. Their separate all_lines_short check now succeeds, so - 5 degrees overnight. becomes a standalone paragraph; element_from_text() classifies it as a bullet and clean_bullets() removes the minus sign, producing ListItem("5 degrees overnight."). On the baseline, the six-token final item makes the original paragraph take newline normalization, preserving the signed expression. The terminal newline shown selects this grouping through the default partitioner.

Keep non-list signed continuations from becoming standalone bullets as a side effect of subdivision. A conservative option is to retain the original paragraph when a dash/en-dash line occurs outside an accepted colon-led list; alternatively preserve these non-list spans as units. Add cleaner and default-partitioner regressions with LF/CRLF and a genuine list elsewhere in the paragraph, including a suffix after a short final item, while retaining positive list and custom-separator coverage. The current signed-prose preservation test has no later genuine list and misses this interaction.

(authored by codex)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 10f3e29 with the conservative option. _split_off_bullet_lists() now returns the paragraph unchanged as soon as a bullet line is neither inside a list nor right after a line that ends with :, so the paragraph takes the main path.

Your input, in LF and CRLF, gives NarrativeText("The temperature dropped to - 5 degrees overnight. Observations: - Ice formed on the lake") again, the same as main. A signed line after a list with a short final item (Observations:\n- Ice\nThe temperature dropped to\n- 5 degrees overnight.\n, LF and CRLF) now also matches main exactly, both in group_broken_paragraphs() and in partition_text(). I compared all four inputs against a main checkout.

The keep-whole cases now include those four paragraphs, and partition_text() pins your input in LF and CRLF. All six fail on fb8f7a2 and pass now. The positive list cases and the custom-separator tests are unchanged and still pass. test_unstructured/cleaners, partition/test_text.py, partition/test_text_type.py and nlp: 395 passed (without test_translate.py, which needs transformers).

…ead-in list

A line such as '- 5 degrees overnight.' that follows a line without a colon is a dash or a sign in prose. When a colon-led list came later in the same paragraph, splitting that list off isolated the signed line, the short-lines check made it a paragraph of its own, and it became a ListItem without its minus sign. Keep the whole paragraph on the main path as soon as a bullet line is neither inside a list nor right after a line that ends with ':'.

@cragwolfe cragwolfe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 10f3e29f79801b252f12fa6c9053ad0153ccc524 with GPT Pro. The previous reported examples are repaired, including signed prose before a list and after a short item. Two P2 regressions remain, detailed inline: signed prose after a long item loses its minus sign, and a multiplication operator at a wrapped line boundary is removed as a bullet.

Verified against the complete current diff, surrounding source, shared consumers, and checked-in tests. No local tests or reproductions were run. Exact-head CI, Security, CodeQL, and benchmark workflows await approval; only the two Socket checks have passed. Author changes are needed before approval, so workflow approval and auto-merge remain inactive.

(authored by codex)

text = line.strip()
indent = len(line) - len(line.lstrip())
if _starts_list_item(line):
if not (in_list or lines[idx - 1].strip().endswith(":")):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 — Preserve signed prose after a long list item. For default partition_text(text="Observations:\n- Ice formed on the lake\nThe temperature dropped to\n- 5 degrees overnight.\n"), the six-token first item makes the continuation heuristic retain The temperature dropped to inside the list. This condition then accepts the signed line solely because in_list is still true. The isolated suffix reaches group_bullet_paragraph() and clean_bullets(), producing ListItem("Ice formed on the lake The temperature dropped to") and ListItem("5 degrees overnight."): the minus sign disappears. On the baseline, the long item keeps the original paragraph on newline normalization, preserving the signed expression.

The new suffix fixtures use short - Ice, which ends list mode before the signed line. Keep continuation recognition tentative when validating later dash/en-dash numeric lines; conservatively retaining the original paragraph when the sign can continue intervening prose is one option. Add cleaner and default-partitioner regressions for this long-item suffix with LF/CRLF and a lowercase continuation variant, preserving signs, genuine consecutive bullets, and legitimate wrapped items.

(authored by codex)

@L4XB L4XB Oct 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c3499bc by dropping the continuation rules instead of making them tentative. After an item, only another item or the lead-in of the next list may follow; any other line, such as The temperature dropped to after - Ice formed on the lake, keeps the whole paragraph on the main path. Your input gives NarrativeText("Observations: - Ice formed on the lake The temperature dropped to - 5 degrees overnight.") again, the same as main, with LF and CRLF and with a lowercase continuation. Keep-whole cleaner cases and a partition_text() case cover them, and they fail on 10f3e29. The cost is that a wrapped item no longer splits off; it is grouped as on main. I also compared 16,000 random lists with a non-lead-in line after an item against main: all identical.

Comment thread unstructured/cleaners/core.py Outdated

lines = paragraph.split("\n")
if any(
UNAMBIGUOUS_BULLETS_RE.search(line.strip()[1:] if _starts_list_item(line) else line)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 — Preserve a multiplication operator at a wrapped line boundary. For default partition_text(text="Calculations:\n- Multiply the two numbers 3\n· 4 to get twelve\n"), _starts_list_item() accepts the leading multiplication dot, and this check skips that first character. The helper therefore isolates the list and treats the arithmetic continuation as another item. The existing splitter and cleaner produce ListItem("Multiply the two numbers 3") and ListItem("4 to get twelve"), deleting the operator. The same applies to ∙ (U+2219). On the baseline, the six-token first item sends the whole paragraph through newline normalization, preserving 3 · 4.

The inline-product tests do not cover an operator at the start of a wrapped line. Check arithmetic continuations across physical line boundaries before exempting a leading dot; conservatively retaining the paragraph when the dot lies between numeric operands fits the current approach. Add cleaner and default-partitioner coverage for both dot glyphs with LF/CRLF, and retain positive middle-dot lists and no-space Unicode bullets. Keep this correction local to the new helper rather than changing shared bullet classification.

(authored by codex)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c3499bc, locally in _starts_list_item(): a middle dot or bullet operator (·, ∙) followed by a digit no longer starts an item. The wrapped · 4 to get twelve therefore counts as a glyph outside a line-start bullet, and the paragraph stays whole: NarrativeText("Calculations: - Multiply the two numbers 3 · 4 to get twelve"), as on main, for both glyphs with LF and CRLF. Shopping list: / · milk / · bread still gives two ListItems, and no-space bullets (○item one) are unchanged. Shared bullet classification is untouched.

A line after an item that was not the next lead-in was read as a wrapped continuation when the item looked long, so 'The temperature dropped to' stayed in the list and the signed '- 5 degrees overnight.' that followed became a ListItem without its minus sign. A middle dot at the start of a wrapped product ('3\n· 4') was read as a bullet in the same way. Drop the continuation rules: such a paragraph now stays whole and is grouped as on main, and a middle dot or bullet operator before a digit does not start an item.

@cragwolfe cragwolfe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed c3499bcd381fa9d5d3172b0482b4bd89d8cdec27 with GPT Pro. Both latest reported examples are repaired: signed prose after a long item stays on the baseline path, and digit-leading wrapped multiplication retains its operator. One P2 regression remains, detailed inline: other ordinary arithmetic operand forms and ASCII multiplication can still lose their operator through false list boundaries.

Verified against the complete current diff, surrounding source and shared consumers, and checked-in tests. No local tests or reproductions were run. Exact-head CI, Security, CodeQL, and benchmark workflows await approval; only the two Socket checks have passed. Author changes are needed before approval, so workflow approval and auto-merge remain inactive.

(authored by codex)

Comment thread unstructured/cleaners/core.py Outdated
Comment on lines +150 to +152
if bullet.group() in ("\u00b7", "\u2219") and stripped[1:].lstrip()[:1].isdigit():
return False
return bullet.group() != "*" or len(stripped) == 1 or stripped[1].isspace()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 — Preserve wrapped multiplication across ordinary operand forms. For default partition_text(text="Calculations:\n- Multiply the two numbers 3\n· -4 to get negative twelve\n"), this check rejects a leading dot only before a digit. The signed operand therefore passes _starts_list_item(), the glyph scan skips the dot, and the list scan accepts the line as another item. group_bullet_paragraph() splits before the operator and downstream clean_bullets() removes it, yielding ListItem("Multiply the two numbers 3") and ListItem("-4 to get negative twelve"). The baseline six-token item selects normalization of the original paragraph and preserves the expression. The same issue affects ∙ -4, · .5, · (4 + 5), and ASCII * 4, whose whitespace check accepts multiplication unconditionally. Conservatively keep the original paragraph when a prospective leading operator can continue the preceding expression. Keep the change local to the new segmentation logic, and add cleaner/default-partitioner regressions with LF/CRLF for these operand forms while retaining genuine middle-dot/star lists and no-space Unicode bullets.

(authored by codex)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 3d94ba1 for the whole class rather than the listed forms: after a line that ends in a digit, ), ] or %, a *, · or ∙ followed by an operand (a digit, a sign before a digit or ., .5, ( or [) does not start an item, so the paragraph stays on the baseline path. · -4, ∙ -4, · .5, · (4 + 5) and ASCII * 4 now give the same partition_text output as main (LF and CRLF cases in the cleaner and partitioner tests). A list after a lead-in still splits, including Ingredients:\n* 4 eggs\n* 2 cups of flour, the existing middle-dot and star lists, and no-space Unicode bullets.

Locally: cleaners, nlp, test_text.py, test_text_type.py and test_md.py pass (450); the 7 new cases fail on the previous head. ruff 0.15.2 check and format pass.

After a line that ends in a number, `*`, `·` and `∙` followed by another
operand, such as -4, .5, (4 + 5) or 4, continue the product wrapped from the
line above, so they no longer start a list item and the paragraph stays
whole. A list after a lead-in line still splits, also when its items start
with numbers.

@cragwolfe cragwolfe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the new head 3d94ba13d9f307b93d9af0a7a2f24590ae3921b8 with GPT Pro. The previously reported numeric multiplication examples are repaired. One P2 boundary-classification defect remains.

P2 — Wrapped signs and symbolic products still lose their operators (unstructured/cleaners/core.py:163–170,211–217). For default partition_text(text="Observations:\n- The overnight temperature dropped to\n- 5 degrees Celsius.\n"), both dash-prefixed lines pass _starts_list_item(). Once in list mode, the helper accepts the signed continuation as another item, bypassing the non-bullet continuation fallback. The isolated block reaches group_bullet_paragraph() and clean_bullets(), producing ListItem("The overnight temperature dropped to") and ListItem("5 degrees Celsius."): the negative temperature loses its minus sign. The baseline long-line branch normalizes the intact paragraph and preserves that sign. The terminal newline makes this example reach the changed path through the default paragraph grouper.

The same route loses symbolic multiplication for Calculations:\n- Multiply the two variables x\n* y to obtain the result\n: the preceding-character and operand checks both exclude variables, so x * y becomes two items with no star. Numeric subtraction (Calculations:\n- Subtract the second value from 10\n- 4 to obtain six\n) also loses its operator because the guard excludes -. These are one remaining ambiguity in the new subdivision path, not defects introduced by the unchanged downstream cleaner.

Keep the correction local to subdivision: retain the original paragraph when a prospective item can continue signed prose or an expression, before routing it into bullet grouping. Add cleaner and default-partitioner regressions for these cases with LF/CRLF, asserting sign/operator preservation. Cover symbolic operands on both sides; expanding only the right-operand check misses symbolic left operands, and requiring a numeric preceding character misses negative values after prose. Retain genuine dash/star/middle-dot lists, numeric ingredients, successive lead-ins, and no-space Unicode bullets.

I verified the finding against the full current change and fresh main source. No local tests or reproductions were run; author measurements remain claims. Exact-head CI, Security, CodeQL, and benchmark workflows still await approval, with only Socket checks successful. Because the source review is not clean, workflow approval and auto-merge remain inactive.

(authored by codex)

@L4XB

L4XB commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Before another round, I'd like to ask how you want the scope, because the remaining forms can only be told apart by what the words mean.

A dash or star line after a line without end punctuation is a list item in Steps:\n- Preheat the oven\n- 5 minutes later, add the eggs and in Packages:\n* react\n* vue, and a continuation in these examples. Each cue that separates them is a word-level heuristic: a trailing number before - 4, a dangling to before - 5, single-letter variables around *. Each round so far found a form beyond the last cue (by about\n- 5, x2\n* y2, a Unicode minus would be next). Main avoids the question by never splitting such a paragraph, at the cost of merging every list after a lead-in into one text, which is what this PR fixes.

Two ways forward, and I'm fine with either:

  1. Keep the current rules plus one more of the same kind as 3d94ba1: after a line that ends in a number, - 4 and + 4 continue it. A signed number or a symbolic product wrapped onto a line that starts with - or * after prose would still read as an item.
  2. Close this PR and keep main's behavior for lists after a lead-in.

Which do you prefer?

@cragwolfe

Copy link
Copy Markdown
Contributor

Thanks for working through the review iterations. I think we can move this forward by narrowing this PR to simple colon-led lists using •, ●, and ○, while preserving the whole paragraph when the structure is ambiguous.

Let’s defer dash (-) and star (*) markers to a separate follow-up. They can represent list markers, arithmetic operators, ordinary punctuation, or Markdown syntax such as emphasis and thematic breaks. We should agree on which contexts qualify as lists and capture those rules in examples before adding more heuristics.

That gives this PR a concrete target: split the supported bullet forms, preserve ambiguous text, and cover both behaviors with focused tests. Dash/star support can then follow separately with an agreed set of recognition rules.

(authored by codex)

…et glyph

Following review, only lists whose items start with the bullet glyphs U+2022, U+25CF or U+25CB after a line that ends with a colon are split off. A paragraph with a dash, star or middle-dot line, a bullet inside a line, a bullet without a lead-in or a line that may continue an item stays whole and is grouped as before. Dash and star lists are left to a follow-up with agreed recognition rules.
@L4XB

L4XB commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, that is a clear target. Done in d95b0f9:

  • Only lists after a : lead-in whose items start with •, ● or ○ are split off. The operand and emphasis heuristics are gone, and UNAMBIGUOUS_BULLETS_RE is no longer added to patterns.py.
  • Every other shape keeps the paragraph whole and is grouped exactly as on main: a line that starts with -, *, · or another bullet glyph (or e ), a bullet inside a line, a bullet without a lead-in, and any non-lead-in line after an item.
  • The tests cover both sides: the supported lists (each glyph, short and long items, successive and indented lists, through partition_text() too) and the ambiguous shapes, including dash, star and middle-dot lists, which now stay whole. 16,000 random ambiguous paragraphs (LF and CRLF) match main, and 3,000 random supported lists keep every item as a ListItem.

I updated the PR description to the narrowed scope. Dash and star lists can follow in a separate PR once the recognition rules are agreed.

@cragwolfe cragwolfe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed d95b0f9318d12c810e5cd1f54b692e4357cda867 with GPT Pro against the agreed simplified scope. Dash/star list recognition remains deferred. The previous wrapped-sign and symbolic-operator examples now retain baseline behavior, and the supported simple lists, whole-paragraph rejection, and custom splitter bypass are implemented as intended.

One P2 preservation regression remains, detailed inline: inline emphasis and middle-dot punctuation inside supported-marker items or their lead-ins can still be removed after subdivision. A conservative whole-paragraph fallback can address this without expanding the accepted grammar.

Verified against the complete final diff, surrounding base/head source and consumers, prior discussion, and checked-in tests. No local tests or reproductions were run. Exact-head CI has no failed checks; Docker and benchmark jobs are still running, while unit, lint, and CodeQL checks have passed.

(authored by codex)

Comment thread unstructured/cleaners/core.py Outdated
text = line.strip()
is_item = text.startswith(_LEAD_IN_LIST_BULLETS)
body = text[1:] if is_item else text
if any(bullet in body for bullet in _LEAD_IN_LIST_BULLETS) or (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 — Preserve inline punctuation when isolating supported lists. This body check excludes only •, ●, and ○, but the downstream BULLET_SPLIT_RE_0W also splits at inline *, ·, and ∙. For default partition_text(text="Requirements:\n• Tighten the bolt to 10 N·m of torque\n"), the helper admits the supported list and isolates it. group_bullet_paragraph() splits before ·; classification and clean_bullets() then produce separate item texts Tighten the bolt to 10 N and m of torque, deleting the unit separator. The baseline's long-fragment branch normalizes the original paragraph intact and preserves N·m. The terminal newline makes this example reach the changed path through the default grouper.

The same admission gap removes inline emphasis from a supported item such as • This installation must always be *really* safe, and can fragment the lead-in Required *production* settings: when a long supported item follows. These are content-preservation failures within the agreed scope, not requests to recognize star or middle-dot lists.

Keep the accepted marker set unchanged. Conservatively return the entire original paragraph when item bodies or surrounding text contain delimiters that the downstream splitters would reinterpret. Add helper, public-cleaner, and default-partitioner regressions for inline emphasis in items and lead-ins, N·m, and spaced 3 · 4 / 3 ∙ 4, with LF/CRLF and a late rejection after an earlier supported list. Assert whole-paragraph fallback and baseline content preservation. No new arithmetic or emphasis grammar is needed.

(authored by codex)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 08d4f79 with the conservative fallback, keeping the marker set unchanged: if any line, after its leading •/●/○ for an item, still contains a glyph from UNAMBIGUOUS_BULLETS_PATTERN (the set BULLET_SPLIT_RE_0W and PARAGRAPH_PATTERN_RE cut at), the helper returns the original paragraph. That covers 10 N·m, *really* in an item, Required *production* settings: as a lead-in, spaced 3 · 4 and 3 ∙ 4, and inline lists.

Regressions, each with LF and CRLF: the helper returns [paragraph] and group_broken_paragraphs() returns main's text for all five shapes plus a late rejection (a supported Fruits: list followed by Vegetables: with 2 · 3 kg in its item). Through the default partition_text(), N·m, *really* (CRLF) and the late rejection come out as the same single NarrativeText as on main. The 15 new cases fail on d95b0f9. The random battery now mixes these lines into the ambiguous paragraphs: 0 of 16,000 differ from main with this commit (1,676 differed on d95b0f9), and all 3,000 supported lists still keep every item.

… inside it

The bullet splitters downstream also cut at an unambiguous glyph inside a line, so an isolated list lost the middle dot of "10 N·m" or the stars of "*really*", and a lone lead-in could fragment at "*production*". A paragraph with such a glyph after a line's leading marker is now grouped exactly as before.

@cragwolfe cragwolfe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 08d4f79affefefb61c32b8612000a510e42b49e1 with GPT Pro across the full current change and related parsing code. The prior inline-emphasis and middle-dot preservation finding is resolved. One P2 remains: an adjacent supported bullet and minus sign can pass the new admission check but fail the downstream bullet matcher, allowing the minus to be removed. Details and a conservative fallback fix are inline.

The agreed scope remains simple colon-led •, ●, and ○ lists with whole-paragraph fallback for ambiguity; dash/star list support stays deferred. Source and checked-in tests were reviewed; no local tests were run. Exact-head CI currently has 45 successful checks, 6 running, and 1 skipped; running checks are not treated as passed.

(authored by codex)

Comment thread unstructured/cleaners/core.py Outdated
body = text[1:] if is_item else text
# -- the bullet splitters downstream also cut at a glyph inside a line, such as the "·"
# in "10 N·m" or the "*" of "*really*", so such a paragraph is grouped as before --
if UNAMBIGUOUS_BULLETS_RE.search(body) or (not is_item and UNICODE_BULLETS_RE.match(text)):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 — Reject supported prefixes that the downstream matcher refuses. The helper accepts •- 5 °C: startswith() accepts •, the remaining dash is outside UNAMBIGUOUS_BULLETS_RE, and the other guard runs only for non-items. But UNICODE_BULLETS_RE rejects •- because its final negative lookahead forbids an adjacent bullet glyph.

For partition_text(text="Allowed temperature offsets for this process:\n•- 5 °C\n• 0 °C\n") (including the final newline), the original long paragraph preserves the signed value. After this helper isolates the list, the rejected prefix sends it through the short-line branch instead of group_bullet_paragraph(). PARAGRAPH_PATTERN_RE separates • from - 5 °C; final partitioning discards the lone bullet and cleans the dash from the remaining fragment, yielding ListItem("5 °C").

Conservatively return [paragraph] during the paragraph-wide preflight whenever is_item is true but UNICODE_BULLETS_RE.match(text) is None. This preserves the existing downstream acceptance rule and atomic fallback. Add LF/CRLF regressions for the adjacent dash/en-dash forms and a rejection after an earlier supported list; retain valid no-space ○item and spaced • - 5 °C behavior. The acceptance criterion is baseline content preservation through the helper, public cleaner, and default partitioner.

(authored by codex)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 8884905 with the conservative rule you suggested, written as one condition in the preflight: a line counts as an item exactly when UNICODE_BULLETS_RE.match(text) reads a bullet there (is_item != bool(...) returns the original paragraph). So •- 5 °C and •– 5 °C, which the matcher refuses because of its lookahead, keep the paragraph whole, and the earlier rule for non-item lines that start with another glyph is the other half of the same check.

Regressions with LF and CRLF: the adjacent dash and en-dash forms and a rejection after an earlier supported Fruits: list return [paragraph] from the helper and main's text from group_broken_paragraphs(); through partition_text() the CRLF dash form is the same single NarrativeText as on main. Retained: ○item without a space still splits, and spaced • - 5 °C still becomes ListItem("- 5 °C") with its sign. The 7 new cases fail on 08d4f79. The random battery now also mixes •- 5 °C, •– 5 °C, ●-3 dB and ○– 2 points into the ambiguous paragraphs: 1,540 of 16,000 differed from main on 08d4f79, 0 with this commit (two seeds), and all supported lists keep every item. Broader suites: 976 passed, 1 skipped.

… bullet on an item line

UNICODE_BULLETS_RE refuses a bullet that another glyph follows directly, as in "•- 5 °C", so such an isolated item went through the short-line branch and lost its minus sign. A line now counts as an item exactly when that matcher reads a bullet there; otherwise the paragraph is grouped as before.

@cragwolfe cragwolfe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 8884905854ed9cdf28e70f19a10734c2008b3fef against 803b9005f9f2406b839e9bbec603f40e6d322693 with GPT Pro. No actionable defects remain within the agreed scope: simple colon-led •/●/○ lists, with whole-paragraph fallback for ambiguous input. Dash/star list recognition remains deferred.

The previous P2 minus-sign loss for •- 5 °C is fixed: the new matcher-agreement check preserves the original paragraph before any partial split. Cleaner and partitioner regression coverage supports the repair. Earlier punctuation/emphasis and custom-splitter findings remain resolved.

Exact-head CI reports 51 successful checks and one skipped check. This review used source and checked-in tests; no local project tests or reproductions were run.

(authored by codex)

@cragwolfe
cragwolfe added this pull request to the merge queue Oct 24, 2026
Merged via the queue into Unstructured-IO:main with commit adc72fd Oct 24, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants