Skip to content

Commit b40efb0

Browse files
committed
Tighten the citation-range and chained-heading tests
Re-review on #163: the <sup> range case passed with or without the dash fix, so both range cases now also assert no minus sign appears; the chained-heading test pins the exact output. The two dash sets in the XML extractor are one _DASHES constant, and the welded-heading docstring says a heading after any ": " is split. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qm4PkP29FwrZN1NkwYjWMs
1 parent a5c9185 commit b40efb0

4 files changed

Lines changed: 17 additions & 7 deletions

File tree

‎src/linkml_reference_validator/etl/extract/xml.py‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ def is_stub_notice(text: str) -> bool:
119119
)
120120

121121

122+
#: Dashes that can join the numbers of a citation range ("1-3", "1–3").
123+
_DASHES = "-\u2010\u2011\u2012\u2013\u2014\u2015\u2212"
124+
125+
122126
def _is_citation_marker(tag: Tag) -> bool:
123127
"""Whether ``tag`` is a bibliographic citation marker.
124128
@@ -144,7 +148,7 @@ def _is_citation_marker(tag: Tag) -> bool:
144148
loose = "".join(
145149
str(child) for child in tag.children if type(child) in (NavigableString, CData)
146150
)
147-
return re.fullmatch(r"[\s,;\-\u2010-\u2015\u2212]*", loose) is not None
151+
return re.fullmatch(rf"[\s,;{re.escape(_DASHES)}]*", loose) is not None
148152

149153

150154
def _welded_to_next_word(tag: Tag) -> bool:
@@ -192,9 +196,10 @@ def walk(tag: Tag) -> str:
192196
# No space before a dash that follows: "[1</xref>-3]" is
193197
# a range, and " -3" would read as a minus sign.
194198
following = child.next_sibling
195-
dash_next = isinstance(following, NavigableString) and str(
196-
following
197-
)[:1] in "-\u2010\u2011\u2012\u2013\u2014\u2212"
199+
dash_next = (
200+
isinstance(following, NavigableString)
201+
and str(following)[:1] in _DASHES
202+
)
198203
value = " " + value + ("" if dash_next else " ")
199204
elif lead_in:
200205
# A paragraph's bold lead-in label ("<bold>R 2.6</bold>We

‎src/linkml_reference_validator/etl/sources/pmid.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,12 @@ def _set_off_welded_headings(text: str) -> str:
5757
5858
Only a listed heading, at the start of the text or right after a sentence
5959
ends, and directly followed by a capital letter, so "The Results were"
60-
and "Methodsical" are left alone. Title-case headings only, on purpose:
61-
all-caps welds ("RESULTSThe") and welds after a bracket
62-
("exposures)Conclusions") are left as they are.
60+
and "Methodsical" are left alone. A heading right after ": " also counts,
61+
which splits chained headings ("AbstractBackgroundIt" becomes "Abstract:
62+
Background: It") and a welded heading after any earlier label ("Aim:
63+
MethodsWe"). Title-case headings only, on purpose: all-caps welds
64+
("RESULTSThe") and welds after a bracket ("exposures)Conclusions") are
65+
left as they are.
6366
6467
Examples:
6568
>>> _set_off_welded_headings("IntroductionThe spider. ResultsA total.")

‎tests/test_inline_abstract_headings.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,4 @@ def test_bold_after_a_full_stop_but_not_welded_is_not_a_label():
124124
def test_chained_welded_headings_are_all_split():
125125
text = render("<Abstract><AbstractText>AbstractBackgroundIt began.</AbstractText></Abstract>")
126126
assert found("It began", text), text
127+
assert text == "Abstract: Background: It began."

‎tests/test_welded_markers.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,4 @@ def test_citation_range_with_its_first_number_linked_keeps_its_dash(body, quote)
181181
"""A dash after a padded marker must not become a minus sign."""
182182
text = extract(body)
183183
assert found(quote, text), text
184+
assert "neg" not in SupportingTextValidator.normalize_text(text), text

0 commit comments

Comments
 (0)