mirror of
https://git.pumpin.online/funkpower/catena.git
synced 2026-12-03 14:43:05 +00:00
colophon: the record a book prints in its own front matter
A catalogue's worst records are the ones whose file says nothing true about itself: a PDF titled `Untitled` by an author called `Oxford`, which is a publisher, from a filename that was never anything but a filename. What those books do have is pages. The title page carries the title as the publisher set it; the copyright page carries the imprint, the year, the ISBN, and in most English books since the 1970s the cataloguing block, which is a catalogue record a librarian already made, subject headings and all. So this reads the pages. Every field names the page it came from, and a book that printed nothing comes back empty with its fields in `unsettled` rather than filled with something plausible — an extraction that starts at chapter one has no front matter in it, and saying so is the answer. Two pages look like a title page and are not, and both are how a catalogue comes to name the wrong book. A series advertisement lists other titles in the shape a title page uses, over as many as four pages with only the first announcing itself. A translation's cataloguing block prints the original title in brackets above the real one. Both are found and refused. Three things the pages give that no file does: the subject headings a librarian assigned, an ISBN that exists only in print — which turns a book with no identifier into one `bibfetch` can look up — and a title in the case the publisher meant, because a half title prints unbroken what the title page breaks across two lines and sets in capitals. `--prompt` and `--merge` are citefind's: a question about exactly the fields the pages left unsettled, composed here and answered wherever the caller keeps a model, with the advertising taken out of what the model is shown. A field a model answered is marked `model`, so a record always says which of it was read and which was inferred. Measured against 600 books of the home corpus: the cataloguing block answered for 21% of them and agreed with the catalogue 89% of the time, most of the residue being the catalogue's error rather than this one's. Title pages answered for another 41%. The remaining 38% print nothing readable, and are what the prompt is for.
This commit is contained in:
13 files changed
+2064
No files matched your search
@@ -0,0 +1,104 @@
|
||||
//! The copyright page: who published it, where, when, and under what ISBN.
|
||||
//!
|
||||
//! Everything on this page is formula. The same dozen sentences appear in
|
||||
//! every book printed in English, which is what makes them worth matching
|
||||
//! exactly rather than interpreting.
|
||||
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use regex::Regex;
|
||||
|
||||
/// What the copyright page stated.
|
||||
#[derive(Debug, Default, Clone, PartialEq)]
|
||||
pub struct Imprint {
|
||||
/// The press.
|
||||
pub publisher: Option<String>,
|
||||
/// Where it publishes from, where the page named one place.
|
||||
pub place: Option<String>,
|
||||
/// The year of this edition, preferring first publication.
|
||||
pub year: Option<u16>,
|
||||
/// Every checksum-valid ISBN printed on the page, in the order printed.
|
||||
pub isbns: Vec<String>,
|
||||
}
|
||||
|
||||
static PUBLISHED_BY: LazyLock<Regex> = LazyLock::new(|| {
|
||||
Regex::new(r"(?im)^\s*(?:first\s+)?published(?:\s+(?:in\s+)?(?:1[5-9]|20)\d{2})?\s+by\s+(?P<who>[^,.\n]{3,60})")
|
||||
.expect("a valid pattern")
|
||||
});
|
||||
static PRESS_LINE: LazyLock<Regex> = LazyLock::new(|| {
|
||||
Regex::new(r"(?im)^\s*(?P<who>[A-Z][^\n]{2,58}?(?:University Press|Press|Publishers|Publishing|Books|Verlag))\s*[,.]?\s*$")
|
||||
.expect("a valid pattern")
|
||||
});
|
||||
static FIRST_PUBLISHED: LazyLock<Regex> = LazyLock::new(|| {
|
||||
Regex::new(r"(?i)first published[^.\n]{0,40}?((?:1[5-9]|20)\d{2})").expect("a valid pattern")
|
||||
});
|
||||
static COPYRIGHT_YEAR: LazyLock<Regex> = LazyLock::new(|| {
|
||||
Regex::new(r"(?i)(?:©|\(c\)|copyright)\s*(?:by\s+)?((?:1[5-9]|20)\d{2})")
|
||||
.expect("a valid pattern")
|
||||
});
|
||||
static ISBN: LazyLock<Regex> = LazyLock::new(|| {
|
||||
Regex::new(r"(?i)isbn(?:[-\s]?1[03])?[:\s]*([0-9][0-9\s\-–—]{8,24}[0-9Xx])")
|
||||
.expect("a valid pattern")
|
||||
});
|
||||
/// `Oxford : Oxford University Press, 2007` — the labelled CIP's description,
|
||||
/// which states all three at once.
|
||||
static DESCRIPTION: LazyLock<Regex> = LazyLock::new(|| {
|
||||
Regex::new(r"(?im)^\s*Description\s*:\s*(?P<place>[^:|\n]{2,40}?)\s*:\s*(?P<who>[^,|\n]{3,60}?)\s*,\s*(?P<year>(?:1[5-9]|20)\d{2})")
|
||||
.expect("a valid pattern")
|
||||
});
|
||||
|
||||
fn tidy(s: &str) -> String {
|
||||
s.trim()
|
||||
.trim_end_matches([',', '.', ';'])
|
||||
.trim()
|
||||
.to_string()
|
||||
}
|
||||
|
||||
/// Every checksum-valid ISBN announced in a piece of text.
|
||||
pub fn isbns(text: &str) -> Vec<String> {
|
||||
let mut out: Vec<String> = Vec::new();
|
||||
for caps in ISBN.captures_iter(text) {
|
||||
let digits = bibclean::isbn::digits(&caps[1]);
|
||||
if matches!(digits.len(), 10 | 13)
|
||||
&& bibclean::isbn::valid(&digits)
|
||||
&& !out.contains(&digits)
|
||||
{
|
||||
out.push(digits);
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Read the copyright page.
|
||||
pub fn read(text: &str) -> Imprint {
|
||||
let mut out = Imprint {
|
||||
isbns: isbns(text),
|
||||
..Imprint::default()
|
||||
};
|
||||
|
||||
if let Some(caps) = DESCRIPTION.captures(text) {
|
||||
out.place = Some(tidy(&caps["place"]));
|
||||
out.publisher = Some(tidy(&caps["who"]));
|
||||
out.year = caps["year"].parse().ok();
|
||||
return out;
|
||||
}
|
||||
|
||||
out.publisher = PUBLISHED_BY
|
||||
.captures(text)
|
||||
.or_else(|| PRESS_LINE.captures(text))
|
||||
.map(|caps| tidy(&caps["who"]));
|
||||
out.year = FIRST_PUBLISHED
|
||||
.captures(text)
|
||||
.or_else(|| COPYRIGHT_YEAR.captures(text))
|
||||
.and_then(|caps| caps[1].parse().ok());
|
||||
out.place = text
|
||||
.lines()
|
||||
.map(str::trim)
|
||||
.find(|line| crate::title::PLACE.is_match(line) && line.split_whitespace().count() <= 4)
|
||||
.and_then(|line| {
|
||||
crate::title::PLACE
|
||||
.find(line)
|
||||
.map(|m| tidy(m.as_str().trim_end_matches(|c: char| !c.is_alphabetic())))
|
||||
});
|
||||
out
|
||||
}
|
||||
Reference in new issue
Block a user