@natlibfi/melinda-record-matching 4.4.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 (123) hide show
  1. package/.github/workflows/melinda-node-tests.yml +13 -9
  2. package/LICENSE.txt +21 -165
  3. package/README.md +2 -2
  4. package/dist/candidate-search/candidate-search-utils.js +6 -43
  5. package/dist/candidate-search/candidate-search-utils.js.map +7 -1
  6. package/dist/candidate-search/choose-queries.js +75 -0
  7. package/dist/candidate-search/choose-queries.js.map +7 -0
  8. package/dist/candidate-search/index.js +89 -225
  9. package/dist/candidate-search/index.js.map +7 -1
  10. package/dist/candidate-search/index.test.js +92 -0
  11. package/dist/candidate-search/index.test.js.map +7 -0
  12. package/dist/candidate-search/query-list/bib.js +141 -320
  13. package/dist/candidate-search/query-list/bib.js.map +7 -1
  14. package/dist/candidate-search/query-list/bib.test.js +34 -0
  15. package/dist/candidate-search/query-list/bib.test.js.map +7 -0
  16. package/dist/candidate-search/query-list/component.js +87 -0
  17. package/dist/candidate-search/query-list/component.js.map +7 -0
  18. package/dist/candidate-search/query-list/index.js +39 -52
  19. package/dist/candidate-search/query-list/index.js.map +7 -1
  20. package/dist/cli.js +138 -0
  21. package/dist/cli.js.map +7 -0
  22. package/dist/index.js +87 -462
  23. package/dist/index.js.map +7 -1
  24. package/dist/index.test.js +69 -0
  25. package/dist/index.test.js.map +7 -0
  26. package/dist/match-detection/features/bib/all-source-ids.js +20 -91
  27. package/dist/match-detection/features/bib/all-source-ids.js.map +7 -1
  28. package/dist/match-detection/features/bib/authors.js +20 -76
  29. package/dist/match-detection/features/bib/authors.js.map +7 -1
  30. package/dist/match-detection/features/bib/bibliographic-level.js +4 -40
  31. package/dist/match-detection/features/bib/bibliographic-level.js.map +7 -1
  32. package/dist/match-detection/features/bib/host-component.js +5 -41
  33. package/dist/match-detection/features/bib/host-component.js.map +7 -1
  34. package/dist/match-detection/features/bib/index.js +17 -119
  35. package/dist/match-detection/features/bib/index.js.map +7 -1
  36. package/dist/match-detection/features/bib/index.test.js +40 -0
  37. package/dist/match-detection/features/bib/index.test.js.map +7 -0
  38. package/dist/match-detection/features/bib/isbn.js +13 -69
  39. package/dist/match-detection/features/bib/isbn.js.map +7 -1
  40. package/dist/match-detection/features/bib/issn.js +5 -50
  41. package/dist/match-detection/features/bib/issn.js.map +7 -1
  42. package/dist/match-detection/features/bib/language.js +25 -86
  43. package/dist/match-detection/features/bib/language.js.map +7 -1
  44. package/dist/match-detection/features/bib/media-type.js +12 -64
  45. package/dist/match-detection/features/bib/media-type.js.map +7 -1
  46. package/dist/match-detection/features/bib/melinda-id.js +5 -47
  47. package/dist/match-detection/features/bib/melinda-id.js.map +7 -1
  48. package/dist/match-detection/features/bib/melinda-identifier-factory.js +16 -67
  49. package/dist/match-detection/features/bib/melinda-identifier-factory.js.map +7 -1
  50. package/dist/match-detection/features/bib/other-standard-identifier.js +5 -51
  51. package/dist/match-detection/features/bib/other-standard-identifier.js.map +7 -1
  52. package/dist/match-detection/features/bib/publication-time-allow-cons-years-multi.js +49 -189
  53. package/dist/match-detection/features/bib/publication-time-allow-cons-years-multi.js.map +7 -1
  54. package/dist/match-detection/features/bib/publication-time-allow-cons-years.js +10 -53
  55. package/dist/match-detection/features/bib/publication-time-allow-cons-years.js.map +7 -1
  56. package/dist/match-detection/features/bib/publication-time.js +8 -46
  57. package/dist/match-detection/features/bib/publication-time.js.map +7 -1
  58. package/dist/match-detection/features/bib/record-type.js +4 -43
  59. package/dist/match-detection/features/bib/record-type.js.map +7 -1
  60. package/dist/match-detection/features/bib/standard-identifier-factory.js +47 -163
  61. package/dist/match-detection/features/bib/standard-identifier-factory.js.map +7 -1
  62. package/dist/match-detection/features/bib/title-version-original.js +11 -53
  63. package/dist/match-detection/features/bib/title-version-original.js.map +7 -1
  64. package/dist/match-detection/features/bib/title.js +20 -72
  65. package/dist/match-detection/features/bib/title.js.map +7 -1
  66. package/dist/match-detection/features/index.js +3 -11
  67. package/dist/match-detection/features/index.js.map +7 -1
  68. package/dist/match-detection/index.js +35 -150
  69. package/dist/match-detection/index.js.map +7 -1
  70. package/dist/match-detection/index.test.js +44 -0
  71. package/dist/match-detection/index.test.js.map +7 -0
  72. package/dist/matching-utils.js +38 -102
  73. package/dist/matching-utils.js.map +7 -1
  74. package/eslint.config.js +52 -0
  75. package/example.env +4 -0
  76. package/package.json +29 -78
  77. package/src/candidate-search/candidate-search-utils.js +1 -28
  78. package/src/candidate-search/choose-queries.js +93 -0
  79. package/src/candidate-search/index.js +85 -119
  80. package/src/candidate-search/{index.spec.js → index.test.js} +30 -43
  81. package/src/candidate-search/query-list/bib.js +54 -55
  82. package/src/candidate-search/query-list/bib.test.js +38 -0
  83. package/src/candidate-search/query-list/component.js +127 -0
  84. package/src/candidate-search/query-list/index.js +31 -35
  85. package/src/cli.js +177 -0
  86. package/src/index.js +27 -68
  87. package/src/{index.spec.js → index.test.js} +11 -42
  88. package/src/match-detection/features/bib/all-source-ids.js +2 -29
  89. package/src/match-detection/features/bib/authors.js +5 -30
  90. package/src/match-detection/features/bib/bibliographic-level.js +0 -27
  91. package/src/match-detection/features/bib/host-component.js +0 -27
  92. package/src/match-detection/features/bib/index.js +16 -43
  93. package/src/match-detection/features/bib/index.test.js +52 -0
  94. package/src/match-detection/features/bib/isbn.js +2 -29
  95. package/src/match-detection/features/bib/issn.js +1 -28
  96. package/src/match-detection/features/bib/language.js +5 -32
  97. package/src/match-detection/features/bib/media-type.js +2 -28
  98. package/src/match-detection/features/bib/melinda-id.js +1 -28
  99. package/src/match-detection/features/bib/melinda-identifier-factory.js +5 -32
  100. package/src/match-detection/features/bib/other-standard-identifier.js +1 -28
  101. package/src/match-detection/features/bib/publication-time-allow-cons-years-multi.js +7 -34
  102. package/src/match-detection/features/bib/publication-time-allow-cons-years.js +1 -28
  103. package/src/match-detection/features/bib/publication-time.js +2 -28
  104. package/src/match-detection/features/bib/record-type.js +0 -27
  105. package/src/match-detection/features/bib/standard-identifier-factory.js +1 -28
  106. package/src/match-detection/features/bib/title-version-original.js +2 -28
  107. package/src/match-detection/features/bib/title.js +6 -34
  108. package/src/match-detection/features/index.js +1 -28
  109. package/src/match-detection/index.js +1 -28
  110. package/src/match-detection/{index.spec.js → index.test.js} +9 -35
  111. package/src/matching-utils.js +8 -37
  112. package/dist/candidate-search/index.spec.js +0 -144
  113. package/dist/candidate-search/index.spec.js.map +0 -1
  114. package/dist/candidate-search/query-list/bib.spec.js +0 -64
  115. package/dist/candidate-search/query-list/bib.spec.js.map +0 -1
  116. package/dist/index.spec.js +0 -127
  117. package/dist/index.spec.js.map +0 -1
  118. package/dist/match-detection/features/bib/index.spec.js +0 -93
  119. package/dist/match-detection/features/bib/index.spec.js.map +0 -1
  120. package/dist/match-detection/index.spec.js +0 -91
  121. package/dist/match-detection/index.spec.js.map +0 -1
  122. package/src/candidate-search/query-list/bib.spec.js +0 -54
  123. package/src/match-detection/features/bib/index.spec.js +0 -78
