Rework scan screen, make lookups non-blocking, fix review findings
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
468cafc6db
commit
b5defb4e4f
46 files changed
+1957
-406
No files matched your search
@@ -0,0 +1,26 @@
|
||||
import { mainEntry } from '../../shared/cutter.ts';
|
||||
import type { MarcFields } from '../sources/marc.ts';
|
||||
|
||||
const plain = (s: string): string =>
|
||||
s.normalize('NFD').replace(/[̀-ͯ]/g, '').toLowerCase().replace(/[^a-z0-9]+/g, ' ').trim();
|
||||
|
||||
/** Lower-case, main title only (before any ":"), no punctuation, no leading article. */
|
||||
export function normalizeTitle(title: string): string {
|
||||
return plain(title.split(':')[0]!).replace(/^(a|an|the) /, '');
|
||||
}
|
||||
|
||||
/** Equal, or one is a prefix of the other (a record may carry a longer or shorter main title). */
|
||||
export function titlesMatch(a: string, b: string): boolean {
|
||||
const x = normalizeTitle(a);
|
||||
const y = normalizeTitle(b);
|
||||
if (!x || !y) return false;
|
||||
return x === y || x.startsWith(y + ' ') || y.startsWith(x + ' ');
|
||||
}
|
||||
|
||||
/** Does a LoC record plausibly describe this book? Title must match and a 100/700 name must contain the surname. */
|
||||
export function recordMatches(rec: MarcFields, title: string, author: string): boolean {
|
||||
if (!rec.meta.title || !titlesMatch(rec.meta.title, title)) return false;
|
||||
const surname = plain(mainEntry([author], title));
|
||||
if (!surname) return false;
|
||||
return rec.names.some((n) => (' ' + plain(n) + ' ').includes(' ' + surname + ' '));
|
||||
}
|
||||
Reference in new issue
Block a user