Skip to content

Keep hyphens in hyphenated names (#310) - #311

Merged
dfalster merged 3 commits into
masterfrom
fix-hyphen-310
Nov 14, 2026
Merged

dfalster merged 3 commits into
masterfrom
fix-hyphen-310

Conversation

@dfalster

Copy link
Copy Markdown
Member

Fixes #310.

strip_names() turned every punctuation mark into a space, hyphens included. A hyphenated genus (Van-royena) or epithet (plantago-aquatica) therefore became two words, every later word shifted along, and the binomial and trinomial match steps matched the wrong names: "Van-royena" aligned to the species Van-royena castanosperma, and "Acacia undulata-elegans var. …" to Acacia undulata var. elegans. A hyphen between two letters is now kept; hyphens next to digits or spaces (collector numbers, -- intergrades) are still removed.

The issue's five examples are added to the matcher benchmark and to a new test file. Measurements and checks are in the first comment.

🤖 Generated with Claude Code

strip_names() turned every hyphen into a space, so a hyphenated genus or
epithet became two words and the binomial/trinomial keys matched the wrong
names. A hyphen between two letters is now kept; others still go. Adds the
issue's examples to the matcher benchmark and a dedicated test file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dfalster

Copy link
Copy Markdown
Member Author

How this was checked

All against data version 2024-10-11.

  • The issue's five examples. I reproduced all five on master. With this change each gives the result the issue expects:

    Input Now aligns to Step
    Van-royena genus Van-royena sp. […] 12a
    Van-royena fooensis genus Van-royena sp. […] 12a
    Alisma plantago-aquatica subsp. … Alisma plantago-aquatica 10a
    Acacia undulata-elegans var. … Acacia undulata-elegans 10b, then updated to Acacia paradoxa
    Araucaria van-geertii subsp. … Araucaria van-geertii 10b
  • Exactly spelled hyphenated names were never affected. Van-royena castanosperma, Duval-jouvea maritima, Apera spica-venti/-ventii, Acacia undulata-elegans and Alisma plantago-aquatica align to themselves on master and here, through the exact-match steps 01c and 01d, which don't use the stripped keys.

  • No existing alignment changed.

    • All 239 rows of the matcher benchmark pass unchanged.
    • The full-output snapshot (_snaps/match_branches.md) differs only by the 5 new rows. I checked this by parsing both versions: none of the old 239 rows changed.
    • The only other benchmark that moved is standardise_names.csv: Psychotria daphnoides f. 'small-leaved' now strips to … small-leaved, which is the intended change.
  • The suite. devtools::test() passes in full.

Tests added

  • tests/testthat/test-hyphenated_names.R covers three things:
    • strip_names() unit cases: hyphens between letters are kept; collector numbers, -- intergrades, and spaced or leading hyphens are still removed.
    • The issue's five examples, with name, rank and match step, and checks that the reference binomials keep the hyphen.
    • That the exact hyphenated names still align to themselves.
  • Benchmark rows. The five examples are added to benchmarks/test_matches_alignments_updates.csv, with alignment_code-OLD set to NA, as for other new rows.

The word(…, 2, 2) guard mentioned in the issue

APCalign has no guard of that form: match_10a here is a plain binomial %in% lookup. A bare one-word hyphenated name such as "Van-royena", now one word, falls through to the genus steps without error (tested).

Merge order

This touches only strip_names() and tests, so it is independent of #309. Whichever merges second regenerates the snapshot or resolves the NEWS.md conflict.

@dfalster
dfalster requested a review from ehwenk November 14, 2026 09:37
From an independent review: names written with a space where the reference
has a hyphen (Ipomoea pes caprae) matched only by accident before and now
aligned worse. match_taxa() now puts the hyphen back where the reference
names use the word only hyphenated. A hyphen after a rank marker, qualifier
or full stop (sp-Mt, var.-x, x-aneura) still separates words.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dfalster

Copy link
Copy Markdown
Member Author

Independent review, and follow-up fix (e82eced)

Copilot and Antigravity are out of quota, so a fresh Claude agent reviewed this PR, working from the code. I checked its findings against the code before acting on them.

Confirmed regression, now fixed. The reviewer took all 848 hyphenated APC/APNI names and rewrote each with a space in place of the hyphen (Ipomoea pes caprae subsp. brasiliensis). Against master, 76 of them aligned worse with the first version of this PR, and 9 of those went to a different species (e.g. Ptilotus roseo albus var. conglomeratus → Ptilotus roei). On master these names matched only because the hyphen was stripped from the reference names too. fuzzy_match() can't rescue them, because the spaced name has one word more than the hyphenated reference.

The fix (in match_taxa.R and load_taxonomic_resources.R; fuzzy_match.R is untouched):

  • load_taxonomic_resources() now also returns hyphenated_words: the hyphenated words of the stripped reference names (390 in 2024-10-11, e.g. pes-caprae, van-royena, roseo-albus).
    • A word is left out if its parts also occur as two separate words in some reference name, so joining them would be ambiguous.
    • Computing the list adds 0.2 s to loading.
  • match_taxa() puts the hyphen back into the stripped input name (rehyphenate()), so the name and the binomial and trinomial keys built from it line up with the references again.
  • strip_names() keeps treating a hyphen as a separator when it touches a full stop or follows a rank marker, qualifier or hybrid marker (sp.-Mt Magnet, sp-Mt Magnet, var-intermedia, aff-aneura, x-aneura). The reviewer found that these became single words.
  • U+2010 and U+2011 count as hyphens.

Re-measured on the reviewer's own inputs, comparing master with this branch:

Variant of the 848 hyphenated names Worse Better
space for hyphen 4 (was 76) 9
- for hyphen 4 (was 76) 9
hyphen left out 1 71
+ subsp. fooensis 7 69
ALL CAPS 12 7
en-dash, U+2010, -- 0 2

What remains "worse", and why I left it:

  • Bare spaced genera (Van royena, Filix mas, Balls headleya) are now unaligned. On master they aligned to an arbitrary species of the genus, which is exactly the bug reported in Hyphenated genera and epithets are split into two words when stripping names, giving wrong matches #310.
  • Pseudo Elephantopus spicatus now gives the accepted Pseudelephantopus spicatus instead of the synonym.
  • ALL-CAPS infraspecific names drop to the species. This is an existing ALL-CAPS limitation: ACACIA ANEURA VAR. INTERMEDIA does the same on master, so master was right for the hyphenated ones only by accident.
  • Series names are the one real loss. ser. Pantogynae-Pleurogynae subsp. fooensis and three like it now fall back to the genus. They are series-rank names with a made-up subspecies, so I've left them.
  • Messy inputs. Two changed: Acacia dealbata-mearnsii (a single-hyphen intergrade) now gives the genus rather than Acacia dealbata, and bare Duval jouvea is now unaligned. Both were right on master only by the same accident.

Benchmark. The 239 existing rows are unchanged. 9 rows are added: the 5 issue examples, plus Ipomoea pes caprae subsp. brasiliensis, Van royena castanosperma, Ptilotus roseo albus var. conglomeratus and Acacia sp-Mt Magnet. The snapshot differs only by those 9 rows; I parsed both versions to check.

Tests. test-hyphenated_names.R now also covers:

  • the marker and full-stop cases in strip_names()
  • rehyphenate()
  • seven space-for-hyphen names, each aligning to its hyphenated name
  • the rank-marker hyphens

devtools::test() passes in full.

Merge order. #309 also edits load_taxonomic_resources.R and match_taxa.R. Whichever merges second will need a small merge, and its snapshot accepted.

# Conflicts:
#	NEWS.md
#	R/load_taxonomic_resources.R
#	R/match_taxa.R
@dfalster
dfalster merged commit 55d95ac into master Nov 14, 2026
4 checks passed
@dfalster
dfalster deleted the fix-hyphen-310 branch November 14, 2026 19:34
dfalster added a commit that referenced this pull request Nov 15, 2026
Acts on the maintainer decisions on the open questions in #309's first
comment.

- **`collapse_to_higher_taxon`: docs now describe the code.**
`accepted_name` is `Genus sp.`, `suggested_name` is `Genus sp.
[collapsed names: ...]`; `taxon_rank`, `taxon_ID` and `scientific_name`
stay those of the most likely taxon. Output unchanged; a dead line that
"demoted" the rank in a table column never joined back is removed.
Pinned by new assertions.
- **Old downloaded versions are not pruned** (decision recorded in
AGENTS.md; location already documented).
- **Benchmarks tightened.** The 118 rows that only asserted
`suggested_name != updated_name` now assert the full expected
`suggested_name`; each was checked against the target genus/family the
row originally named. `test_splits_synonyms.csv` is now asserted
(taxon_ID and status), with two rows updated for APC data changes.
- **LICENSE** names Elizabeth Wenk, matching `cph` in DESCRIPTION.

Merges cleanly with #311 and passes together. Details in the first
comment.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

Hyphenated genera and epithets are split into two words when stripping names, giving wrong matches

1 participant