colophon: cover credits, praise pages, other books by, library stamps and layout slugs are not titles

Every line added to the tests was read as a book's title off a real
library. Run over the front matter of 400 books, the only titles that
change are five of these, and each becomes no title at all.
This commit is contained in:
funkpower committed 2026-11-24 07:30:52 -05:00
1 parent 6f636f894e
commit c2990904a0
1 file changed
+70 -2
+70 -2
View File
@@ -58,6 +58,33 @@ static CATALOGUE_ENTRY: LazyLock<Regex> = LazyLock::new(|| {
static DEDICATION: LazyLock<Regex> = LazyLock::new(|| { static DEDICATION: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r"(?i)^\s*(to|for|in memory of)\s+\S.*,\s*$").expect("a valid pattern") Regex::new(r"(?i)^\s*(to|for|in memory of)\s+\S.*,\s*$").expect("a valid pattern")
}); });
/// Front matter that is about the book rather than the book: the cover's
/// credit, a dedication set without its comma, the list of the author's other
/// books, the page of praise, a library's stamp, a scanner's watermark.
static ABOUT_THE_BOOK: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(concat!(
r"(?i)^\s*(?:",
r"(?:cover|jacket)\s+(?:design|art|artwork|illustration|photograph|photo|image|painting)s?\b",
r"|(?:interior|book|text)\s+design(?:ed)?\s+by\b",
r"|(?:to|for)\s+(?:my|our)\s+\S+(?:\s+\S+){0,3}\s*[,.]?\s*$",
r"|also\s+by\b|by\s+the\s+same\s+author\b|other\s+(?:books|titles|works)\s+by\b",
r"|praise\s+for\b",
r"|(?:brought\s+to\s+you|digiti[sz]ed|scanned)\s+by\b|brought\s+to\s+you\s*$",
r")",
))
.expect("a valid pattern")
});
/// A library's ownership stamp: "Trent University Library".
static LIBRARY_STAMP: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r"(?i)\b(?:university|college|seminary)\b.*\blibrar(?:y|ies)\s*$")
.expect("a valid pattern")
});
/// The slug a layout program prints at the foot of a proof page: the file's
/// name, or the date and time it was output.
static LAYOUT_SLUG: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r"(?i)\.(?:qxd|qxp|indd|pmd)\b|\b\d{1,2}/\d{1,2}/\d{2,4}\s+\d{1,2}:\d{2}\s*[ap]m\b")
.expect("a valid pattern")
});
static COPYRIGHT_NOTICE: LazyLock<Regex> = LazyLock::new(|| { static COPYRIGHT_NOTICE: LazyLock<Regex> = LazyLock::new(|| {
// The year need not follow the symbol directly: "(c) Alfredo Ferrarin // The year need not follow the symbol directly: "(c) Alfredo Ferrarin
// 2004" puts the holder between them, and was read as a title. // 2004" puts the holder between them, and was read as a title.
@@ -184,7 +211,9 @@ fn strip_folio(norm: &str) -> &str {
/// edition's own list of volumes. /// edition's own list of volumes.
fn is_furniture(line: &str) -> bool { fn is_furniture(line: &str) -> bool {
let t = line.trim(); let t = line.trim();
if t.starts_with('[') || t.starts_with('\\') { // A line that opens on the copyright sign is a credit or a notice even
// when it carries no year: "© Vladimir Pcholkin / FPG International".
if t.starts_with('[') || t.starts_with('\\') || t.starts_with('\u{a9}') {
return true; return true;
} }
// A converter that left its markup in. Nothing printed on a title page is // A converter that left its markup in. Nothing printed on a title page is
@@ -224,7 +253,18 @@ fn is_furniture(line: &str) -> bool {
return true; return true;
} }
} }
if DEDICATION.is_match(t) { if DEDICATION.is_match(t)
|| ABOUT_THE_BOOK.is_match(t)
|| LIBRARY_STAMP.is_match(t)
|| LAYOUT_SLUG.is_match(t)
{
return true;
}
// A trademark sign on the end marks a brand: "A Forthright Edition™",
// printed beside the title, never inside one. A converter that dropped
// the superscript leaves the letters run on: "EditionTM".
let run_on_mark = t.ends_with("TM") && t.chars().rev().nth(2).is_some_and(char::is_lowercase);
if t.ends_with('™') || run_on_mark {
return true; return true;
} }
let lower = t.to_lowercase(); let lower = t.to_lowercase();
@@ -467,6 +507,25 @@ mod furniture_tests {
"Vol. 11. HENRY JAMES, JR.", "Vol. 11. HENRY JAMES, JR.",
"All rights reserved", "All rights reserved",
"First published 1971", "First published 1971",
"Cover design by David Ferris (www.davidferrisdesign.com).",
"Cover art",
"Jacket photograph © Getty Images",
"Book design by Jane Doe",
"To my family",
"For my parents",
"Also by Fyodor Dostoyevsky",
"By the same author",
"Other books by Anne Rice",
"Praise for *The Singularity Is Near",
"Hond_FM.qxd 7/12/04 12:48 PM Page iii",
"M956 LEVENTIS PRE M/UP.qxd 3/10/07 1:42 PM Page i",
"Trent University Library",
"The University of Chicago Libraries",
"brought to you",
"Digitized by Google",
"A Forthright EditionTM",
"A Forthright Edition\u{2122}",
"\u{a9} Vladimir Pcholkin / FPG International",
] { ] {
assert!( assert!(
is_structural(line) || is_furniture(line), is_structural(line) || is_furniture(line),
@@ -486,6 +545,15 @@ mod furniture_tests {
"Contents of Consciousness", "Contents of Consciousness",
"August 1914", "August 1914",
"Copyright and Its Discontents", "Copyright and Its Discontents",
"Book Design",
"Cover Story",
"To Kill a Mockingbird",
"For Whom the Bell Tolls",
"In Praise of Folly",
"The Library of Babel",
"University Libraries in Transition",
"The Public Library",
"Atomic Habits",
] { ] {
assert!( assert!(
!(is_structural(line) || is_furniture(line)), !(is_structural(line) || is_furniture(line)),