@natlibfi/melinda-record-matching 6.0.0-alpha.1 → 6.0.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/candidate-search/candidate-search-utils.js +21 -3
- package/dist/candidate-search/candidate-search-utils.js.map +2 -2
- package/dist/candidate-search/query-list/bib.js +64 -15
- package/dist/candidate-search/query-list/bib.js.map +3 -3
- package/dist/match-detection/features/bib/publisherNumber.js +1 -1
- package/dist/match-detection/features/bib/publisherNumber.js.map +2 -2
- package/dist/match-detection/features/bib/title.js +11 -3
- package/dist/match-detection/features/bib/title.js.map +2 -2
- package/package.json +2 -2
- package/src/candidate-search/candidate-search-utils.js +26 -3
- package/src/candidate-search/query-list/bib.js +90 -16
- package/src/match-detection/features/bib/publisherNumber.js +2 -1
- package/src/match-detection/features/bib/title.js +21 -3
|
@@ -1,15 +1,33 @@
|
|
|
1
1
|
import createDebugLogger from "debug";
|
|
2
|
+
import { uniqArray } from "@natlibfi/marc-record-validators-melinda/dist/utils.js";
|
|
2
3
|
export function toQueries(identifiers, queryString) {
|
|
3
4
|
const debug = createDebugLogger("@natlibfi/melinda-record-matching:toQueries");
|
|
4
5
|
const debugData = debug.extend("data");
|
|
5
|
-
const
|
|
6
|
+
const debugDev = debug.extend("dev");
|
|
7
|
+
const useMaxLength = queryString === "dc.identifier" ? true : false;
|
|
8
|
+
const maxLength = 40;
|
|
9
|
+
debugData(`Adding ${queryString} to ${JSON.stringify(identifiers)}`);
|
|
10
|
+
debugDev(`We are ${useMaxLength ? `using maxLength ${maxLength}, queryString ${queryString}` : `not using maxLength, queryString ${queryString}`}`);
|
|
11
|
+
const croppedIdentifiers = uniqArray(useMaxLength ? identifiers.map((identifier) => identifier.substring(0, maxLength)) : identifiers);
|
|
12
|
+
const quotedIdentifiers = croppedIdentifiers.map((identifier) => identifier.match(/\//u) || identifier.match(/\^/u) ? `"${identifier}"` : `${identifier}`);
|
|
6
13
|
const caretPairs = toPairs(quotedIdentifiers.filter((identifier) => identifier.match(/\^/u)));
|
|
7
14
|
const nonCaretPairs = toPairs(quotedIdentifiers.filter((identifier) => !identifier.match(/\^/u)));
|
|
8
15
|
const pairs = nonCaretPairs.concat(caretPairs);
|
|
9
16
|
debugData(`Pairs (${pairs.length}): ${JSON.stringify(pairs)}`);
|
|
10
|
-
const queries = pairs.map(
|
|
17
|
+
const queries = pairs.map(
|
|
18
|
+
([a, b]) => {
|
|
19
|
+
const lengths = a.length + (b ? b.length : 0);
|
|
20
|
+
debugDev(`Lengths: A: ${a} (${a.length}) + B: ${b} (${b ? b.length : 0}) = ${lengths}`);
|
|
21
|
+
if (useMaxLength && lengths > maxLength && a && b) {
|
|
22
|
+
return [`${queryString}=${a}`, `${queryString}=${b}`];
|
|
23
|
+
}
|
|
24
|
+
return b ? `${queryString}=${a} or ${queryString}=${b}` : `${queryString}=${a}`;
|
|
25
|
+
}
|
|
26
|
+
);
|
|
11
27
|
debugData(`Queries (${queries.length}): ${JSON.stringify(queries)}`);
|
|
12
|
-
|
|
28
|
+
const flatQueries = queries.flat();
|
|
29
|
+
debugData(`FlatQueries (${flatQueries.length}): ${JSON.stringify(flatQueries)}`);
|
|
30
|
+
return flatQueries;
|
|
13
31
|
}
|
|
14
32
|
function toPairs(array) {
|
|
15
33
|
if (array.length === 0) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/candidate-search/candidate-search-utils.js"],
|
|
4
|
-
"sourcesContent": ["import createDebugLogger from 'debug';\n\nexport function toQueries(identifiers, queryString) {\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:toQueries');\n const debugData = debug.extend('data');\n\n // We quote the identifier, if it contains a slash! (Slash in non-quoted SRU-search breaks search.)\n // We also quote the identifier, if it starts with caret (f028 searches fail without caret and quotes...)\n const quotedIdentifiers =
|
|
5
|
-
"mappings": "AAAA,OAAO,uBAAuB;
|
|
4
|
+
"sourcesContent": ["import createDebugLogger from 'debug';\nimport {uniqArray} from '@natlibfi/marc-record-validators-melinda/dist/utils.js';\n\nexport function toQueries(identifiers, queryString) {\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:toQueries');\n const debugData = debug.extend('data');\n const debugDev = debug.extend('dev');\n\n // For dc.identifier search use max length of 40 characters to avoid dc.identifier -> 1007 mapped query from crashing\n // DEVELOP: check if the length crash is related to mapping the query to multiple Aleph indexes\n const useMaxLength = queryString === 'dc.identifier' ? true : false;\n const maxLength = 40;\n debugData(`Adding ${queryString} to ${JSON.stringify(identifiers)}`)\n debugDev(`We are ${useMaxLength ? `using maxLength ${maxLength}, queryString ${queryString}` : `not using maxLength, queryString ${queryString}`}`);\n const croppedIdentifiers = uniqArray(useMaxLength ? identifiers.map((identifier) => identifier.substring(0, maxLength)) : identifiers);\n\n // We quote the identifier, if it contains a slash! (Slash in non-quoted SRU-search breaks search.)\n // We also quote the identifier, if it starts with caret (f028 searches fail without caret and quotes...)\n const quotedIdentifiers = croppedIdentifiers.map(identifier => identifier.match(/\\//u) || identifier.match(/\\^/u) ? `\"${identifier}\"` : `${identifier}`);\n\n // We can't pair queries with starting caret and without (ie. left anchored queries with non-left anchored queries)\n const caretPairs = toPairs(quotedIdentifiers.filter(identifier => identifier.match(/\\^/u)));\n const nonCaretPairs = toPairs(quotedIdentifiers.filter(identifier => !identifier.match(/\\^/u)));\n\n const pairs = nonCaretPairs.concat(caretPairs);\n debugData(`Pairs (${pairs.length}): ${JSON.stringify(pairs)}`);\n\n // Aleph supports only two queries with or -operator (This is not actually true)\n const queries = pairs.map(([a, b]) => {\n const lengths = a.length + (b ? b.length : 0);\n debugDev(`Lengths: A: ${a} (${a.length}) + B: ${b} (${b ? b.length : 0}) = ${lengths}`);\n\n // Do not create a paired query if query length would be too long\n if (useMaxLength && lengths > maxLength && a && b) {\n return [`${queryString}=${a}`, `${queryString}=${b}`];\n }\n return b ? `${queryString}=${a} or ${queryString}=${b}` : `${queryString}=${a}`}\n );\n\n debugData(`Queries (${queries.length}): ${JSON.stringify(queries)}`);\n const flatQueries = queries.flat();\n debugData(`FlatQueries (${flatQueries.length}): ${JSON.stringify(flatQueries)}`);\n\n return flatQueries;\n}\n\nfunction toPairs(array) {\n if (array.length === 0) {\n return [];\n }\n return [array.slice(0, 2)].concat(toPairs(array.slice(2), 2));\n}\n\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,uBAAuB;AAC9B,SAAQ,iBAAgB;AAEjB,gBAAS,UAAU,aAAa,aAAa;AAElD,QAAM,QAAQ,kBAAkB,6CAA6C;AAC7E,QAAM,YAAY,MAAM,OAAO,MAAM;AACrC,QAAM,WAAW,MAAM,OAAO,KAAK;AAInC,QAAM,eAAe,gBAAgB,kBAAkB,OAAO;AAC9D,QAAM,YAAY;AAClB,YAAU,UAAU,WAAW,OAAO,KAAK,UAAU,WAAW,CAAC,EAAE;AACnE,WAAS,UAAU,eAAe,mBAAmB,SAAS,iBAAiB,WAAW,KAAK,oCAAoC,WAAW,EAAE,EAAE;AAClJ,QAAM,qBAAqB,UAAU,eAAe,YAAY,IAAI,CAAC,eAAe,WAAW,UAAU,GAAG,SAAS,CAAC,IAAI,WAAW;AAIrI,QAAM,oBAAoB,mBAAmB,IAAI,gBAAc,WAAW,MAAM,KAAK,KAAK,WAAW,MAAM,KAAK,IAAI,IAAI,UAAU,MAAM,GAAG,UAAU,EAAE;AAGvJ,QAAM,aAAa,QAAQ,kBAAkB,OAAO,gBAAc,WAAW,MAAM,KAAK,CAAC,CAAC;AAC1F,QAAM,gBAAgB,QAAQ,kBAAkB,OAAO,gBAAc,CAAC,WAAW,MAAM,KAAK,CAAC,CAAC;AAE9F,QAAM,QAAQ,cAAc,OAAO,UAAU;AAC7C,YAAU,UAAU,MAAM,MAAM,MAAM,KAAK,UAAU,KAAK,CAAC,EAAE;AAG7D,QAAM,UAAU,MAAM;AAAA,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM;AACpC,YAAM,UAAU,EAAE,UAAU,IAAI,EAAE,SAAS;AAC3C,eAAS,eAAe,CAAC,KAAK,EAAE,MAAM,UAAU,CAAC,KAAK,IAAI,EAAE,SAAS,CAAC,OAAO,OAAO,EAAE;AAGtF,UAAI,gBAAgB,UAAU,aAAa,KAAK,GAAG;AACjD,eAAO,CAAC,GAAG,WAAW,IAAI,CAAC,IAAI,GAAG,WAAW,IAAI,CAAC,EAAE;AAAA,MACtD;AACA,aAAO,IAAI,GAAG,WAAW,IAAI,CAAC,OAAO,WAAW,IAAI,CAAC,KAAK,GAAG,WAAW,IAAI,CAAC;AAAA,IAAE;AAAA,EACjF;AAEA,YAAU,YAAY,QAAQ,MAAM,MAAM,KAAK,UAAU,OAAO,CAAC,EAAE;AACnE,QAAM,cAAc,QAAQ,KAAK;AACjC,YAAU,gBAAgB,YAAY,MAAM,MAAM,KAAK,UAAU,WAAW,CAAC,EAAE;AAE/E,SAAO;AACT;AAEA,SAAS,QAAQ,OAAO;AACtB,MAAI,MAAM,WAAW,GAAG;AACtB,WAAO,CAAC;AAAA,EACV;AACA,SAAO,CAAC,MAAM,MAAM,GAAG,CAAC,CAAC,EAAE,OAAO,QAAQ,MAAM,MAAM,CAAC,GAAG,CAAC,CAAC;AAC9D;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -4,7 +4,9 @@ import { getMelindaIdsF035, validateSidFieldSubfieldCounts, getSubfieldValues, t
|
|
|
4
4
|
import { extractHostMelindaIdsFromField, extractPublicationYearFrom773, getHostMelindaFields } from "./component.js";
|
|
5
5
|
import { fieldToString } from "@natlibfi/marc-record-validators-melinda";
|
|
6
6
|
import { getTitle } from "../../match-detection/features/bib/title.js";
|
|
7
|
+
import { uniqArray } from "@natlibfi/marc-record-validators-melinda/dist/utils.js";
|
|
7
8
|
const debug = createDebugLogger("@natlibfi/melinda-record-matching:candidate-search:query");
|
|
9
|
+
const debugDev = debug.extend("dev");
|
|
8
10
|
const IS_OK_ALONE_THRESHOLD = 5;
|
|
9
11
|
export function bibSourceIds(record) {
|
|
10
12
|
const debug2 = createDebugLogger("@natlibfi/melinda-record-matching:candidate-search:query:source-ids");
|
|
@@ -101,6 +103,7 @@ export function bibTitleAuthorYearAlternates(record) {
|
|
|
101
103
|
}
|
|
102
104
|
function getTitleForQuery(record) {
|
|
103
105
|
const title = getTitle(record, ["a"]);
|
|
106
|
+
debug(`getTitleForQuery: title ${title}`);
|
|
104
107
|
if (title) {
|
|
105
108
|
const nWords = title.split(" ");
|
|
106
109
|
if (nWords < 3 || title.length < 12) {
|
|
@@ -115,15 +118,20 @@ function getTitleForQuery(record) {
|
|
|
115
118
|
}
|
|
116
119
|
function dcTitle(record, onlyTitleLength, alternates = false) {
|
|
117
120
|
const title = getTitleForQuery(record);
|
|
121
|
+
debug(`dcTitle: title: ${title}`);
|
|
118
122
|
if (!testStringOrNumber(title)) {
|
|
119
123
|
return [];
|
|
120
124
|
}
|
|
121
125
|
const formatted = getFormattedTitle(title);
|
|
126
|
+
debug(`dcTitle: formatted: ${formatted}`);
|
|
122
127
|
const useWordSearch = checkUseWordSearch(formatted);
|
|
123
128
|
if (formatted.length >= onlyTitleLength && !alternates) {
|
|
124
129
|
return [`dc.title="${useWordSearch ? "" : "^"}${formatted}*"`, formatted, true];
|
|
125
130
|
}
|
|
126
131
|
const queryIsOkAlone = !useWordSearch && formatted.length >= IS_OK_ALONE_THRESHOLD;
|
|
132
|
+
if (formatted.length < 1) {
|
|
133
|
+
return ["", formatted, queryIsOkAlone];
|
|
134
|
+
}
|
|
127
135
|
return [`dc.title="${useWordSearch || !queryIsOkAlone ? "" : "^"}${formatted}${queryIsOkAlone ? "*" : ""}"`, formatted, queryIsOkAlone];
|
|
128
136
|
function getFormattedTitle(title2) {
|
|
129
137
|
const formatted2 = String(title2).replace(/[\-+ !"(){}\[\]<>;:.?/@*%=^_`~]/gu, " ").replace(/[^\w\s\p{Alphabetic}]/gu, "").replace(/ +/gu, " ").trim().replace(/^(.{30}\S*) .*$/, "$1").trim();
|
|
@@ -133,6 +141,7 @@ function dcTitle(record, onlyTitleLength, alternates = false) {
|
|
|
133
141
|
export function bibTitleAuthorPublisher({ record, onlyTitleLength, addYear = false, alternates = false, alternateQueries = [] }) {
|
|
134
142
|
debug(`bibTitleAuthorPublisher, onlyTitleLength: ${onlyTitleLength}, addYear: ${addYear}, alternates: ${alternates}`);
|
|
135
143
|
const [query, formatted, queryIsOkAlone] = dcTitle(record, onlyTitleLength, alternates);
|
|
144
|
+
debug(`query ${JSON.stringify(query)}, formatted: ${JSON.stringify(formatted)}, isOKAlone: ${JSON.stringify(queryIsOkAlone)}`);
|
|
136
145
|
if (query === void 0) {
|
|
137
146
|
return [];
|
|
138
147
|
}
|
|
@@ -146,22 +155,24 @@ export function bibTitleAuthorPublisher({ record, onlyTitleLength, addYear = fal
|
|
|
146
155
|
debug("addAuthorsToSearch");
|
|
147
156
|
const [authorQuery] = bibAuthors(record);
|
|
148
157
|
if (authorQuery !== void 0) {
|
|
158
|
+
const combinedQuery = query2.length > 0 ? `${authorQuery} AND ${query2}` : `${authorQuery}`;
|
|
149
159
|
if (addYear2) {
|
|
150
|
-
const newAlternateQueries2 = alternates2 ? [...alternateQueries2,
|
|
151
|
-
return addYearToSearch({ query:
|
|
160
|
+
const newAlternateQueries2 = alternates2 ? [...alternateQueries2, combinedQuery] : alternateQueries2;
|
|
161
|
+
return addYearToSearch({ query: combinedQuery, queryIsOkAlone: true, alternates: alternates2, alternateQueries: newAlternateQueries2 });
|
|
152
162
|
}
|
|
153
|
-
return alternates2 ? alternateQueries2 : [
|
|
163
|
+
return alternates2 ? alternateQueries2 : [combinedQuery];
|
|
154
164
|
}
|
|
155
165
|
return addPublisherToSearch({ query: query2, queryIsOkAlone: queryIsOkAlone2, addYear: addYear2, alternates: alternates2, alternateQueries: alternateQueries2 });
|
|
156
166
|
}
|
|
157
167
|
function addPublisherToSearch({ query: query2, queryIsOkAlone: queryIsOkAlone2 = false, addYear: addYear2 = false, alternates: alternates2 = false, alternateQueries: alternateQueries2 = [] }) {
|
|
158
168
|
const [publisherQuery] = bibPublishers(record);
|
|
159
169
|
if (publisherQuery !== void 0) {
|
|
170
|
+
const combinedQuery = query2.length > 0 ? `${publisherQuery} AND ${query2}` : `${publisherQuery}`;
|
|
160
171
|
if (addYear2) {
|
|
161
|
-
const newAlternateQueries2 = alternates2 ? [...alternateQueries2,
|
|
162
|
-
return addYearToSearch({ query:
|
|
172
|
+
const newAlternateQueries2 = alternates2 ? [...alternateQueries2, combinedQuery] : alternateQueries2;
|
|
173
|
+
return addYearToSearch({ query: combinedQuery, queryIsOkAlone: true, alternates: alternates2, alternateQueries: newAlternateQueries2 });
|
|
163
174
|
}
|
|
164
|
-
return alternates2 ? alternateQueries2 : [
|
|
175
|
+
return alternates2 ? alternateQueries2 : [combinedQuery];
|
|
165
176
|
}
|
|
166
177
|
if (queryIsOkAlone2 && !addYear2) {
|
|
167
178
|
return alternates2 ? alternateQueries2 : [`${query2}`];
|
|
@@ -171,7 +182,7 @@ export function bibTitleAuthorPublisher({ record, onlyTitleLength, addYear = fal
|
|
|
171
182
|
function addYearToSearch({ query: query2, queryIsOkAlone: queryIsOkAlone2 = false, alternates: alternates2 = false, alternateQueries: alternateQueries2 = [] }) {
|
|
172
183
|
const [yearQuery] = bibYear(record);
|
|
173
184
|
if (yearQuery !== void 0) {
|
|
174
|
-
const yearAndOtherQueries = `${yearQuery} AND ${query2}`;
|
|
185
|
+
const yearAndOtherQueries = query2.length > 0 ? `${yearQuery} AND ${query2}` : `${yearQuery}`;
|
|
175
186
|
return alternates2 ? [...alternateQueries2, yearAndOtherQueries] : [yearAndOtherQueries];
|
|
176
187
|
}
|
|
177
188
|
if (queryIsOkAlone2) {
|
|
@@ -244,10 +255,12 @@ export function bibYear(record) {
|
|
|
244
255
|
}
|
|
245
256
|
debugData(`f008: ${JSON.stringify(f008)}`);
|
|
246
257
|
const { value } = f008;
|
|
247
|
-
|
|
258
|
+
const year2 = value.slice(7, 11);
|
|
259
|
+
if (year2 === "||||" || year2 === " ") {
|
|
260
|
+
debug2("Meaningless year in f008");
|
|
248
261
|
return false;
|
|
249
262
|
}
|
|
250
|
-
return
|
|
263
|
+
return year2;
|
|
251
264
|
}
|
|
252
265
|
}
|
|
253
266
|
export function checkUseWordSearch(formatted) {
|
|
@@ -258,6 +271,7 @@ export function checkUseWordSearch(formatted) {
|
|
|
258
271
|
export function bibStandardIdentifiers(record) {
|
|
259
272
|
const debug2 = createDebugLogger("@natlibfi/melinda-record-matching:candidate-search:query:bibStandardIdentifiers");
|
|
260
273
|
const debugData = debug2.extend("data");
|
|
274
|
+
const debugDev2 = debug2.extend("dev");
|
|
261
275
|
debug2(`Creating queries for standard identifiers`);
|
|
262
276
|
const fields = record.get(/^(?<def>015|020|022|024|028)$/u);
|
|
263
277
|
const identifiers = [].concat(...fields.map(toIdentifiers));
|
|
@@ -283,14 +297,49 @@ export function bibStandardIdentifiers(record) {
|
|
|
283
297
|
return subfields.filter((sub) => ["a", "z", "y"].includes(sub.code) && testStringOrNumber(sub.value) && issnIsbnReqExp.test(String(sub.value))).map(({ value }) => String(value));
|
|
284
298
|
}
|
|
285
299
|
if (tag === "028") {
|
|
300
|
+
let cleanQualifiers = function(val) {
|
|
301
|
+
if (val !== void 0) {
|
|
302
|
+
const cleanVal = val.replace(/ +\(.*\)/gu, "").replace(/ +/ug, " ").replace(/^ +/ug, "").replace(/ +$/ug, "");
|
|
303
|
+
return uniqArray([val, cleanVal]);
|
|
304
|
+
}
|
|
305
|
+
return [];
|
|
306
|
+
}, normalizeF028ForSearch = function(val) {
|
|
307
|
+
const f028NormCharsRegex = /[-"<>;:%=~`!\(\)\{\}\.\?\/\@\*\^]/g;
|
|
308
|
+
const normVal = val.replace(f028NormCharsRegex, " ").replace(/ +/ug, " ").replace(/^ +/ug, "").replace(/ +$/ug, "").toLowerCase();
|
|
309
|
+
return normVal !== " " ? normVal : "";
|
|
310
|
+
};
|
|
286
311
|
const a = subfields.find((sf) => sf.code === "a");
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
312
|
+
const b = subfields.find((sf) => sf.code === "b");
|
|
313
|
+
const cleanAs = cleanQualifiers(a?.value);
|
|
314
|
+
const cleanBs = cleanQualifiers(b?.value);
|
|
315
|
+
debugDev2(JSON.stringify(cleanAs));
|
|
316
|
+
debugDev2(JSON.stringify(cleanBs));
|
|
317
|
+
const splitAs = cleanAs.map((elem) => elem.split(",")).concat(cleanAs).flat();
|
|
318
|
+
const splitBs = cleanBs.map((elem) => elem.split(",")).concat(cleanBs).flat();
|
|
319
|
+
debugDev2(JSON.stringify(splitAs));
|
|
320
|
+
debugDev2(JSON.stringify(splitBs));
|
|
321
|
+
const normAs = splitAs.map((elem) => normalizeF028ForSearch(elem));
|
|
322
|
+
const normBs = splitBs.map((elem) => normalizeF028ForSearch(elem));
|
|
323
|
+
debugDev2(JSON.stringify(normAs));
|
|
324
|
+
debugDev2(JSON.stringify(normBs));
|
|
325
|
+
const identifiers2 = normAs.map((normA, index) => {
|
|
326
|
+
debugDev2(`Handling ${normA} from index: ${index}`);
|
|
327
|
+
if (normA.length > 0 && normBs[index]?.length > 0) {
|
|
328
|
+
debugDev2(`Found a (${normA}) + b (${normBs[index]})`);
|
|
329
|
+
return [`^${normBs[index]} ${normA}`, `^${normA} ${normBs[index]}`, `^${normA}`];
|
|
291
330
|
}
|
|
292
|
-
|
|
293
|
-
|
|
331
|
+
if (normA.length > 0 && normBs[0]?.length > 0) {
|
|
332
|
+
debugDev2(`Found a (${normA}) + b (${normBs[0]})`);
|
|
333
|
+
return [`^${normBs[0]} ${normA}`, `^${normA} ${normBs[0]}`, `^${normA}`];
|
|
334
|
+
}
|
|
335
|
+
if (normA.length > 0) {
|
|
336
|
+
debugDev2(`Found a (${normA}) but no b ${normBs[index]}`);
|
|
337
|
+
return [`^${normA}`];
|
|
338
|
+
}
|
|
339
|
+
return [];
|
|
340
|
+
});
|
|
341
|
+
debugDev2(`Current identifiers from f028: ${JSON.stringify(identifiers2)}`);
|
|
342
|
+
return uniqArray(identifiers2.flat());
|
|
294
343
|
}
|
|
295
344
|
return subfields.filter((sub) => ["a", "z"].includes(sub.code) && testStringOrNumber(sub.value) && otherIdReqExp.test(String(sub.value))).map(({ value }) => String(value));
|
|
296
345
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/candidate-search/query-list/bib.js"],
|
|
4
|
-
"sourcesContent": ["import createDebugLogger from 'debug';\nimport {toQueries} from '../candidate-search-utils.js';\nimport {getMelindaIdsF035, validateSidFieldSubfieldCounts, getSubfieldValues, testStringOrNumber} from '../../matching-utils.js';\nimport {extractHostMelindaIdsFromField, extractPublicationYearFrom773, getHostMelindaFields} from './component.js';\nimport {fieldToString} from '@natlibfi/marc-record-validators-melinda';\nimport {getTitle} from '../../match-detection/features/bib/title.js';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query');\n\nconst IS_OK_ALONE_THRESHOLD = 5;\n\nexport function bibSourceIds(record) {\n\n /* Melinda's SRU-index melinda.sourceid includes source IDs from SID fields in Melinda records\n SID-fields in Melinda have sf $c with local id and sf $b with a code for the local db:\n\n SID__ $c 123457 $b helka\n SID__ $c (ANDL100020)1077305 $b sata\n SID__ $c VER999999 $ FI-KV\n SID__ $c /10024/508126 $ REPO_THESEUS\n\n In melinda.sourceid -index case is kept, sourceprefixes in brackets and hyphens are normalized away:\n Note: slashes are not normalized away, but a SRU-search-string including slashes needs to be quoted\n\n 1234567helka\n 1077305sata\n VER999999FIKV\n /10024/508126REPO_THESEUS\n\n Note: All Melinda records that have a matching records in a local db do NOT have SID for that local records,\n existence of a SID field depends on how the record has been added to Melinda and how it has been handled\n afterwards. SIDs are also not reliably maintained. A record might or might not have a SID for a local db\n after the matching record is removed from the local db.\n\n */\n\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:source-ids');\n const debugData = debug.extend('data');\n //const debugInfo = debug.extend('info');\n\n debug(`Creating queries for sourceid's`);\n\n const fSids = record.get('SID');\n debugData(`SID-fields (${fSids.length}): ${JSON.stringify(fSids)}`);\n\n return fSids.length > 0 ? toSidQueries(fSids) : [];\n\n function toSidQueries(fSids) {\n debug(`Creating actual queries for sourceid's`);\n\n const sidStrings = getSidStrings(fSids);\n\n if (sidStrings.length < 1) {\n debug(`No identifiers found, no queries created.`);\n return [];\n }\n\n const sidQueries = toQueries(sidStrings, 'melinda.sourceid');\n\n return sidQueries;\n\n function getSidStrings(fSids) {\n debug(`Getting Sid strings from SID fields`);\n\n // Map SID fields to valid sidStrings, filter out empty strings\n const sidStrings = fSids.map(toSidString).filter(nonEmptySid => nonEmptySid);\n return sidStrings;\n\n function toSidString(field) {\n debug(`Getting string from a field`);\n\n return validateSidFieldSubfieldCounts(field) ? createSidString(field) : '';\n\n function createSidString(field) {\n debug(`Creating string from a field`);\n const [sfC] = getSubfieldValues(field, 'c');\n const [sfB] = getSubfieldValues(field, 'b');\n\n const cleanedSfC = removeSourcePrefix(normalizeSidSubfieldValue(sfC));\n const cleanedSfB = normalizeSidSubfieldValue(sfB);\n\n debugData(`${JSON.stringify(sfC)} + ${JSON.stringify(sfB)}`);\n return cleanedSfC.concat(cleanedSfB);\n }\n\n function removeSourcePrefix(subfieldValue) {\n const sourcePrefixRegex = (/^(?<sourcePrefix>\\([A-Za-z0-9-]+\\))(?<id>.+)$/u);\n const normalizedValue = testStringOrNumber(subfieldValue) ? String(subfieldValue).replace(sourcePrefixRegex, '$<id>') : '';\n debugData(`Normalized ${subfieldValue} to ${normalizedValue}`);\n return normalizedValue;\n }\n\n function normalizeSidSubfieldValue(subfieldValue) {\n debugData(`Normalizing ${subfieldValue}`);\n const normalizeAwayRegex = (/[- ]/u);\n return testStringOrNumber(subfieldValue) ? String(subfieldValue).replace(normalizeAwayRegex, '') : '';\n }\n\n }\n }\n }\n}\n\nexport function bibMelindaIds(record) {\n // Melinda's SRU-index melinda.melindaid includes f001 controlnumbers and old Melinda-IDs from f035z's for all non-deleted Melinda-records\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibMelindaIds');\n const debugData = debug.extend('data');\n debug(`Creating queries for MelindaIds`);\n\n // Note: Melinda-ID's for search queries are created just from records f035a's and f035z's\n // Both (FI-MELINDA)- and FCC-prefixed forms are found\n // f001 controlnumber is not currently included, even if record's f003 is FI-MELINDA\n const melindaIds = getMelindaIdsF035(record);\n\n debugData(`Unique identifiers (${melindaIds.length}): ${JSON.stringify(melindaIds)}`);\n\n if (melindaIds.length < 1) {\n debug(`No identifiers found, no queries created.`);\n return [];\n }\n\n return toQueries(melindaIds, 'melinda.melindaid');\n}\n\n\n// bibHostComponents returns host id from the first subfield $w of first field f773, see test-fixtures 04 and 05\n// bibHostComponents should search all 773 $ws for possible host id, but what should it do in case of multiple host ids?\nexport function bibHostComponents(record) {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibHostComponents');\n const debugData = debug.extend('data');\n debug(`Creating queries for hostIds`);\n const f773s = getHostMelindaFields(record);\n if (f773s.length !== 1) { // This needs some thinking...\n return [];\n }\n\n const [id] = extractHostMelindaIdsFromField(f773s[0]);\n debug(`Found id: ${JSON.stringify(id)}`);\n\n // NB! record.isCR() does not work if LDR/07=a, so we get year from 773$g!\n const year = extractPublicationYearFrom773(f773s[0]);\n debug(`${fieldToString(f773s[0])} => ${year ? year : 'N/A'}`);\n if (year) {\n return [`dc.date=${year} AND melinda.partsofhost=${id}`];\n }\n\n return [`melinda.partsofhost=${id}`];\n\n}\n\n\n\n\n// SRU search dc.title with a search phrase starting with ^ maps currently in Melinda to (probably) to *headings* index TIT\n// - Aleph cannot currently handle headings searches starting with a boolean - in these cases use word search\n\nexport function bibTitle(record) {\n // We get author/publisher only when formatted title is shorter than 5 chars\n return bibTitleAuthorPublisher({record, onlyTitleLength: 5});\n}\n\nexport function bibTitleAuthor(record) {\n debug('bibTitleAuthor');\n // We use onlyTitleLength that is longer than our formatted length to\n // get an author or an publisher always\n return bibTitleAuthorPublisher({record, onlyTitleLength: 100});\n}\n\nexport function bibTitleAuthorYear(record) {\n debug('bibTitleAuthorYearAlternates');\n // We use onlyTitleLength that is longer than our formatted length to\n // get an author or an publisher always\n\n return bibTitleAuthorPublisher({record, onlyTitleLength: 100, addYear: true});\n}\n\nexport function bibTitleAuthorYearAlternates(record) {\n debug('bibTitleAuthorYearAlternates');\n // We use onlyTitleLength that is longer than our formatted length to\n // get an author or an publisher always\n const origQueryList = bibTitleAuthorPublisher({record, onlyTitleLength: 100, addYear: true, alternates: true, alternateQueries: []});\n debug(`${JSON.stringify(origQueryList)}`);\n return {queryList: Array.from(origQueryList).reverse(), queryListType: 'alternates'};\n}\n\nfunction getTitleForQuery(record) {\n const title = getTitle(record, ['a']);\n if (title) {\n const nWords = title.split(' ');\n // If lone $a is deemed too short, fetch $b as well:\n // (NV: I've seen pairs with 245$a-only vs 245$a$b, so I'd like to use $a only if it is long enough)\n\n if (nWords < 3 || title.length < 12) {\n const [f245] = record.get('245');\n // If punctuation is ' =' I think that f245$a is good enough despite shortness. Trying to balance between two bad situations...\n // \"Suo (= short title) siell\u00E4, vetel\u00E4 (= missing $b name in another language) t\u00E4\u00E4ll\u00E4...\"\n if (f245 && f245.subfields.find(sf => sf.code === 'a' && sf.value.match(/ =$/u)) && title.length >= IS_OK_ALONE_THRESHOLD) {\n return title;\n }\n return getTitle(record, ['a', 'b']); // Try to get a longer title\n }\n }\n return title;\n}\n\nfunction dcTitle(record, onlyTitleLength, alternates = false) {\n const title = getTitleForQuery(record);\n if (!testStringOrNumber(title)) {\n return [];\n }\n\n const formatted = getFormattedTitle(title);\n\n // use word search for titles starting with a boolean\n const useWordSearch = checkUseWordSearch(formatted);\n // Prevent too many matches / SRU crashing by having a minimum length\n // Note that currently this fails matching if there are no matches from previous matchers\n if (formatted.length >= onlyTitleLength && !alternates) {\n return [`dc.title=\"${useWordSearch ? '' : '^'}${formatted}*\"`, formatted, true];\n }\n\n const queryIsOkAlone = !useWordSearch && formatted.length >= IS_OK_ALONE_THRESHOLD;\n\n // use word search without ending * also in combination searches to avoid SRU-server crashes [MRA-189]\n return [`dc.title=\"${useWordSearch || !queryIsOkAlone ? '' : '^'}${formatted}${queryIsOkAlone ? '*' : ''}\"`, formatted, queryIsOkAlone];\n\n function getFormattedTitle(title) {\n const formatted = String(title)\n .replace(/[\\-+ !\"(){}\\[\\]<>;:.?/@*%=^_`~]/gu, ' ')\n .replace(/[^\\w\\s\\p{Alphabetic}]/gu, '') // Apparently matches to/works with non-aplhabetic scripts such as Chinese as well\n .replace(/ +/gu, ' ') // Clean up concurrent spaces from eg. subfield changes\n .trim()\n .replace(/^(.{30}\\S*) .*$/, \"$1\")\n .trim();\n\n return formatted;\n }\n}\n\nexport function bibTitleAuthorPublisher({record, onlyTitleLength, addYear = false, alternates = false, alternateQueries = []}) {\n debug(`bibTitleAuthorPublisher, onlyTitleLength: ${onlyTitleLength}, addYear: ${addYear}, alternates: ${alternates}`);\n const [query, formatted, queryIsOkAlone] = dcTitle(record, onlyTitleLength, alternates);\n if (query === undefined) {\n return [];\n }\n\n debug(`query: ${query}`);\n\n // Prevent too many matches / SRU crashing by having a minimum length\n // Note that currently this fails matching if there are no matches from previous matchers\n if (formatted.length >= onlyTitleLength && !alternates) {\n return [query];\n }\n\n const newAlternateQueries = alternates ? [...alternateQueries, query] : alternateQueries;\n\n return addAuthorsToSearch({query, queryIsOkAlone, addYear, alternates, alternateQueries: newAlternateQueries});\n\n function addAuthorsToSearch({query, queryIsOkAlone = false, addYear = false, alternates = false, alternateQueries = []}) {\n debug('addAuthorsToSearch');\n const [authorQuery] = bibAuthors(record);\n if (authorQuery !== undefined) {\n if (addYear) {\n const newAlternateQueries = alternates ? [...alternateQueries, `${authorQuery} AND ${query}`] : alternateQueries;\n return addYearToSearch({query: `${authorQuery} AND ${query}`, queryIsOkAlone: true, alternates, alternateQueries: newAlternateQueries});\n }\n return alternates ? alternateQueries : [`${authorQuery} AND ${query}`];\n }\n return addPublisherToSearch({query, queryIsOkAlone, addYear, alternates, alternateQueries});\n //return [];\n }\n\n function addPublisherToSearch({query, queryIsOkAlone = false, addYear = false, alternates = false, alternateQueries = []}) {\n const [publisherQuery] = bibPublishers(record);\n if (publisherQuery !== undefined) {\n if (addYear) {\n const newAlternateQueries = alternates ? [...alternateQueries, `${publisherQuery} AND ${query}`] : alternateQueries;\n return addYearToSearch({query: `${publisherQuery} AND ${query}`, queryIsOkAlone: true, alternates, alternateQueries: newAlternateQueries});\n }\n return alternates ? alternateQueries : [`${publisherQuery} AND ${query}`];\n }\n if (queryIsOkAlone && !addYear) {\n return alternates ? alternateQueries : [`${query}`];\n }\n return addYearToSearch({query, queryIsOkAlone, alternates, alternateQueries});\n }\n\n function addYearToSearch({query, queryIsOkAlone = false, alternates = false, alternateQueries = []}) {\n const [yearQuery] = bibYear(record);\n if (yearQuery !== undefined) {\n const yearAndOtherQueries = `${yearQuery} AND ${query}`;\n return alternates ? [...alternateQueries, yearAndOtherQueries] : [yearAndOtherQueries];\n }\n if (queryIsOkAlone) {\n return alternates ? alternateQueries : [`${query}`];\n }\n return [];\n }\n\n}\n\nexport function bibAuthors(record) {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibAuthors');\n const debugData = debug.extend('data');\n debug(`Creating query for the first author`);\n //debugData(record);\n\n const author = getAuthor(record);\n\n if (testStringOrNumber(author)) {\n const formatted = String(author)\n .replace(/[^\\w\\s\\p{Alphabetic}]/gu, '')\n // Clean up concurrent spaces from fe. subfield changes\n .replace(/ +/gu, ' ')\n .trim()\n .slice(0, 30)\n .trim();\n\n // use word search for authors starting with a boolean\n const useWordSearch = checkUseWordSearch(formatted);\n // Prevent too many matches by having a minimum length\n debugData(`Author string: ${formatted}`);\n if (formatted.length >= 5) {\n return [`dc.author=\"${useWordSearch ? '' : '^'}${formatted}*\"`];\n }\n return [];\n }\n\n return [];\n\n function getAuthor(record) {\n //debugData(record);\n const [field] = record.get(/^(?:100|110|111|700|710|711)$/u);\n //debugData(field);\n\n if (field) {\n const authorString = field.subfields\n .filter(({code}) => ['a'].includes(code)) // We might use different subfield code sets for X00, X10 and X11?\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .filter(value => value)\n // In Melinda's index subfield separators are indexed as ' '\n .join(' ');\n return authorString;\n }\n return false;\n }\n}\n\nexport function bibPublishers(record) {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibPublishers');\n const debugData = debug.extend('data');\n debug(`Creating query for the first publisher`);\n //debugData(record);\n\n const publisher = getPublisher(record);\n if (testStringOrNumber(publisher)) {\n const formatted = String(publisher)\n .replace(/[^\\w\\s\\p{Alphabetic}]/gu, '')\n // Clean up concurrent spaces from fe. subfield changes\n .replace(/ +/gu, ' ')\n .trim()\n .slice(0, 30)\n .trim();\n\n debugData(`Publisher string: '${formatted}'`);\n if (formatted.length === 0) {\n return [];\n }\n // use non-wildcard word search from dc.publisher\n return [`dc.publisher=\"${formatted}\"`];\n }\n\n return [];\n\n function getPublisher(record) {\n //debugData(record);\n const [field] = record.get(/^26[04]$/u).filter(f => f.subfields.some(sf => sf.code === 'b')); // Filter removes copyright-only fields\n //debugData(field);\n\n if (field) {\n const publisherString = field.subfields\n .filter(({code}) => ['b'].includes(code))\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .filter(value => value)\n // In Melinda's index subfield separators are indexed as ' '\n .join(' ')\n .trim();\n return publisherString;\n }\n return false;\n }\n}\n\nexport function bibYear(record) {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibYear');\n const debugData = debug.extend('data');\n debug(`Creating query for the publishing year`);\n\n const year = getYear(record);\n if (year) {\n return [`dc.date=\"${year}\"`];\n }\n return [];\n\n function getYear(record) {\n const [f008] = record.get(/^008$/u);\n if (!f008 || !f008.value || f008.value.length < 11) {\n debug('f008 missing/crappy');\n return false;\n }\n\n debugData(`f008: ${JSON.stringify(f008)}`);\n const {value} = f008;\n if (value === '||||' || value === ' ') { // Meaningless values\n return false;\n }\n return value.slice(7, 11);\n }\n}\n\nexport function checkUseWordSearch(formatted) {\n const lowercased = formatted.toLowerCase();\n // Note: add a space to startWords to catch just actual boolean words\n const booleanStartWords = ['and ', 'or ', 'nor ', 'not '];\n return booleanStartWords.some(word => lowercased.startsWith(word));\n}\n\nexport function bibStandardIdentifiers(record) {\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibStandardIdentifiers');\n const debugData = debug.extend('data');\n debug(`Creating queries for standard identifiers`);\n\n // DEVELOP: should we query also f015 and f028?\n\n // const fields = record.get(/^(?<def>020|022|024)$/u);\n const fields = record.get(/^(?<def>015|020|022|024|028)$/u);\n const identifiers = [].concat(...fields.map(toIdentifiers));\n const uniqueIdentifiers = [...new Set(identifiers)];\n\n debugData(`Standard identifier fields: ${JSON.stringify(fields)}`);\n debugData(`Identifiers (${identifiers.length}): ${JSON.stringify(identifiers)}`);\n debugData(`Unique identifiers (${uniqueIdentifiers.length}): ${JSON.stringify(uniqueIdentifiers)}`);\n\n if (uniqueIdentifiers.length < 1) {\n debug(`No identifiers found, no queries created.`);\n return [];\n }\n\n return toQueries(uniqueIdentifiers, 'dc.identifier');\n\n function toIdentifiers({tag, subfields}) {\n const issnIsbnReqExp = (/^[A-Za-z0-9-]+$/u);\n const otherIdReqExp = (/^[A-Za-z0-9-:]+$/u);\n\n if (tag === '015') { // TODO: test (does this use the right index etc.)\n return subfields\n .filter(sf => sf.code === 'a' && sf.value.match(/^[A-Z0-9\\-]+$/ui))\n .map(sf => sf.value)\n }\n\n if (tag === '020') {\n return subfields\n .filter(sub => ['a', 'z'].includes(sub.code) && testStringOrNumber(sub.value) && issnIsbnReqExp.test(String(sub.value)))\n .map(({value}) => String(value));\n }\n\n if (tag === '022') {\n return subfields\n .filter(sub => ['a', 'z', 'y'].includes(sub.code) && testStringOrNumber(sub.value) && issnIsbnReqExp.test(String(sub.value)))\n .map(({value}) => String(value));\n }\n\n if (tag === '028') { // TODO: test\n const a = subfields.find(sf => sf.code === 'a');\n if (a) {\n const b = subfields.find(sf => sf.code === 'b');\n // TODO: normalize?\n if (b) {\n return [`^${a.value}`, `^${b.value} ${a.value}`];\n }\n return [`^${a.value}`];\n }\n }\n\n // Default seems to be 024:\n return subfields\n .filter(sub => ['a', 'z'].includes(sub.code) && testStringOrNumber(sub.value) && otherIdReqExp.test(String(sub.value)))\n .map(({value}) => String(value));\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAAO,uBAAuB;AAC9B,SAAQ,iBAAgB;AACxB,SAAQ,mBAAmB,gCAAgC,mBAAmB,0BAAyB;AACvG,SAAQ,gCAAgC,+BAA+B,4BAA2B;AAClG,SAAQ,qBAAoB;AAC5B,SAAQ,gBAAe;AAEvB,MAAM,QAAQ,kBAAkB,0DAA0D;AAE1F,MAAM,wBAAwB;AAEvB,gBAAS,aAAa,QAAQ;AA0BnC,QAAMA,SAAQ,kBAAkB,qEAAqE;AACrG,QAAM,YAAYA,OAAM,OAAO,MAAM;AAGrC,EAAAA,OAAM,iCAAiC;AAEvC,QAAM,QAAQ,OAAO,IAAI,KAAK;AAC9B,YAAU,eAAe,MAAM,MAAM,MAAM,KAAK,UAAU,KAAK,CAAC,EAAE;AAElE,SAAO,MAAM,SAAS,IAAI,aAAa,KAAK,IAAI,CAAC;AAEjD,WAAS,aAAaC,QAAO;AAC3B,IAAAD,OAAM,wCAAwC;AAE9C,UAAM,aAAa,cAAcC,MAAK;AAEtC,QAAI,WAAW,SAAS,GAAG;AACzB,MAAAD,OAAM,2CAA2C;AACjD,aAAO,CAAC;AAAA,IACV;AAEA,UAAM,aAAa,UAAU,YAAY,kBAAkB;AAE3D,WAAO;AAEP,aAAS,cAAcC,QAAO;AAC5B,MAAAD,OAAM,qCAAqC;AAG3C,YAAME,cAAaD,OAAM,IAAI,WAAW,EAAE,OAAO,iBAAe,WAAW;AAC3E,aAAOC;AAEP,eAAS,YAAY,OAAO;AAC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O,IAAI,KAAK,CAAC,CAAC,EAC3H,IAAI,CAAC,EAAC,MAAK,MAAM,OAAO,KAAK,CAAC;AAAA,IACnC;AAEA,QAAI,QAAQ,OAAO;AACjB,YAAM,IAAI,UAAU,KAAK,QAAM,GAAG,SAAS,GAAG;AAC9C,UAAI,GAAG;AACL,cAAM,IAAI,UAAU,KAAK,QAAM,GAAG,SAAS,GAAG;AAE9C,YAAI,GAAG;AACL,iBAAO,CAAC,IAAI,EAAE,KAAK,IAAI,IAAI,EAAE,KAAK,IAAI,EAAE,KAAK,EAAE;AAAA,QACjD;AACA,eAAO,CAAC,IAAI,EAAE,KAAK,EAAE;AAAA,MACvB;AAAA,IACF;AAGA,WAAO,UACJ,OAAO,SAAO,CAAC,KAAK,GAAG,EAAE,SAAS,IAAI,IAAI,KAAK,mBAAmB,IAAI,KAAK,KAAK,cAAc,KAAK,OAAO,IAAI,KAAK,CAAC,CAAC,EACrH,IAAI,CAAC,EAAC,MAAK,MAAM,OAAO,KAAK,CAAC;AAAA,EACnC;AACF;",
|
|
6
|
-
"names": ["debug", "fSids", "sidStrings", "field", "title", "formatted", "query", "queryIsOkAlone", "addYear", "alternates", "alternateQueries", "newAlternateQueries", "record"]
|
|
4
|
+
"sourcesContent": ["import createDebugLogger from 'debug';\nimport {toQueries} from '../candidate-search-utils.js';\nimport {getMelindaIdsF035, validateSidFieldSubfieldCounts, getSubfieldValues, testStringOrNumber} from '../../matching-utils.js';\nimport {extractHostMelindaIdsFromField, extractPublicationYearFrom773, getHostMelindaFields} from './component.js';\nimport {fieldToString} from '@natlibfi/marc-record-validators-melinda';\nimport {getTitle} from '../../match-detection/features/bib/title.js';\nimport {uniqArray} from '@natlibfi/marc-record-validators-melinda/dist/utils.js';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query');\nconst debugDev = debug.extend('dev');\n\n\nconst IS_OK_ALONE_THRESHOLD = 5;\n\nexport function bibSourceIds(record) {\n\n /* Melinda's SRU-index melinda.sourceid includes source IDs from SID fields in Melinda records\n SID-fields in Melinda have sf $c with local id and sf $b with a code for the local db:\n\n SID__ $c 123457 $b helka\n SID__ $c (ANDL100020)1077305 $b sata\n SID__ $c VER999999 $ FI-KV\n SID__ $c /10024/508126 $ REPO_THESEUS\n\n In melinda.sourceid -index case is kept, sourceprefixes in brackets and hyphens are normalized away:\n Note: slashes are not normalized away, but a SRU-search-string including slashes needs to be quoted\n\n 1234567helka\n 1077305sata\n VER999999FIKV\n /10024/508126REPO_THESEUS\n\n Note: All Melinda records that have a matching records in a local db do NOT have SID for that local records,\n existence of a SID field depends on how the record has been added to Melinda and how it has been handled\n afterwards. SIDs are also not reliably maintained. A record might or might not have a SID for a local db\n after the matching record is removed from the local db.\n\n */\n\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:source-ids');\n const debugData = debug.extend('data');\n //const debugInfo = debug.extend('info');\n\n debug(`Creating queries for sourceid's`);\n\n const fSids = record.get('SID');\n debugData(`SID-fields (${fSids.length}): ${JSON.stringify(fSids)}`);\n\n return fSids.length > 0 ? toSidQueries(fSids) : [];\n\n function toSidQueries(fSids) {\n debug(`Creating actual queries for sourceid's`);\n\n const sidStrings = getSidStrings(fSids);\n\n if (sidStrings.length < 1) {\n debug(`No identifiers found, no queries created.`);\n return [];\n }\n\n const sidQueries = toQueries(sidStrings, 'melinda.sourceid');\n\n return sidQueries;\n\n function getSidStrings(fSids) {\n debug(`Getting Sid strings from SID fields`);\n\n // Map SID fields to valid sidStrings, filter out empty strings\n const sidStrings = fSids.map(toSidString).filter(nonEmptySid => nonEmptySid);\n return sidStrings;\n\n function toSidString(field) {\n debug(`Getting string from a field`);\n\n return validateSidFieldSubfieldCounts(field) ? createSidString(field) : '';\n\n function createSidString(field) {\n debug(`Creating string from a field`);\n const [sfC] = getSubfieldValues(field, 'c');\n const [sfB] = getSubfieldValues(field, 'b');\n\n const cleanedSfC = removeSourcePrefix(normalizeSidSubfieldValue(sfC));\n const cleanedSfB = normalizeSidSubfieldValue(sfB);\n\n debugData(`${JSON.stringify(sfC)} + ${JSON.stringify(sfB)}`);\n return cleanedSfC.concat(cleanedSfB);\n }\n\n function removeSourcePrefix(subfieldValue) {\n const sourcePrefixRegex = (/^(?<sourcePrefix>\\([A-Za-z0-9-]+\\))(?<id>.+)$/u);\n const normalizedValue = testStringOrNumber(subfieldValue) ? String(subfieldValue).replace(sourcePrefixRegex, '$<id>') : '';\n debugData(`Normalized ${subfieldValue} to ${normalizedValue}`);\n return normalizedValue;\n }\n\n function normalizeSidSubfieldValue(subfieldValue) {\n debugData(`Normalizing ${subfieldValue}`);\n const normalizeAwayRegex = (/[- ]/u);\n return testStringOrNumber(subfieldValue) ? String(subfieldValue).replace(normalizeAwayRegex, '') : '';\n }\n\n }\n }\n }\n}\n\nexport function bibMelindaIds(record) {\n // Melinda's SRU-index melinda.melindaid includes f001 controlnumbers and old Melinda-IDs from f035z's for all non-deleted Melinda-records\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibMelindaIds');\n const debugData = debug.extend('data');\n debug(`Creating queries for MelindaIds`);\n\n // Note: Melinda-ID's for search queries are created just from records f035a's and f035z's\n // Both (FI-MELINDA)- and FCC-prefixed forms are found\n // f001 controlnumber is not currently included, even if record's f003 is FI-MELINDA\n const melindaIds = getMelindaIdsF035(record);\n\n debugData(`Unique identifiers (${melindaIds.length}): ${JSON.stringify(melindaIds)}`);\n\n if (melindaIds.length < 1) {\n debug(`No identifiers found, no queries created.`);\n return [];\n }\n\n return toQueries(melindaIds, 'melinda.melindaid');\n}\n\n\n// bibHostComponents returns host id from the first subfield $w of first field f773, see test-fixtures 04 and 05\n// bibHostComponents should search all 773 $ws for possible host id, but what should it do in case of multiple host ids?\nexport function bibHostComponents(record) {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibHostComponents');\n const debugData = debug.extend('data');\n debug(`Creating queries for hostIds`);\n const f773s = getHostMelindaFields(record);\n if (f773s.length !== 1) { // This needs some thinking...\n return [];\n }\n\n const [id] = extractHostMelindaIdsFromField(f773s[0]);\n debug(`Found id: ${JSON.stringify(id)}`);\n\n // NB! record.isCR() does not work if LDR/07=a, so we get year from 773$g!\n const year = extractPublicationYearFrom773(f773s[0]);\n debug(`${fieldToString(f773s[0])} => ${year ? year : 'N/A'}`);\n if (year) {\n return [`dc.date=${year} AND melinda.partsofhost=${id}`];\n }\n\n return [`melinda.partsofhost=${id}`];\n\n}\n\n\n\n\n// SRU search dc.title with a search phrase starting with ^ maps currently in Melinda to (probably) to *headings* index TIT\n// - Aleph cannot currently handle headings searches starting with a boolean - in these cases use word search\n\nexport function bibTitle(record) {\n // We get author/publisher only when formatted title is shorter than 5 chars\n return bibTitleAuthorPublisher({record, onlyTitleLength: 5});\n}\n\nexport function bibTitleAuthor(record) {\n debug('bibTitleAuthor');\n // We use onlyTitleLength that is longer than our formatted length to\n // get an author or an publisher always\n return bibTitleAuthorPublisher({record, onlyTitleLength: 100});\n}\n\nexport function bibTitleAuthorYear(record) {\n debug('bibTitleAuthorYearAlternates');\n // We use onlyTitleLength that is longer than our formatted length to\n // get an author or an publisher always\n\n return bibTitleAuthorPublisher({record, onlyTitleLength: 100, addYear: true});\n}\n\nexport function bibTitleAuthorYearAlternates(record) {\n debug('bibTitleAuthorYearAlternates');\n // We use onlyTitleLength that is longer than our formatted length to\n // get an author or an publisher always\n const origQueryList = bibTitleAuthorPublisher({record, onlyTitleLength: 100, addYear: true, alternates: true, alternateQueries: []});\n debug(`${JSON.stringify(origQueryList)}`);\n return {queryList: Array.from(origQueryList).reverse(), queryListType: 'alternates'};\n}\n\nfunction getTitleForQuery(record) {\n const title = getTitle(record, ['a']);\n debug(`getTitleForQuery: title ${title}`);\n if (title) {\n const nWords = title.split(' ');\n // If lone $a is deemed too short, fetch $b as well:\n // (NV: I've seen pairs with 245$a-only vs 245$a$b, so I'd like to use $a only if it is long enough)\n\n if (nWords < 3 || title.length < 12) {\n const [f245] = record.get('245');\n // If punctuation is ' =' I think that f245$a is good enough despite shortness. Trying to balance between two bad situations...\n // \"Suo (= short title) siell\u00E4, vetel\u00E4 (= missing $b name in another language) t\u00E4\u00E4ll\u00E4...\"\n if (f245 && f245.subfields.find(sf => sf.code === 'a' && sf.value.match(/ =$/u)) && title.length >= IS_OK_ALONE_THRESHOLD) {\n return title;\n }\n return getTitle(record, ['a', 'b']); // Try to get a longer title\n }\n }\n return title;\n}\n\nfunction dcTitle(record, onlyTitleLength, alternates = false) {\n const title = getTitleForQuery(record);\n debug(`dcTitle: title: ${title}`);\n if (!testStringOrNumber(title)) {\n return [];\n }\n\n const formatted = getFormattedTitle(title);\n debug(`dcTitle: formatted: ${formatted}`);\n\n // use word search for titles starting with a boolean\n const useWordSearch = checkUseWordSearch(formatted);\n // Prevent too many matches / SRU crashing by having a minimum length\n // Note that currently this fails matching if there are no matches from previous matchers\n if (formatted.length >= onlyTitleLength && !alternates) {\n return [`dc.title=\"${useWordSearch ? '' : '^'}${formatted}*\"`, formatted, true];\n }\n\n const queryIsOkAlone = !useWordSearch && formatted.length >= IS_OK_ALONE_THRESHOLD;\n\n if (formatted.length<1) {\n return [\"\", formatted, queryIsOkAlone];\n }\n\n // use word search without ending * also in combination searches to avoid SRU-server crashes [MRA-189]\n return [`dc.title=\"${useWordSearch || !queryIsOkAlone ? '' : '^'}${formatted}${queryIsOkAlone ? '*' : ''}\"`, formatted, queryIsOkAlone];\n\n function getFormattedTitle(title) {\n const formatted = String(title)\n .replace(/[\\-+ !\"(){}\\[\\]<>;:.?/@*%=^_`~]/gu, ' ')\n .replace(/[^\\w\\s\\p{Alphabetic}]/gu, '') // Apparently matches to/works with non-aplhabetic scripts such as Chinese as well\n .replace(/ +/gu, ' ') // Clean up concurrent spaces from eg. subfield changes\n .trim()\n .replace(/^(.{30}\\S*) .*$/, \"$1\")\n .trim();\n\n return formatted;\n }\n}\n\nexport function bibTitleAuthorPublisher({record, onlyTitleLength, addYear = false, alternates = false, alternateQueries = []}) {\n debug(`bibTitleAuthorPublisher, onlyTitleLength: ${onlyTitleLength}, addYear: ${addYear}, alternates: ${alternates}`);\n const [query, formatted, queryIsOkAlone] = dcTitle(record, onlyTitleLength, alternates);\n debug(`query ${JSON.stringify(query)}, formatted: ${JSON.stringify(formatted)}, isOKAlone: ${JSON.stringify(queryIsOkAlone)}`);\n if (query === undefined) {\n return [];\n }\n\n debug(`query: ${query}`);\n\n // Prevent too many matches / SRU crashing by having a minimum length\n // Note that currently this fails matching if there are no matches from previous matchers\n if (formatted.length >= onlyTitleLength && !alternates) {\n return [query];\n }\n\n const newAlternateQueries = alternates ? [...alternateQueries, query] : alternateQueries;\n\n return addAuthorsToSearch({query, queryIsOkAlone, addYear, alternates, alternateQueries: newAlternateQueries});\n\n function addAuthorsToSearch({query, queryIsOkAlone = false, addYear = false, alternates = false, alternateQueries = []}) {\n debug('addAuthorsToSearch');\n const [authorQuery] = bibAuthors(record);\n if (authorQuery !== undefined) {\n const combinedQuery = query.length > 0 ? `${authorQuery} AND ${query}` : `${authorQuery}`;\n if (addYear) {\n const newAlternateQueries = alternates ? [...alternateQueries, combinedQuery] : alternateQueries;\n return addYearToSearch({query: combinedQuery, queryIsOkAlone: true, alternates, alternateQueries: newAlternateQueries});\n }\n return alternates ? alternateQueries : [combinedQuery];\n }\n return addPublisherToSearch({query, queryIsOkAlone, addYear, alternates, alternateQueries});\n //return [];\n }\n\n function addPublisherToSearch({query, queryIsOkAlone = false, addYear = false, alternates = false, alternateQueries = []}) {\n const [publisherQuery] = bibPublishers(record);\n if (publisherQuery !== undefined) {\n const combinedQuery = query.length > 0 ? `${publisherQuery} AND ${query}` : `${publisherQuery}`;\n if (addYear) {\n const newAlternateQueries = alternates ? [...alternateQueries, combinedQuery] : alternateQueries;\n return addYearToSearch({query: combinedQuery, queryIsOkAlone: true, alternates, alternateQueries: newAlternateQueries});\n }\n return alternates ? alternateQueries : [combinedQuery];\n }\n if (queryIsOkAlone && !addYear) {\n return alternates ? alternateQueries : [`${query}`];\n }\n return addYearToSearch({query, queryIsOkAlone, alternates, alternateQueries});\n }\n\n function addYearToSearch({query, queryIsOkAlone = false, alternates = false, alternateQueries = []}) {\n const [yearQuery] = bibYear(record);\n if (yearQuery !== undefined) {\n const yearAndOtherQueries = query.length > 0 ? `${yearQuery} AND ${query}` : `${yearQuery}`;\n return alternates ? [...alternateQueries, yearAndOtherQueries] : [yearAndOtherQueries];\n }\n if (queryIsOkAlone) {\n return alternates ? alternateQueries : [`${query}`];\n }\n return [];\n }\n\n}\n\nexport function bibAuthors(record) {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibAuthors');\n const debugData = debug.extend('data');\n debug(`Creating query for the first author`);\n //debugData(record);\n\n const author = getAuthor(record);\n\n if (testStringOrNumber(author)) {\n const formatted = String(author)\n .replace(/[^\\w\\s\\p{Alphabetic}]/gu, '')\n // Clean up concurrent spaces from fe. subfield changes\n .replace(/ +/gu, ' ')\n .trim()\n .slice(0, 30)\n .trim();\n\n // use word search for authors starting with a boolean\n const useWordSearch = checkUseWordSearch(formatted);\n // Prevent too many matches by having a minimum length\n debugData(`Author string: ${formatted}`);\n if (formatted.length >= 5) {\n return [`dc.author=\"${useWordSearch ? '' : '^'}${formatted}*\"`];\n }\n return [];\n }\n\n return [];\n\n function getAuthor(record) {\n //debugData(record);\n const [field] = record.get(/^(?:100|110|111|700|710|711)$/u);\n //debugData(field);\n\n if (field) {\n const authorString = field.subfields\n .filter(({code}) => ['a'].includes(code)) // We might use different subfield code sets for X00, X10 and X11?\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .filter(value => value)\n // In Melinda's index subfield separators are indexed as ' '\n .join(' ');\n return authorString;\n }\n return false;\n }\n}\n\nexport function bibPublishers(record) {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibPublishers');\n const debugData = debug.extend('data');\n debug(`Creating query for the first publisher`);\n //debugData(record);\n\n const publisher = getPublisher(record);\n if (testStringOrNumber(publisher)) {\n const formatted = String(publisher)\n .replace(/[^\\w\\s\\p{Alphabetic}]/gu, '')\n // Clean up concurrent spaces from fe. subfield changes\n .replace(/ +/gu, ' ')\n .trim()\n .slice(0, 30)\n .trim();\n\n debugData(`Publisher string: '${formatted}'`);\n if (formatted.length === 0) {\n return [];\n }\n // use non-wildcard word search from dc.publisher\n return [`dc.publisher=\"${formatted}\"`];\n }\n\n return [];\n\n function getPublisher(record) {\n //debugData(record);\n const [field] = record.get(/^26[04]$/u).filter(f => f.subfields.some(sf => sf.code === 'b')); // Filter removes copyright-only fields\n //debugData(field);\n\n if (field) {\n const publisherString = field.subfields\n .filter(({code}) => ['b'].includes(code))\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .filter(value => value)\n // In Melinda's index subfield separators are indexed as ' '\n .join(' ')\n .trim();\n return publisherString;\n }\n return false;\n }\n}\n\nexport function bibYear(record) {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibYear');\n const debugData = debug.extend('data');\n debug(`Creating query for the publishing year`);\n\n const year = getYear(record);\n if (year) {\n return [`dc.date=\"${year}\"`];\n }\n return [];\n\n function getYear(record) {\n const [f008] = record.get(/^008$/u);\n if (!f008 || !f008.value || f008.value.length < 11) {\n debug('f008 missing/crappy');\n return false;\n }\n\n debugData(`f008: ${JSON.stringify(f008)}`);\n const {value} = f008;\n const year = value.slice(7, 11);\n if (year === '||||' || year === ' ') { // Meaningless values\n debug('Meaningless year in f008');\n return false;\n }\n return year;\n }\n}\n\nexport function checkUseWordSearch(formatted) {\n const lowercased = formatted.toLowerCase();\n // Note: add a space to startWords to catch just actual boolean words\n const booleanStartWords = ['and ', 'or ', 'nor ', 'not '];\n return booleanStartWords.some(word => lowercased.startsWith(word));\n}\n\nexport function bibStandardIdentifiers(record) {\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibStandardIdentifiers');\n const debugData = debug.extend('data');\n const debugDev = debug.extend('dev');\n\n debug(`Creating queries for standard identifiers`);\n\n // DEVELOP: query identifiers from their own indexes (this needs some mapping work in SRU/Aleph)\n\n // const fields = record.get(/^(?<def>020|022|024)$/u);\n const fields = record.get(/^(?<def>015|020|022|024|028)$/u);\n const identifiers = [].concat(...fields.map(toIdentifiers));\n const uniqueIdentifiers = [...new Set(identifiers)];\n\n debugData(`Standard identifier fields: ${JSON.stringify(fields)}`);\n debugData(`Identifiers (${identifiers.length}): ${JSON.stringify(identifiers)}`);\n debugData(`Unique identifiers (${uniqueIdentifiers.length}): ${JSON.stringify(uniqueIdentifiers)}`);\n\n if (uniqueIdentifiers.length < 1) {\n debug(`No identifiers found, no queries created.`);\n return [];\n }\n\n return toQueries(uniqueIdentifiers, 'dc.identifier');\n\n function toIdentifiers({tag, subfields}) {\n const issnIsbnReqExp = (/^[A-Za-z0-9-]+$/u);\n const otherIdReqExp = (/^[A-Za-z0-9-:]+$/u);\n\n if (tag === '015') { // TODO: test (does this use the right index etc.)\n return subfields\n .filter(sf => sf.code === 'a' && sf.value.match(/^[A-Z0-9\\-]+$/ui))\n .map(sf => sf.value)\n }\n\n if (tag === '020') {\n return subfields\n .filter(sub => ['a', 'z'].includes(sub.code) && testStringOrNumber(sub.value) && issnIsbnReqExp.test(String(sub.value)))\n .map(({value}) => String(value));\n }\n\n if (tag === '022') {\n return subfields\n .filter(sub => ['a', 'z', 'y'].includes(sub.code) && testStringOrNumber(sub.value) && issnIsbnReqExp.test(String(sub.value)))\n .map(({value}) => String(value));\n }\n\n if (tag === '028') { // TODO: test\n const a = subfields.find(sf => sf.code === 'a');\n const b = subfields.find(sf => sf.code === 'b');\n\n // Handle cases where there is a qualifier in brackets after value\n const cleanAs = cleanQualifiers(a?.value);\n const cleanBs = cleanQualifiers(b?.value);\n debugDev(JSON.stringify(cleanAs));\n debugDev(JSON.stringify(cleanBs));\n\n // Handle cases where there are several values separated by a comma in subfield\n const splitAs = cleanAs.map(elem => elem.split(',')).concat(cleanAs).flat();\n const splitBs = cleanBs.map(elem => elem.split(',')).concat(cleanBs).flat();\n debugDev(JSON.stringify(splitAs));\n debugDev(JSON.stringify(splitBs));\n\n const normAs = splitAs.map(elem => normalizeF028ForSearch(elem));\n const normBs = splitBs.map(elem => normalizeF028ForSearch(elem));\n debugDev(JSON.stringify(normAs));\n debugDev(JSON.stringify(normBs));\n\n const identifiers = normAs.map((normA, index) => {\n debugDev(`Handling ${normA} from index: ${index}`);\n // Paired $a + $b\n if (normA.length > 0 && normBs[index]?.length > 0) {\n debugDev(`Found a (${normA}) + b (${normBs[index]})`);\n // let's not return plain $b\n return [`^${normBs[index]} ${normA}`, `^${normA} ${normBs[index]}`, `^${normA}`];\n //return [`^${normA}`, `^${normBs[index]}`, `^${normBs[index]} ${normA}`, `^${normA} ${normBs[index]}`];\n\n }\n // if there is no pair, get $a + first $b\n // NOTE: we do not get all possible pairs\n if (normA.length > 0 && normBs[0]?.length > 0) {\n debugDev(`Found a (${normA}) + b (${normBs[0]})`);\n // let's not return plain $b\n return [`^${normBs[0]} ${normA}`, `^${normA} ${normBs[0]}`, `^${normA}`];\n //return [`^${normA}`, `^${normBs[index]}`, `^${normBs[index]} ${normA}`, `^${normA} ${normBs[index]}`];\n\n }\n // Otherwise just $a\n if (normA.length > 0) {\n debugDev(`Found a (${normA}) but no b ${normBs[index]}`);\n return [`^${normA}`];\n }\n return [];\n });\n\n debugDev(`Current identifiers from f028: ${JSON.stringify(identifiers)}`);\n return uniqArray(identifiers.flat());\n\n function cleanQualifiers(val) {\n if (val !== undefined) {\n const cleanVal = val.replace(/ +\\(.*\\)/gu, '').replace(/ +/ug, ' ').replace(/^ +/ug, '').replace(/ +$/ug, '');\n return uniqArray([val, cleanVal]);\n }\n return [];\n }\n\n function normalizeF028ForSearch(val) {\n // see normalization routine 34 used for 028-index in Aleph\n const f028NormCharsRegex = /[-\"<>;:%=~`!\\(\\)\\{\\}\\.\\?\\/\\@\\*\\^]/g;\n const normVal = val.replace(f028NormCharsRegex, ' ').replace(/ +/ug, ' ').replace(/^ +/ug, '').replace(/ +$/ug, '').toLowerCase();\n // Do not return a value normalized to just a space\n return normVal !== \" \" ? normVal : \"\";\n }\n\n }\n\n // Default seems to be 024:\n return subfields\n .filter(sub => ['a', 'z'].includes(sub.code) && testStringOrNumber(sub.value) && otherIdReqExp.test(String(sub.value)))\n .map(({value}) => String(value));\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,uBAAuB;AAC9B,SAAQ,iBAAgB;AACxB,SAAQ,mBAAmB,gCAAgC,mBAAmB,0BAAyB;AACvG,SAAQ,gCAAgC,+BAA+B,4BAA2B;AAClG,SAAQ,qBAAoB;AAC5B,SAAQ,gBAAe;AACvB,SAAQ,iBAAgB;AAExB,MAAM,QAAQ,kBAAkB,0DAA0D;AAC1F,MAAM,WAAW,MAAM,OAAO,KAAK;AAGnC,MAAM,wBAAwB;AAEvB,gBAAS,aAAa,QAAQ;AA0BnC,QAAMA,SAAQ,kBAAkB,qEAAqE;AACrG,QAAM,YAAYA,OAAM,OAAO,MAAM;AAGrC,EAAAA,OAAM,iCAAiC;AAEvC,QAAM,QAAQ,OAAO,IAAI,KAAK;AAC9B,YAAU,eAAe,MAAM,MAAM,MAAM,KAAK,UAAU,KAAK,CAAC,EAAE;AAElE,SAAO,MAAM,SAAS,IAAI,aAAa,KAAK,IAAI,CAAC;AAEjD,WAAS,aAAaC,QAAO;AAC3B,IAAAD,OAAM,wCAAwC;AAE9C,UAAM,aAAa,cAAcC,MAAK;AAEtC,QAAI,WAAW,SAAS,GAAG;AACzB,MAAAD,OAAM,2CAA2C;AACjD,aAAO,CAAC;AAAA,IACV;AAEA,UAAM,aAAa,UAAU,YAAY,kBAAkB;AAE3D,WAAO;AAEP,aAAS,cAAcC,QAAO;AAC5B,MAAAD,OAAM,qCAAqC;AAG3C,YAAME,cAAaD,OAAM,IAAI,WAAW,EAAE,OAAO,iBAAe,WAAW;AAC3E,aAAOC;AAEP,eAAS,YAAY,OAAO;AAC1B,QAAAF,OAAM,6BAA6B;AAEnC,eAAO,+BAA+B,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AE;AACvD,iBAAO,CAAC,IAAI,KAAK,EAAE;AAAA,QACrB;AACA,eAAO,CAAC;AAAA,MACV,CAAC;AAED,MAAAA,UAAS,kCAAkC,KAAK,UAAUC,YAAW,CAAC,EAAE;AACxE,aAAO,UAAUA,aAAY,KAAK,CAAC;AAAA,IAkBrC;AAGA,WAAO,UACJ,OAAO,SAAO,CAAC,KAAK,GAAG,EAAE,SAAS,IAAI,IAAI,KAAK,mBAAmB,IAAI,KAAK,KAAK,cAAc,KAAK,OAAO,IAAI,KAAK,CAAC,CAAC,EACrH,IAAI,CAAC,EAAC,MAAK,MAAM,OAAO,KAAK,CAAC;AAAA,EACnC;AACF;",
|
|
6
|
+
"names": ["debug", "fSids", "sidStrings", "field", "title", "formatted", "query", "queryIsOkAlone", "addYear", "alternates", "alternateQueries", "newAlternateQueries", "record", "year", "debugDev", "identifiers"]
|
|
7
7
|
}
|
|
@@ -31,7 +31,7 @@ export default () => ({
|
|
|
31
31
|
return fieldsToPublisherNumber(remainingFields, [...result, baval, aval]);
|
|
32
32
|
}
|
|
33
33
|
function normalizePublisherNumber(val) {
|
|
34
|
-
return val.replace(/[- .,:;]/ug, "");
|
|
34
|
+
return val.replace(/[- .,:;]/ug, "").toLowerCase();
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/match-detection/features/bib/publisherNumber.js"],
|
|
4
|
-
"sourcesContent": ["// Compare publusher number (028$b$a or 028$a)\nimport {uniqArray} from '@natlibfi/marc-record-validators-melinda/dist/utils.js';\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features:publisher-number');\nconst debugData = debug.extend('data');\n\nexport default () => ({\n name: 'Publisher or Distributor Number',\n extract: ({record/*, recordExternal*/}) => {\n //const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';\n\n return getIdentifiers();\n\n function getIdentifiers() {\n const values = fieldsToPublisherNumber(record.get(/^028$/u));\n\n debug(`\\t ${values.length} potential publisher identifiers: ${values.join(', ')}`);\n\n return uniqArray(values);\n\n function fieldsToPublisherNumber(fields, result = []) {\n const [field, ...remainingFields] = fields;\n if (!field) {\n return result;\n }\n const a = field.subfields.find(sf => sf.code === 'a');\n // NB! Publisher number must contain a digit! :-)\n if (!a || !a.value || !a.value.match(/[0-9]/u)) {\n return fieldsToPublisherNumber(remainingFields, result);\n }\n const aval = normalizePublisherNumber(`${a.value}`);\n\n const b = field.subfields.find(sf => sf.code === 'b');\n if (!b || !b.value) {\n return fieldsToPublisherNumber(remainingFields, [...result, aval]);\n }\n const baval = normalizePublisherNumber(`${b.value}${a.value}`);\n return fieldsToPublisherNumber(remainingFields, [...result, baval, aval]);\n }\n\n function normalizePublisherNumber(val) {\n return val.replace(/[- .,:;]/ug, '');\n }\n }\n },\n compare: (aa, bb) => {\n debugData(`Comparing identifier sets ${JSON.stringify(aa)} and ${JSON.stringify(bb)}`);\n if (aa.length === 0 || bb.length === 0) {\n // No data for decision\n return 0;\n }\n const sharedIdentifiers = aa.filter(val => bb.includes(val));\n if (sharedIdentifiers.length > 0) {\n const goodMatch = sharedIdentifiers.find(identifier => identifier.match(/[^0-9]/u));\n if (goodMatch) {\n debug(`\\tShared identifier found: '${goodMatch}'`);\n return 0.5;\n }\n debug(`\\tShared identifier (numbers only) found: '${sharedIdentifiers[0]}'`);\n return 0.2;\n }\n\n const aa2 = aa.map(a => a.replace(/[^0-9]/ug, ''));\n const bb2 = bb.map(b => b.replace(/[^0-9]/ug, ''));\n\n // Numbers matches (aka don't penalize \"Fazer F-123\" vs \"F-123\")\n // Note that FOOLP-123 vs FOOCD-123 will now also return 0.0. Still nothing positive is returned, so no damage done.\n if (aa2.find(val => val !== '' && bb2.includes(val))) {\n return 0.0;\n }\n\n return -0.2;\n\n }\n});\n\n"],
|
|
5
|
-
"mappings": "AACA,SAAQ,iBAAgB;AACxB,OAAO,uBAAuB;AAE9B,MAAM,QAAQ,kBAAkB,6EAA6E;AAC7G,MAAM,YAAY,MAAM,OAAO,MAAM;AAErC,eAAe,OAAO;AAAA,EACpB,MAAM;AAAA,EACN,SAAS,CAAC;AAAA,IAAC;AAAA;AAAA,EAA0B,MAAM;AAGzC,WAAO,eAAe;AAEtB,aAAS,iBAAiB;AACxB,YAAM,SAAS,wBAAwB,OAAO,IAAI,QAAQ,CAAC;AAE3D,YAAM,KAAM,OAAO,MAAM,qCAAqC,OAAO,KAAK,IAAI,CAAC,EAAE;AAEjF,aAAO,UAAU,MAAM;AAEvB,eAAS,wBAAwB,QAAQ,SAAS,CAAC,GAAG;AACpD,cAAM,CAAC,OAAO,GAAG,eAAe,IAAI;AACpC,YAAI,CAAC,OAAO;AACV,iBAAO;AAAA,QACT;AACA,cAAM,IAAI,MAAM,UAAU,KAAK,QAAM,GAAG,SAAS,GAAG;
|
|
4
|
+
"sourcesContent": ["// Compare publusher number (028$b$a or 028$a)\nimport {uniqArray} from '@natlibfi/marc-record-validators-melinda/dist/utils.js';\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features:publisher-number');\nconst debugData = debug.extend('data');\n\nexport default () => ({\n name: 'Publisher or Distributor Number',\n extract: ({record/*, recordExternal*/}) => {\n //const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';\n\n return getIdentifiers();\n\n function getIdentifiers() {\n const values = fieldsToPublisherNumber(record.get(/^028$/u));\n\n debug(`\\t ${values.length} potential publisher identifiers: ${values.join(', ')}`);\n\n return uniqArray(values);\n\n function fieldsToPublisherNumber(fields, result = []) {\n const [field, ...remainingFields] = fields;\n if (!field) {\n return result;\n }\n const a = field.subfields.find(sf => sf.code === 'a');\n // NB! Publisher number must contain a digit! :-)\n // NOTE: we might have some rare cases with publisher numbers that do not have numbers...\n if (!a || !a.value || !a.value.match(/[0-9]/u)) {\n return fieldsToPublisherNumber(remainingFields, result);\n }\n const aval = normalizePublisherNumber(`${a.value}`);\n\n const b = field.subfields.find(sf => sf.code === 'b');\n if (!b || !b.value) {\n return fieldsToPublisherNumber(remainingFields, [...result, aval]);\n }\n const baval = normalizePublisherNumber(`${b.value}${a.value}`);\n return fieldsToPublisherNumber(remainingFields, [...result, baval, aval]);\n }\n\n function normalizePublisherNumber(val) {\n return val.replace(/[- .,:;]/ug, '').toLowerCase();\n }\n }\n },\n compare: (aa, bb) => {\n debugData(`Comparing identifier sets ${JSON.stringify(aa)} and ${JSON.stringify(bb)}`);\n if (aa.length === 0 || bb.length === 0) {\n // No data for decision\n return 0;\n }\n const sharedIdentifiers = aa.filter(val => bb.includes(val));\n if (sharedIdentifiers.length > 0) {\n const goodMatch = sharedIdentifiers.find(identifier => identifier.match(/[^0-9]/u));\n if (goodMatch) {\n debug(`\\tShared identifier found: '${goodMatch}'`);\n return 0.5;\n }\n debug(`\\tShared identifier (numbers only) found: '${sharedIdentifiers[0]}'`);\n return 0.2;\n }\n\n const aa2 = aa.map(a => a.replace(/[^0-9]/ug, ''));\n const bb2 = bb.map(b => b.replace(/[^0-9]/ug, ''));\n\n // Numbers matches (aka don't penalize \"Fazer F-123\" vs \"F-123\")\n // Note that FOOLP-123 vs FOOCD-123 will now also return 0.0. Still nothing positive is returned, so no damage done.\n if (aa2.find(val => val !== '' && bb2.includes(val))) {\n return 0.0;\n }\n\n return -0.2;\n\n }\n});\n\n"],
|
|
5
|
+
"mappings": "AACA,SAAQ,iBAAgB;AACxB,OAAO,uBAAuB;AAE9B,MAAM,QAAQ,kBAAkB,6EAA6E;AAC7G,MAAM,YAAY,MAAM,OAAO,MAAM;AAErC,eAAe,OAAO;AAAA,EACpB,MAAM;AAAA,EACN,SAAS,CAAC;AAAA,IAAC;AAAA;AAAA,EAA0B,MAAM;AAGzC,WAAO,eAAe;AAEtB,aAAS,iBAAiB;AACxB,YAAM,SAAS,wBAAwB,OAAO,IAAI,QAAQ,CAAC;AAE3D,YAAM,KAAM,OAAO,MAAM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,WAAW;AACb,cAAM,8BAA+B,SAAS,GAAG;AACjD,eAAO;AAAA,MACT;AACA,YAAM,6CAA8C,kBAAkB,CAAC,CAAC,GAAG;AAC3E,aAAO;AAAA,IACT;AAEA,UAAM,MAAM,GAAG,IAAI,OAAK,EAAE,QAAQ,YAAY,EAAE,CAAC;AACjD,UAAM,MAAM,GAAG,IAAI,OAAK,EAAE,QAAQ,YAAY,EAAE,CAAC;AAIjD,QAAI,IAAI,KAAK,SAAO,QAAQ,MAAM,IAAI,SAAS,GAAG,CAAC,GAAG;AACpD,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EAET;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -5,6 +5,7 @@ import { testStringOrNumber } from "../../../matching-utils.js";
|
|
|
5
5
|
import { subfieldToString } from "@natlibfi/marc-record-validators-melinda/dist/utils.js";
|
|
6
6
|
const debug = createDebugLogger("@natlibfi/melinda-record-matching:match-detection:features/bib/title");
|
|
7
7
|
const debugData = debug.extend("data");
|
|
8
|
+
const debugDev = debug.extend("dev");
|
|
8
9
|
const TITLE_MAX = 0.5;
|
|
9
10
|
export default ({ threshold = 0.9 } = {}) => ({
|
|
10
11
|
name: "Title",
|
|
@@ -172,12 +173,19 @@ export default ({ threshold = 0.9 } = {}) => ({
|
|
|
172
173
|
export function getTitle(record, targetSubfieldCodes = ["a", "b", "n", "p"]) {
|
|
173
174
|
const [field] = record.get(/^245$/u);
|
|
174
175
|
debugData(`titleField: ${JSON.stringify(field)}`);
|
|
176
|
+
debugDev(`targetSubfieldCodes: ${JSON.stringify(targetSubfieldCodes)}`);
|
|
175
177
|
if (field) {
|
|
176
|
-
const title = field.subfields.filter(({ code }) => targetSubfieldCodes.includes(code)).map(({ value }) => testStringOrNumber(value) ? String(value) : "").join(" ").replace(
|
|
178
|
+
const title = field.subfields.filter(({ code }) => targetSubfieldCodes.includes(code)).map(({ value }) => testStringOrNumber(value) ? String(value) : "").join(" ").replace(/ [=\/:](?:$| )/ug, " ").replace(/ +/ug, " ").replace(/^ +/u, "").replace(/ +$/u, "");
|
|
179
|
+
debugDev(`getTitle: title: ${title}`);
|
|
180
|
+
const cleanTitle = title.replace(/\[[^\]]*\]/ug, " ").replace(/ +/ug, " ").replace(/^ +/u, "").replace(/ +$/u, "");
|
|
181
|
+
debugDev(`getTitle: cleanTitle: ${cleanTitle} (${cleanTitle.length})`);
|
|
182
|
+
const usableTitle = cleanTitle.length > 0 ? cleanTitle : title;
|
|
183
|
+
debugDev(`getTitle: usableTitle: ${usableTitle} (${usableTitle.length})`);
|
|
177
184
|
if (/^[1-8]$/u.test(field.ind2)) {
|
|
178
|
-
|
|
185
|
+
const nonFilingTitle = usableTitle.slice(parseInt(field.ind2));
|
|
186
|
+
if (nonFilingTitle.length > 0) return nonFilingTitle;
|
|
179
187
|
}
|
|
180
|
-
return
|
|
188
|
+
return usableTitle;
|
|
181
189
|
}
|
|
182
190
|
return false;
|
|
183
191
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/match-detection/features/bib/title.js"],
|
|
4
|
-
"sourcesContent": ["import createDebugLogger from 'debug';\nimport naturalPkg from 'natural';\nconst {LevenshteinDistance: leven} = naturalPkg;\nimport {testStringOrNumber} from '../../../matching-utils.js';\nimport { subfieldToString } from '@natlibfi/marc-record-validators-melinda/dist/utils.js';\n\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib/title');\nconst debugData = debug.extend('data');\n\nconst TITLE_MAX = 0.5;\nexport default ({threshold = 0.9} = {}) => ({\n name: 'Title',\n extract: ({record, recordExternal}) => {\n const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';\n const a = getTitle(record, ['a']);\n debug(`${label}: title: ${a}`);\n\n if (a) {\n const b = normalizeTitle(getTitle(record, ['b'])) || '';\n const n = normalizeTitle(getTitle(record, ['n'])) || '';\n const p = normalizeTitle(getTitle(record, ['p'])) || '';\n return [normalizeTitle(a), b, n, p];\n }\n\n return ['', '', '', ''];\n\n function normalizeTitle(title) {\n return title\n // decompose unicode diacritics\n .normalize('NFD')\n .replace(/\\b(?:ein|ett|I|one|uno|yksi)\\b/uig, '1')\n .replace(/\\b(?:dos|kaksi|II|tv\u00E5|two|zwei)\\b/uig, '2')\n .replace(/\\b(?:drei|III|kolme|three|tre|tres)\\b/uig, '3')\n .replace(/\\b(?:four|fyra|IV|nelj\u00E4|quat+ro|vier)\\b/uig, '4')\n .replace(/\\b(?:five|f\u00FCnf|fyra|viisi|V)\\b/uig, '5')\n .replace(/\\b(?:kuusi|sechts|sex|six|VI)\\b/uig, '6')\n .replace(/\\b(and|ja|och|und)\\b/uig, '&')\n // strip non-letters/numbers\n // - note: combined with decomposing unicode diacritics this normalizes both 'saa' and 's\u00E4\u00E4' as 'saa'\n // - we could precompose the Finnish letters back to avoid this\n // - see validator normalize-utf8-diacritics for details\n .replace(/[^\\p{Letter}\\p{Number}& ]/gu, '') // 2026-07-01: keep ' '. We need it for splitToBaseAndNumber()\n .replace(/\\s+/ug, ' ')\n .replace(/ $/u, '')\n .replace(/^ /u, '')\n .toLowerCase();\n }\n\n },\n compare: (origA, origB) => {\n return compare2(origA, origB);\n\n function compare2(a, b) { // Added this wrapper function as I had issues with recursion\n\n const [aa, ab, an, ap] = a;\n const [ba, bb, bn, bp] = b;\n debugData(`COMPARE:\\n['${aa}', '${ab}', '${an}', '${ap}'] VS\\n['${ba}', '${bb}', '${bn}', '${bp}']`);\n\n const aFull = toFullTitle(a);\n const bFull = toFullTitle(b);\n\n // debugData(`JOINED COMPARE:\\n '${aFull}' vs \\n '${bFull}'`);\n\n if (isEmpty(aa) || isEmpty(ba)) {\n return -1.0;\n }\n\n if (aFull === bFull) {\n return TITLE_MAX;\n }\n\n // MELKEHITYS-3496-ish: move part of $a to $n:\n const [altAa, altAn, altBa, altBn] = reconstructTitleAndNumber(aa, an, ba, bn);\n if (altAa) {\n return compare2([altAa, ab, altAn, ap], [altBa, bb, altBn, bp]);\n }\n\n if (ab && ab !== '' && ab === bb) { // Remove $b from equation (MELKEHITYS-3494)\n debug(`Ignore \\$b ${ab}`);\n return compare2([aa, '', an, ap], [ba, '', bn, bp]);\n }\n if (an && an !== '' && an === bn) { // Remove $n from equation\n debug(`Ignore \\$n ${an}`);\n return compare2([aa, ab, '', ap], [ba, bb, '', bp]);\n }\n if (ap && ap !== '' && ap === bp) { // Remove $p from equation\n debug(`Ignore \\$p ${ap}`);\n return compare2([aa, ab, an, ''], [ba, bb, bn, '']);\n }\n // There seems to be wobble between $b and $p:\n if (!isEmpty(ab) && ab === bp) {\n return compare2([aa, '', an, ap], [ba, bb, bn, '']);\n }\n if (!isEmpty(ap) && ap === bp) {\n return compare2([aa, ab, an, ''], [ba, '', bn, bp]);\n }\n\n if (an && bn && an.match(/[0-9]/u)) {\n debug(`NUMBER FOUND. Compare ${an} and ${bn}`);\n const atmp = an.replace(/[^0-9]/ug, '');\n const btmp = bn.replace(/[^0-9]/ug, '');\n if (atmp === btmp) {\n debug(`Ignore \\$n '${an}' vs '${bn}'`);\n return compare2([aa, ab, '', ap], [ba, bb, '', bp]);\n }\n }\n\n\n // f245$n information is critical; it can not mismatch at all (exceptions have already been handled above):\n if (an && an !== bn) {\n return -1.0;\n }\n\n const [distance, maxLength, correctness] = doLevenshtein(aFull.replace(/ /ug, ''), bFull.replace(/ /ug, ''));\n\n debug(`'${aFull}' vs '${bFull}': Max length = ${maxLength}, distance = ${distance}, correctness = ${correctness}`);\n\n\n if (correctness >= threshold) {\n return TITLE_MAX * 0.8;\n }\n\n // Subset removal (MELKEHITYS-3498-ish)\n if (ab && bb) { // At this point ab and bb are never equal...\n // If X is a subset of Y, then remove X and shorten Y (= remove the shared content)\n if (ab.indexOf(bb) === 0) {\n return compare2([aa, ab.substring(bb.length), an, ap], [ba, '', bn, bp]);\n }\n if (bb.indexOf(ab) === 0) {\n return compare2([aa, '', an, ap], [ba, bb.substring(ab.length), bn, bp]);\n }\n }\n\n // Try the same without $p:\n if (localXor(ap, bp)) {\n const result = compare2([aa, ab, an, ''], [ba, bb, bn, '']);\n return result > 0.0 ? result * 0.8 : result;\n }\n\n if (aa === ba && an === bn) {\n const candScore = TITLE_MAX/2;\n // $b is missing from one:\n if (ap === bp && localXor(ab, bb)) {\n debug(`Handle omitted \\$b using x ${candScore}`);\n return candScore;\n }\n if (ab === bb && localXor(ap, bp)) {\n debug(`Handle omitted \\$p using x ${candScore}`);\n return candScore;\n }\n }\n\n if (an === bn && ap === bp ) {\n // $b-less $a is other record's $b, see MELKEHITYS-3485 for motivation (though we skip 246 and 490 here):\n const candScore = TITLE_MAX/2;\n if (aa === bb && !ab) {\n return candScore;\n }\n if (ba === ab && !bb) {\n return candScore;\n }\n }\n\n return -0.5; // Not likely\n }\n\n function isEmpty(x) {\n return !x || x.length === 0;\n }\n\n function localXor(x, y) {\n if (isEmpty(x)) {\n return !isEmpty(y);\n }\n // 'x' exists, thus 'y' can not exist:\n return isEmpty(y);\n }\n\n function doLevenshtein(string1, string2) {\n const distance = leven(string1, string2);\n const len = getMaxLength(string1, string2);\n const correctness = 1.0 - (distance / len);\n return [distance, len, correctness];\n }\n\n function toFullTitle(arr) {\n const relevant = arr.filter(val => typeof val === 'string' && val.length);\n // No longer add space between subfields. Due to heavy normalization there are no spaces left in array elements either!\n return relevant.join('');\n }\n\n function getMaxLength(str1, str2) {\n return str1.length > str2.length ? str1.length : str2.length;\n }\n\n function reconstructTitleAndNumber(a1, n1, a2, n2) {\n if (!n1 && n2) {\n const [altA1, altN1] = splitToBaseAndNumber(a1);\n if (altN1) {\n debugData(`A: Reconstruct:\\n $a '${a1}' =>\\n $a '${altA1}' +\\n $n '${altN1}`);\n return [altA1, altN1, a2, n2];\n }\n }\n if (n1 && !n2) {\n const [altA2, altN2] = splitToBaseAndNumber(a2);\n if (altN2) {\n debugData(`B: Reconstruct $a '${a2}' as $a '${altA2}' and $n '${altN2}`);\n return [a1, n1, altA2, altN2];\n }\n\n }\n return [null, null, null, null]; // Fail\n }\n\n\n function splitToBaseAndNumber(val) {\n const words = val.split(' ');\n const len = words.length;\n if (len < 2 || !words[len-1].match(/^[1-9][0-9]*$/)) {\n return [val, null];\n }\n if (len > 2 && words[len-2].match(/^(del|osa|vol|volume)$/u)) { // NB! \"vol.\" has lost it's '.' during normalization!\n const number = `${words[len-2]} ${words[len-1]}`;\n return [words.slice(0, len-2).join(' '), number];\n }\n\n const number = words.pop();\n return [words.join(' '), number];\n }\n\n }\n});\n\nexport function getTitle(record, targetSubfieldCodes = ['a', 'b', 'n', 'p']) {\n const [field] = record.get(/^245$/u);\n debugData(`titleField: ${JSON.stringify(field)}`);\n\n if (field) {\n const title = field.subfields\n // get also $n:s and $p:s here\n .filter(({code}) => targetSubfieldCodes.includes(code))\n // Would be nice to normalize $n values...\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .join(' ')\n .replace(/\\[[^\\]]*\\]/ug, ' ') // Remove [whatever] stuff. ADD TEST FOR THIS\n .replace(/ [=\\/:](?:$| )/ug, ' ') // Strip punctuation\n // Also \u0111 vs d pairs seen:\n //.replace(/(?:\u0111|\u0227|t\u0304|k\u030C|\u01E7|s\u0306|c\u0306)/ug, '') // Hack. Saamelaisbibliografia has often dropped this wierd characters (oft old articles, no longer used in sami either)\n // trim:\n .replace(/ +/ug, ' ')\n .replace(/^ +/u, '')\n .replace(/ +$/u, '');\n\n // Skip non-filing indicator (note that '9' is a magic indicator value, so we don't do it):\n if (/^[1-8]$/u.test(field.ind2)) { // Skip non-filing characters\n return title.slice(parseInt(field.ind2));\n }\n return title;\n\n }\n return false;\n}"],
|
|
5
|
-
"mappings": "AAAA,OAAO,uBAAuB;AAC9B,OAAO,gBAAgB;AACvB,MAAM,EAAC,qBAAqB,MAAK,IAAI;AACrC,SAAQ,0BAAyB;AACjC,SAAS,wBAAwB;AAGjC,MAAM,QAAQ,kBAAkB,sEAAsE;AACtG,MAAM,YAAY,MAAM,OAAO,MAAM;
|
|
4
|
+
"sourcesContent": ["import createDebugLogger from 'debug';\nimport naturalPkg from 'natural';\nconst {LevenshteinDistance: leven} = naturalPkg;\nimport {testStringOrNumber} from '../../../matching-utils.js';\nimport { subfieldToString } from '@natlibfi/marc-record-validators-melinda/dist/utils.js';\n\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib/title');\nconst debugData = debug.extend('data');\nconst debugDev = debug.extend('dev');\n\n\nconst TITLE_MAX = 0.5;\nexport default ({threshold = 0.9} = {}) => ({\n name: 'Title',\n extract: ({record, recordExternal}) => {\n const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';\n const a = getTitle(record, ['a']);\n debug(`${label}: title: ${a}`);\n\n if (a) {\n const b = normalizeTitle(getTitle(record, ['b'])) || '';\n const n = normalizeTitle(getTitle(record, ['n'])) || '';\n const p = normalizeTitle(getTitle(record, ['p'])) || '';\n return [normalizeTitle(a), b, n, p];\n }\n\n return ['', '', '', ''];\n\n function normalizeTitle(title) {\n return title\n // decompose unicode diacritics\n .normalize('NFD')\n .replace(/\\b(?:ein|ett|I|one|uno|yksi)\\b/uig, '1')\n .replace(/\\b(?:dos|kaksi|II|tv\u00E5|two|zwei)\\b/uig, '2')\n .replace(/\\b(?:drei|III|kolme|three|tre|tres)\\b/uig, '3')\n .replace(/\\b(?:four|fyra|IV|nelj\u00E4|quat+ro|vier)\\b/uig, '4')\n .replace(/\\b(?:five|f\u00FCnf|fyra|viisi|V)\\b/uig, '5')\n .replace(/\\b(?:kuusi|sechts|sex|six|VI)\\b/uig, '6')\n .replace(/\\b(and|ja|och|und)\\b/uig, '&')\n // strip non-letters/numbers\n // - note: combined with decomposing unicode diacritics this normalizes both 'saa' and 's\u00E4\u00E4' as 'saa'\n // - we could precompose the Finnish letters back to avoid this\n // - see validator normalize-utf8-diacritics for details\n .replace(/[^\\p{Letter}\\p{Number}& ]/gu, '') // 2026-07-01: keep ' '. We need it for splitToBaseAndNumber()\n .replace(/\\s+/ug, ' ')\n .replace(/ $/u, '')\n .replace(/^ /u, '')\n .toLowerCase();\n }\n\n },\n compare: (origA, origB) => {\n return compare2(origA, origB);\n\n function compare2(a, b) { // Added this wrapper function as I had issues with recursion\n\n const [aa, ab, an, ap] = a;\n const [ba, bb, bn, bp] = b;\n debugData(`COMPARE:\\n['${aa}', '${ab}', '${an}', '${ap}'] VS\\n['${ba}', '${bb}', '${bn}', '${bp}']`);\n\n const aFull = toFullTitle(a);\n const bFull = toFullTitle(b);\n\n // debugData(`JOINED COMPARE:\\n '${aFull}' vs \\n '${bFull}'`);\n\n if (isEmpty(aa) || isEmpty(ba)) {\n return -1.0;\n }\n\n if (aFull === bFull) {\n return TITLE_MAX;\n }\n\n // MELKEHITYS-3496-ish: move part of $a to $n:\n const [altAa, altAn, altBa, altBn] = reconstructTitleAndNumber(aa, an, ba, bn);\n if (altAa) {\n return compare2([altAa, ab, altAn, ap], [altBa, bb, altBn, bp]);\n }\n\n if (ab && ab !== '' && ab === bb) { // Remove $b from equation (MELKEHITYS-3494)\n debug(`Ignore \\$b ${ab}`);\n return compare2([aa, '', an, ap], [ba, '', bn, bp]);\n }\n if (an && an !== '' && an === bn) { // Remove $n from equation\n debug(`Ignore \\$n ${an}`);\n return compare2([aa, ab, '', ap], [ba, bb, '', bp]);\n }\n if (ap && ap !== '' && ap === bp) { // Remove $p from equation\n debug(`Ignore \\$p ${ap}`);\n return compare2([aa, ab, an, ''], [ba, bb, bn, '']);\n }\n // There seems to be wobble between $b and $p:\n if (!isEmpty(ab) && ab === bp) {\n return compare2([aa, '', an, ap], [ba, bb, bn, '']);\n }\n if (!isEmpty(ap) && ap === bp) {\n return compare2([aa, ab, an, ''], [ba, '', bn, bp]);\n }\n\n if (an && bn && an.match(/[0-9]/u)) {\n debug(`NUMBER FOUND. Compare ${an} and ${bn}`);\n const atmp = an.replace(/[^0-9]/ug, '');\n const btmp = bn.replace(/[^0-9]/ug, '');\n if (atmp === btmp) {\n debug(`Ignore \\$n '${an}' vs '${bn}'`);\n return compare2([aa, ab, '', ap], [ba, bb, '', bp]);\n }\n }\n\n\n // f245$n information is critical; it can not mismatch at all (exceptions have already been handled above):\n if (an && an !== bn) {\n return -1.0;\n }\n\n const [distance, maxLength, correctness] = doLevenshtein(aFull.replace(/ /ug, ''), bFull.replace(/ /ug, ''));\n\n debug(`'${aFull}' vs '${bFull}': Max length = ${maxLength}, distance = ${distance}, correctness = ${correctness}`);\n\n\n if (correctness >= threshold) {\n return TITLE_MAX * 0.8;\n }\n\n // Subset removal (MELKEHITYS-3498-ish)\n if (ab && bb) { // At this point ab and bb are never equal...\n // If X is a subset of Y, then remove X and shorten Y (= remove the shared content)\n if (ab.indexOf(bb) === 0) {\n return compare2([aa, ab.substring(bb.length), an, ap], [ba, '', bn, bp]);\n }\n if (bb.indexOf(ab) === 0) {\n return compare2([aa, '', an, ap], [ba, bb.substring(ab.length), bn, bp]);\n }\n }\n\n // Try the same without $p:\n if (localXor(ap, bp)) {\n const result = compare2([aa, ab, an, ''], [ba, bb, bn, '']);\n return result > 0.0 ? result * 0.8 : result;\n }\n\n if (aa === ba && an === bn) {\n const candScore = TITLE_MAX/2;\n // $b is missing from one:\n if (ap === bp && localXor(ab, bb)) {\n debug(`Handle omitted \\$b using x ${candScore}`);\n return candScore;\n }\n if (ab === bb && localXor(ap, bp)) {\n debug(`Handle omitted \\$p using x ${candScore}`);\n return candScore;\n }\n }\n\n if (an === bn && ap === bp ) {\n // $b-less $a is other record's $b, see MELKEHITYS-3485 for motivation (though we skip 246 and 490 here):\n const candScore = TITLE_MAX/2;\n if (aa === bb && !ab) {\n return candScore;\n }\n if (ba === ab && !bb) {\n return candScore;\n }\n }\n\n return -0.5; // Not likely\n }\n\n function isEmpty(x) {\n return !x || x.length === 0;\n }\n\n function localXor(x, y) {\n if (isEmpty(x)) {\n return !isEmpty(y);\n }\n // 'x' exists, thus 'y' can not exist:\n return isEmpty(y);\n }\n\n function doLevenshtein(string1, string2) {\n const distance = leven(string1, string2);\n const len = getMaxLength(string1, string2);\n const correctness = 1.0 - (distance / len);\n return [distance, len, correctness];\n }\n\n function toFullTitle(arr) {\n const relevant = arr.filter(val => typeof val === 'string' && val.length);\n // No longer add space between subfields. Due to heavy normalization there are no spaces left in array elements either!\n return relevant.join('');\n }\n\n function getMaxLength(str1, str2) {\n return str1.length > str2.length ? str1.length : str2.length;\n }\n\n function reconstructTitleAndNumber(a1, n1, a2, n2) {\n if (!n1 && n2) {\n const [altA1, altN1] = splitToBaseAndNumber(a1);\n if (altN1) {\n debugData(`A: Reconstruct:\\n $a '${a1}' =>\\n $a '${altA1}' +\\n $n '${altN1}`);\n return [altA1, altN1, a2, n2];\n }\n }\n if (n1 && !n2) {\n const [altA2, altN2] = splitToBaseAndNumber(a2);\n if (altN2) {\n debugData(`B: Reconstruct $a '${a2}' as $a '${altA2}' and $n '${altN2}`);\n return [a1, n1, altA2, altN2];\n }\n\n }\n return [null, null, null, null]; // Fail\n }\n\n\n function splitToBaseAndNumber(val) {\n const words = val.split(' ');\n const len = words.length;\n if (len < 2 || !words[len-1].match(/^[1-9][0-9]*$/)) {\n return [val, null];\n }\n if (len > 2 && words[len-2].match(/^(del|osa|vol|volume)$/u)) { // NB! \"vol.\" has lost it's '.' during normalization!\n const number = `${words[len-2]} ${words[len-1]}`;\n return [words.slice(0, len-2).join(' '), number];\n }\n\n const number = words.pop();\n return [words.join(' '), number];\n }\n\n }\n});\n\nexport function getTitle(record, targetSubfieldCodes = ['a', 'b', 'n', 'p']) {\n const [field] = record.get(/^245$/u);\n debugData(`titleField: ${JSON.stringify(field)}`);\n debugDev(`targetSubfieldCodes: ${JSON.stringify(targetSubfieldCodes)}`);\n\n\n if (field) {\n const title = field.subfields\n // get also $n:s and $p:s here\n .filter(({code}) => targetSubfieldCodes.includes(code))\n // Would be nice to normalize $n values...\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .join(' ')\n // Note: we do not want to removed stuff in brackets if its the only stuff in field ... (245 $a [Psi] / ... )\n //.replace(/\\[[^\\]]*\\]/ug, ' ') // Remove [whatever] stuff. ADD TEST FOR THIS\n .replace(/ [=\\/:](?:$| )/ug, ' ') // Strip punctuation\n // Also \u0111 vs d pairs seen:\n //.replace(/(?:\u0111|\u0227|t\u0304|k\u030C|\u01E7|s\u0306|c\u0306)/ug, '') // Hack. Saamelaisbibliografia has often dropped this wierd characters (oft old articles, no longer used in sami either)\n // trim:\n .replace(/ +/ug, ' ')\n .replace(/^ +/u, '')\n .replace(/ +$/u, '');\n\n debugDev(`getTitle: title: ${title}`)\n\n const cleanTitle = title.replace(/\\[[^\\]]*\\]/ug, ' ') // Remove [whatever] stuff. ADD TEST FOR THIS\n .replace(/ +/ug, ' ')\n .replace(/^ +/u, '')\n .replace(/ +$/u, '');\n\n debugDev(`getTitle: cleanTitle: ${cleanTitle} (${cleanTitle.length})`);\n const usableTitle = cleanTitle.length > 0 ? cleanTitle : title;\n debugDev(`getTitle: usableTitle: ${usableTitle} (${usableTitle.length})`);\n \n\n // Skip non-filing indicator (note that '9' is a magic indicator value, so we don't do it):\n if (/^[1-8]$/u.test(field.ind2)) { // Skip non-filing characters\n const nonFilingTitle = usableTitle.slice(parseInt(field.ind2));\n if (nonFilingTitle.length > 0) return nonFilingTitle;\n }\n return usableTitle;\n\n }\n return false;\n}"],
|
|
5
|
+
"mappings": "AAAA,OAAO,uBAAuB;AAC9B,OAAO,gBAAgB;AACvB,MAAM,EAAC,qBAAqB,MAAK,IAAI;AACrC,SAAQ,0BAAyB;AACjC,SAAS,wBAAwB;AAGjC,MAAM,QAAQ,kBAAkB,sEAAsE;AACtG,MAAM,YAAY,MAAM,OAAO,MAAM;AACrC,MAAM,WAAW,MAAM,OAAO,KAAK;AAGnC,MAAM,YAAY;AAClB,eAAe,CAAC,EAAC,YAAY,IAAG,IAAI,CAAC,OAAO;AAAA,EAC1C,MAAM;AAAA,EACN,SAAS,CAAC,EAAC,QAAQ,eAAc,MAAM;AACrC,UAAM,QAAQ,kBAAkB,eAAe,QAAQ,eAA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D,IAAI,CAAC,EAAC,MAAK,MAAM,mBAAmB,KAAK,IAAI,OAAO,KAAK,IAAI,EAAE,EAC/D,KAAK,GAAG,EAGR,QAAQ,oBAAoB,GAAG,EAI/B,QAAQ,QAAQ,GAAG,EACnB,QAAQ,QAAQ,EAAE,EAClB,QAAQ,QAAQ,EAAE;AAErB,aAAS,oBAAoB,KAAK,EAAE;AAEpC,UAAM,aAAa,MAAM,QAAQ,gBAAgB,GAAG,EACjD,QAAQ,QAAQ,GAAG,EACnB,QAAQ,QAAQ,EAAE,EAClB,QAAQ,QAAQ,EAAE;AAErB,aAAS,yBAAyB,UAAU,KAAK,WAAW,MAAM,GAAG;AACrE,UAAM,cAAc,WAAW,SAAS,IAAI,aAAa;AACzD,aAAS,0BAA0B,WAAW,KAAK,YAAY,MAAM,GAAG;AAIxE,QAAI,WAAW,KAAK,MAAM,IAAI,GAAG;AAC/B,YAAM,iBAAiB,YAAY,MAAM,SAAS,MAAM,IAAI,CAAC;AAC7D,UAAI,eAAe,SAAS,EAAG,QAAO;AAAA,IACxC;AACA,WAAO;AAAA,EAET;AACA,SAAO;AACT;",
|
|
6
6
|
"names": ["number"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"url": "https://github.com/NatLibFi/melinda-record-matching-js"
|
|
14
14
|
},
|
|
15
15
|
"license": "MIT",
|
|
16
|
-
"version": "6.0.
|
|
16
|
+
"version": "6.0.1-alpha.1",
|
|
17
17
|
"type": "module",
|
|
18
18
|
"main": "./dist/index.js",
|
|
19
19
|
"bin": "./dist/cli.js",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"test:base": "node --test --test-force-exit --experimental-test-coverage --test-reporter=spec 'test/**/*.test.js'",
|
|
34
34
|
"test": "npm run lint && npm run test:base",
|
|
35
35
|
"test:only": "npm run lint && npm run test:base:only",
|
|
36
|
-
"test:base:only": "cross-env DEBUG=@natlibfi/* NODE_ENV=test node --test --test-only --test-force-exit --experimental-test-coverage --test-reporter=spec 'test/**/*.test.js'",
|
|
36
|
+
"test:base:only": "cross-env DEBUG=@natlibfi/* NODE_ENV=test node --test --test-only --test-force-exit --experimental-test-coverage --test-reporter=spec 'test/*.test.js' 'test/**/*.test.js'",
|
|
37
37
|
"test:base:only:index": "cross-env DEBUG=@natlibfi/* NODE_ENV=test node --test --test-only --test-force-exit --experimental-test-coverage --test-reporter=spec './test/index.test.js'",
|
|
38
38
|
"watch:test": "cross-env DEBUG=@natlibfi/* NODE_ENV=test node --watch --test --experimental-test-coverage --test-reporter=spec 'test/**/*.test.js'",
|
|
39
39
|
"dev": "npm run watch:test",
|
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
import createDebugLogger from 'debug';
|
|
2
|
+
import {uniqArray} from '@natlibfi/marc-record-validators-melinda/dist/utils.js';
|
|
2
3
|
|
|
3
4
|
export function toQueries(identifiers, queryString) {
|
|
4
5
|
|
|
5
6
|
const debug = createDebugLogger('@natlibfi/melinda-record-matching:toQueries');
|
|
6
7
|
const debugData = debug.extend('data');
|
|
8
|
+
const debugDev = debug.extend('dev');
|
|
9
|
+
|
|
10
|
+
// For dc.identifier search use max length of 40 characters to avoid dc.identifier -> 1007 mapped query from crashing
|
|
11
|
+
// DEVELOP: check if the length crash is related to mapping the query to multiple Aleph indexes
|
|
12
|
+
const useMaxLength = queryString === 'dc.identifier' ? true : false;
|
|
13
|
+
const maxLength = 40;
|
|
14
|
+
debugData(`Adding ${queryString} to ${JSON.stringify(identifiers)}`)
|
|
15
|
+
debugDev(`We are ${useMaxLength ? `using maxLength ${maxLength}, queryString ${queryString}` : `not using maxLength, queryString ${queryString}`}`);
|
|
16
|
+
const croppedIdentifiers = uniqArray(useMaxLength ? identifiers.map((identifier) => identifier.substring(0, maxLength)) : identifiers);
|
|
7
17
|
|
|
8
18
|
// We quote the identifier, if it contains a slash! (Slash in non-quoted SRU-search breaks search.)
|
|
9
19
|
// We also quote the identifier, if it starts with caret (f028 searches fail without caret and quotes...)
|
|
10
|
-
const quotedIdentifiers =
|
|
20
|
+
const quotedIdentifiers = croppedIdentifiers.map(identifier => identifier.match(/\//u) || identifier.match(/\^/u) ? `"${identifier}"` : `${identifier}`);
|
|
11
21
|
|
|
12
22
|
// We can't pair queries with starting caret and without (ie. left anchored queries with non-left anchored queries)
|
|
13
23
|
const caretPairs = toPairs(quotedIdentifiers.filter(identifier => identifier.match(/\^/u)));
|
|
@@ -17,10 +27,22 @@ export function toQueries(identifiers, queryString) {
|
|
|
17
27
|
debugData(`Pairs (${pairs.length}): ${JSON.stringify(pairs)}`);
|
|
18
28
|
|
|
19
29
|
// Aleph supports only two queries with or -operator (This is not actually true)
|
|
20
|
-
const queries = pairs.map(([a, b]) =>
|
|
30
|
+
const queries = pairs.map(([a, b]) => {
|
|
31
|
+
const lengths = a.length + (b ? b.length : 0);
|
|
32
|
+
debugDev(`Lengths: A: ${a} (${a.length}) + B: ${b} (${b ? b.length : 0}) = ${lengths}`);
|
|
33
|
+
|
|
34
|
+
// Do not create a paired query if query length would be too long
|
|
35
|
+
if (useMaxLength && lengths > maxLength && a && b) {
|
|
36
|
+
return [`${queryString}=${a}`, `${queryString}=${b}`];
|
|
37
|
+
}
|
|
38
|
+
return b ? `${queryString}=${a} or ${queryString}=${b}` : `${queryString}=${a}`}
|
|
39
|
+
);
|
|
40
|
+
|
|
21
41
|
debugData(`Queries (${queries.length}): ${JSON.stringify(queries)}`);
|
|
42
|
+
const flatQueries = queries.flat();
|
|
43
|
+
debugData(`FlatQueries (${flatQueries.length}): ${JSON.stringify(flatQueries)}`);
|
|
22
44
|
|
|
23
|
-
return
|
|
45
|
+
return flatQueries;
|
|
24
46
|
}
|
|
25
47
|
|
|
26
48
|
function toPairs(array) {
|
|
@@ -29,3 +51,4 @@ function toPairs(array) {
|
|
|
29
51
|
}
|
|
30
52
|
return [array.slice(0, 2)].concat(toPairs(array.slice(2), 2));
|
|
31
53
|
}
|
|
54
|
+
|
|
@@ -4,8 +4,11 @@ import {getMelindaIdsF035, validateSidFieldSubfieldCounts, getSubfieldValues, te
|
|
|
4
4
|
import {extractHostMelindaIdsFromField, extractPublicationYearFrom773, getHostMelindaFields} from './component.js';
|
|
5
5
|
import {fieldToString} from '@natlibfi/marc-record-validators-melinda';
|
|
6
6
|
import {getTitle} from '../../match-detection/features/bib/title.js';
|
|
7
|
+
import {uniqArray} from '@natlibfi/marc-record-validators-melinda/dist/utils.js';
|
|
7
8
|
|
|
8
9
|
const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query');
|
|
10
|
+
const debugDev = debug.extend('dev');
|
|
11
|
+
|
|
9
12
|
|
|
10
13
|
const IS_OK_ALONE_THRESHOLD = 5;
|
|
11
14
|
|
|
@@ -187,6 +190,7 @@ export function bibTitleAuthorYearAlternates(record) {
|
|
|
187
190
|
|
|
188
191
|
function getTitleForQuery(record) {
|
|
189
192
|
const title = getTitle(record, ['a']);
|
|
193
|
+
debug(`getTitleForQuery: title ${title}`);
|
|
190
194
|
if (title) {
|
|
191
195
|
const nWords = title.split(' ');
|
|
192
196
|
// If lone $a is deemed too short, fetch $b as well:
|
|
@@ -207,11 +211,13 @@ function getTitleForQuery(record) {
|
|
|
207
211
|
|
|
208
212
|
function dcTitle(record, onlyTitleLength, alternates = false) {
|
|
209
213
|
const title = getTitleForQuery(record);
|
|
214
|
+
debug(`dcTitle: title: ${title}`);
|
|
210
215
|
if (!testStringOrNumber(title)) {
|
|
211
216
|
return [];
|
|
212
217
|
}
|
|
213
218
|
|
|
214
219
|
const formatted = getFormattedTitle(title);
|
|
220
|
+
debug(`dcTitle: formatted: ${formatted}`);
|
|
215
221
|
|
|
216
222
|
// use word search for titles starting with a boolean
|
|
217
223
|
const useWordSearch = checkUseWordSearch(formatted);
|
|
@@ -223,6 +229,10 @@ function dcTitle(record, onlyTitleLength, alternates = false) {
|
|
|
223
229
|
|
|
224
230
|
const queryIsOkAlone = !useWordSearch && formatted.length >= IS_OK_ALONE_THRESHOLD;
|
|
225
231
|
|
|
232
|
+
if (formatted.length<1) {
|
|
233
|
+
return ["", formatted, queryIsOkAlone];
|
|
234
|
+
}
|
|
235
|
+
|
|
226
236
|
// use word search without ending * also in combination searches to avoid SRU-server crashes [MRA-189]
|
|
227
237
|
return [`dc.title="${useWordSearch || !queryIsOkAlone ? '' : '^'}${formatted}${queryIsOkAlone ? '*' : ''}"`, formatted, queryIsOkAlone];
|
|
228
238
|
|
|
@@ -242,6 +252,7 @@ function dcTitle(record, onlyTitleLength, alternates = false) {
|
|
|
242
252
|
export function bibTitleAuthorPublisher({record, onlyTitleLength, addYear = false, alternates = false, alternateQueries = []}) {
|
|
243
253
|
debug(`bibTitleAuthorPublisher, onlyTitleLength: ${onlyTitleLength}, addYear: ${addYear}, alternates: ${alternates}`);
|
|
244
254
|
const [query, formatted, queryIsOkAlone] = dcTitle(record, onlyTitleLength, alternates);
|
|
255
|
+
debug(`query ${JSON.stringify(query)}, formatted: ${JSON.stringify(formatted)}, isOKAlone: ${JSON.stringify(queryIsOkAlone)}`);
|
|
245
256
|
if (query === undefined) {
|
|
246
257
|
return [];
|
|
247
258
|
}
|
|
@@ -262,11 +273,12 @@ export function bibTitleAuthorPublisher({record, onlyTitleLength, addYear = fals
|
|
|
262
273
|
debug('addAuthorsToSearch');
|
|
263
274
|
const [authorQuery] = bibAuthors(record);
|
|
264
275
|
if (authorQuery !== undefined) {
|
|
276
|
+
const combinedQuery = query.length > 0 ? `${authorQuery} AND ${query}` : `${authorQuery}`;
|
|
265
277
|
if (addYear) {
|
|
266
|
-
const newAlternateQueries = alternates ? [...alternateQueries,
|
|
267
|
-
return addYearToSearch({query:
|
|
278
|
+
const newAlternateQueries = alternates ? [...alternateQueries, combinedQuery] : alternateQueries;
|
|
279
|
+
return addYearToSearch({query: combinedQuery, queryIsOkAlone: true, alternates, alternateQueries: newAlternateQueries});
|
|
268
280
|
}
|
|
269
|
-
return alternates ? alternateQueries : [
|
|
281
|
+
return alternates ? alternateQueries : [combinedQuery];
|
|
270
282
|
}
|
|
271
283
|
return addPublisherToSearch({query, queryIsOkAlone, addYear, alternates, alternateQueries});
|
|
272
284
|
//return [];
|
|
@@ -275,11 +287,12 @@ export function bibTitleAuthorPublisher({record, onlyTitleLength, addYear = fals
|
|
|
275
287
|
function addPublisherToSearch({query, queryIsOkAlone = false, addYear = false, alternates = false, alternateQueries = []}) {
|
|
276
288
|
const [publisherQuery] = bibPublishers(record);
|
|
277
289
|
if (publisherQuery !== undefined) {
|
|
290
|
+
const combinedQuery = query.length > 0 ? `${publisherQuery} AND ${query}` : `${publisherQuery}`;
|
|
278
291
|
if (addYear) {
|
|
279
|
-
const newAlternateQueries = alternates ? [...alternateQueries,
|
|
280
|
-
return addYearToSearch({query:
|
|
292
|
+
const newAlternateQueries = alternates ? [...alternateQueries, combinedQuery] : alternateQueries;
|
|
293
|
+
return addYearToSearch({query: combinedQuery, queryIsOkAlone: true, alternates, alternateQueries: newAlternateQueries});
|
|
281
294
|
}
|
|
282
|
-
return alternates ? alternateQueries : [
|
|
295
|
+
return alternates ? alternateQueries : [combinedQuery];
|
|
283
296
|
}
|
|
284
297
|
if (queryIsOkAlone && !addYear) {
|
|
285
298
|
return alternates ? alternateQueries : [`${query}`];
|
|
@@ -290,7 +303,7 @@ export function bibTitleAuthorPublisher({record, onlyTitleLength, addYear = fals
|
|
|
290
303
|
function addYearToSearch({query, queryIsOkAlone = false, alternates = false, alternateQueries = []}) {
|
|
291
304
|
const [yearQuery] = bibYear(record);
|
|
292
305
|
if (yearQuery !== undefined) {
|
|
293
|
-
const yearAndOtherQueries = `${yearQuery} AND ${query}`;
|
|
306
|
+
const yearAndOtherQueries = query.length > 0 ? `${yearQuery} AND ${query}` : `${yearQuery}`;
|
|
294
307
|
return alternates ? [...alternateQueries, yearAndOtherQueries] : [yearAndOtherQueries];
|
|
295
308
|
}
|
|
296
309
|
if (queryIsOkAlone) {
|
|
@@ -413,10 +426,12 @@ export function bibYear(record) {
|
|
|
413
426
|
|
|
414
427
|
debugData(`f008: ${JSON.stringify(f008)}`);
|
|
415
428
|
const {value} = f008;
|
|
416
|
-
|
|
429
|
+
const year = value.slice(7, 11);
|
|
430
|
+
if (year === '||||' || year === ' ') { // Meaningless values
|
|
431
|
+
debug('Meaningless year in f008');
|
|
417
432
|
return false;
|
|
418
433
|
}
|
|
419
|
-
return
|
|
434
|
+
return year;
|
|
420
435
|
}
|
|
421
436
|
}
|
|
422
437
|
|
|
@@ -431,9 +446,11 @@ export function bibStandardIdentifiers(record) {
|
|
|
431
446
|
|
|
432
447
|
const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibStandardIdentifiers');
|
|
433
448
|
const debugData = debug.extend('data');
|
|
449
|
+
const debugDev = debug.extend('dev');
|
|
450
|
+
|
|
434
451
|
debug(`Creating queries for standard identifiers`);
|
|
435
452
|
|
|
436
|
-
// DEVELOP:
|
|
453
|
+
// DEVELOP: query identifiers from their own indexes (this needs some mapping work in SRU/Aleph)
|
|
437
454
|
|
|
438
455
|
// const fields = record.get(/^(?<def>020|022|024)$/u);
|
|
439
456
|
const fields = record.get(/^(?<def>015|020|022|024|028)$/u);
|
|
@@ -475,14 +492,71 @@ export function bibStandardIdentifiers(record) {
|
|
|
475
492
|
|
|
476
493
|
if (tag === '028') { // TODO: test
|
|
477
494
|
const a = subfields.find(sf => sf.code === 'a');
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
495
|
+
const b = subfields.find(sf => sf.code === 'b');
|
|
496
|
+
|
|
497
|
+
// Handle cases where there is a qualifier in brackets after value
|
|
498
|
+
const cleanAs = cleanQualifiers(a?.value);
|
|
499
|
+
const cleanBs = cleanQualifiers(b?.value);
|
|
500
|
+
debugDev(JSON.stringify(cleanAs));
|
|
501
|
+
debugDev(JSON.stringify(cleanBs));
|
|
502
|
+
|
|
503
|
+
// Handle cases where there are several values separated by a comma in subfield
|
|
504
|
+
const splitAs = cleanAs.map(elem => elem.split(',')).concat(cleanAs).flat();
|
|
505
|
+
const splitBs = cleanBs.map(elem => elem.split(',')).concat(cleanBs).flat();
|
|
506
|
+
debugDev(JSON.stringify(splitAs));
|
|
507
|
+
debugDev(JSON.stringify(splitBs));
|
|
508
|
+
|
|
509
|
+
const normAs = splitAs.map(elem => normalizeF028ForSearch(elem));
|
|
510
|
+
const normBs = splitBs.map(elem => normalizeF028ForSearch(elem));
|
|
511
|
+
debugDev(JSON.stringify(normAs));
|
|
512
|
+
debugDev(JSON.stringify(normBs));
|
|
513
|
+
|
|
514
|
+
const identifiers = normAs.map((normA, index) => {
|
|
515
|
+
debugDev(`Handling ${normA} from index: ${index}`);
|
|
516
|
+
// Paired $a + $b
|
|
517
|
+
if (normA.length > 0 && normBs[index]?.length > 0) {
|
|
518
|
+
debugDev(`Found a (${normA}) + b (${normBs[index]})`);
|
|
519
|
+
// let's not return plain $b
|
|
520
|
+
return [`^${normBs[index]} ${normA}`, `^${normA} ${normBs[index]}`, `^${normA}`];
|
|
521
|
+
//return [`^${normA}`, `^${normBs[index]}`, `^${normBs[index]} ${normA}`, `^${normA} ${normBs[index]}`];
|
|
522
|
+
|
|
523
|
+
}
|
|
524
|
+
// if there is no pair, get $a + first $b
|
|
525
|
+
// NOTE: we do not get all possible pairs
|
|
526
|
+
if (normA.length > 0 && normBs[0]?.length > 0) {
|
|
527
|
+
debugDev(`Found a (${normA}) + b (${normBs[0]})`);
|
|
528
|
+
// let's not return plain $b
|
|
529
|
+
return [`^${normBs[0]} ${normA}`, `^${normA} ${normBs[0]}`, `^${normA}`];
|
|
530
|
+
//return [`^${normA}`, `^${normBs[index]}`, `^${normBs[index]} ${normA}`, `^${normA} ${normBs[index]}`];
|
|
531
|
+
|
|
483
532
|
}
|
|
484
|
-
|
|
533
|
+
// Otherwise just $a
|
|
534
|
+
if (normA.length > 0) {
|
|
535
|
+
debugDev(`Found a (${normA}) but no b ${normBs[index]}`);
|
|
536
|
+
return [`^${normA}`];
|
|
537
|
+
}
|
|
538
|
+
return [];
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
debugDev(`Current identifiers from f028: ${JSON.stringify(identifiers)}`);
|
|
542
|
+
return uniqArray(identifiers.flat());
|
|
543
|
+
|
|
544
|
+
function cleanQualifiers(val) {
|
|
545
|
+
if (val !== undefined) {
|
|
546
|
+
const cleanVal = val.replace(/ +\(.*\)/gu, '').replace(/ +/ug, ' ').replace(/^ +/ug, '').replace(/ +$/ug, '');
|
|
547
|
+
return uniqArray([val, cleanVal]);
|
|
548
|
+
}
|
|
549
|
+
return [];
|
|
485
550
|
}
|
|
551
|
+
|
|
552
|
+
function normalizeF028ForSearch(val) {
|
|
553
|
+
// see normalization routine 34 used for 028-index in Aleph
|
|
554
|
+
const f028NormCharsRegex = /[-"<>;:%=~`!\(\)\{\}\.\?\/\@\*\^]/g;
|
|
555
|
+
const normVal = val.replace(f028NormCharsRegex, ' ').replace(/ +/ug, ' ').replace(/^ +/ug, '').replace(/ +$/ug, '').toLowerCase();
|
|
556
|
+
// Do not return a value normalized to just a space
|
|
557
|
+
return normVal !== " " ? normVal : "";
|
|
558
|
+
}
|
|
559
|
+
|
|
486
560
|
}
|
|
487
561
|
|
|
488
562
|
// Default seems to be 024:
|
|
@@ -26,6 +26,7 @@ export default () => ({
|
|
|
26
26
|
}
|
|
27
27
|
const a = field.subfields.find(sf => sf.code === 'a');
|
|
28
28
|
// NB! Publisher number must contain a digit! :-)
|
|
29
|
+
// NOTE: we might have some rare cases with publisher numbers that do not have numbers...
|
|
29
30
|
if (!a || !a.value || !a.value.match(/[0-9]/u)) {
|
|
30
31
|
return fieldsToPublisherNumber(remainingFields, result);
|
|
31
32
|
}
|
|
@@ -40,7 +41,7 @@ export default () => ({
|
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
function normalizePublisherNumber(val) {
|
|
43
|
-
return val.replace(/[- .,:;]/ug, '');
|
|
44
|
+
return val.replace(/[- .,:;]/ug, '').toLowerCase();
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
47
|
},
|
|
@@ -7,6 +7,8 @@ import { subfieldToString } from '@natlibfi/marc-record-validators-melinda/dist/
|
|
|
7
7
|
|
|
8
8
|
const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib/title');
|
|
9
9
|
const debugData = debug.extend('data');
|
|
10
|
+
const debugDev = debug.extend('dev');
|
|
11
|
+
|
|
10
12
|
|
|
11
13
|
const TITLE_MAX = 0.5;
|
|
12
14
|
export default ({threshold = 0.9} = {}) => ({
|
|
@@ -235,6 +237,8 @@ export default ({threshold = 0.9} = {}) => ({
|
|
|
235
237
|
export function getTitle(record, targetSubfieldCodes = ['a', 'b', 'n', 'p']) {
|
|
236
238
|
const [field] = record.get(/^245$/u);
|
|
237
239
|
debugData(`titleField: ${JSON.stringify(field)}`);
|
|
240
|
+
debugDev(`targetSubfieldCodes: ${JSON.stringify(targetSubfieldCodes)}`);
|
|
241
|
+
|
|
238
242
|
|
|
239
243
|
if (field) {
|
|
240
244
|
const title = field.subfields
|
|
@@ -243,7 +247,8 @@ export function getTitle(record, targetSubfieldCodes = ['a', 'b', 'n', 'p']) {
|
|
|
243
247
|
// Would be nice to normalize $n values...
|
|
244
248
|
.map(({value}) => testStringOrNumber(value) ? String(value) : '')
|
|
245
249
|
.join(' ')
|
|
246
|
-
|
|
250
|
+
// Note: we do not want to removed stuff in brackets if its the only stuff in field ... (245 $a [Psi] / ... )
|
|
251
|
+
//.replace(/\[[^\]]*\]/ug, ' ') // Remove [whatever] stuff. ADD TEST FOR THIS
|
|
247
252
|
.replace(/ [=\/:](?:$| )/ug, ' ') // Strip punctuation
|
|
248
253
|
// Also đ vs d pairs seen:
|
|
249
254
|
//.replace(/(?:đ|ȧ|t̄|ǩ|ǧ|s̆|c̆)/ug, '') // Hack. Saamelaisbibliografia has often dropped this wierd characters (oft old articles, no longer used in sami either)
|
|
@@ -252,11 +257,24 @@ export function getTitle(record, targetSubfieldCodes = ['a', 'b', 'n', 'p']) {
|
|
|
252
257
|
.replace(/^ +/u, '')
|
|
253
258
|
.replace(/ +$/u, '');
|
|
254
259
|
|
|
260
|
+
debugDev(`getTitle: title: ${title}`)
|
|
261
|
+
|
|
262
|
+
const cleanTitle = title.replace(/\[[^\]]*\]/ug, ' ') // Remove [whatever] stuff. ADD TEST FOR THIS
|
|
263
|
+
.replace(/ +/ug, ' ')
|
|
264
|
+
.replace(/^ +/u, '')
|
|
265
|
+
.replace(/ +$/u, '');
|
|
266
|
+
|
|
267
|
+
debugDev(`getTitle: cleanTitle: ${cleanTitle} (${cleanTitle.length})`);
|
|
268
|
+
const usableTitle = cleanTitle.length > 0 ? cleanTitle : title;
|
|
269
|
+
debugDev(`getTitle: usableTitle: ${usableTitle} (${usableTitle.length})`);
|
|
270
|
+
|
|
271
|
+
|
|
255
272
|
// Skip non-filing indicator (note that '9' is a magic indicator value, so we don't do it):
|
|
256
273
|
if (/^[1-8]$/u.test(field.ind2)) { // Skip non-filing characters
|
|
257
|
-
|
|
274
|
+
const nonFilingTitle = usableTitle.slice(parseInt(field.ind2));
|
|
275
|
+
if (nonFilingTitle.length > 0) return nonFilingTitle;
|
|
258
276
|
}
|
|
259
|
-
return
|
|
277
|
+
return usableTitle;
|
|
260
278
|
|
|
261
279
|
}
|
|
262
280
|
return false;
|