Add QR codes to cards, stop inventing call number parts
Cards now carry a QR code holding the book's own record (call number, title, authors, ISBN, year), and the scanner reads it back to find or add that book. Call number selection no longer pads catalogue numbers with generated cutters. A number is "exact" only when it comes verbatim from a record for this edition; a bare class is a hint that steers the other-edition and similar-books lookups; a record fetched by LCCN must list the book's ISBN to count as this edition. "Look up again" bypasses every cached result, and shelf order breaks ties by author then title. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
6cec404e21
commit
ad2956e868
56 files changed
+4020
-156
No files matched your search
@@ -2,7 +2,7 @@ import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { classified, finishSimilar, keywordsOf, mergeCandidates, queryPlan, stem, voteSimilar } from './similar.ts';
|
||||
import { classified, finishSimilar, keywordsOf, mergeCandidates, queryPlan, searchWords, stem, voteSimilar } from './similar.ts';
|
||||
import type { SimilarCandidate } from './similar.ts';
|
||||
import { parseMarcXml } from '../sources/marc.ts';
|
||||
import { parseSimilar } from '../sources/openlibrary.ts';
|
||||
@@ -141,3 +141,62 @@ test('real responses: bread books vote for TX769', () => {
|
||||
const v = voteSimilar(keywordsOf('Artisan Flour Water Bread'), cands);
|
||||
assert.equal(v?.key, 'TX769');
|
||||
});
|
||||
|
||||
test('hinted vote: only candidates in the hinted class count, and one good match is enough', () => {
|
||||
const kw = keywordsOf('Sierra Nevada Backpacking Guide');
|
||||
const cands = [
|
||||
c('Sierra Nevada backpacking', ['GV199.42.S55 S54 2020']),
|
||||
c('Sierra backpacking trips', ['GV199.62.C57 2011']),
|
||||
c('Sierra Nevada backpacking', ['GV199.62.C57 2012']),
|
||||
c('Backpacking the Sierra', ['GV199.62.C57 2013']),
|
||||
];
|
||||
// Unhinted, the three GV199.62 books win; hinted to GV199.42, only the one book in that class is heard.
|
||||
assert.equal(voteSimilar(kw, cands)?.key, 'GV199.62');
|
||||
const v = voteSimilar(kw, cands, { hint: 'GV199.42' });
|
||||
assert.equal(v?.key, 'GV199.42.S55');
|
||||
assert.equal(v?.support, 1);
|
||||
});
|
||||
|
||||
test('hinted vote: a weak lone match, a bare-class candidate, or scattered places give nothing', () => {
|
||||
const kw = keywordsOf('Sierra Nevada Backpacking Guide');
|
||||
assert.equal(voteSimilar(kw, [c('Sierra history', ['GV199.42.S55 A1'])], { hint: 'GV199.42' }), null);
|
||||
assert.equal(voteSimilar(kw, [c('Sierra Nevada backpacking', ['GV199.42'])], { hint: 'GV199.42' }), null);
|
||||
const scattered = [
|
||||
c('Sierra Nevada backpacking', ['GV199.42.S55 A1']), c('Sierra Nevada backpacking', ['GV199.42.C2 B1']),
|
||||
c('Sierra Nevada backpacking', ['GV199.42.W3 C1']), c('Sierra Nevada backpacking', ['GV199.42.N4 D1']),
|
||||
];
|
||||
assert.equal(voteSimilar(kw, scattered, { hint: 'GV199.42' }), null);
|
||||
});
|
||||
|
||||
test('hinted vote: a winning key may equal the hint when real records have a single cutter', () => {
|
||||
const kw = keywordsOf('Trail Runners Handbook Colorado');
|
||||
const v = voteSimilar(kw, [
|
||||
c('Colorado trail runners', ['GV199.62.C57 2011']), c('Trail running Colorado', ['GV199.62.C57 2012']),
|
||||
], { hint: 'GV199.62' });
|
||||
assert.equal(v?.key, 'GV199.62');
|
||||
});
|
||||
|
||||
test('queries come from the title: capitalised mid-title words first, then longer, and subtitle words stay out', () => {
|
||||
const k = keywordsOf('Day hikes & overnights on the Pacific Crest Trail', 'Southern California : from the Mexican Border to Los Angeles County', ['Guidebooks', 'Hiking']);
|
||||
assert.deepEqual(k.own, ['pacific', 'crest', 'trail', 'overnights', 'hikes']);
|
||||
assert.deepEqual(k.sub.slice(0, 3), ['california', 'mexican', 'angeles']);
|
||||
assert.deepEqual(k.title.slice(0, 5), k.own); // scoring still sees the subtitle after the title's words
|
||||
assert.deepEqual(searchWords(k), [
|
||||
['pacific', 'crest', 'trail', 'overnights', 'hikes'], ['pacific', 'crest', 'trail', 'overnights'], ['pacific', 'crest', 'trail'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('a Title Case title carries no signal from capitals: longest words first, as before', () => {
|
||||
const k = keywordsOf('Beyond Trails in the Wind River Mountains of Wyoming');
|
||||
assert.deepEqual(k.own, ['mountains', 'wyoming', 'trails', 'river', 'wind']);
|
||||
assert.deepEqual(searchWords(k)[2], ['mountains', 'wyoming', 'trails']);
|
||||
});
|
||||
|
||||
test('a title with fewer than two usable words borrows the subtitle, then the subjects, in one query of three', () => {
|
||||
const k = keywordsOf('Dune', 'Messiah of the desert planet', ['Science fiction', 'Arrakis (Imaginary place)']);
|
||||
assert.deepEqual(k.own, ['dune']);
|
||||
assert.deepEqual(searchWords(k), [['dune', 'messiah', 'desert']]);
|
||||
const bare = keywordsOf('Dune', undefined, ['Science fiction', 'Arrakis (Imaginary place)']);
|
||||
assert.deepEqual(searchWords(bare), [['dune', 'imaginary', 'science']]);
|
||||
assert.deepEqual(searchWords(keywordsOf('The Complete Guide')), []);
|
||||
});
|
||||
Reference in new issue
Block a user