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
@@ -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.
|
||||
const WEIGHTS: &[(&str, u32)] = &[
|
||||
("account_author", 3),
|
||||
("allcaps_title", 2),
|
||||
("author_is_title", 4),
|
||||
("author_last_first", 1),
|
||||
@@ -249,6 +250,9 @@ pub fn problems(title: Option<&str>, author: Option<&str>, isbn: Option<&str>) -
|
||||
{
|
||||
reasons.push("possible_swap");
|
||||
}
|
||||
if is_account_name(author) {
|
||||
reasons.push("account_author");
|
||||
}
|
||||
if author_is_title(title, author) {
|
||||
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)
|
||||
}
|
||||
|
||||
/// 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.
|
||||
fn fold(text: &str) -> String {
|
||||
text.chars()
|
||||
@@ -420,6 +451,42 @@ fn is_publisher(author: &str) -> bool {
|
||||
.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)]
|
||||
mod author_is_title_tests {
|
||||
use super::*;
|
||||
|
||||
Reference in new issue
Block a user