Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions python/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
- Added `Name.is_valid()` to check the basic validity of first and last names.
- `Name.case_normalize()` now repairs lowercase initials (for example, `C.s.` to `C.S.`); this is applied automatically by `create_paper()` and `create_volume()`.

### Changed

- Fixed a bug with `xml.ensure_minimal_diff()` that would sometimes break with markup-containing tags.

### Removed

- Removed `NameSpecification.case_normalize()` in favor of `.normalize()`.
Expand Down
8 changes: 8 additions & 0 deletions python/acl_anthology/utils/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
TAGS_WITH_MARKUP = {
"b",
"i",
"u",
"sc",
"tt",
"a",
"fixed-case",
"title",
"abstract",
Expand Down Expand Up @@ -280,6 +284,10 @@ def ensure_minimal_diff(elem: etree._Element, reference: etree._Element) -> None
for key, value in attribs:
elem.set(key, value)

# If element contains markup, we do NOT recurse into its children and stop here
if elem.tag in TAGS_WITH_MARKUP:
return

# Sort child elements to match order in reference, if element allows reordering
if elem.tag in TAGS_WITH_UNORDERED_CHILDREN:
# Follow tag order in reference, with keys new in elem coming last
Expand Down
22 changes: 22 additions & 0 deletions python/tests/utils/xml_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ def test_xml_indent(inp, out):
"<title><i>Italics</i><b>Bold</b></title>",
False,
),
( # Formatting markup differences are not logically equivalent
"<abstract><b>Important</b> message</abstract>",
"<abstract>Important message</abstract>",
False,
),
)


Expand Down Expand Up @@ -388,6 +393,23 @@ def test_xml_assert_equals(a, b, should_be_equal):
<attachment type="software" hash="079d4f4b">2022.acl-long.48.software.zip</attachment>
</paper>""",
),
# Added markup after <tex-math>
(
"<abstract><tex-math>a</tex-math> <b>xxx</b></abstract>",
"<abstract><tex-math>a</tex-math> xxx</abstract>",
"<abstract><tex-math>a</tex-math> <b>xxx</b></abstract>",
),
# Test <par/>
(
"<abstract>a<par/><b>xxx</b></abstract>",
"<abstract>a<par/>xxx</abstract>",
"<abstract>a<par/><b>xxx</b></abstract>",
),
(
"<abstract><i>a</i><par/><b>xxx</b></abstract>",
"<abstract><i>a</i>\n<b>xxx</b></abstract>",
"<abstract><i>a</i><par/><b>xxx</b></abstract>",
),
)


Expand Down
Loading