mirror of
https://git.pumpin.online/funkpower/catena.git
synced 2026-11-24 19:32:56 +00:00
bibclean: name a login in the author field; read more copyright notices
account_author (weight 3): one word in a shape no published name has,
such as all lowercase, an underscore, digits, or capitals run on after
lowercase ("mymarasigan", "HP_Administrator", "SaravanakumarCS"). It
also asks for an author from the front matter.
The copyright reader now takes "© 2004 by …" without the word
"Copyright", passes over a notice for a translation, introduction,
notes or the like, refuses more firms (publishing houses, "Media",
"Editions", "Center", well-known imprints), and drops a particle left
dangling when the run stops at a firm's name ("Walter de").
Over 400 books' front matter, against the catalogue's own author:
proposals right 91 -> 96, wrong 23 -> 17.
This commit is contained in:
4 files changed
+135
-7
No files matched your search
@@ -99,9 +99,9 @@ through this and back into whatever it came from.
|
|||||||
## Recovering a missing author
|
## Recovering a missing author
|
||||||
|
|
||||||
A book says who wrote it on its own copyright page. Hand in the opening pages
|
A book says who wrote it on its own copyright page. Hand in the opening pages
|
||||||
as `front_matter` and a record whose author is missing, a placeholder, or the title copied into the
|
as `front_matter` and a record whose author is missing, a placeholder, a login,
|
||||||
field gets a name proposed,
|
or the title copied into the field gets a name proposed, with the evidence and
|
||||||
with the evidence and how far it is worth trusting:
|
how far it is worth trusting:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ bibclean authors.ndjson
|
$ bibclean authors.ndjson
|
||||||
@@ -185,6 +185,7 @@ bibclean books.ndjson | jq -c 'select(.slug_proposal.tier | IN("placeholder-auth
|
|||||||
| `filename_title` | 3 | A bare filename, extension and all |
|
| `filename_title` | 3 | A bare filename, extension and all |
|
||||||
| `junk_title` | 3 | The name of the tool that made the file, not the work |
|
| `junk_title` | 3 | The name of the tool that made the file, not the work |
|
||||||
| `author_is_title` | 4 | The title copied into the author field |
|
| `author_is_title` | 4 | The title copied into the author field |
|
||||||
|
| `account_author` | 3 | The login of whoever made the file: "mymarasigan", "HP_Administrator" |
|
||||||
| `publisher_as_author` | 3 | An imprint in the author field |
|
| `publisher_as_author` | 3 | An imprint in the author field |
|
||||||
| `title_in_author` | 3 | The title is a placeholder and the real title is in the author field |
|
| `title_in_author` | 3 | The title is a placeholder and the real title is in the author field |
|
||||||
| `allcaps_title` | 2 | Shouting |
|
| `allcaps_title` | 2 | Shouting |
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ fn pattern(source: &str) -> Regex {
|
|||||||
/// person. Without them the looser heuristics propose the imprint.
|
/// person. Without them the looser heuristics propose the imprint.
|
||||||
static NOT_A_PERSON: LazyLock<Boundaried> = LazyLock::new(|| {
|
static NOT_A_PERSON: LazyLock<Boundaried> = LazyLock::new(|| {
|
||||||
Boundaried::new(&format!(
|
Boundaried::new(&format!(
|
||||||
r"(?i){WORD_START}(press|edition|introduction|university|volume|reprint|copyright|published|printed|rights|reserved|library|congress|isbn|inc|ltd|company|regents|trustees|foundation|institute|society|association|board|council|committee|department|ministry|editors?|trust|publishing|publishers|books|publications|sons|llc|gmbh|verlag|all|limited){WORD_END}"
|
r"(?i){WORD_START}(press|edition|introduction|university|volume|reprint|copyright|published|printed|rights|reserved|library|congress|isbn|inc|ltd|company|regents|trustees|foundation|institute|society|association|board|council|committee|department|ministry|editors?|trust|publishing|publishers|books|publications|sons|llc|gmbh|verlag|all|limited|house|media|editions|éditions|center|centre|seminary|classics|wiley|gruyter|brill|siebeck|seuil|gallimard|payot|routledge|springer|elsevier|macmillan|penguin|blackwell|norton|knopf|doubleday|vintage|bantam|harpercollins|nv|bv){WORD_END}"
|
||||||
))
|
))
|
||||||
.expect("a valid pattern")
|
.expect("a valid pattern")
|
||||||
});
|
});
|
||||||
@@ -55,12 +55,21 @@ static ISBN: LazyLock<Regex> = LazyLock::new(|| {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/// The strongest thing a book says about who wrote it.
|
/// The strongest thing a book says about who wrote it.
|
||||||
|
///
|
||||||
|
/// The word "Copyright" is often left off: "© 2004 by Stanley Hauerwas".
|
||||||
static COPYRIGHT: LazyLock<Regex> = LazyLock::new(|| {
|
static COPYRIGHT: LazyLock<Regex> = LazyLock::new(|| {
|
||||||
pattern(&format!(
|
pattern(&format!(
|
||||||
r"(?i)Copyright{SPACE}*(?:©|\(c\))?{SPACE}*\d{{4}}{SPACE}+by{SPACE}+(.{{2,90}})"
|
r"(?i)(?:Copyright{SPACE}*(?:©|\(c\))?|©|\(c\)){SPACE}*\d{{4}}{SPACE}+by{SPACE}+(.{{2,90}})"
|
||||||
))
|
))
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/// What a notice can be for besides the work itself.
|
||||||
|
static SUBSIDIARY: LazyLock<Regex> = LazyLock::new(|| {
|
||||||
|
pattern(
|
||||||
|
r"(?i)\b(?:translat\w*|introduction|notes|foreword|afterword|preface|editorial|selection|compilation|illustrations?|cover|map|maps|abridg\w*|chronology)\b",
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
/// The cataloguing block a national library prints on the copyright page.
|
/// The cataloguing block a national library prints on the copyright page.
|
||||||
static CATALOGUING: LazyLock<Regex> = LazyLock::new(|| {
|
static CATALOGUING: LazyLock<Regex> = LazyLock::new(|| {
|
||||||
pattern(&format!(
|
pattern(&format!(
|
||||||
@@ -177,7 +186,15 @@ pub fn from_front_matter(text: &str) -> Vec<Suggestion> {
|
|||||||
let mut out = Vec::new();
|
let mut out = Vec::new();
|
||||||
|
|
||||||
// Strongest: the book saying who holds its copyright.
|
// Strongest: the book saying who holds its copyright.
|
||||||
if let Some(found) = COPYRIGHT.captures(text)
|
// A notice for a translation, an introduction or the notes names whoever
|
||||||
|
// wrote those, not the book: "Translation copyright © 2014 by Oliver
|
||||||
|
// Ready" is in front of Dostoevsky.
|
||||||
|
let for_the_work = COPYRIGHT.captures_iter(text).find(|found| {
|
||||||
|
let at = found.get(0).map_or(0, |whole| whole.start());
|
||||||
|
let line_start = text[..at].rfind('\n').map_or(0, |n| n + 1);
|
||||||
|
!SUBSIDIARY.is_match(&text[line_start..at])
|
||||||
|
});
|
||||||
|
if let Some(found) = for_the_work
|
||||||
&& let Some(name) = clean(&name_prefix(&found[1]))
|
&& let Some(name) = clean(&name_prefix(&found[1]))
|
||||||
&& name.split_whitespace().count() >= 2
|
&& name.split_whitespace().count() >= 2
|
||||||
{
|
{
|
||||||
@@ -271,6 +288,16 @@ pub fn name_prefix(text: &str) -> String {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// A particle belongs to the surname after it. Left on the end, it means
|
||||||
|
// the run stopped at a firm's name: "Walter de" from "Walter de Gruyter".
|
||||||
|
while tokens.last().is_some_and(|last| {
|
||||||
|
[
|
||||||
|
"de", "van", "von", "der", "den", "du", "da", "di", "la", "le",
|
||||||
|
]
|
||||||
|
.contains(last)
|
||||||
|
}) {
|
||||||
|
tokens.pop();
|
||||||
|
}
|
||||||
tokens.join(" ")
|
tokens.join(" ")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -398,6 +425,38 @@ mod tests {
|
|||||||
assert_eq!(found[0].confidence, 0.9);
|
assert_eq!(found[0].confidence, 0.9);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_notice_without_the_word_copyright_names_the_author() {
|
||||||
|
let text = "\u{a9} 2004 by Stanley Hauerwas and Samuel Wells\n350 Main Street";
|
||||||
|
let found = from_front_matter(text);
|
||||||
|
assert_eq!(found[0].method, "front_matter_copyright");
|
||||||
|
assert!(
|
||||||
|
found[0].author.starts_with("Stanley Hauerwas"),
|
||||||
|
"{}",
|
||||||
|
found[0].author
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_publisher_holding_the_copyright_is_not_an_author() {
|
||||||
|
for text in [
|
||||||
|
"Copyright \u{a9} 1990 by John Wiley & Sons",
|
||||||
|
"\u{a9} 2004 by Random House, Inc.",
|
||||||
|
"Copyright \u{a9} 2011 by Walter de Gruyter",
|
||||||
|
"Copyright \u{a9} 2014 by Arktos Media Ltd.",
|
||||||
|
] {
|
||||||
|
assert!(from_front_matter(text).is_empty(), "{text}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_translators_notice_is_passed_over() {
|
||||||
|
let text = "Translation copyright \u{a9} 2014 by Oliver Ready\nIntroduction copyright \u{a9} 2014 by Someone Else";
|
||||||
|
assert!(from_front_matter(text).is_empty());
|
||||||
|
let text = "Translation copyright \u{a9} 2014 by Oliver Ready\nCopyright \u{a9} 1999 by James H. Billington";
|
||||||
|
assert_eq!(from_front_matter(text)[0].author, "James H. Billington");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn a_cataloguing_block_names_the_author_surname_first() {
|
fn a_cataloguing_block_names_the_author_surname_first() {
|
||||||
let text = "Library of Congress Cataloging-in-Publication Data\n\
|
let text = "Library of Congress Cataloging-in-Publication Data\n\
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ pub fn clean(book: &Book) -> Cleaned {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Only for a record that has no real author to overwrite: none, a
|
// Only for a record that has no real author to overwrite: none, a
|
||||||
// placeholder, or the title copied into the field. A name recovered from
|
// placeholder, the title copied into the field, or a login. A name recovered from
|
||||||
// the text is evidence, not an improvement on one somebody entered.
|
// the text is evidence, not an improvement on one somebody entered.
|
||||||
let author_proposal = reasons
|
let author_proposal = reasons
|
||||||
.iter()
|
.iter()
|
||||||
@@ -246,6 +246,7 @@ pub fn clean(book: &Book) -> Cleaned {
|
|||||||
reason == "unknown_author"
|
reason == "unknown_author"
|
||||||
|| reason == "placeholder_author"
|
|| reason == "placeholder_author"
|
||||||
|| reason == "author_is_title"
|
|| reason == "author_is_title"
|
||||||
|
|| reason == "account_author"
|
||||||
})
|
})
|
||||||
.then(|| {
|
.then(|| {
|
||||||
author::best(
|
author::best(
|
||||||
|
|||||||
@@ -148,6 +148,7 @@ const PERSON_SUFFIXES: &[&str] = &["ed", "eds", "ii", "iii", "iv", "jr", "md", "
|
|||||||
|
|
||||||
/// What each fault is worth when the worst records are wanted first.
|
/// What each fault is worth when the worst records are wanted first.
|
||||||
const WEIGHTS: &[(&str, u32)] = &[
|
const WEIGHTS: &[(&str, u32)] = &[
|
||||||
|
("account_author", 3),
|
||||||
("allcaps_title", 2),
|
("allcaps_title", 2),
|
||||||
("author_is_title", 4),
|
("author_is_title", 4),
|
||||||
("author_last_first", 1),
|
("author_last_first", 1),
|
||||||
@@ -249,6 +250,9 @@ pub fn problems(title: Option<&str>, author: Option<&str>, isbn: Option<&str>) -
|
|||||||
{
|
{
|
||||||
reasons.push("possible_swap");
|
reasons.push("possible_swap");
|
||||||
}
|
}
|
||||||
|
if is_account_name(author) {
|
||||||
|
reasons.push("account_author");
|
||||||
|
}
|
||||||
if author_is_title(title, author) {
|
if author_is_title(title, author) {
|
||||||
reasons.push("author_is_title");
|
reasons.push("author_is_title");
|
||||||
}
|
}
|
||||||
@@ -305,6 +309,33 @@ pub fn author_is_title(title: &str, author: &str) -> bool {
|
|||||||
folded == fold(title.split([':', '(']).next().unwrap_or("")) && !looks_like_person(bare_author)
|
folded == fold(title.split([':', '(']).next().unwrap_or("")) && !looks_like_person(bare_author)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether the author field is the login of whoever made the file:
|
||||||
|
/// "mymarasigan", "HP_Administrator", "SaravanakumarCS", "user42".
|
||||||
|
///
|
||||||
|
/// One word, and a shape no published name has: all lowercase, an underscore,
|
||||||
|
/// digits among letters, or capitals run on after lowercase. A capitalised
|
||||||
|
/// single name ("Plato", "Voltaire") is a name and is left alone.
|
||||||
|
pub fn is_account_name(author: &str) -> bool {
|
||||||
|
let author = author.trim_matches(textkit::is_space);
|
||||||
|
if author.chars().count() < 4 || author.chars().any(textkit::is_space) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if !author.chars().any(char::is_alphabetic) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
let lowercase = author
|
||||||
|
.chars()
|
||||||
|
.all(|c| c.is_lowercase() || c.is_ascii_digit() || c == '.');
|
||||||
|
let underscored = author.contains('_');
|
||||||
|
let digits = author.chars().any(|c| c.is_ascii_digit());
|
||||||
|
let run_on_capitals = author
|
||||||
|
.chars()
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.windows(3)
|
||||||
|
.any(|w| w[0].is_lowercase() && w[1].is_uppercase() && w[2].is_uppercase());
|
||||||
|
lowercase || underscored || digits || run_on_capitals
|
||||||
|
}
|
||||||
|
|
||||||
/// Lowercase words, punctuation dropped.
|
/// Lowercase words, punctuation dropped.
|
||||||
fn fold(text: &str) -> String {
|
fn fold(text: &str) -> String {
|
||||||
text.chars()
|
text.chars()
|
||||||
@@ -420,6 +451,42 @@ fn is_publisher(author: &str) -> bool {
|
|||||||
.is_ok()
|
.is_ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod account_name_tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_login_is_named() {
|
||||||
|
for author in [
|
||||||
|
"mymarasigan",
|
||||||
|
"HP_Administrator",
|
||||||
|
"SaravanakumarCS",
|
||||||
|
"user42",
|
||||||
|
"pubassist",
|
||||||
|
"vitzliputzli",
|
||||||
|
] {
|
||||||
|
assert!(is_account_name(author), "{author}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_name_is_not() {
|
||||||
|
for author in [
|
||||||
|
"Plato",
|
||||||
|
"Voltaire",
|
||||||
|
"Hannah Arendt",
|
||||||
|
"bell hooks",
|
||||||
|
"McLuhan",
|
||||||
|
"DeLillo",
|
||||||
|
"Joe",
|
||||||
|
"",
|
||||||
|
"Anonymous",
|
||||||
|
] {
|
||||||
|
assert!(!is_account_name(author), "{author}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod author_is_title_tests {
|
mod author_is_title_tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
Reference in new issue
Block a user