@@ -1,35 +1,7 @@
1
- /**
2
- *
3
- * @licstart The following is the entire license notice for the JavaScript code in this file.
4
- *
5
- * Melinda record matching modules for Javascript
6
- *
7
- * Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
8
- *
9
- * This file is part of melinda-record-matching-js
10
- *
11
- * melinda-record-matching-js program is free software: you can redistribute it and/or modify
12
- * it under the terms of the GNU Lesser General Public License as
13
- * published by the Free Software Foundation, either version 3 of the
14
- * License, or (at your option) any later version.
15
- *
16
- * melinda-record-matching-js is distributed in the hope that it will be useful,
17
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
- * GNU Lesser General Public License for more details.
20
- *
21
- * You should have received a copy of the GNU Affero General Public License
22
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
- *
24
- * @licend The above is the entire license notice
25
- * for the JavaScript code in this file.
26
- *
27
- */
28
-
29
-
30
- import {LevenshteinDistance as leven} from 'natural';
31
- import {testStringOrNumber} from '../../../matching-utils';
32
1
  import createDebugLogger from 'debug';
2
+ import naturalPkg from 'natural';
3
+ const {LevenshteinDistance: leven} = naturalPkg;
4
+ import {testStringOrNumber} from '../../../matching-utils.js';
33
5
 
34
6
  const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features:title');
35
7
  const debugData = debug.extend('data');
