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
@@ -99,7 +99,8 @@ 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 gets a name proposed,
|
as `front_matter` and a record whose author is missing, a placeholder, or the title copied into the
|
||||||
|
field gets a name proposed,
|
||||||
with the evidence and how far it is worth trusting:
|
with the evidence and how far it is worth trusting:
|
||||||
|
|
||||||
```
|
```
|
||||||
@@ -183,6 +184,7 @@ bibclean books.ndjson | jq -c 'select(.slug_proposal.tier | IN("placeholder-auth
|
|||||||
| `unknown_author` | 3 | "Unknown", "Anonymous", empty |
|
| `unknown_author` | 3 | "Unknown", "Anonymous", empty |
|
||||||
| `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 |
|
||||||
| `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 |
|
||||||
|
|||||||
@@ -237,11 +237,16 @@ pub fn clean(book: &Book) -> Cleaned {
|
|||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Only for a record that has no author to overwrite. A name recovered
|
// Only for a record that has no real author to overwrite: none, a
|
||||||
// from the text is evidence, not an improvement on one somebody entered.
|
// placeholder, or the title copied into the field. A name recovered from
|
||||||
|
// the text is evidence, not an improvement on one somebody entered.
|
||||||
let author_proposal = reasons
|
let author_proposal = reasons
|
||||||
.iter()
|
.iter()
|
||||||
.any(|reason| reason == "unknown_author" || reason == "placeholder_author")
|
.any(|reason| {
|
||||||
|
reason == "unknown_author"
|
||||||
|
|| reason == "placeholder_author"
|
||||||
|
|| reason == "author_is_title"
|
||||||
|
})
|
||||||
.then(|| {
|
.then(|| {
|
||||||
author::best(
|
author::best(
|
||||||
book.title.as_deref().unwrap_or(""),
|
book.title.as_deref().unwrap_or(""),
|
||||||
|
|||||||
@@ -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.
|
/// What each fault is worth when the worst records are wanted first.
|
||||||
const WEIGHTS: &[(&str, u32)] = &[
|
const WEIGHTS: &[(&str, u32)] = &[
|
||||||
("allcaps_title", 2),
|
("allcaps_title", 2),
|
||||||
|
("author_is_title", 4),
|
||||||
("author_last_first", 1),
|
("author_last_first", 1),
|
||||||
("author_role_suffix", 2),
|
("author_role_suffix", 2),
|
||||||
("edited_volume", 1),
|
("edited_volume", 1),
|
||||||
@@ -248,6 +249,9 @@ pub fn problems(title: Option<&str>, author: Option<&str>, isbn: Option<&str>) -
|
|||||||
{
|
{
|
||||||
reasons.push("possible_swap");
|
reasons.push("possible_swap");
|
||||||
}
|
}
|
||||||
|
if author_is_title(title, author) {
|
||||||
|
reasons.push("author_is_title");
|
||||||
|
}
|
||||||
if title_in_author(Some(title), Some(author)) {
|
if title_in_author(Some(title), Some(author)) {
|
||||||
reasons.push("title_in_author");
|
reasons.push("title_in_author");
|
||||||
}
|
}
|
||||||
@@ -280,6 +284,38 @@ pub fn worth_fixing(reasons: &[String]) -> bool {
|
|||||||
reasons.iter().any(|reason| reason != "missing_isbn")
|
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.
|
/// Whether a title is a placeholder rather than a work's name.
|
||||||
pub(crate) fn is_placeholder_title(title: &str) -> bool {
|
pub(crate) fn is_placeholder_title(title: &str) -> bool {
|
||||||
PLACEHOLDER_TITLE.is_match(title.trim_matches(textkit::is_space))
|
PLACEHOLDER_TITLE.is_match(title.trim_matches(textkit::is_space))
|
||||||
@@ -384,6 +420,59 @@ fn is_publisher(author: &str) -> bool {
|
|||||||
.is_ok()
|
.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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
Reference in new issue
Block a user