mirror of
https://git.pumpin.online/funkpower/catena.git
synced 2026-11-24 19:32:56 +00:00
bibclean: name a title copied into the author field
author_is_title (weight 4): the author field is the whole title, or the whole of the title before its subtitle when that part does not read as a person. "Isaac Newton: Philosophical Writings" by Isaac Newton is not caught; "Consciousness Reconsidered" by "Consciousness Reconsidered" is. A record with this fault also gets an author proposed from its front matter, as a missing or placeholder author already did. Over a 6,022-record catalogue: 67 records, 37 distinct, none of them a real author.
This commit is contained in:
3 files changed
+100
-4
No files matched your search
@@ -149,6 +149,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)] = &[
|
||||
("allcaps_title", 2),
|
||||
("author_is_title", 4),
|
||||
("author_last_first", 1),
|
||||
("author_role_suffix", 2),
|
||||
("edited_volume", 1),
|
||||
@@ -248,6 +249,9 @@ pub fn problems(title: Option<&str>, author: Option<&str>, isbn: Option<&str>) -
|
||||
{
|
||||
reasons.push("possible_swap");
|
||||
}
|
||||
if author_is_title(title, author) {
|
||||
reasons.push("author_is_title");
|
||||
}
|
||||
if title_in_author(Some(title), Some(author)) {
|
||||
reasons.push("title_in_author");
|
||||
}
|
||||
@@ -280,6 +284,38 @@ pub fn worth_fixing(reasons: &[String]) -> bool {
|
||||
reasons.iter().any(|reason| reason != "missing_isbn")
|
||||
}
|
||||
|
||||
/// Whether the author field holds the title, copied there by whatever made
|
||||
/// the record: "Cultural Imperialism" by "Cultural Imperialism".
|
||||
///
|
||||
/// The author has to be the whole title, or the whole of the title before its
|
||||
/// subtitle or a bracketed aside, compared without case or punctuation. A
|
||||
/// person whose name merely opens the title ("Plato" for "Plato and the
|
||||
/// Republic") is not caught, because the name is not all of the title, and
|
||||
/// nor is a person named before the subtitle: "Isaac Newton: Philosophical
|
||||
/// Writings" is by Isaac Newton.
|
||||
pub fn author_is_title(title: &str, author: &str) -> bool {
|
||||
let bare_author = author.split('(').next().unwrap_or("");
|
||||
let folded = fold(bare_author);
|
||||
if folded.is_empty() {
|
||||
return false;
|
||||
}
|
||||
if folded == fold(title.split('(').next().unwrap_or("")) {
|
||||
return true;
|
||||
}
|
||||
folded == fold(title.split([':', '(']).next().unwrap_or("")) && !looks_like_person(bare_author)
|
||||
}
|
||||
|
||||
/// Lowercase words, punctuation dropped.
|
||||
fn fold(text: &str) -> String {
|
||||
text.chars()
|
||||
.map(|c| if c.is_alphanumeric() { c } else { ' ' })
|
||||
.collect::<String>()
|
||||
.to_lowercase()
|
||||
.split_whitespace()
|
||||
.collect::<Vec<_>>()
|
||||
.join(" ")
|
||||
}
|
||||
|
||||
/// Whether a title is a placeholder rather than a work's name.
|
||||
pub(crate) fn is_placeholder_title(title: &str) -> bool {
|
||||
PLACEHOLDER_TITLE.is_match(title.trim_matches(textkit::is_space))
|
||||
@@ -384,6 +420,59 @@ fn is_publisher(author: &str) -> bool {
|
||||
.is_ok()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod author_is_title_tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn a_title_in_the_author_field_is_named() {
|
||||
for (title, author) in [
|
||||
("Cultural Imperialism", "Cultural Imperialism"),
|
||||
("Consciousness Reconsidered", "Consciousness Reconsidered"),
|
||||
("The Brain", "The Brain (1979)"),
|
||||
(
|
||||
"A Slim Book About Narrow Content",
|
||||
"A Slim Book About Narrow Content (Contem",
|
||||
),
|
||||
(
|
||||
"Neural Correlates of Consciousness: Empirical and Conceptual Questions",
|
||||
"Neural Correlates Of Consciousness",
|
||||
),
|
||||
("Reed", "Reed"),
|
||||
] {
|
||||
assert!(author_is_title(title, author), "{title} / {author}");
|
||||
assert!(
|
||||
problems(Some(title), Some(author), None).contains(&"author_is_title".to_string())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_person_who_shares_words_with_the_title_is_not() {
|
||||
for (title, author) in [
|
||||
("Plato and the Republic", "Plato"),
|
||||
("Kant: A Very Short Introduction", "Roger Scruton"),
|
||||
("Hegel and Aristotle", "Alfredo Ferrarin"),
|
||||
("Aristotle", "Jonathan Barnes"),
|
||||
("Isaac Newton: Philosophical Writings", "Isaac Newton"),
|
||||
(
|
||||
"Margaret Cavendish: Observations Upon Experimental Philosophy",
|
||||
"Margaret Cavendish",
|
||||
),
|
||||
// Two capitalised words read as a name, so before a subtitle they
|
||||
// are given the benefit of the doubt even when they are a title.
|
||||
(
|
||||
"Cultural Imperialism: A Critical Introduction",
|
||||
"Cultural Imperialism",
|
||||
),
|
||||
("", "Someone"),
|
||||
("Untitled", ""),
|
||||
] {
|
||||
assert!(!author_is_title(title, author), "{title} / {author}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in new issue
Block a user