@@ -40,7 +12,7 @@ export default ({treshold = 10} = {}) => ({
40
12
  extract: ({record, recordExternal}) => {
41
13
  const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';
42
14
  const title = getTitle();
43
- debug(`${label} title: ${title}`);
15
+ debug(`${label}: title: ${title}`);
44
16
 
45
17
  if (testStringOrNumber(title)) {
46
18
  const titleAsNormalizedString = String(title)
@@ -51,7 +23,7 @@ export default ({treshold = 10} = {}) => ({
51
23
  // - we could precompose the finnish letters back to avoid this
52
24
  .replace(/[^\p{Letter}\p{Number}]/gu, '')
53
25
  .toLowerCase();
54
- debug(`${label} titleString: ${titleAsNormalizedString}`);
26
+ debug(`${label}: titleString: ${titleAsNormalizedString}`);
55
27
  return [titleAsNormalizedString];
56
28
  }
57
29
 
@@ -59,7 +31,7 @@ export default ({treshold = 10} = {}) => ({
59
31
 
60
32
  function getTitle() {
61
33
  const [field] = record.get(/^245$/u);
62
- debugData(`${label} titleField: ${JSON.stringify(field)}`);
34
+ debugData(`${label}: titleField: ${JSON.stringify(field)}`);
63
35
 
64
36
  if (field) {
65
37
  return field.subfields
@@ -1,30 +1,3 @@
1
- /**
2
- *
3
- * @licstart The following is the entire license notice for the JavaScript code in this file.
4
- *
5
- * Melinda record matching modules for Javascript
6
- *
7
- * Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
8
- *
9
- * This file is part of melinda-record-matching-js
10
- *
11
- * melinda-record-matching-js program is free software: you can redistribute it and/or modify
12
- * it under the terms of the GNU Lesser General Public License as
13
- * published by the Free Software Foundation, either version 3 of the
14
- * License, or (at your option) any later version.
15
- *
16
- * melinda-record-matching-js is distributed in the hope that it will be useful,
17
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
- * GNU Lesser General Public License for more details.
20
- *
21
- * You should have received a copy of the GNU Affero General Public License
22
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
- *
24
- * @licend The above is the entire license notice
25
- * for the JavaScript code in this file.
26
- *
27
- */
28
1
 
29
- import * as bib from './bib';
2
+ import * as bib from './bib/index.js';
30
3
  export {bib};
@@ -1,33 +1,6 @@
1
- /**
2
- *
3
- * @licstart The following is the entire license notice for the JavaScript code in this file.
4
- *
5
- * Melinda record matching modules for Javascript
6
- *
7
- * Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
8
- *
9
- * This file is part of melinda-record-matching-js
10
- *
11
- * melinda-record-matching-js program is free software: you can redistribute it and/or modify
12
- * it under the terms of the GNU Lesser General Public License as
13
- * published by the Free Software Foundation, either version 3 of the
14
- * License, or (at your option) any later version.
15
- *
16
- * melinda-record-matching-js is distributed in the hope that it will be useful,
17
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
- * GNU Lesser General Public License for more details.
20
- *
21
- * You should have received a copy of the GNU Affero General Public License
22
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
- *
24
- * @licend The above is the entire license notice
25
- * for the JavaScript code in this file.
26
- *
27
- */
28
1
 
29
2
  import createDebugLogger from 'debug';
30
- import * as features from './features';
3
+ import * as features from './features/index.js';
31
4
 
32
5
  export {features};
33
6
 
@@ -1,46 +1,20 @@
1
- /**
2
- *
3
- * @licstart The following is the entire license notice for the JavaScript code in this file.
4
- *
5
- * Melinda record matching modules for Javascript
6
- *
7
- * Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
8
- *
9
- * This file is part of melinda-record-matching-js
10
- *
11
- * melinda-record-matching-js program is free software: you can redistribute it and/or modify
12
- * it under the terms of the GNU Lesser General Public License as
13
- * published by the Free Software Foundation, either version 3 of the
14
- * License, or (at your option) any later version.
15
- *
16
- * melinda-record-matching-js is distributed in the hope that it will be useful,
17
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
- * GNU Lesser General Public License for more details.
20
- *
21
- * You should have received a copy of the GNU Affero General Public License
22
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
- *
24
- * @licend The above is the entire license notice
25
- * for the JavaScript code in this file.
26
- *
27
- */
28
-
1
+ import assert from 'node:assert';
2
+ import {describe} from 'node:test';
3
+ import createDebugLogger from 'debug';
4
+ import {inspect} from 'util';
29
5
  import generateTests from '@natlibfi/fixugen';
30
6
  import {READERS} from '@natlibfi/fixura';
31
- import {expect} from 'chai';
32
7
  import {MarcRecord} from '@natlibfi/marc-record';
33
- import * as features from './features';
34
- import createDetectionInterface from '.';
35
- import {inspect} from 'util';
36
- import createDebugLogger from 'debug';
8
+
9
+ import createDetectionInterface from './index.js';
10
+ import * as features from './features/index.js';
37
11
 
38
12
  const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:test');
39
13
  const debugData = debug.extend('data');
40
14
 
41
15
  describe('match-detection', () => {
42
16
  generateTests({
43
- path: [__dirname, '..', '..', 'test-fixtures', 'match-detection', 'index'],
17
+ path: [import.meta.dirname, '..', '..', 'test-fixtures', 'match-detection', 'index'],
44
18
  useMetadataFile: true,
45
19
  recurse: false,
46
20
  fixura: {
@@ -66,7 +40,7 @@ describe('match-detection', () => {
66
40
  const results = detect({recordA, recordB});
67
41
  debugData(`${JSON.stringify(results)}`);
68
42
 
69
- expect(results).to.eql(expectedResults);
43
+ assert.deepStrictEqual(results, expectedResults);
70
44
 
71
45
  function formatOptions() {
72
46
  const contextFeatures = features[options.strategy.type];
@@ -1,31 +1,3 @@
1
- /**
2
- *
3
- * @licstart The following is the entire license notice for the JavaScript code in this file.
4
- *
5
- * Melinda record matching modules for Javascript
6
- *
7
- * Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
8
- *
9
- * This file is part of melinda-record-matching-js
10
- *
11
- * melinda-record-matching-js program is free software: you can redistribute it and/or modify
12
- * it under the terms of the GNU Lesser General Public License as
13
- * published by the Free Software Foundation, either version 3 of the
14
- * License, or (at your option) any later version.
15
- *
16
- * melinda-record-matching-js is distributed in the hope that it will be useful,
17
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
- * GNU Lesser General Public License for more details.
20
- *
21
- * You should have received a copy of the GNU Affero General Public License
22
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
- *
24
- * @licend The above is the entire license notice
25
- * for the JavaScript code in this file.
26
- *
27
- */
28
-
29
1
  import createDebugLogger from 'debug';
30
2
 
31
3
  const debug = createDebugLogger('@natlibfi/melinda-record-matching:utils');
@@ -43,7 +15,7 @@ export function getMelindaIdsF035(record) {
43
15
  return [];
44
16
  }
45
17
 
46
- const allF035MelindaIds = [].concat(...f035s.map(toMelindaIds));
18
+ const allF035MelindaIds = [].concat(...f035s.map(field => toMelindaIds(field)));
47
19
  const f035MelindaIds = [...new Set(allF035MelindaIds)];
48
20
 
49
21
  debugData(`Fields (${f035s.length}): ${JSON.stringify(f035s)}`);
@@ -51,16 +23,15 @@ export function getMelindaIdsF035(record) {
51
23
  debugData(`Unique ids (${f035MelindaIds.length}): ${JSON.stringify(f035MelindaIds)}`);
52
24
 
53
25
  return f035MelindaIds;
26
+ }
54
27
 
55
- function toMelindaIds({subfields}) {
56
- const melindaIdRegExp = /^(?<prefix>\(FI-MELINDA\)|FCC)(?<id>\d{9})$/u;
57
-
58
- return subfields
59
- .filter(sub => ['a', 'z'].includes(sub.code))
60
- .filter(sub => testStringOrNumber(sub.value) && melindaIdRegExp.test(String(sub.value)))
61
- .map(({value}) => testStringOrNumber(value) ? String(value).replace(melindaIdRegExp, '$<id>') : '');
28
+ export function toMelindaIds({subfields}, subfieldsToParse = ['a', 'z']) {
29
+ const melindaIdRegExp = /^(?<prefix>\(FI-MELINDA\)|FCC)(?<id>\d{9})$/u;
62
30
 
63
- }
31
+ return subfields
32
+ .filter(sub => subfieldsToParse.includes(sub.code))
33
+ .filter(sub => testStringOrNumber(sub.value) && melindaIdRegExp.test(String(sub.value)))
34
+ .map(({value}) => testStringOrNumber(value) ? String(value).replace(melindaIdRegExp, '$<id>') : '');
64
35
  }
65
36
 
66
37
  export function validateSidFieldSubfieldCounts(field) {
@@ -1,144 +0,0 @@
1
- "use strict";
2
-
3
- var _chai = require("chai");
4
- var _fixura = require("@natlibfi/fixura");
5
- var _fixugenHttpClient = _interopRequireDefault(require("@natlibfi/fixugen-http-client"));
6
- var _marcRecord = require("@natlibfi/marc-record");
7
- var _melindaCommons = require("@natlibfi/melinda-commons");
8
- var _ = _interopRequireWildcard(require("."));
9
- var _debug = _interopRequireDefault(require("debug"));
10
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
11
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
- /**
14
- *
15
- * @licstart The following is the entire license notice for the JavaScript code in this file.
16
- *
17
- * Melinda record matching modules for Javascript
18
- *
19
- * Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
20
- *
21
- * This file is part of melinda-record-matching-js
22
- *
23
- * melinda-record-matching-js program is free software: you can redistribute it and/or modify
24
- * it under the terms of the GNU Lesser General Public License as
25
- * published by the Free Software Foundation, either version 3 of the
26
- * License, or (at your option) any later version.
27
- *
28
- * melinda-record-matching-js is distributed in the hope that it will be useful,
29
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
30
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31
- * GNU Lesser General Public License for more details.
32
- *
33
- * You should have received a copy of the GNU Affero General Public License
34
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
35
- *
36
- * @licend The above is the entire license notice
37
- * for the JavaScript code in this file.
38
- *
39
- */
40
-
41
- const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:candidate-search:test');
42
- describe('candidate-search', () => {
43
- (0, _fixugenHttpClient.default)({
44
- callback,
45
- path: [__dirname, '..', '..', 'test-fixtures', 'candidate-search', 'index'],
46
- recurse: false,
47
- fixura: {
48
- reader: _fixura.READERS.JSON
49
- }
50
- });
51
- async function callback({
52
- getFixture,
53
- factoryOptions,
54
- searchOptions,
55
- expectedFactoryError = false,
56
- expectedSearchError = false,
57
- enabled = true
58
- }) {
59
- const url = 'http://foo.bar';
60
- if (!enabled) {
61
- return;
62
- }
63
- if (expectedFactoryError) {
64
- if (expectedFactoryError.isCandidateSearchError) {
65
- (0, _chai.expect)(() => (0, _.default)({
66
- ...formatFactoryOptions(),
67
- url
68
- })).to.throw(_.CandidateSearchError, new RegExp(expectedFactoryError, 'u'));
69
- return;
70
- }
71
- (0, _chai.expect)(() => (0, _.default)({
72
- ...formatFactoryOptions(),
73
- url
74
- })).to.throw(new RegExp(expectedFactoryError, 'u'));
75
- return;
76
- }
77
- const search = (0, _.default)({
78
- ...formatFactoryOptions(),
79
- url
80
- });
81
- await iterate({
82
- searchOptions,
83
- expectedSearchError
84
- });
85
- function formatFactoryOptions() {
86
- debug(`Using factoryOptions: ${JSON.stringify(factoryOptions)}`);
87
- return {
88
- ...factoryOptions,
89
- maxRecordsPerRequest: factoryOptions.maxRecordsPerRequest || 1,
90
- maxServerResults: factoryOptions.maxServerResults || undefined,
91
- record: new _marcRecord.MarcRecord(factoryOptions.record, {
92
- subfieldValues: false
93
- })
94
- };
95
- }
96
- async function iterate({
97
- searchOptions,
98
- expectedSearchError,
99
- expectedErrorStatus,
100
- count = 1
101
- }) {
102
- const expectedResults = getFixture(`expectedResults${count}.json`);
103
- if (expectedSearchError) {
104
- // eslint-disable-line functional/no-conditional-statements
105
- try {
106
- await search(searchOptions);
107
- throw new Error('Expected an error');
108
- } catch (err) {
109
- debug(`Got an error: ${err}`);
110
- (0, _chai.expect)(err).to.be.an('error');
111
- const errorMessage = err instanceof _melindaCommons.Error ? err.payload.message : err.message;
112
- const errorStatus = err instanceof _melindaCommons.Error ? err.status : undefined;
113
- debug(`errorMessage: ${errorMessage}, errorStatus: ${errorStatus}`);
114
- (0, _chai.expect)(errorMessage).to.match(new RegExp(expectedSearchError, 'u'));
115
- if (expectedErrorStatus) {
116
- (0, _chai.expect)(errorStatus).to.be(expectedErrorStatus);
117
- return;
118
- }
119
- return;
120
- }
121
- }
122
-
123
- // eslint-disable-next-line functional/no-conditional-statements
124
- if (!expectedSearchError) {
125
- const results = await search(searchOptions);
126
- (0, _chai.expect)(formatResults(results)).to.eql(expectedResults);
127
- }
128
- function formatResults(results) {
129
- debug(results);
130
- return {
131
- ...results,
132
- records: results.records.map(({
133
- record,
134
- id
135
- }) => ({
136
- id,
137
- record: record.toObject()
138
- }))
139
- };
140
- }
141
- }
142
- }
143
- });
144
- //# sourceMappingURL=index.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.spec.js","names":["_chai","require","_fixura","_fixugenHttpClient","_interopRequireDefault","_marcRecord","_melindaCommons","_","_interopRequireWildcard","_debug","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","obj","debug","createDebugLogger","describe","generateTests","callback","path","__dirname","recurse","fixura","reader","READERS","JSON","getFixture","factoryOptions","searchOptions","expectedFactoryError","expectedSearchError","enabled","url","isCandidateSearchError","expect","createSearchInterface","formatFactoryOptions","to","throw","CandidateSearchError","RegExp","search","iterate","stringify","maxRecordsPerRequest","maxServerResults","undefined","record","MarcRecord","subfieldValues","expectedErrorStatus","count","expectedResults","Error","err","be","an","errorMessage","MatchingError","payload","message","errorStatus","status","match","results","formatResults","eql","records","map","id","toObject"],"sources":["../../src/candidate-search/index.spec.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-record-matching-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport {expect} from 'chai';\nimport {READERS} from '@natlibfi/fixura';\nimport generateTests from '@natlibfi/fixugen-http-client';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {Error as MatchingError} from '@natlibfi/melinda-commons';\nimport createSearchInterface, {CandidateSearchError} from '.';\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:test');\n\ndescribe('candidate-search', () => {\n generateTests({\n callback,\n path: [__dirname, '..', '..', 'test-fixtures', 'candidate-search', 'index'],\n recurse: false,\n fixura: {\n reader: READERS.JSON\n }\n });\n\n async function callback({getFixture, factoryOptions, searchOptions, expectedFactoryError = false, expectedSearchError = false, enabled = true}) {\n const url = 'http://foo.bar';\n\n if (!enabled) {\n return;\n }\n\n if (expectedFactoryError) {\n if (expectedFactoryError.isCandidateSearchError) {\n expect(() => createSearchInterface({...formatFactoryOptions(), url})).to.throw(CandidateSearchError, new RegExp(expectedFactoryError, 'u'));\n return;\n }\n\n expect(() => createSearchInterface({...formatFactoryOptions(), url})).to.throw(new RegExp(expectedFactoryError, 'u'));\n return;\n }\n\n const search = createSearchInterface({...formatFactoryOptions(), url});\n await iterate({searchOptions, expectedSearchError});\n\n function formatFactoryOptions() {\n debug(`Using factoryOptions: ${JSON.stringify(factoryOptions)}`);\n return {\n ...factoryOptions,\n maxRecordsPerRequest: factoryOptions.maxRecordsPerRequest || 1,\n maxServerResults: factoryOptions.maxServerResults || undefined,\n record: new MarcRecord(factoryOptions.record, {subfieldValues: false})\n };\n }\n\n async function iterate({searchOptions, expectedSearchError, expectedErrorStatus, count = 1}) {\n const expectedResults = getFixture(`expectedResults${count}.json`);\n\n if (expectedSearchError) { // eslint-disable-line functional/no-conditional-statements\n try {\n await search(searchOptions);\n throw new Error('Expected an error');\n } catch (err) {\n debug(`Got an error: ${err}`);\n expect(err).to.be.an('error');\n const errorMessage = err instanceof MatchingError ? err.payload.message : err.message;\n const errorStatus = err instanceof MatchingError ? err.status : undefined;\n debug(`errorMessage: ${errorMessage}, errorStatus: ${errorStatus}`);\n expect(errorMessage).to.match(new RegExp(expectedSearchError, 'u'));\n\n if (expectedErrorStatus) {\n expect(errorStatus).to.be(expectedErrorStatus);\n return;\n }\n return;\n }\n }\n\n // eslint-disable-next-line functional/no-conditional-statements\n if (!expectedSearchError) {\n const results = await search(searchOptions);\n expect(formatResults(results)).to.eql(expectedResults);\n }\n\n function formatResults(results) {\n debug(results);\n return {\n ...results,\n records: results.records.map(({record, id}) => ({id, record: record.toObject()}))\n };\n }\n\n }\n }\n});\n"],"mappings":";;AA4BA,IAAAA,KAAA,GAAA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AAC,OAAO,CAAC;UAC7B,MAAMC,YAAY,GAAGH,GAAG,YAAYI,qBAAa,GAAGJ,GAAG,CAACK,OAAO,CAACC,OAAO,GAAGN,GAAG,CAACM,OAAO;UACrF,MAAMC,WAAW,GAAGP,GAAG,YAAYI,qBAAa,GAAGJ,GAAG,CAACQ,MAAM,GAAGhB,SAAS;UACzEhC,KAAK,CAAE,iBAAgB2C,YAAa,kBAAiBI,WAAY,EAAC,CAAC;UACnE,IAAA3B,YAAM,EAACuB,YAAY,CAAC,CAACpB,EAAE,CAAC0B,KAAK,CAAC,IAAIvB,MAAM,CAACV,mBAAmB,EAAE,GAAG,CAAC,CAAC;UAEnE,IAAIoB,mBAAmB,EAAE;YACvB,IAAAhB,YAAM,EAAC2B,WAAW,CAAC,CAACxB,EAAE,CAACkB,EAAE,CAACL,mBAAmB,CAAC;YAC9C;UACF;UACA;QACF;MACF;;MAEA;MACA,IAAI,CAACpB,mBAAmB,EAAE;QACxB,MAAMkC,OAAO,GAAG,MAAMvB,MAAM,CAACb,aAAa,CAAC;QAC3C,IAAAM,YAAM,EAAC+B,aAAa,CAACD,OAAO,CAAC,CAAC,CAAC3B,EAAE,CAAC6B,GAAG,CAACd,eAAe,CAAC;MACxD;MAEA,SAASa,aAAaA,CAACD,OAAO,EAAE;QAC9BlD,KAAK,CAACkD,OAAO,CAAC;QACd,OAAO;UACL,GAAGA,OAAO;UACVG,OAAO,EAAEH,OAAO,CAACG,OAAO,CAACC,GAAG,CAAC,CAAC;YAACrB,MAAM;YAAEsB;UAAE,CAAC,MAAM;YAACA,EAAE;YAAEtB,MAAM,EAAEA,MAAM,CAACuB,QAAQ,CAAC;UAAC,CAAC,CAAC;QAClF,CAAC;MACH;IAEF;EACF;AACF,CAAC,CAAC"}
@@ -1,64 +0,0 @@
1
- "use strict";
2
-
3
- var _fixugen = _interopRequireDefault(require("@natlibfi/fixugen"));
4
- var _fixura = require("@natlibfi/fixura");
5
- var _chai = require("chai");
6
- var _marcRecord = require("@natlibfi/marc-record");
7
- var generators = _interopRequireWildcard(require("./bib"));
8
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
9
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
- /**
12
- *
13
- * @licstart The following is the entire license notice for the JavaScript code in this file.
14
- *
15
- * Melinda record matching modules for Javascript
16
- *
17
- * Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
18
- *
19
- * This file is part of melinda-record-matching-js
20
- *
21
- * melinda-record-matching-js program is free software: you can redistribute it and/or modify
22
- * it under the terms of the GNU Lesser General Public License as
23
- * published by the Free Software Foundation, either version 3 of the
24
- * License, or (at your option) any later version.
25
- *
26
- * melinda-record-matching-js is distributed in the hope that it will be useful,
27
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
28
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29
- * GNU Lesser General Public License for more details.
30
- *
31
- * You should have received a copy of the GNU Affero General Public License
32
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
33
- *
34
- * @licend The above is the entire license notice
35
- * for the JavaScript code in this file.
36
- *
37
- */
38
-
39
- describe('candidate-search/query-list/bib/', () => {
40
- (0, _fixugen.default)({
41
- path: [__dirname, '..', '..', '..', 'test-fixtures', 'candidate-search', 'query-list', 'bib'],
42
- useMetadataFile: true,
43
- fixura: {
44
- reader: _fixura.READERS.JSON
45
- },
46
- callback: ({
47
- type,
48
- inputRecord,
49
- expectedQuery,
50
- enabled = true
51
- }) => {
52
- const generate = generators[type];
53
- const record = new _marcRecord.MarcRecord(inputRecord, {
54
- subfieldValues: false
55
- });
56
- if (!enabled) {
57
- return;
58
- }
59
- const queryList = generate(record);
60
- (0, _chai.expect)(queryList).to.eql(expectedQuery);
61
- }
62
- });
63
- });
64
- //# sourceMappingURL=bib.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bib.spec.js","names":["_fixugen","_interopRequireDefault","require","_fixura","_chai","_marcRecord","generators","_interopRequireWildcard","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","obj","describe","generateTests","path","__dirname","useMetadataFile","fixura","reader","READERS","JSON","callback","type","inputRecord","expectedQuery","enabled","generate","record","MarcRecord","subfieldValues","queryList","expect","to","eql"],"sources":["../../../src/candidate-search/query-list/bib.spec.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-record-matching-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport generateTests from '@natlibfi/fixugen';\nimport {READERS} from '@natlibfi/fixura';\nimport {expect} from 'chai';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport * as generators from './bib';\n\ndescribe('candidate-search/query-list/bib/', () => {\n generateTests({\n path: [__dirname, '..', '..', '..', 'test-fixtures', 'candidate-search', 'query-list', 'bib'],\n useMetadataFile: true,\n fixura: {\n reader: READERS.JSON\n },\n callback: ({type, inputRecord, expectedQuery, enabled = true}) => {\n const generate = generators[type];\n const record = new MarcRecord(inputRecord, {subfieldValues: false});\n\n if (!enabled) {\n return;\n }\n\n const queryList = generate(record);\n expect(queryList).to.eql(expectedQuery);\n }\n });\n});\n"],"mappings":";;AA4BA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAC,uBAAA,CAAAL,OAAA;AAAoC,SAAAM,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAF,wBAAAE,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC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;QACZ;MACF;MAEA,MAAMK,SAAS,GAAGJ,QAAQ,CAACC,MAAM,CAAC;MAClC,IAAAI,YAAM,EAACD,SAAS,CAAC,CAACE,EAAE,CAACC,GAAG,CAACT,aAAa,CAAC;IACzC;EACF,CAAC,CAAC;AACJ,CAAC,CAAC"}
@@ -1,127 +0,0 @@
1
- "use strict";
2
-
3
- var _chai = require("chai");
4
- var _fixura = require("@natlibfi/fixura");
5
- var _fixugenHttpClient = _interopRequireDefault(require("@natlibfi/fixugen-http-client"));
6
- var _marcRecord = require("@natlibfi/marc-record");
7
- var _ = _interopRequireWildcard(require("."));
8
- var _debug = _interopRequireDefault(require("debug"));
9
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
10
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
- /**
13
- *
14
- * @licstart The following is the entire license notice for the JavaScript code in this file.
15
- *
16
- * Melinda record matching modules for Javascript
17
- *
18
- * Copyright (C) 2020-2023 University Of Helsinki (The National Library Of Finland)
19
- *
20
- * This file is part of melinda-record-matching-js
21
- *
22
- * melinda-record-matching-js program is free software: you can redistribute it and/or modify
23
- * it under the terms of the GNU Lesser General Public License as
24
- * published by the Free Software Foundation, either version 3 of the
25
- * License, or (at your option) any later version.
26
- *
27
- * melinda-record-matching-js is distributed in the hope that it will be useful,
28
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
29
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30
- * GNU Lesser General Public License for more details.
31
- *
32
- * You should have received a copy of the GNU Affero General Public License
33
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
34
- *
35
- * @licend The above is the entire license notice
36
- * for the JavaScript code in this file.
37
- *
38
- */
39
-
40
- const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:index:test');
41
- const debugData = debug.extend('data');
42
- describe('INDEX', () => {
43
- (0, _fixugenHttpClient.default)({
44
- callback,
45
- path: [__dirname, '..', 'test-fixtures', 'index'],
46
- recurse: false,
47
- fixura: {
48
- reader: _fixura.READERS.JSON
49
- }
50
- });
51
-
52
- // eslint-disable-next-line max-statements
53
- async function callback({
54
- getFixture,
55
- options,
56
- expectedMatchStatus,
57
- expectedStopReason,
58
- expectedFailures,
59
- expectedCandidateCount
60
- }) {
61
- const record = new _marcRecord.MarcRecord(getFixture('inputRecord.json'), {
62
- subfieldValues: false
63
- });
64
- const expectedMatches = getFixture('expectedMatches.json');
65
- const expectedNonMatches = getFixture('expectedNonMatches.json') || [];
66
- const match = (0, _.default)(formatOptions());
67
- const {
68
- matches,
69
- matchStatus,
70
- nonMatches,
71
- conversionFailures,
72
- candidateCount
73
- } = await match({
74
- record
75
- });
76
- debugData(`Matches: ${matches.length}, Status: ${matchStatus.status}/${matchStatus.stopReason}, NonMatches: ${nonMatches ? nonMatches.length : 'not returned'}, ConversionFailures: ${conversionFailures ? conversionFailures.length : 'not returned'}`);
77
- (0, _chai.expect)(matchStatus.status).to.eql(expectedMatchStatus);
78
- (0, _chai.expect)(matchStatus.stopReason).to.eql(expectedStopReason);
79
- (0, _chai.expect)(candidateCount).to.eql(expectedCandidateCount);
80
- const formattedMatchResult = formatRecordResults(matches);
81
- (0, _chai.expect)(formattedMatchResult).to.eql(expectedMatches);
82
- const formattedNonMatchResult = formatRecordResults(nonMatches);
83
- (0, _chai.expect)(formattedNonMatchResult).to.eql(expectedNonMatches);
84
-
85
- // eslint-disable-next-line functional/no-conditional-statements
86
- if (expectedFailures) {
87
- (0, _chai.expect)(conversionFailures).to.eql(expectedFailures);
88
- }
89
- function formatOptions() {
90
- const contextFeatures = _.matchDetection.features[options.detection.strategy.type];
91
- return {
92
- ...options,
93
- search: {
94
- ...options.search
95
- },
96
- detection: {
97
- ...options.detect,
98
- strategy: options.detection.strategy.features.map(v => contextFeatures[v]())
99
- }
100
- };
101
- }
102
- function formatRecordResults(matches) {
103
- if (matches) {
104
- debugData(JSON.stringify(matches));
105
- return matches.map(match => ({
106
- ...match,
107
- candidate: formatCandidate(match.candidate)
108
- }));
109
- }
110
- return [];
111
- }
112
-
113
- // Format candidate to remove validationOptions from record
114
- function formatCandidate({
115
- id,
116
- record
117
- }) {
118
- const newId = id;
119
- const newRecord = record;
120
- return {
121
- id: newId,
122
- record: newRecord.toObject()
123
- };
124
- }
125
- }
126
- });
127
- //# sourceMappingURL=index.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.spec.js","names":["_chai","require","_fixura","_fixugenHttpClient","_interopRequireDefault","_marcRecord","_","_interopRequireWildcard","_debug","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","obj","debug","createDebugLogger","debugData","extend","describe","generateTests","callback","path","__dirname","recurse","fixura","reader","READERS","JSON","getFixture","options","expectedMatchStatus","expectedStopReason","expectedFailures","expectedCandidateCount","record","MarcRecord","subfieldValues","expectedMatches","expectedNonMatches","match","createMatchInterface","formatOptions","matches","matchStatus","nonMatches","conversionFailures","candidateCount","length","status","stopReason","expect","to","eql","formattedMatchResult","formatRecordResults","formattedNonMatchResult","contextFeatures","matchDetection","features","detection","strategy","type","search","detect","map","v","stringify","candidate","formatCandidate","id","newId","newRecord","toObject"],"sources":["../src/index.spec.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020-2023 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-record-matching-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport {expect} from 'chai';\nimport {READERS} from '@natlibfi/fixura';\nimport generateTests from '@natlibfi/fixugen-http-client';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport createMatchInterface, {matchDetection} from '.';\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:index:test');\nconst debugData = debug.extend('data');\n\ndescribe('INDEX', () => {\n generateTests({\n callback,\n path: [__dirname, '..', 'test-fixtures', 'index'],\n recurse: false,\n fixura: {\n reader: READERS.JSON\n }\n });\n\n // eslint-disable-next-line max-statements\n async function callback({getFixture, options, expectedMatchStatus, expectedStopReason, expectedFailures, expectedCandidateCount}) {\n\n const record = new MarcRecord(getFixture('inputRecord.json'), {subfieldValues: false});\n const expectedMatches = getFixture('expectedMatches.json');\n const expectedNonMatches = getFixture('expectedNonMatches.json') || [];\n\n\n const match = createMatchInterface(formatOptions());\n const {matches, matchStatus, nonMatches, conversionFailures, candidateCount} = await match({record});\n debugData(`Matches: ${matches.length}, Status: ${matchStatus.status}/${matchStatus.stopReason}, NonMatches: ${nonMatches ? nonMatches.length : 'not returned'}, ConversionFailures: ${conversionFailures ? conversionFailures.length : 'not returned'}`);\n\n expect(matchStatus.status).to.eql(expectedMatchStatus);\n expect(matchStatus.stopReason).to.eql(expectedStopReason);\n expect(candidateCount).to.eql(expectedCandidateCount);\n\n const formattedMatchResult = formatRecordResults(matches);\n expect(formattedMatchResult).to.eql(expectedMatches);\n\n const formattedNonMatchResult = formatRecordResults(nonMatches);\n expect(formattedNonMatchResult).to.eql(expectedNonMatches);\n\n // eslint-disable-next-line functional/no-conditional-statements\n if (expectedFailures) {\n expect(conversionFailures).to.eql(expectedFailures);\n }\n\n function formatOptions() {\n const contextFeatures = matchDetection.features[options.detection.strategy.type];\n\n return {\n ...options,\n search: {\n ...options.search\n },\n detection: {\n ...options.detect,\n strategy: options.detection.strategy.features.map(v => contextFeatures[v]())\n }\n };\n }\n\n function formatRecordResults(matches) {\n if (matches) {\n debugData(JSON.stringify(matches));\n return matches.map((match) => ({\n ...match,\n candidate: formatCandidate(match.candidate)\n }));\n }\n return [];\n }\n\n // Format candidate to remove validationOptions from record\n function formatCandidate({id, record}) {\n const newId = id;\n const newRecord = record;\n return {\n id: newId,\n record: newRecord.toObject()\n };\n }\n\n\n }\n\n});\n"],"mappings":";;AA4BA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,kBAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AACA,IAAAK,CAAA,GAAAC,uBAAA,CAAAN,OAAA;AACA,IAAAO,MAAA,GAAAJ,sBAAA,CAAAH,OAAA;AAAsC,SAAAQ,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAH,wBAAAG,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA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