@natlibfi/melinda-record-matching 5.0.0-alpha.1 → 5.0.0-alpha.2

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.
Files changed (71) hide show
  1. package/dist/candidate-search/candidate-search-utils.js +18 -0
  2. package/dist/candidate-search/candidate-search-utils.js.map +7 -0
  3. package/dist/candidate-search/choose-queries.js +75 -0
  4. package/dist/candidate-search/choose-queries.js.map +7 -0
  5. package/dist/candidate-search/index.js +118 -0
  6. package/dist/candidate-search/index.js.map +7 -0
  7. package/dist/candidate-search/index.test.js +92 -0
  8. package/dist/candidate-search/index.test.js.map +7 -0
  9. package/dist/candidate-search/query-list/bib.js +260 -0
  10. package/dist/candidate-search/query-list/bib.js.map +7 -0
  11. package/dist/candidate-search/query-list/bib.test.js +34 -0
  12. package/dist/candidate-search/query-list/bib.test.js.map +7 -0
  13. package/dist/candidate-search/query-list/component.js +87 -0
  14. package/dist/candidate-search/query-list/component.js.map +7 -0
  15. package/dist/candidate-search/query-list/index.js +53 -0
  16. package/dist/candidate-search/query-list/index.js.map +7 -0
  17. package/dist/cli.js +138 -0
  18. package/dist/cli.js.map +7 -0
  19. package/dist/index.js +204 -0
  20. package/dist/index.js.map +7 -0
  21. package/dist/index.test.js +69 -0
  22. package/dist/index.test.js.map +7 -0
  23. package/dist/match-detection/features/bib/all-source-ids.js +48 -0
  24. package/dist/match-detection/features/bib/all-source-ids.js.map +7 -0
  25. package/dist/match-detection/features/bib/authors.js +57 -0
  26. package/dist/match-detection/features/bib/authors.js.map +7 -0
  27. package/dist/match-detection/features/bib/bibliographic-level.js +6 -0
  28. package/dist/match-detection/features/bib/bibliographic-level.js.map +7 -0
  29. package/dist/match-detection/features/bib/host-component.js +6 -0
  30. package/dist/match-detection/features/bib/host-component.js.map +7 -0
  31. package/dist/match-detection/features/bib/index.js +17 -0
  32. package/dist/match-detection/features/bib/index.js.map +7 -0
  33. package/dist/match-detection/features/bib/index.test.js +40 -0
  34. package/dist/match-detection/features/bib/index.test.js.map +7 -0
  35. package/dist/match-detection/features/bib/isbn.js +21 -0
  36. package/dist/match-detection/features/bib/isbn.js.map +7 -0
  37. package/dist/match-detection/features/bib/issn.js +6 -0
  38. package/dist/match-detection/features/bib/issn.js.map +7 -0
  39. package/dist/match-detection/features/bib/language.js +80 -0
  40. package/dist/match-detection/features/bib/language.js.map +7 -0
  41. package/dist/match-detection/features/bib/media-type.js +31 -0
  42. package/dist/match-detection/features/bib/media-type.js.map +7 -0
  43. package/dist/match-detection/features/bib/melinda-id.js +6 -0
  44. package/dist/match-detection/features/bib/melinda-id.js.map +7 -0
  45. package/dist/match-detection/features/bib/melinda-identifier-factory.js +38 -0
  46. package/dist/match-detection/features/bib/melinda-identifier-factory.js.map +7 -0
  47. package/dist/match-detection/features/bib/other-standard-identifier.js +6 -0
  48. package/dist/match-detection/features/bib/other-standard-identifier.js.map +7 -0
  49. package/dist/match-detection/features/bib/publication-time-allow-cons-years-multi.js +116 -0
  50. package/dist/match-detection/features/bib/publication-time-allow-cons-years-multi.js.map +7 -0
  51. package/dist/match-detection/features/bib/publication-time-allow-cons-years.js +28 -0
  52. package/dist/match-detection/features/bib/publication-time-allow-cons-years.js.map +7 -0
  53. package/dist/match-detection/features/bib/publication-time.js +10 -0
  54. package/dist/match-detection/features/bib/publication-time.js.map +7 -0
  55. package/dist/match-detection/features/bib/record-type.js +6 -0
  56. package/dist/match-detection/features/bib/record-type.js.map +7 -0
  57. package/dist/match-detection/features/bib/standard-identifier-factory.js +99 -0
  58. package/dist/match-detection/features/bib/standard-identifier-factory.js.map +7 -0
  59. package/dist/match-detection/features/bib/title-version-original.js +37 -0
  60. package/dist/match-detection/features/bib/title-version-original.js.map +7 -0
  61. package/dist/match-detection/features/bib/title.js +46 -0
  62. package/dist/match-detection/features/bib/title.js.map +7 -0
  63. package/dist/match-detection/features/index.js +3 -0
  64. package/dist/match-detection/features/index.js.map +7 -0
  65. package/dist/match-detection/index.js +86 -0
  66. package/dist/match-detection/index.js.map +7 -0
  67. package/dist/match-detection/index.test.js +44 -0
  68. package/dist/match-detection/index.test.js.map +7 -0
  69. package/dist/matching-utils.js +79 -0
  70. package/dist/matching-utils.js.map +7 -0
  71. package/package.json +2 -1
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/match-detection/features/bib/index.test.js"],
4
+ "sourcesContent": ["\nimport assert from 'node:assert';\nimport {describe} from 'node:test';\nimport createDebugLogger from 'debug';\nimport generateTests from '@natlibfi/fixugen';\nimport {READERS} from '@natlibfi/fixura';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport * as features from './index.js';\n\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib:test');\nconst debugData = debug.extend('data');\n\n\ndescribe('match-detection/features/bib/', () => {\n generateTests({\n path: [import.meta.dirname, '..', '..', '..', '..', 'test-fixtures', 'match-detection', 'features', 'bib'],\n useMetadataFile: true,\n fixura: {\n reader: READERS.JSON\n },\n\n callback: ({enabled = true, feature, options, type, ...expectations}) => {\n\n if (!enabled) {\n return;\n }\n\n debug(`Testing: ${feature} ${type}`);\n\n if (type === 'extract') {\n const {expectedFeatures, inputRecord} = expectations;\n const record = new MarcRecord(inputRecord, {subfieldValues: false});\n debugData(`Record: ${record}`);\n const {extract} = features[feature](options);\n\n assert.deepStrictEqual(extract({record}), expectedFeatures);\n return;\n }\n\n if (type === 'compare') {\n const {featuresA, featuresB, expectedPoints} = expectations;\n const {compare} = features[feature](options);\n\n assert.equal(compare(featuresA, featuresB), expectedPoints);\n return;\n }\n\n throw new Error(`Invalid type ${type}`);\n }\n });\n});\n"],
5
+ "mappings": "AACA,OAAO,YAAY;AACnB,SAAQ,gBAAe;AACvB,OAAO,uBAAuB;AAC9B,OAAO,mBAAmB;AAC1B,SAAQ,eAAc;AACtB,SAAQ,kBAAiB;AACzB,YAAY,cAAc;AAG1B,MAAM,QAAQ,kBAAkB,qEAAqE;AACrG,MAAM,YAAY,MAAM,OAAO,MAAM;AAGrC,SAAS,iCAAiC,MAAM;AAC9C,gBAAc;AAAA,IACZ,MAAM,CAAC,YAAY,SAAS,MAAM,MAAM,MAAM,MAAM,iBAAiB,mBAAmB,YAAY,KAAK;AAAA,IACzG,iBAAiB;AAAA,IACjB,QAAQ;AAAA,MACN,QAAQ,QAAQ;AAAA,IAClB;AAAA,IAEA,UAAU,CAAC,EAAC,UAAU,MAAM,SAAS,SAAS,MAAM,GAAG,aAAY,MAAM;AAEvE,UAAI,CAAC,SAAS;AACZ;AAAA,MACF;AAEA,YAAM,YAAY,OAAO,IAAI,IAAI,EAAE;AAEnC,UAAI,SAAS,WAAW;AACtB,cAAM,EAAC,kBAAkB,YAAW,IAAI;AACxC,cAAM,SAAS,IAAI,WAAW,aAAa,EAAC,gBAAgB,MAAK,CAAC;AAClE,kBAAU,WAAW,MAAM,EAAE;AAC7B,cAAM,EAAC,QAAO,IAAI,SAAS,OAAO,EAAE,OAAO;AAE3C,eAAO,gBAAgB,QAAQ,EAAC,OAAM,CAAC,GAAG,gBAAgB;AAC1D;AAAA,MACF;AAEA,UAAI,SAAS,WAAW;AACtB,cAAM,EAAC,WAAW,WAAW,eAAc,IAAI;AAC/C,cAAM,EAAC,QAAO,IAAI,SAAS,OAAO,EAAE,OAAO;AAE3C,eAAO,MAAM,QAAQ,WAAW,SAAS,GAAG,cAAc;AAC1D;AAAA,MACF;AAEA,YAAM,IAAI,MAAM,gBAAgB,IAAI,EAAE;AAAA,IACxC;AAAA,EACF,CAAC;AACH,CAAC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,21 @@
1
+ import createDebugLogger from "debug";
2
+ import { parse as isbnParse } from "isbn3";
3
+ import createInterface from "./standard-identifier-factory.js";
4
+ const debug = createDebugLogger(`@natlibfi/melinda-record-matching:match-detection:features:standard-identifiers:ISBN`);
5
+ const debugData = debug.extend("data");
6
+ export default () => {
7
+ const IDENTIFIER_NAME = "ISBN";
8
+ function validatorAndNormalizer(string) {
9
+ const isbnParseResult = isbnParse(string);
10
+ debugData(`isbnParseResult: ${JSON.stringify(isbnParseResult)}`);
11
+ if (isbnParseResult === null) {
12
+ debug(`Not parseable ISBN, just removing hyphens`);
13
+ return { valid: false, value: string.replace(/-/ug, "") };
14
+ }
15
+ debug(`Parseable ISBN, normalizing to ISBN-13`);
16
+ return { valid: true, value: isbnParseResult.isbn13 };
17
+ }
18
+ const { extract, compare } = createInterface({ identifier: IDENTIFIER_NAME, pattern: /^020$/u, subfieldCodes: ["a", "z"], validIdentifierSubfieldCodes: ["a"], invalidIdentifierSubfieldCodes: ["z"], validatorAndNormalizer });
19
+ return { extract, compare, name: IDENTIFIER_NAME };
20
+ };
21
+ //# sourceMappingURL=isbn.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/match-detection/features/bib/isbn.js"],
4
+ "sourcesContent": ["\nimport createDebugLogger from 'debug';\nimport {parse as isbnParse} from 'isbn3';\nimport createInterface from './standard-identifier-factory.js';\n\nconst debug = createDebugLogger(`@natlibfi/melinda-record-matching:match-detection:features:standard-identifiers:ISBN`);\nconst debugData = debug.extend('data');\n\nexport default () => {\n const IDENTIFIER_NAME = 'ISBN';\n\n function validatorAndNormalizer(string) {\n const isbnParseResult = isbnParse(string);\n debugData(`isbnParseResult: ${JSON.stringify(isbnParseResult)}`);\n if (isbnParseResult === null) {\n debug(`Not parseable ISBN, just removing hyphens`);\n return {valid: false, value: string.replace(/-/ug, '')};\n }\n debug(`Parseable ISBN, normalizing to ISBN-13`);\n return {valid: true, value: isbnParseResult.isbn13};\n }\n\n const {extract, compare} = createInterface({identifier: IDENTIFIER_NAME, pattern: /^020$/u, subfieldCodes: ['a', 'z'], validIdentifierSubfieldCodes: ['a'], invalidIdentifierSubfieldCodes: ['z'], validatorAndNormalizer});\n return {extract, compare, name: IDENTIFIER_NAME};\n};\n\n"],
5
+ "mappings": "AACA,OAAO,uBAAuB;AAC9B,SAAQ,SAAS,iBAAgB;AACjC,OAAO,qBAAqB;AAE5B,MAAM,QAAQ,kBAAkB,sFAAsF;AACtH,MAAM,YAAY,MAAM,OAAO,MAAM;AAErC,eAAe,MAAM;AACnB,QAAM,kBAAkB;AAExB,WAAS,uBAAuB,QAAQ;AACtC,UAAM,kBAAkB,UAAU,MAAM;AACxC,cAAU,oBAAoB,KAAK,UAAU,eAAe,CAAC,EAAE;AAC/D,QAAI,oBAAoB,MAAM;AAC5B,YAAM,2CAA2C;AACjD,aAAO,EAAC,OAAO,OAAO,OAAO,OAAO,QAAQ,OAAO,EAAE,EAAC;AAAA,IACxD;AACA,UAAM,wCAAwC;AAC9C,WAAO,EAAC,OAAO,MAAM,OAAO,gBAAgB,OAAM;AAAA,EACpD;AAEA,QAAM,EAAC,SAAS,QAAO,IAAI,gBAAgB,EAAC,YAAY,iBAAiB,SAAS,UAAU,eAAe,CAAC,KAAK,GAAG,GAAG,8BAA8B,CAAC,GAAG,GAAG,gCAAgC,CAAC,GAAG,GAAG,uBAAsB,CAAC;AAC1N,SAAO,EAAC,SAAS,SAAS,MAAM,gBAAe;AACjD;",
6
+ "names": []
7
+ }
@@ -0,0 +1,6 @@
1
+ import createInterface from "./standard-identifier-factory.js";
2
+ export default () => {
3
+ const { extract, compare } = createInterface({ pattern: /^022$/u, subfieldCodes: ["a", "z", "y"] });
4
+ return { extract, compare, name: "ISSN" };
5
+ };
6
+ //# sourceMappingURL=issn.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/match-detection/features/bib/issn.js"],
4
+ "sourcesContent": ["\nimport createInterface from './standard-identifier-factory.js';\n\nexport default () => {\n const {extract, compare} = createInterface({pattern: /^022$/u, subfieldCodes: ['a', 'z', 'y']});\n return {extract, compare, name: 'ISSN'};\n};\n"],
5
+ "mappings": "AACA,OAAO,qBAAqB;AAE5B,eAAe,MAAM;AACnB,QAAM,EAAC,SAAS,QAAO,IAAI,gBAAgB,EAAC,SAAS,UAAU,eAAe,CAAC,KAAK,KAAK,GAAG,EAAC,CAAC;AAC9F,SAAO,EAAC,SAAS,SAAS,MAAM,OAAM;AACxC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,80 @@
1
+ import createDebugLogger from "debug";
2
+ import { getMatchCounts } from "../../../matching-utils.js";
3
+ const debug = createDebugLogger("@natlibfi/melinda-record-matching:match-detection:features:language");
4
+ const debugData = debug.extend("data");
5
+ export default () => ({
6
+ name: "Language",
7
+ extract: ({ record, recordExternal }) => {
8
+ const label = recordExternal && recordExternal.label ? recordExternal.label : "record";
9
+ const value008 = get008Value();
10
+ const values041 = get041Values();
11
+ debugData(`${label}: 008: ${JSON.stringify(value008)}, 041: ${JSON.stringify(values041)}`);
12
+ if (!value008 && values041.length < 1) {
13
+ debugData(`${label}: No actual values found`);
14
+ return [];
15
+ }
16
+ const allValues = value008 === void 0 ? values041 : values041.concat(value008);
17
+ const uniqueSortedValues = [...new Set(allValues)].sort();
18
+ return uniqueSortedValues;
19
+ function get008Value() {
20
+ const value = record.get(/^008$/u)?.[0]?.value || void 0;
21
+ debugData(`${label}: 008 value: ${value}`);
22
+ if (!value) {
23
+ return void 0;
24
+ }
25
+ const code = value.slice(35, 38);
26
+ debugData(`${label}: 008 code: ${code}`);
27
+ return isLangCodeForALanguage(code) ? code : void 0;
28
+ }
29
+ function get041Values() {
30
+ return record.get(/^041$/u).filter(({ ind2 }) => ind2 === " ").map(({ subfields }) => subfields).flat().filter(({ code }) => code === "a" || code === "d").filter(({ value }) => value && isLangCodeForALanguage(value)).map(({ value }) => value);
31
+ }
32
+ function isLangCodeForALanguage(code) {
33
+ if (code.length !== 3) {
34
+ debugData(`Code ${code} is not correct length (3) for a language code.`);
35
+ return false;
36
+ }
37
+ if (code === "|||" || code === " " || code === "^^^" || code === "mul" || code === "zxx") {
38
+ debugData(`Code ${code} is not code for a spesific language.`);
39
+ return false;
40
+ }
41
+ const langCodePattern = /^[a-z][a-z][a-z]$/ui;
42
+ if (!langCodePattern.test(code)) {
43
+ debugData(`Code ${code} is not valid as a language code`);
44
+ return false;
45
+ }
46
+ return true;
47
+ }
48
+ },
49
+ // eslint-disable-next-line max-statements
50
+ compare: (a, b) => {
51
+ debugData(`Comparing ${JSON.stringify(a)} and ${JSON.stringify(b)}`);
52
+ if (a.length === 0 || b.length === 0) {
53
+ debugData(`No language to compare`);
54
+ return 0;
55
+ }
56
+ if (a.length === b.length && a.every((element, index) => element === b[index])) {
57
+ debugData(`All languages match`);
58
+ return 0.1;
59
+ }
60
+ const { matchingValues, possibleMatchValues, maxValues } = getMatchCounts(a, b);
61
+ if (matchingValues < 1) {
62
+ debug(`Both have languages, but none of these match.`);
63
+ return -1;
64
+ }
65
+ debug(`Both have languages, ${matchingValues}/${possibleMatchValues} valid languages match.`);
66
+ debug(`Possible matches: ${possibleMatchValues}/${maxValues}`);
67
+ const missingCount = maxValues - possibleMatchValues;
68
+ const misMatchCount = possibleMatchValues - matchingValues;
69
+ debug(` missing: ${missingCount}`);
70
+ debug(` mismatches: ${misMatchCount}`);
71
+ const penaltyForMissing = 0.02 * (maxValues - possibleMatchValues);
72
+ const penaltyForMisMatch = 0.05 * (possibleMatchValues - matchingValues);
73
+ debug(` points: penaltyForMissing: ${penaltyForMissing}`);
74
+ debug(` points: penaltyForMisMatch: ${penaltyForMisMatch}`);
75
+ const points = Number(Number(0.1 - penaltyForMisMatch - penaltyForMissing).toFixed(2));
76
+ debug(`Total points: ${points}`);
77
+ return points;
78
+ }
79
+ });
80
+ //# sourceMappingURL=language.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/match-detection/features/bib/language.js"],
4
+ "sourcesContent": ["\nimport createDebugLogger from 'debug';\nimport {getMatchCounts} from '../../../matching-utils.js';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features:language');\nconst debugData = debug.extend('data');\n\nexport default () => ({\n name: 'Language',\n extract: ({record, recordExternal}) => {\n const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';\n\n const value008 = get008Value();\n const values041 = get041Values();\n debugData(`${label}: 008: ${JSON.stringify(value008)}, 041: ${JSON.stringify(values041)}`);\n\n if (!value008 && values041.length < 1) {\n debugData(`${label}: No actual values found`);\n return [];\n }\n\n const allValues = value008 === undefined ? values041 : values041.concat(value008);\n const uniqueSortedValues = [...new Set(allValues)].sort();\n\n return uniqueSortedValues;\n\n function get008Value() {\n const value = record.get(/^008$/u)?.[0]?.value || undefined;\n debugData(`${label}: 008 value: ${value}`);\n\n if (!value) {\n return undefined;\n }\n\n const code = value.slice(35, 38);\n debugData(`${label}: 008 code: ${code}`);\n return isLangCodeForALanguage(code) ? code : undefined;\n }\n\n // Uses only f041s that have 2nd ind ' ', which means that the codes used are MARC 21 language codes\n\n function get041Values() {\n return record.get(/^041$/u)\n .filter(({ind2}) => ind2 === ' ')\n .map(({subfields}) => subfields)\n .flat()\n .filter(({code}) => code === 'a' || code === 'd')\n .filter(({value}) => value && isLangCodeForALanguage(value))\n .map(({value}) => value);\n }\n\n // Check if a string is a possible, validly formed language code for a single language\n // Currently accept also codes in capitals\n function isLangCodeForALanguage(code) {\n if (code.length !== 3) {\n debugData(`Code ${code} is not correct length (3) for a language code.`);\n return false;\n }\n if (code === '|||' || code === ' ' || code === '^^^' || code === 'mul' || code === 'zxx') {\n debugData(`Code ${code} is not code for a spesific language.`);\n return false;\n }\n const langCodePattern = /^[a-z][a-z][a-z]$/ui;\n if (!langCodePattern.test(code)) {\n debugData(`Code ${code} is not valid as a language code`);\n return false;\n }\n return true;\n }\n\n },\n // eslint-disable-next-line max-statements\n compare: (a, b) => {\n debugData(`Comparing ${JSON.stringify(a)} and ${JSON.stringify(b)}`);\n\n if (a.length === 0 || b.length === 0) {\n debugData(`No language to compare`);\n return 0;\n }\n\n if (a.length === b.length && a.every((element, index) => element === b[index])) {\n debugData(`All languages match`);\n return 0.1;\n }\n\n const {matchingValues, possibleMatchValues, maxValues} = getMatchCounts(a, b);\n\n if (matchingValues < 1) {\n debug(`Both have languages, but none of these match.`);\n return -1.0;\n }\n debug(`Both have languages, ${matchingValues}/${possibleMatchValues} valid languages match.`);\n // ignore non-matches if there is mismatching amount of values\n debug(`Possible matches: ${possibleMatchValues}/${maxValues}`);\n //we give some kind of penalty for mismatching amount of values instead of simple divide?\n const missingCount = maxValues - possibleMatchValues;\n const misMatchCount = possibleMatchValues - matchingValues;\n debug(`\\t missing: ${missingCount}`);\n debug(`\\t mismatches: ${misMatchCount}`);\n\n const penaltyForMissing = 0.02 * (maxValues - possibleMatchValues);\n const penaltyForMisMatch = 0.05 * (possibleMatchValues - matchingValues);\n debug(`\\t points: penaltyForMissing: ${penaltyForMissing}`);\n debug(`\\t points: penaltyForMisMatch: ${penaltyForMisMatch}`);\n\n const points = Number(Number(0.1 - penaltyForMisMatch - penaltyForMissing).toFixed(2));\n debug(`Total points: ${points}`);\n\n return points;\n }\n});\n"],
5
+ "mappings": "AACA,OAAO,uBAAuB;AAC9B,SAAQ,sBAAqB;AAE7B,MAAM,QAAQ,kBAAkB,qEAAqE;AACrG,MAAM,YAAY,MAAM,OAAO,MAAM;AAErC,eAAe,OAAO;AAAA,EACpB,MAAM;AAAA,EACN,SAAS,CAAC,EAAC,QAAQ,eAAc,MAAM;AACrC,UAAM,QAAQ,kBAAkB,eAAe,QAAQ,eAAe,QAAQ;AAE9E,UAAM,WAAW,YAAY;AAC7B,UAAM,YAAY,aAAa;AAC/B,cAAU,GAAG,KAAK,UAAU,KAAK,UAAU,QAAQ,CAAC,UAAU,KAAK,UAAU,SAAS,CAAC,EAAE;AAEzF,QAAI,CAAC,YAAY,UAAU,SAAS,GAAG;AACrC,gBAAU,GAAG,KAAK,0BAA0B;AAC5C,aAAO,CAAC;AAAA,IACV;AAEA,UAAM,YAAY,aAAa,SAAY,YAAY,UAAU,OAAO,QAAQ;AAChF,UAAM,qBAAqB,CAAC,GAAG,IAAI,IAAI,SAAS,CAAC,EAAE,KAAK;AAExD,WAAO;AAEP,aAAS,cAAc;AACrB,Y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IACT;AAEA,QAAI,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,CAAC,SAAS,UAAU,YAAY,EAAE,KAAK,CAAC,GAAG;AAC9E,gBAAU,qBAAqB;AAC/B,aAAO;AAAA,IACT;AAEA,UAAM,EAAC,gBAAgB,qBAAqB,UAAS,IAAI,eAAe,GAAG,CAAC;AAE5E,QAAI,iBAAiB,GAAG;AACtB,YAAM,+CAA+C;AACrD,aAAO;AAAA,IACT;AACA,UAAM,wBAAwB,cAAc,IAAI,mBAAmB,yBAAyB;AAE5F,UAAM,qBAAqB,mBAAmB,IAAI,SAAS,EAAE;AAE7D,UAAM,eAAe,YAAY;AACjC,UAAM,gBAAgB,sBAAsB;AAC5C,UAAM,cAAe,YAAY,EAAE;AACnC,UAAM,iBAAkB,aAAa,EAAE;AAEvC,UAAM,oBAAoB,QAAQ,YAAY;AAC9C,UAAM,qBAAqB,QAAQ,sBAAsB;AACzD,UAAM,gCAAiC,iBAAiB,EAAE;AAC1D,UAAM,iCAAkC,kBAAkB,EAAE;AAE5D,UAAM,SAAS,OAAO,OAAO,MAAM,qBAAqB,iBAAiB,EAAE,QAAQ,CAAC,CAAC;AACrF,UAAM,iBAAiB,MAAM,EAAE;AAE/B,WAAO;AAAA,EACT;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,31 @@
1
+ import createDebugLogger from "debug";
2
+ const debug = createDebugLogger("@natlibfi/melinda-record-matching:match-detection:features:media-type");
3
+ const debugData = debug.extend("data");
4
+ export default () => ({
5
+ name: "Media type",
6
+ extract: ({ record, recordExternal }) => {
7
+ const label = recordExternal && recordExternal.label ? recordExternal.label : "record";
8
+ debugData(`Record (${label}): ${JSON.stringify(record)}`);
9
+ debugData(`RecordExternal: ${JSON.stringify(recordExternal)}`);
10
+ const values337 = get337Values();
11
+ debug(`${label}: 337 $b values: ${JSON.stringify(values337)}`);
12
+ return values337;
13
+ function get337Values() {
14
+ return record.get(/^337$/u).filter((f) => f.subfields.some((subfield) => subfield.code === "2" && subfield.value === "rdamedia")).map(({ subfields }) => subfields).flat().filter(({ code }) => code === "b").map(({ value }) => value);
15
+ }
16
+ },
17
+ compare: (a, b) => {
18
+ debugData(`Comparing ${JSON.stringify(a)} and ${JSON.stringify(b)}`);
19
+ if (a.every((elem) => b.includes(elem))) {
20
+ debug(`All mediaTypes from A are in B`);
21
+ return 1;
22
+ }
23
+ if (b.every((elem) => a.includes(elem))) {
24
+ debug(`All mediaTypes from B are in A`);
25
+ return 1;
26
+ }
27
+ debug(`Mismatch in mediaTypes between A and B`);
28
+ return -1;
29
+ }
30
+ });
31
+ //# sourceMappingURL=media-type.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/match-detection/features/bib/media-type.js"],
4
+ "sourcesContent": ["/* eslint-disable max-statements */\n\n\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features:media-type');\nconst debugData = debug.extend('data');\n\nexport default () => ({\n name: 'Media type',\n extract: ({record, recordExternal}) => {\n const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';\n debugData(`Record (${label}): ${JSON.stringify(record)}`);\n debugData(`RecordExternal: ${JSON.stringify(recordExternal)}`);\n const values337 = get337Values();\n debug(`${label}: 337 $b values: ${JSON.stringify(values337)}`);\n\n return values337;\n\n function get337Values() {\n return record.get(/^337$/u)\n .filter(f => f.subfields.some((subfield) => subfield.code === '2' && subfield.value === 'rdamedia'))\n .map(({subfields}) => subfields)\n .flat()\n .filter(({code}) => code === 'b')\n .map(({value}) => value);\n }\n },\n compare: (a, b) => {\n debugData(`Comparing ${JSON.stringify(a)} and ${JSON.stringify(b)}`);\n\n // Should we give extra good points if all mediaTypes match?\n // Should we give partial points for partially matching mediaTypes?\n // Should we check whether recordType is 'mixedMaterials'\n // Should we okay typical cases of not totally matching mediaTypes? What would these be?\n\n if (a.every(elem => b.includes(elem))) {\n debug(`All mediaTypes from A are in B`);\n return 1;\n }\n\n if (b.every(elem => a.includes(elem))) {\n debug(`All mediaTypes from B are in A`);\n return 1;\n }\n\n debug(`Mismatch in mediaTypes between A and B`);\n return -1;\n\n }\n});\n"],
5
+ "mappings": "AAGA,OAAO,uBAAuB;AAE9B,MAAM,QAAQ,kBAAkB,uEAAuE;AACvG,MAAM,YAAY,MAAM,OAAO,MAAM;AAErC,eAAe,OAAO;AAAA,EACpB,MAAM;AAAA,EACN,SAAS,CAAC,EAAC,QAAQ,eAAc,MAAM;AACrC,UAAM,QAAQ,kBAAkB,eAAe,QAAQ,eAAe,QAAQ;AAC9E,cAAU,WAAW,KAAK,MAAM,KAAK,UAAU,MAAM,CAAC,EAAE;AACxD,cAAU,mBAAmB,KAAK,UAAU,cAAc,CAAC,EAAE;AAC7D,UAAM,YAAY,aAAa;AAC/B,UAAM,GAAG,KAAK,oBAAoB,KAAK,UAAU,SAAS,CAAC,EAAE;AAE7D,WAAO;AAEP,aAAS,eAAe;AACtB,aAAO,OAAO,IAAI,QAAQ,EACvB,OAAO,OAAK,EAAE,UAAU,KAAK,CAAC,aAAa,SAAS,SAAS,OAAO,SAAS,UAAU,UAAU,CAAC,EAClG,IAAI,CAAC,EAAC,UAAS,MAAM,SAAS,EAC9B,KAAK,EACL,OAAO,CAAC,EAAC,KAAI,MAAM,SAAS,GAAG,EAC/B,IAAI,CAAC,EAAC,MAAK,MAAM,KAAK;AAAA,IAC3B;AAAA,EACF;AAAA,EACA,SAAS,CAAC,GAAG,MAAM;AACjB,cAAU,aAAa,KAAK,UAAU,CAAC,CAAC,QAAQ,KAAK,UAAU,CAAC,CAAC,EAAE;AAOnE,QAAI,EAAE,MAAM,UAAQ,EAAE,SAAS,IAAI,CAAC,GAAG;AACrC,YAAM,gCAAgC;AACtC,aAAO;AAAA,IACT;AAEA,QAAI,EAAE,MAAM,UAAQ,EAAE,SAAS,IAAI,CAAC,GAAG;AACrC,YAAM,gCAAgC;AACtC,aAAO;AAAA,IACT;AAEA,UAAM,wCAAwC;AAC9C,WAAO;AAAA,EAET;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,6 @@
1
+ import createInterface from "./melinda-identifier-factory.js";
2
+ export default () => {
3
+ const { extract, compare } = createInterface();
4
+ return { extract, compare, name: "melinda-id" };
5
+ };
6
+ //# sourceMappingURL=melinda-id.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/match-detection/features/bib/melinda-id.js"],
4
+ "sourcesContent": ["\nimport createInterface from './melinda-identifier-factory.js';\n\nexport default () => {\n const {extract, compare} = createInterface();\n return {extract, compare, name: 'melinda-id'};\n};\n"],
5
+ "mappings": "AACA,OAAO,qBAAqB;AAE5B,eAAe,MAAM;AACnB,QAAM,EAAC,SAAS,QAAO,IAAI,gBAAgB;AAC3C,SAAO,EAAC,SAAS,SAAS,MAAM,aAAY;AAC9C;",
6
+ "names": []
7
+ }
@@ -0,0 +1,38 @@
1
+ import createDebugLogger from "debug";
2
+ import { getMelindaIdsF035 } from "../../../matching-utils.js";
3
+ export default () => {
4
+ const debug = createDebugLogger("@natlibfi/melinda-record-matching:match-detection:features/bib/melinda-id");
5
+ const debugData = debug.extend("data");
6
+ return { extract, compare };
7
+ function extract({ record, recordExternal }) {
8
+ const isMelindaRecord = record.get("003").some((f003) => f003.value === "FI-MELINDA");
9
+ const [f001] = record.get("001").map((field) => field.value);
10
+ const f035MelindaIds = getMelindaIdsF035(record);
11
+ if (isMelindaRecord === void 0 && f001 === void 0 && f035MelindaIds.length < 1) {
12
+ debug(`${recordExternal.label} No Melinda-IDs found`);
13
+ return {};
14
+ }
15
+ return { isMelindaRecord, f001, f035MelindaIds };
16
+ }
17
+ function compare(a, b) {
18
+ if (a.isMelindaRecord && b.isMelindaRecord && a.f001 === b.f001) {
19
+ debugData(`Melinda record's A f001 ${a.f001} matches Melinda record's B f001 ${a.f001}`);
20
+ return 1;
21
+ }
22
+ if (a.isMelindaRecord && typeof b.f035MelindaIds !== "undefined" && b.f035MelindaIds.some((id) => id === a.f001)) {
23
+ debugData(`Melinda record's A f001 ${a.f001} matches record B f035 ${JSON.stringify(b.f035MelindaIds)}`);
24
+ return 1;
25
+ }
26
+ if (b.isMelindaRecord && typeof a.f035MelindaIds !== "undefined" && a.f035MelindaIds.some((id) => id === b.f001)) {
27
+ debugData(`Melinda record's B f001 ${b.f001} matches record A f035 ${JSON.stringify(a.f035MelindaIds)}`);
28
+ return 1;
29
+ }
30
+ if (typeof a.f035MelindaIds !== "undefined" && typeof b.f035MelindaIds !== "undefined" && a.f035MelindaIds.some((idA) => b.f035MelindaIds.some((idB) => idB === idA))) {
31
+ debugData(`Record A f035 ${JSON.stringify(a.f035MelindaIds)} matches record B f035 ${JSON.stringify(b.f035MelindaIds)}`);
32
+ return 1;
33
+ }
34
+ debug(`No matching Melinda-IDs.`);
35
+ return 0;
36
+ }
37
+ };
38
+ //# sourceMappingURL=melinda-identifier-factory.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/match-detection/features/bib/melinda-identifier-factory.js"],
4
+ "sourcesContent": ["\nimport createDebugLogger from 'debug';\nimport {getMelindaIdsF035} from '../../../matching-utils.js';\n\n// 003+001 FI-MELINDA <melinda-id>\n// 035 $a (FI-MELINDA)<melinda-id>\n// 035 $z (FI-MELINDA)<melinda-id>\n// 035 $a FCC<melinda-id>\n// 035 $z FCC<melinda-id>\n// melinda-id = 001234567\n\nexport default () => {\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib/melinda-id');\n const debugData = debug.extend('data');\n\n return {extract, compare};\n\n function extract({record, recordExternal}) {\n\n const isMelindaRecord = record.get('003').some(f003 => f003.value === 'FI-MELINDA');\n const [f001] = record.get('001').map(field => field.value);\n const f035MelindaIds = getMelindaIdsF035(record);\n\n if (\n isMelindaRecord === undefined &&\n f001 === undefined &&\n f035MelindaIds.length < 1) {\n\n debug(`${recordExternal.label} No Melinda-IDs found`);\n return {};\n }\n\n return {isMelindaRecord, f001, f035MelindaIds};\n\n }\n\n function compare(a, b) {\n\n if (a.isMelindaRecord && b.isMelindaRecord &&\n a.f001 === b.f001) {\n debugData(`Melinda record's A f001 ${a.f001} matches Melinda record's B f001 ${a.f001}`);\n return 1;\n }\n\n if (a.isMelindaRecord && typeof b.f035MelindaIds !== 'undefined' &&\n b.f035MelindaIds.some(id => id === a.f001)) {\n debugData(`Melinda record's A f001 ${a.f001} matches record B f035 ${JSON.stringify(b.f035MelindaIds)}`);\n return 1;\n }\n\n if (b.isMelindaRecord && typeof a.f035MelindaIds !== 'undefined' &&\n a.f035MelindaIds.some(id => id === b.f001)) {\n debugData(`Melinda record's B f001 ${b.f001} matches record A f035 ${JSON.stringify(a.f035MelindaIds)}`);\n return 1;\n }\n\n if (typeof a.f035MelindaIds !== 'undefined' && typeof b.f035MelindaIds !== 'undefined' &&\n a.f035MelindaIds.some(idA => b.f035MelindaIds.some(idB => idB === idA))) {\n debugData(`Record A f035 ${JSON.stringify(a.f035MelindaIds)} matches record B f035 ${JSON.stringify(b.f035MelindaIds)}`);\n return 1;\n }\n debug(`No matching Melinda-IDs.`);\n return 0;\n }\n};\n"],
5
+ "mappings": "AACA,OAAO,uBAAuB;AAC9B,SAAQ,yBAAwB;AAShC,eAAe,MAAM;AAEnB,QAAM,QAAQ,kBAAkB,2EAA2E;AAC3G,QAAM,YAAY,MAAM,OAAO,MAAM;AAErC,SAAO,EAAC,SAAS,QAAO;AAExB,WAAS,QAAQ,EAAC,QAAQ,eAAc,GAAG;AAEzC,UAAM,kBAAkB,OAAO,IAAI,KAAK,EAAE,KAAK,UAAQ,KAAK,UAAU,YAAY;AAClF,UAAM,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,EAAE,IAAI,WAAS,MAAM,KAAK;AACzD,UAAM,iBAAiB,kBAAkB,MAAM;AAE/C,QACE,oBAAoB,UACpB,SAAS,UACT,eAAe,SAAS,GAAG;AAE3B,YAAM,GAAG,eAAe,KAAK,uBAAuB;AACpD,aAAO,CAAC;AAAA,IACV;AAEA,WAAO,EAAC,iBAAiB,MAAM,eAAc;AAAA,EAE/C;AAEA,WAAS,QAAQ,GAAG,GAAG;AAErB,QAAI,EAAE,mBAAmB,EAAE,mBACzB,EAAE,SAAS,EAAE,MAAM;AACnB,gBAAU,2BAA2B,EAAE,IAAI,oCAAoC,EAAE,IAAI,EAAE;AACvF,aAAO;AAAA,IACT;AAEA,QAAI,EAAE,mBAAmB,OAAO,EAAE,mBAAmB,eACnD,EAAE,eAAe,KAAK,QAAM,OAAO,EAAE,IAAI,GAAG;AAC5C,gBAAU,2BAA2B,EAAE,IAAI,0BAA0B,KAAK,UAAU,EAAE,cAAc,CAAC,EAAE;AACvG,aAAO;AAAA,IACT;AAEA,QAAI,EAAE,mBAAmB,OAAO,EAAE,mBAAmB,eACnD,EAAE,eAAe,KAAK,QAAM,OAAO,EAAE,IAAI,GAAG;AAC5C,gBAAU,2BAA2B,EAAE,IAAI,0BAA0B,KAAK,UAAU,EAAE,cAAc,CAAC,EAAE;AACvG,aAAO;AAAA,IACT;AAEA,QAAI,OAAO,EAAE,mBAAmB,eAAe,OAAO,EAAE,mBAAmB,eACzE,EAAE,eAAe,KAAK,SAAO,EAAE,eAAe,KAAK,SAAO,QAAQ,GAAG,CAAC,GAAG;AACzE,gBAAU,iBAAiB,KAAK,UAAU,EAAE,cAAc,CAAC,0BAA0B,KAAK,UAAU,EAAE,cAAc,CAAC,EAAE;AACvH,aAAO;AAAA,IACT;AACA,UAAM,0BAA0B;AAChC,WAAO;AAAA,EACT;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,6 @@
1
+ import createInterface from "./standard-identifier-factory.js";
2
+ export default () => {
3
+ const { extract, compare } = createInterface({ pattern: /^024$/u, subfieldCodes: ["a", "z"] });
4
+ return { extract, compare, name: "Other standard identifier" };
5
+ };
6
+ //# sourceMappingURL=other-standard-identifier.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/match-detection/features/bib/other-standard-identifier.js"],
4
+ "sourcesContent": ["\nimport createInterface from './standard-identifier-factory.js';\n\n// DEVELOP: we should compare indicators and sf2 for f024\n\nexport default () => {\n const {extract, compare} = createInterface({pattern: /^024$/u, subfieldCodes: ['a', 'z']});\n return {extract, compare, name: 'Other standard identifier'};\n};\n"],
5
+ "mappings": "AACA,OAAO,qBAAqB;AAI5B,eAAe,MAAM;AACnB,QAAM,EAAC,SAAS,QAAO,IAAI,gBAAgB,EAAC,SAAS,UAAU,eAAe,CAAC,KAAK,GAAG,EAAC,CAAC;AACzF,SAAO,EAAC,SAAS,SAAS,MAAM,4BAA2B;AAC7D;",
6
+ "names": []
7
+ }
@@ -0,0 +1,116 @@
1
+ import createDebugLogger from "debug";
2
+ import { testStringOrNumber } from "../../../matching-utils.js";
3
+ export default () => ({
4
+ name: "Publication time, allow consequent years, years from multiple sources",
5
+ extract: ({ record, recordExternal }) => {
6
+ const debug = createDebugLogger("@natlibfi/melinda-record-matching:match-detection:features/bib/publication-time-allow-cons-years-multi");
7
+ const label = recordExternal && recordExternal.label ? recordExternal.label : "record";
8
+ const f008Values = extractF008Values(record);
9
+ debug(`${label}: f008: ${JSON.stringify(f008Values)}`);
10
+ const f26xValues = extractF26xValues(record);
11
+ debug(`${label}: f26x: ${JSON.stringify(f26xValues)}`);
12
+ const f500Values = extractF500Years(record);
13
+ debug(`${label}: f500: ${JSON.stringify(f500Values)}`);
14
+ const normalYears = [...new Set(f26xValues.normalYears.concat(f008Values.f008Date1).filter((value) => value && value !== " " && value !== "||||"))].sort();
15
+ const copyrightYears = [...new Set(f26xValues.copyrightYears)].sort();
16
+ const reprintYears = [...new Set(f500Values)].sort();
17
+ const combined = { normalYears, copyrightYears, reprintYears };
18
+ debug(`Combined: ${JSON.stringify(combined)}`);
19
+ return combined;
20
+ function extractF008Values(record2) {
21
+ const value = record2.get(/^008$/u)?.[0]?.value || void 0;
22
+ if (value && testStringOrNumber(value)) {
23
+ const f008Date1 = extractF008Date1(value);
24
+ const f008Date2 = extractF008Date2(value);
25
+ const f008YearType = extractF008YearType(value);
26
+ return { f008Date1, f008Date2, f008YearType };
27
+ }
28
+ return { f008Date1: void 0, f008Date2: void 0, f008YearType: void 0 };
29
+ function extractF008Date1(value2) {
30
+ return String(value2).slice(7, 11);
31
+ }
32
+ function extractF008Date2(value2) {
33
+ return String(value2).slice(11, 15);
34
+ }
35
+ function extractF008YearType(value2) {
36
+ return String(value2).slice(6, 7);
37
+ }
38
+ }
39
+ function extractF26xValues(record2) {
40
+ const copyrightRegex = /^(?<copyrightPrefix>cop|cop.|c|©|p|℗)/u;
41
+ const pubNormalSubFieldValues = extractPubNormalSubfieldValues(record2, copyrightRegex);
42
+ debug(`Normal years: ${JSON.stringify(pubNormalSubFieldValues)}`);
43
+ const pubF264CopySubFieldValues = extractPubF264CopySubfieldValues(record2);
44
+ debug(`F264 copyright years: ${JSON.stringify(pubF264CopySubFieldValues)}`);
45
+ const pubF260CopySubFieldValues = extractPubF260CopySubfieldValues(record2, copyrightRegex);
46
+ debug(`F260 copyright years: ${JSON.stringify(pubF260CopySubFieldValues)}`);
47
+ return { normalYears: pubNormalSubFieldValues, copyrightYears: [...pubF260CopySubFieldValues, ...pubF264CopySubFieldValues] };
48
+ function extractPubNormalSubfieldValues(record3, copyrightRegex2) {
49
+ return record3.get(/^26[04]$/u).filter((field) => !(field.tag === "264" && field.ind2 === "4")).map(({ subfields }) => subfields).flat().filter(({ code }) => code && code === "c").filter(({ value }) => value && !copyrightRegex2.test(value)).map(({ value }) => value).map((value) => removeNonAlphaNumeric(value));
50
+ }
51
+ function extractPubF264CopySubfieldValues(record3, copyrightRegex2) {
52
+ return record3.get(/^264$/u).filter((field) => field.ind2 === "4").map(({ subfields }) => subfields).flat().filter(({ code }) => code && code === "c").filter(({ value }) => value).map(({ value }) => value).map((value) => value.replace(copyrightRegex2, "")).map((value) => removeNonAlphaNumeric(value));
53
+ }
54
+ function extractPubF260CopySubfieldValues(record3, copyrightRegex2) {
55
+ return record3.get(/^260$/u).map(({ subfields }) => subfields).flat().filter(({ code }) => code && code === "c").filter(({ value }) => value && copyrightRegex2.test(value)).map(({ value }) => value).map((value) => value.replace(copyrightRegex2, "")).map((value) => removeNonAlphaNumeric(value));
56
+ }
57
+ function removeNonAlphaNumeric(value) {
58
+ debug(`Cleaning: ${JSON.stringify(value)}`);
59
+ const nonAlphaNumericRegex = /[^A-Za-z0-9]/ug;
60
+ return value ? value.replace(nonAlphaNumericRegex, "") : value;
61
+ }
62
+ }
63
+ function extractF500Years(record2) {
64
+ const reprintRegex = /(?<reprint>Lisäpainokset:|Lisäpainos:)/u;
65
+ const reprintFieldContents = record2.get(/^500$/u).map(({ subfields }) => subfields).flat().filter(({ code }) => code === "a").map(({ value }) => value);
66
+ debug(`f500 reprint field contents: ${JSON.stringify(reprintFieldContents)}`);
67
+ const filteredF500 = reprintFieldContents.filter((content) => content && content.match(reprintRegex));
68
+ debug(`f500 reprint field contents (filtered): ${JSON.stringify(filteredF500)}`);
69
+ const reprintYears2 = extractReprintYears(filteredF500);
70
+ return reprintYears2;
71
+ }
72
+ function extractReprintYears(contents) {
73
+ const yearRegex = /[0-9][0-9][0-9][0-9]/gu;
74
+ const years = contents.map((content) => content.match(yearRegex)).flat();
75
+ debug(`${JSON.stringify(years)}`);
76
+ const uniqYears = [...new Set(years)].sort();
77
+ debug(`${JSON.stringify(uniqYears)}`);
78
+ return uniqYears;
79
+ }
80
+ },
81
+ // eslint-disable-next-line max-statements
82
+ compare: (a, b) => {
83
+ const debug = createDebugLogger("@natlibfi/melinda-record-matching:match-detection:features/bib/publication-time-allow-cons-years-multi");
84
+ debug(`Comparing ${JSON.stringify(a)} to ${JSON.stringify(b)}`);
85
+ const [firstA] = a.normalYears ? a.normalYears : a;
86
+ const [firstB] = b.normalYears ? b.normalYears : b;
87
+ debug(`Comparing ${JSON.stringify(firstA)} to ${JSON.stringify(firstB)}`);
88
+ if (firstA === firstB) {
89
+ return 0.1;
90
+ }
91
+ if (!testStringOrNumber(firstA) || !testStringOrNumber(firstB)) {
92
+ return 0;
93
+ }
94
+ const firstANumber = parseInt(firstA, 10);
95
+ const firstBNumber = parseInt(firstB, 10);
96
+ if (!(isNaN(firstANumber) || isNaN(firstBNumber)) && (firstANumber + 1 === firstBNumber || firstANumber - 1 === firstBNumber)) {
97
+ return 0.1;
98
+ }
99
+ const bNormalInANormal = a.normalYears.filter((aValue) => b.normalYears.some((bValue) => aValue === bValue));
100
+ const aNormalInBNormal = b.normalYears.filter((bValue) => a.normalYears.some((aValue) => bValue === aValue));
101
+ debug(`BNorm in ANorm: ${JSON.stringify(bNormalInANormal)}`);
102
+ debug(`ANorm in BNorm: ${JSON.stringify(aNormalInBNormal)}`);
103
+ if (bNormalInANormal > 0 || aNormalInBNormal > 0) {
104
+ return 0;
105
+ }
106
+ const bNormalInAReprint = a.reprintYears.filter((aValue) => b.normalYears.some((bValue) => aValue === bValue));
107
+ const aNormalInBReprint = b.reprintYears.filter((bValue) => a.normalYears.some((aValue) => bValue === aValue));
108
+ debug(`BNorm in AReprint: ${JSON.stringify(bNormalInAReprint)}`);
109
+ debug(`ANorm in BReprint: ${JSON.stringify(aNormalInBReprint)}`);
110
+ if (bNormalInAReprint > 0 || aNormalInBReprint > 0) {
111
+ return 0;
112
+ }
113
+ return -1;
114
+ }
115
+ });
116
+ //# sourceMappingURL=publication-time-allow-cons-years-multi.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/match-detection/features/bib/publication-time-allow-cons-years-multi.js"],
4
+ "sourcesContent": ["\nimport createDebugLogger from 'debug';\nimport {testStringOrNumber} from '../../../matching-utils.js';\n\n// We should also get copyright time and copyright/publication times from 26x\n// We should also get publishing time type from f008\n// We should get reprint times from f500 $a \"Lis\u00E4painos/Lis\u00E4painokset:\"\n\nexport default () => ({\n name: 'Publication time, allow consequent years, years from multiple sources',\n extract: ({record, recordExternal}) => {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib/publication-time-allow-cons-years-multi');\n const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';\n\n const f008Values = extractF008Values(record);\n debug(`${label}: f008: ${JSON.stringify(f008Values)}`);\n\n const f26xValues = extractF26xValues(record);\n debug(`${label}: f26x: ${JSON.stringify(f26xValues)}`);\n\n const f500Values = extractF500Years(record);\n debug(`${label}: f500: ${JSON.stringify(f500Values)}`);\n\n // We should get copyrightYear from f008Date2 to copyrightYears when f008YearType = 'r'\n // Is the original year (f008Date2) in f008YearType === 'r' comparable to copyrightYear?\n // We should handle unknown years (here or comparison?)\n // We should handle year ranges for continuing resources / collections\n\n const normalYears = [...new Set(f26xValues.normalYears.concat(f008Values.f008Date1).filter(value => value && value !== ' ' && value !== '||||'))].sort();\n const copyrightYears = [...new Set(f26xValues.copyrightYears)].sort();\n const reprintYears = [...new Set(f500Values)].sort();\n\n const combined = {normalYears, copyrightYears, reprintYears};\n\n debug(`Combined: ${JSON.stringify(combined)}`);\n\n return combined;\n\n function extractF008Values(record) {\n // Record should have only one f008 - in case of several, we handle the first one\n const value = record.get(/^008$/u)?.[0]?.value || undefined;\n if (value && testStringOrNumber(value)) {\n const f008Date1 = extractF008Date1(value);\n const f008Date2 = extractF008Date2(value);\n const f008YearType = extractF008YearType(value);\n return {f008Date1, f008Date2, f008YearType};\n }\n return {f008Date1: undefined, f008Date2: undefined, f008YearType: undefined};\n\n function extractF008Date1(value) {\n return String(value).slice(7, 11);\n }\n\n function extractF008Date2(value) {\n return String(value).slice(11, 15);\n }\n\n function extractF008YearType(value) {\n return String(value).slice(6, 7);\n }\n }\n\n function extractF26xValues(record) {\n const copyrightRegex = /^(?<copyrightPrefix>cop|cop.|c|\u00A9|p|\u2117)/u;\n\n const pubNormalSubFieldValues = extractPubNormalSubfieldValues(record, copyrightRegex);\n debug(`Normal years: ${JSON.stringify(pubNormalSubFieldValues)}`);\n\n const pubF264CopySubFieldValues = extractPubF264CopySubfieldValues(record);\n debug(`F264 copyright years: ${JSON.stringify(pubF264CopySubFieldValues)}`);\n\n const pubF260CopySubFieldValues = extractPubF260CopySubfieldValues(record, copyrightRegex);\n debug(`F260 copyright years: ${JSON.stringify(pubF260CopySubFieldValues)}`);\n\n return {normalYears: pubNormalSubFieldValues, copyrightYears: [...pubF260CopySubFieldValues, ...pubF264CopySubFieldValues]};\n\n function extractPubNormalSubfieldValues(record, copyrightRegex) {\n return record.get(/^26[04]$/u)\n .filter((field) => !(field.tag === '264' && field.ind2 === '4'))\n .map(({subfields}) => subfields)\n .flat()\n .filter(({code}) => code && code === 'c')\n .filter(({value}) => value && !copyrightRegex.test(value))\n .map(({value}) => value)\n .map((value) => removeNonAlphaNumeric(value));\n }\n\n function extractPubF264CopySubfieldValues(record, copyrightRegex) {\n return record.get(/^264$/u)\n .filter((field) => field.ind2 === '4')\n .map(({subfields}) => subfields)\n .flat()\n .filter(({code}) => code && code === 'c')\n .filter(({value}) => value)\n .map(({value}) => value)\n .map((value) => value.replace(copyrightRegex, ''))\n .map((value) => removeNonAlphaNumeric(value));\n }\n\n function extractPubF260CopySubfieldValues(record, copyrightRegex) {\n return record.get(/^260$/u)\n .map(({subfields}) => subfields)\n .flat()\n .filter(({code}) => code && code === 'c')\n .filter(({value}) => value && copyrightRegex.test(value))\n .map(({value}) => value)\n .map((value) => value.replace(copyrightRegex, ''))\n .map((value) => removeNonAlphaNumeric(value));\n }\n\n function removeNonAlphaNumeric(value) {\n debug(`Cleaning: ${JSON.stringify(value)}`);\n const nonAlphaNumericRegex = /[^A-Za-z0-9]/ug;\n return value ? value.replace(nonAlphaNumericRegex, '') : value;\n }\n }\n\n function extractF500Years(record) {\n\n const reprintRegex = /(?<reprint>Lis\u00E4painokset:|Lis\u00E4painos:)/u;\n const reprintFieldContents = record.get(/^500$/u)\n .map(({subfields}) => subfields)\n .flat()\n .filter(({code}) => code === 'a')\n .map(({value}) => value);\n //.filter(value => value.test(reprintRegex));\n\n debug(`f500 reprint field contents: ${JSON.stringify(reprintFieldContents)}`);\n\n const filteredF500 = reprintFieldContents.filter((content) => content && content.match(reprintRegex));\n\n debug(`f500 reprint field contents (filtered): ${JSON.stringify(filteredF500)}`);\n\n const reprintYears = extractReprintYears(filteredF500);\n\n return reprintYears;\n }\n\n function extractReprintYears(contents) {\n const yearRegex = /[0-9][0-9][0-9][0-9]/gu;\n const years = contents.map(content => content.match(yearRegex))\n .flat();\n debug(`${JSON.stringify(years)}`);\n const uniqYears = [...new Set(years)].sort();\n debug(`${JSON.stringify(uniqYears)}`);\n return uniqYears;\n }\n\n },\n // eslint-disable-next-line max-statements\n compare: (a, b) => {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib/publication-time-allow-cons-years-multi');\n debug(`Comparing ${JSON.stringify(a)} to ${JSON.stringify(b)}`);\n\n const [firstA] = a.normalYears ? a.normalYears : a;\n const [firstB] = b.normalYears ? b.normalYears : b;\n\n debug(`Comparing ${JSON.stringify(firstA)} to ${JSON.stringify(firstB)}`);\n\n if (firstA === firstB) {\n return 0.1;\n }\n\n // If either of years is a non string/number, values are not comparable\n if (!testStringOrNumber(firstA) || !testStringOrNumber(firstB)) {\n return 0;\n }\n\n const firstANumber = parseInt(firstA, 10);\n const firstBNumber = parseInt(firstB, 10);\n\n // Handle consequent years as a match\n // see publication-time for a version that does not handle consequent years as a match\n if (!(isNaN(firstANumber) || isNaN(firstBNumber)) &&\n (firstANumber + 1 === firstBNumber || firstANumber - 1 === firstBNumber)) {\n return 0.1;\n }\n\n // We should do something with copyrightYears, too\n\n // Do not give minus points if a normal publishing year is found in normal years\n const bNormalInANormal = a.normalYears.filter(aValue => b.normalYears.some(bValue => aValue === bValue));\n const aNormalInBNormal = b.normalYears.filter(bValue => a.normalYears.some(aValue => bValue === aValue));\n debug(`BNorm in ANorm: ${JSON.stringify(bNormalInANormal)}`);\n debug(`ANorm in BNorm: ${JSON.stringify(aNormalInBNormal)}`);\n\n if (bNormalInANormal > 0 || aNormalInBNormal > 0) {\n return 0;\n }\n\n // Do not give minus points if a normal publishing year is found in reprint years\n const bNormalInAReprint = a.reprintYears.filter(aValue => b.normalYears.some(bValue => aValue === bValue));\n const aNormalInBReprint = b.reprintYears.filter(bValue => a.normalYears.some(aValue => bValue === aValue));\n debug(`BNorm in AReprint: ${JSON.stringify(bNormalInAReprint)}`);\n debug(`ANorm in BReprint: ${JSON.stringify(aNormalInBReprint)}`);\n\n if (bNormalInAReprint > 0 || aNormalInBReprint > 0) {\n return 0;\n }\n\n return -1;\n\n }\n});\n\n// https://www.loc.gov/marc/bibliographic/bd008.html\n// field 008\n// 06 - Type of date/Publication status\n// 07-10 - Date 1\n// 11-14 - Date 2\n//\n// 06 - Type of date/Publication status\n// b - No dates given; B.C. date involved\n// c - Continuing resource currently published\n// d - Continuing resource ceased publication\n// e - Detailed date\n// i - Inclusive dates of collection\n// k - Range of years of bulk of collection\n// m - Multiple dates\n// n - Dates unknown\n// p - Date of distribution/release/issue and production/recording session when different\n// q - Questionable date\n// r - Reprint/reissue date and original date\n// s - Single known date/probable date\n// t - Publication date and copyright date\n// u - Continuing resource status unknown\n// | - No attempt to code\n//\n// 07-10 - Date 1\n// 1-9 - Date digit\n// # - Date element is not applicable\n// u - Date element is totally or partially unknown\n// |||| - No attempt to code\n//\n// 11-14 - Date 2\n// 1-9 - Date digit\n// # - Date element is not applicable\n// u - Date element is totally or partially unknown\n// |||| - No attempt to code\n//\n\n"],
5
+ "mappings": "AACA,OAAO,uBAAuB;AAC9B,SAAQ,0BAAyB;AAMjC,eAAe,OAAO;AAAA,EACpB,MAAM;AAAA,EACN,SAAS,CAAC,EAAC,QAAQ,eAAc,MAAM;AACrC,UAAM,QAAQ,kBAAkB,wGAAwG;AACxI,UAAM,QAAQ,kBAAkB,eAAe,QAAQ,eAAe,QAAQ;AAE9E,UAAM,aAAa,kBAAkB,MAAM;AAC3C,UAAM,GAAG,KAAK,WAAW,KAAK,UAAU,UAAU,CAAC,EAAE;AAErD,UAAM,aAAa,kBAAkB,MAAM;AAC3C,UAA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,OAAO,YAAU,EAAE,YAAY,KAAK,YAAU,WAAW,MAAM,CAAC;AACzG,UAAM,sBAAsB,KAAK,UAAU,iBAAiB,CAAC,EAAE;AAC/D,UAAM,sBAAsB,KAAK,UAAU,iBAAiB,CAAC,EAAE;AAE/D,QAAI,oBAAoB,KAAK,oBAAoB,GAAG;AAClD,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EAET;AACF;",
6
+ "names": ["record", "value", "copyrightRegex", "reprintYears"]
7
+ }
@@ -0,0 +1,28 @@
1
+ import createDebugLogger from "debug";
2
+ import { testStringOrNumber } from "../../../matching-utils.js";
3
+ export default () => ({
4
+ name: "Publication time, allow consequent years",
5
+ extract: ({ record }) => {
6
+ const value = record.get(/^008$/u)?.[0]?.value || void 0;
7
+ return testStringOrNumber(value) ? [String(value).slice(7, 11)] : [];
8
+ },
9
+ compare: (a, b) => {
10
+ const debug = createDebugLogger("@natlibfi/melinda-record-matching:match-detection:features/bib/publication-time-allow-cons-years");
11
+ debug(`Comparing ${a[0]} to ${b[0]}`);
12
+ const [firstA] = a;
13
+ const [firstB] = b;
14
+ if (firstA === firstB) {
15
+ return 0.1;
16
+ }
17
+ if (!testStringOrNumber(firstA) || !testStringOrNumber(firstB)) {
18
+ return 0;
19
+ }
20
+ const firstANumber = parseInt(firstA, 10);
21
+ const firstBNumber = parseInt(firstB, 10);
22
+ if (isNaN(firstANumber) || isNaN(firstBNumber)) {
23
+ return -1;
24
+ }
25
+ return firstANumber + 1 === firstBNumber || firstANumber - 1 === firstBNumber ? 0.1 : -1;
26
+ }
27
+ });
28
+ //# sourceMappingURL=publication-time-allow-cons-years.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/match-detection/features/bib/publication-time-allow-cons-years.js"],
4
+ "sourcesContent": ["\nimport createDebugLogger from 'debug';\nimport {testStringOrNumber} from '../../../matching-utils.js';\n\n// We should also get copyright time and copyright/publication times from 26x\n\nexport default () => ({\n name: 'Publication time, allow consequent years',\n extract: ({record}) => {\n const value = record.get(/^008$/u)?.[0]?.value || undefined;\n return testStringOrNumber(value) ? [String(value).slice(7, 11)] : [];\n },\n compare: (a, b) => {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib/publication-time-allow-cons-years');\n debug(`Comparing ${a[0]} to ${b[0]}`);\n\n const [firstA] = a;\n const [firstB] = b;\n\n if (firstA === firstB) {\n return 0.1;\n }\n\n // If either of years is a non string/number, values are not comparable\n if (!testStringOrNumber(firstA) || !testStringOrNumber(firstB)) {\n return 0;\n }\n\n const firstANumber = parseInt(firstA, 10);\n const firstBNumber = parseInt(firstB, 10);\n\n if (isNaN(firstANumber) || isNaN(firstBNumber)) {\n return -1;\n }\n\n // Handle consequent years as a match\n // see publication-time for a version that does not handle consequent years as a match\n return firstANumber + 1 === firstBNumber || firstANumber - 1 === firstBNumber ? 0.1 : -1;\n }\n});\n"],
5
+ "mappings": "AACA,OAAO,uBAAuB;AAC9B,SAAQ,0BAAyB;AAIjC,eAAe,OAAO;AAAA,EACpB,MAAM;AAAA,EACN,SAAS,CAAC,EAAC,OAAM,MAAM;AACrB,UAAM,QAAQ,OAAO,IAAI,QAAQ,IAAI,CAAC,GAAG,SAAS;AAClD,WAAO,mBAAmB,KAAK,IAAI,CAAC,OAAO,KAAK,EAAE,MAAM,GAAG,EAAE,CAAC,IAAI,CAAC;AAAA,EACrE;AAAA,EACA,SAAS,CAAC,GAAG,MAAM;AACjB,UAAM,QAAQ,kBAAkB,kGAAkG;AAClI,UAAM,aAAa,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE;AAEpC,UAAM,CAAC,MAAM,IAAI;AACjB,UAAM,CAAC,MAAM,IAAI;AAEjB,QAAI,WAAW,QAAQ;AACrB,aAAO;AAAA,IACT;AAGA,QAAI,CAAC,mBAAmB,MAAM,KAAK,CAAC,mBAAmB,MAAM,GAAG;AAC9D,aAAO;AAAA,IACT;AAEA,UAAM,eAAe,SAAS,QAAQ,EAAE;AACxC,UAAM,eAAe,SAAS,QAAQ,EAAE;AAExC,QAAI,MAAM,YAAY,KAAK,MAAM,YAAY,GAAG;AAC9C,aAAO;AAAA,IACT;AAIA,WAAO,eAAe,MAAM,gBAAgB,eAAe,MAAM,eAAe,MAAM;AAAA,EACxF;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,10 @@
1
+ import { testStringOrNumber } from "../../../matching-utils.js";
2
+ export default () => ({
3
+ name: "Publication time",
4
+ extract: ({ record }) => {
5
+ const value = record.get(/^008$/u)?.[0]?.value || void 0;
6
+ return testStringOrNumber(value) ? [String(value).slice(7, 11)] : [];
7
+ },
8
+ compare: (a, b) => a[0] === b[0] ? 0.1 : -1
9
+ });
10
+ //# sourceMappingURL=publication-time.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/match-detection/features/bib/publication-time.js"],
4
+ "sourcesContent": ["\n\nimport {testStringOrNumber} from '../../../matching-utils.js';\n\n// We should also get copyright time and copyright/publication times from 26x\n// see publication-time-allow-cons-years for a version allowing consequent years to match\n\nexport default () => ({\n name: 'Publication time',\n extract: ({record}) => {\n const value = record.get(/^008$/u)?.[0]?.value || undefined;\n return testStringOrNumber(value) ? [String(value).slice(7, 11)] : [];\n },\n compare: (a, b) => a[0] === b[0] ? 0.1 : -1.0\n});\n"],
5
+ "mappings": "AAEA,SAAQ,0BAAyB;AAKjC,eAAe,OAAO;AAAA,EACpB,MAAM;AAAA,EACN,SAAS,CAAC,EAAC,OAAM,MAAM;AACrB,UAAM,QAAQ,OAAO,IAAI,QAAQ,IAAI,CAAC,GAAG,SAAS;AAClD,WAAO,mBAAmB,KAAK,IAAI,CAAC,OAAO,KAAK,EAAE,MAAM,GAAG,EAAE,CAAC,IAAI,CAAC;AAAA,EACrE;AAAA,EACA,SAAS,CAAC,GAAG,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,MAAM;AAC3C;",
6
+ "names": []
7
+ }
@@ -0,0 +1,6 @@
1
+ export default () => ({
2
+ name: "Record type",
3
+ extract: ({ record }) => record.leader[6] ? [record.leader[6]] : [],
4
+ compare: (a, b) => a[0] === b[0] ? 0.1 : -0.5
5
+ });
6
+ //# sourceMappingURL=record-type.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/match-detection/features/bib/record-type.js"],
4
+ "sourcesContent": ["\n// we could handle the case of books/notes\n// Recordtype: LDR/06 - Type of Record\n// Note: currently matchValidator fails all mismatching recordTypes, so this won't actually do much\n\nexport default () => ({\n name: 'Record type',\n extract: ({record}) => record.leader[6] ? [record.leader[6]] : [],\n compare: (a, b) => a[0] === b[0] ? 0.1 : -0.5\n});\n"],
5
+ "mappings": "AAKA,eAAe,OAAO;AAAA,EACpB,MAAM;AAAA,EACN,SAAS,CAAC,EAAC,OAAM,MAAM,OAAO,OAAO,CAAC,IAAI,CAAC,OAAO,OAAO,CAAC,CAAC,IAAI,CAAC;AAAA,EAChE,SAAS,CAAC,GAAG,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,MAAM;AAC3C;",
6
+ "names": []
7
+ }