bibclean: name a web address saved as a title, and leave it alone

url_title (weight 4): a title that is an http, file or www address. The
underscore repair no longer runs on an address or a path, where it
turned "stranger_than_fiction.htm" into "stranger than fiction.htm"
and left something that was neither a title nor an address.
This commit is contained in:
funkpower committed 2026-11-24 08:25:47 -05:00
1 parent 894a64add2
commit 14133c9be5
3 files changed
+30

No files matched your search

+1
View File
@@ -180,6 +180,7 @@ bibclean books.ndjson | jq -c 'select(.slug_proposal.tier | IN("placeholder-auth
| `mojibake_title` | 3 | UTF-8 read as Windows-1252: "américain" |
| `mojibake_author` | 3 | The same, in the author field |
| `placeholder_suffix` | 2 | A placeholder author left on the end of the title: "… - Unknown" |
| `url_title` | 4 | A web address saved as the title |
| `path_title` | 4 | A file path sitting in the title |
| `numeric_author` | 4 | An author field opening with a bare year or series number |
| `unknown_author` | 3 | "Unknown", "Anonymous", empty |
+21
View File
@@ -218,8 +218,13 @@ pub fn clean(book: &Book) -> Cleaned {
// Underscores first: a title mangled by a filename may also be shouting,
// and title-casing it before the underscores come out would case the
// format suffix as though it were a word.
// Not in an address or a path, where the underscores are the name and
// taking them out leaves something that is neither title nor address.
if let Some(title) = cleaned.title.clone()
&& reasons.iter().any(|reason| reason == "underscore_title")
&& !reasons
.iter()
.any(|reason| reason == "url_title" || reason == "path_title")
{
let fixed = fix::clean_underscores(&title);
if fixed != title {
@@ -481,6 +486,22 @@ mod tests {
);
}
#[test]
fn an_address_is_named_and_left_alone() {
for title in [
"http://www.voxfux.com/features/stranger_than_fiction.htm",
"file://D:\\Books\\white_paper",
"www.example.org/some_page",
] {
let cleaned = clean(&book(title, "Someone"));
assert_eq!(cleaned.book.title.as_deref(), Some(title), "{title}");
assert!(
cleaned.reasons.iter().any(|reason| reason == "url_title"),
"{title}"
);
}
}
#[test]
fn a_shouting_title_is_cased_and_the_change_is_recorded() {
let cleaned = clean(&book("THE HUMAN CONDITION", "Arendt, Hannah"));
+8
View File
@@ -34,6 +34,10 @@ static JUNK_TITLE: LazyLock<Boundaried> = LazyLock::new(|| {
/// A path sitting in the title field. Distinct from a filename, which is a
/// bare name ending in an extension.
/// A web address saved as the title: "http://www.voxfux.com/features/…".
static URL_TITLE: LazyLock<Regex> =
LazyLock::new(|| pattern(r"(?i)^\W*(?:https?://|file://|www\.)\S"));
static PATH_TITLE: LazyLock<Regex> =
LazyLock::new(|| pattern(r"(^[A-Za-z]:[\\/])|(\\\\[^\\]+\\)|(^/(?:home|users|mnt|tmp|var)/)"));
@@ -173,6 +177,7 @@ const WEIGHTS: &[(&str, u32)] = &[
("title_in_author", 3),
("underscore_title", 1),
("unknown_author", 3),
("url_title", 4),
];
/// Everything wrong with a record, named.
@@ -199,6 +204,9 @@ pub fn problems(title: Option<&str>, author: Option<&str>, isbn: Option<&str>) -
if PATH_TITLE.is_match(title) {
reasons.push("path_title");
}
if URL_TITLE.is_match(title) {
reasons.push("url_title");
}
if FILENAME_TITLE.is_match(title) {
reasons.push("filename_title");
}