Skip to content

Commit 5ff9aaf

Browse files
authored
Merge pull request #184 from gbif/fix/60-code-inference
Infer a code only from evidence of one code (#60)
2 parents dda9bfb + eb77a38 commit 5ff9aaf

61 files changed

Lines changed: 3562 additions & 4060 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎VERSIONS.md‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Versions
2+
3+
The major changes of the Rust name parser. The engine and all its bindings share one version: the
4+
crate `gbif-name-parser`, the CLI, the Python and R packages and the Java `name-parser-rust`. The
5+
model they implement is the Java `org.gbif:name-parser-api`, versioned on its own (see its
6+
[VERSIONS.md](https://github.com/gbif/name-parser/blob/dev/VERSIONS.md)).
7+
8+
## Unreleased (`main`, api 6.0.0)
9+
10+
- No `Informal` parse result any more: a name in open nomenclature is a parsed name of type
11+
`INFORMAL`, with `ParsedName::anchor()` for the taxon it hangs off (#134).
12+
- `Authorship.inAuthors` from in citations (#172); title abbreviations from IPNI tell a title from an
13+
author (#147).
14+
- Made-up ranks, zoological sections within a genus, vectors and plasmids, all-capital authors
15+
(#167, #171, #124, #123).
16+
- The nomenclatural code only from evidence of one code, never from the style of the authorship
17+
(#60). Only Fries and Persoon are sanctioning authors. An unranked infrageneric name or a
18+
zoological subgenus is written in brackets; a subgenus otherwise with `subg.`, or `subgen.` under
19+
the bacterial code.
20+
21+
## 0.4.0 (2026-10-14, api 5.4.0)
22+
23+
`Authorship.bracketedYear` and `Informal.candidatus`; serovars with their own rank and Salmonella's
24+
`ser.`; misspelt rank markers; a whitelist of real names with a blacklisted epithet.
25+
26+
## 0.3.0 (2026-10-08, api 5.1.0 to 5.3.0)
27+
28+
`Authorship.anonymous` and the sanctioning author on `Authorship`; taxonomic notes (`non`, `sensu`,
29+
`auct.`) and authorship placeholders no longer read as authors; notho rank markers; CJK authors
30+
written surname first; the dual-path test harness, so a name parses alike with its authorship
31+
embedded or given separately.
32+
33+
## 0.2.x (2026-08 to 2026-10, api 5.0.1)
34+
35+
- 0.2.0 (2026-08-25): the first release on all four channels (Maven, crates.io, PyPI, CLI). The
36+
informal phrase swallows a trailing authorship, and a rank hint beats an author particle.
37+
ChecklistBank parses through this engine since.
38+
- 0.2.1 (2026-09-04): no silent truncation of numbers, numbered infraspecifics or codes after a rank
39+
marker (#16); the R package builds for CRAN.
40+
- 0.2.2 (2026-10-02): WoRMS' temporary names, quoted names, trace fossils and organism labels.
41+
42+
## 0.1.0 (2026-07-14, api 5.0.0)
43+
44+
The first release: a port of the Java 4.2 pipeline, cross-validated against Java on 11,302 test
45+
names and 6.4 million ChecklistBank names. A native CLI and bindings for Java (FFM, struct-only
46+
wire, no JSON), Python and R. `NameType.IDENTIFIER` for identifiers such as BOLD BINs.
47+
48+
## Before Rust: the Java parser
49+
50+
- 5.0.0 (2026-07): the Java implementation removed, the api alone left in Java.
51+
- 4.x (2026): a new Java step pipeline with code inference; 4.2.0 is what Rust ported.
52+
- 3.x (2017 to 2026): the model in its own `name-parser-api`, authorships parsed down to individual
53+
authors.
54+
- 2.x (2014 to 2017): GBIF's regex parser, filling the `ParsedName` of the GBIF api.

‎bindings/java/src/test/java/org/gbif/nameparser/rust/NameParserRustSmokeTest.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class NameParserRustSmokeTest {
4747

4848
@Test
4949
void parsesAVulpesSubspeciesWithCombinationAuthorship() throws UnparsableNameException {
50-
ParsedName pn = parser.parse("Vulpes vulpes silaceus Miller, 1907", null, null, null).orElseThrow();
50+
ParsedName pn = parser.parse("Vulpes vulpes silaceus Miller, 1907", null, null, NomCode.ZOOLOGICAL).orElseThrow();
5151

5252
assertEquals("Vulpes", pn.getGenus());
5353
assertEquals("vulpes", pn.getSpecificEpithet());
@@ -81,7 +81,7 @@ void anonymousAuthorshipCrossesTheWireAndRendersPerCode() throws UnparsableNameE
8181
assertEquals(List.of("Bennett"), pn.getBasionymAuthorship().getAuthors());
8282
assertEquals("([Bennett], 1830)", pn.authorshipComplete());
8383

84-
ParsedName bot = parser.parse("Physalospora rubiginosa (Fr.) anon.", null, null, null).orElseThrow();
84+
ParsedName bot = parser.parse("Physalospora rubiginosa (Fr.) anon.", null, null, NomCode.BOTANICAL).orElseThrow();
8585
assertTrue(bot.getCombinationAuthorship().isAnonymous());
8686
assertFalse(bot.getCombinationAuthorship().hasAuthors());
8787
assertEquals(NomCode.BOTANICAL, bot.getCode());

‎bindings/r/tests/testthat/test-parse-names.R‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ test_that("scalar columns match the known Java/Python oracle values", {
1919
expect_equal(out$specificEpithet[1], "alba")
2020
expect_true(is.na(out$code[1]))
2121
expect_false(out$candidatus[1])
22-
# Vulpes vulpes silaceus Miller, 1907 -> zoological subspecies
23-
expect_equal(out$rank[2], "SUBSPECIES")
24-
expect_equal(out$code[2], "ZOOLOGICAL")
22+
# Vulpes vulpes silaceus Miller, 1907 -> a trinomial of no code: the year
23+
# tells none (#60)
24+
expect_equal(out$rank[2], "INFRASPECIFIC_NAME")
25+
expect_true(is.na(out$code[2]))
2526
expect_equal(out$infraspecificEpithet[2], "silaceus")
2627
# Tobacco mosaic virus -> unparsable, NameType OTHER (ParseError.code is
2728
# VIRUS, but NameType has no VIRUS variant -- confirmed against the core's

‎crates/nameparser-cli/tests/parse_cli.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ fn parse_stdin_to_stdout_matches_a_verified_java_cli_transcript() {
163163
);
164164
assert_eq!(
165165
lines[1],
166-
r#"{"line":2,"input":"Vulpes vulpes silaceus Miller, 1907","parsed":{"rank":"SUBSPECIES","code":"ZOOLOGICAL","genus":"Vulpes","specificEpithet":"vulpes","infraspecificEpithet":"silaceus","candidatus":false,"type":"SCIENTIFIC","extinct":false,"doubtful":false,"manuscript":false,"state":"COMPLETE","warnings":[],"combinationAuthorship":{"authors":["Miller"],"exAuthors":[],"year":"1907","bracketedYear":false,"anonymous":false},"basionymAuthorship":{"authors":[],"exAuthors":[],"bracketedYear":false,"anonymous":false}}}"#
166+
r#"{"line":2,"input":"Vulpes vulpes silaceus Miller, 1907","parsed":{"rank":"INFRASPECIFIC_NAME","genus":"Vulpes","specificEpithet":"vulpes","infraspecificEpithet":"silaceus","candidatus":false,"type":"SCIENTIFIC","extinct":false,"doubtful":false,"manuscript":false,"state":"COMPLETE","warnings":[],"combinationAuthorship":{"authors":["Miller"],"exAuthors":[],"year":"1907","bracketedYear":false,"anonymous":false},"basionymAuthorship":{"authors":[],"exAuthors":[],"bracketedYear":false,"anonymous":false}}}"#
167167
);
168168
assert_eq!(
169169
lines[2],

‎crates/nameparser-py/python/tests/test_api.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def sci(name: str, *args, **kwargs) -> nameparser.ParsedName:
2929
def test_vulpes_subspecies_core_fields_and_combination_authorship():
3030
# Golden reference row 1 (see crates/nameparser/src/model/name.rs's
3131
# `wire_matches_reference_row_1_vulpes_vulpes_silaceus`).
32-
pn = nameparser.parse("Vulpes vulpes silaceus Miller, 1907")
32+
pn = nameparser.parse("Vulpes vulpes silaceus Miller, 1907", code="ZOOLOGICAL")
3333

3434
assert isinstance(pn, nameparser.ParsedName)
3535
assert pn.rank == "SUBSPECIES"
@@ -145,7 +145,7 @@ def test_parse_all_returns_none_for_unparsable_without_raising():
145145

146146

147147
def test_to_dict_uses_wire_field_names_and_string_enums():
148-
pn = nameparser.parse("Vulpes vulpes silaceus Miller, 1907")
148+
pn = nameparser.parse("Vulpes vulpes silaceus Miller, 1907", code="ZOOLOGICAL")
149149
d = pn.to_dict()
150150

151151
# Wire (JSON/Java) field names, not the Python snake_case getter names.

‎crates/nameparser/src/format.rs‎

Lines changed: 93 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,16 @@ fn phrase_leads_with_rank_marker(n: &ParsedName) -> bool {
347347
.eq_ignore_ascii_case(marker.trim_end_matches('.'))
348348
}
349349

350+
/// The Prokaryotic Code abbreviates subgenus "subgen." (Rules 10c, 34c), where the rank's own
351+
/// marker is the botanical "subg.".
352+
const BACTERIAL_SUBGENUS_MARKER: &str = "subgen.";
353+
354+
/// The marker of a bacterial subgenus, which is not the rank's own.
355+
fn bacterial_subgenus_marker(n: &ParsedName) -> Option<&'static str> {
356+
(n.rank == Rank::Subgenus && n.code == Some(NomCode::Bacterial))
357+
.then_some(BACTERIAL_SUBGENUS_MARKER)
358+
}
359+
350360
/// Java `NameFormatter.appendRankMarker(sb, rank, ifRank, nothoPrefix)` (both the 3- and
351361
/// 4-arg overloads; the 3-arg one passes `if_rank = None`). Returns true if a marker was
352362
/// appended.
@@ -731,9 +741,15 @@ fn build_name(n: &ParsedName, f: &Flags) -> Option<String> {
731741
);
732742
}
733743
sb.push(' ');
734-
// we show zoological infragenerics in brackets, but use rank markers for
735-
// botanical names (unless its no defined rank)
736-
if n.code == Some(NomCode::Zoological) {
744+
// Only a subgenus and an unranked infrageneric go in brackets, with no
745+
// marker: "infragen." is no marker anyone writes ("Calathus (Lindrothius)
746+
// Kurnakov, 1961", "Agaricus (Hypholoma) Fr."). A subgenus only when
747+
// zoological: of no code it keeps the marker it was written with, as a
748+
// botanical one must (ICN Art. 21.1). Every other rank shows its marker
749+
// ("Achillea sect. Ptarmica").
750+
if n.rank == Rank::InfragenericName
751+
|| (n.rank == Rank::Subgenus && n.code == Some(NomCode::Zoological))
752+
{
737753
sb.push('(');
738754
append_qualifier(&mut sb, n, NamePart::Infrageneric, f.show_qualifier);
739755
if f.hybrid_marker && has_notho(n, NamePart::Infrageneric) {
@@ -750,12 +766,14 @@ fn build_name(n: &ParsedName, f: &Flags) -> Option<String> {
750766
// If we know the rank we use explicit rank markers — this is how
751767
// botanical infrageneric names are formed, see
752768
// http://www.iapt-taxon.org/nomen/main.php?page=art21
753-
if append_rank_marker(
754-
&mut sb,
755-
n.rank,
756-
None,
757-
f.hybrid_marker && has_notho(n, NamePart::Infrageneric),
758-
) {
769+
let notho = f.hybrid_marker && has_notho(n, NamePart::Infrageneric);
770+
if let Some(marker) = bacterial_subgenus_marker(n) {
771+
if notho {
772+
sb.push_str(NOTHO_PREFIX);
773+
}
774+
sb.push_str(marker);
775+
sb.push(' ');
776+
} else if append_rank_marker(&mut sb, n.rank, None, notho) {
759777
sb.push(' ');
760778
}
761779
}
@@ -767,8 +785,13 @@ fn build_name(n: &ParsedName, f: &Flags) -> Option<String> {
767785
append_genus(&mut sb, n, f.hybrid_marker, f.show_qualifier, html);
768786
}
769787
if f.infrageneric {
770-
// additional subgenus shown for binomial. Always shown in brackets
788+
// additional subgenus shown for binomial. Always shown in brackets, with
789+
// its marker in bacteriology (Prokaryotic Code Rule 10c)
771790
sb.push_str(" (");
791+
if n.code == Some(NomCode::Bacterial) {
792+
sb.push_str(BACTERIAL_SUBGENUS_MARKER);
793+
sb.push(' ');
794+
}
772795
append_qualifier(&mut sb, n, NamePart::Infrageneric, f.show_qualifier);
773796
append_in_italics(&mut sb, infrageneric_epithet, html);
774797
sb.push(')');
@@ -1145,11 +1168,11 @@ mod tests {
11451168

11461169
#[test]
11471170
fn infrageneric_botanical_uses_rank_marker_and_minimal_drops_genus() {
1148-
// "subg." normalises to the "subgen." marker; minimal shows only the terminal epithet.
1171+
// the botanical "subg." marker; minimal shows only the terminal epithet.
11491172
let n = p("Astragalus subg. Cercidothrix");
11501173
assert_eq!(
11511174
n.canonical_name().as_deref(),
1152-
Some("Astragalus subgen. Cercidothrix")
1175+
Some("Astragalus subg. Cercidothrix")
11531176
);
11541177
assert_eq!(n.canonical_name_minimal().as_deref(), Some("Cercidothrix"));
11551178
}
@@ -1292,6 +1315,63 @@ mod tests {
12921315
);
12931316
}
12941317

1318+
#[test]
1319+
fn only_a_subgenus_or_an_unranked_infrageneric_goes_in_brackets() {
1320+
use crate::model::NomCode;
1321+
let canonical = |name: &str, code| {
1322+
parse(name, None, None, code)
1323+
.unwrap()
1324+
.canonical_name()
1325+
.unwrap()
1326+
};
1327+
assert_eq!(
1328+
canonical("Agaricus trib. Pholiota Fr.", None),
1329+
"Agaricus (Pholiota) Fr."
1330+
);
1331+
assert_eq!(
1332+
canonical("Hieracium unr. Verbasciformia", Some(NomCode::Botanical)),
1333+
"Hieracium (Verbasciformia)"
1334+
);
1335+
assert_eq!(
1336+
canonical("Carabus subgen. Megodontus", Some(NomCode::Zoological)),
1337+
"Carabus (Megodontus)"
1338+
);
1339+
// of no code a subgenus keeps its marker
1340+
assert_eq!(
1341+
canonical("Carabus subgen. Megodontus", None),
1342+
"Carabus subg. Megodontus"
1343+
);
1344+
// the Prokaryotic Code's "subgen.", in a species' brackets too (Rule 10c)
1345+
assert_eq!(
1346+
canonical(
1347+
"Acetobacter subg. Gluconoacetobacter",
1348+
Some(NomCode::Bacterial)
1349+
),
1350+
"Acetobacter subgen. Gluconoacetobacter"
1351+
);
1352+
let complete = |name: &str, code| {
1353+
parse(name, None, None, code)
1354+
.unwrap()
1355+
.canonical_name_complete()
1356+
.unwrap()
1357+
};
1358+
assert_eq!(
1359+
complete(
1360+
"Acetobacter (Gluconoacetobacter) liquefaciens",
1361+
Some(NomCode::Bacterial)
1362+
),
1363+
"Acetobacter (subgen. Gluconoacetobacter) liquefaciens"
1364+
);
1365+
assert_eq!(
1366+
complete("Acetobacter (Gluconoacetobacter) liquefaciens", None),
1367+
"Acetobacter (Gluconoacetobacter) liquefaciens"
1368+
);
1369+
assert_eq!(
1370+
canonical("Achillea sect. Ptarmica", None),
1371+
"Achillea sect. Ptarmica"
1372+
);
1373+
}
1374+
12951375
#[test]
12961376
fn complete_html_italicises_name_parts() {
12971377
assert_eq!(
@@ -1311,7 +1391,7 @@ mod tests {
13111391
p("Astragalus subg. Cercidothrix")
13121392
.canonical_name_complete_html()
13131393
.as_deref(),
1314-
Some("<i>Astragalus</i> subgen. <i>Cercidothrix</i>")
1394+
Some("<i>Astragalus</i> subg. <i>Cercidothrix</i>")
13151395
);
13161396
}
13171397
}

‎crates/nameparser/src/model/enums.rs‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,8 @@ impl NameType {
3535
/// Java `org.gbif.nameparser.api.NomCode`. Nomenclatural codes governing biological taxonomic
3636
/// nomenclature.
3737
///
38-
/// `Hash` (beyond the `Rank`-parity `Debug, Clone, Copy, PartialEq, Eq, Serialize` set) is
39-
/// needed for `pipeline::code_inference::infer`'s vote tally, a `HashSet<NomCode>` mirroring
40-
/// Java's `EnumSet<NomCode> votes` (`CodeInference.java:66`) — added here (Phase 1 Slice 4
41-
/// Task 3) rather than duplicated as a local newtype, since `Rank` already sets this same
42-
/// precedent (it derives `Hash` for its own `HashMap`/`HashSet` static tables above).
38+
/// `Hash` (beyond the `Rank`-parity `Debug, Clone, Copy, PartialEq, Eq, Serialize` set) lets a
39+
/// `NomCode` key a set or map, as `Rank` does for its own static tables above.
4340
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize)]
4441
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
4542
pub enum NomCode {
@@ -719,7 +716,9 @@ impl Rank {
719716
Rank::SupragenericName => Some("supragen."),
720717
Rank::Supergenus => Some("supergen."),
721718
Rank::Genus => Some("gen."),
722-
Rank::Subgenus => Some("subgen."),
719+
// the botanical "subg." (ICN Art. 21 Ex. 1, 3): zoologists bracket a subgenus instead
720+
// (ICZN Art. 6.1); Java's "subgen."
721+
Rank::Subgenus => Some("subg."),
723722
Rank::Infragenus => Some("infrag."),
724723
Rank::InfragenericName => Some("infragen."),
725724
Rank::SpeciesAggregate => Some("agg."),

‎crates/nameparser/src/model/name.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,16 @@ impl Authorship {
7575
}
7676

7777
/// True if there are authors or the work is anonymous: an anonymous author takes an author's
78-
/// place in `pipeline::code_inference`'s votes ("(Fr.) anon." is a botanical recombination).
78+
/// place ("(Fr.) anon." is a recombination).
7979
pub fn has_authors_or_anon(&self) -> bool {
8080
!self.authors.is_empty() || self.anonymous
8181
}
8282

8383
/// Java `Authorship.hasAuthors()`: true if `authors` is non-empty. (Java's own
8484
/// null-guard, `authors != null && …`, is unreachable here — `Vec<String>` is eagerly
8585
/// initialized and never absent, matching the field's Java default `= new
86-
/// ArrayList<>()`.) Used by `pipeline::code_inference`'s vote tally, distinct from
87-
/// [`Self::exists`] (which additionally counts a bare year with no authors).
86+
/// ArrayList<>()`.) Distinct from [`Self::exists`] (which additionally counts a bare year
87+
/// with no authors).
8888
pub fn has_authors(&self) -> bool {
8989
!self.authors.is_empty()
9090
}

0 commit comments

Comments
 (0)