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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/.github/CODEOWNERS +10 -0
  2. package/.github/dependabot.yml +40 -0
  3. package/.github/workflows/melinda-node-tests.yml +70 -0
  4. package/package.json +13 -13
  5. package/src/candidate-search/index.js +11 -8
  6. package/src/candidate-search/query-list/bib.js +2 -2
  7. package/src/index.js +70 -29
  8. package/src/match-detection/features/bib/authors.js +1 -1
  9. package/src/match-detection/features/bib/standard-identifier-factory.js +2 -1
  10. package/src/match-detection/index.js +29 -19
  11. package/src/match-detection/index.spec.js +17 -3
  12. package/src/matching-utils.js +1 -1
  13. package/dist/candidate-search/candidate-search-utils.js +0 -58
  14. package/dist/candidate-search/candidate-search-utils.js.map +0 -1
  15. package/dist/candidate-search/index.js +0 -273
  16. package/dist/candidate-search/index.js.map +0 -1
  17. package/dist/candidate-search/index.spec.js +0 -161
  18. package/dist/candidate-search/index.spec.js.map +0 -1
  19. package/dist/candidate-search/query-list/bib.js +0 -252
  20. package/dist/candidate-search/query-list/bib.js.map +0 -1
  21. package/dist/candidate-search/query-list/bib.spec.js +0 -72
  22. package/dist/candidate-search/query-list/bib.spec.js.map +0 -1
  23. package/dist/candidate-search/query-list/index.js +0 -67
  24. package/dist/candidate-search/query-list/index.js.map +0 -1
  25. package/dist/index.js +0 -508
  26. package/dist/index.js.map +0 -1
  27. package/dist/index.spec.js +0 -133
  28. package/dist/index.spec.js.map +0 -1
  29. package/dist/match-detection/features/bib/all-source-ids.js +0 -122
  30. package/dist/match-detection/features/bib/all-source-ids.js.map +0 -1
  31. package/dist/match-detection/features/bib/authors.js +0 -117
  32. package/dist/match-detection/features/bib/authors.js.map +0 -1
  33. package/dist/match-detection/features/bib/bibliographic-level.js +0 -42
  34. package/dist/match-detection/features/bib/bibliographic-level.js.map +0 -1
  35. package/dist/match-detection/features/bib/host-component.js +0 -42
  36. package/dist/match-detection/features/bib/host-component.js.map +0 -1
  37. package/dist/match-detection/features/bib/index.js +0 -104
  38. package/dist/match-detection/features/bib/index.js.map +0 -1
  39. package/dist/match-detection/features/bib/index.spec.js +0 -97
  40. package/dist/match-detection/features/bib/index.spec.js.map +0 -1
  41. package/dist/match-detection/features/bib/isbn.js +0 -55
  42. package/dist/match-detection/features/bib/isbn.js.map +0 -1
  43. package/dist/match-detection/features/bib/issn.js +0 -55
  44. package/dist/match-detection/features/bib/issn.js.map +0 -1
  45. package/dist/match-detection/features/bib/language.js +0 -113
  46. package/dist/match-detection/features/bib/language.js.map +0 -1
  47. package/dist/match-detection/features/bib/melinda-id.js +0 -52
  48. package/dist/match-detection/features/bib/melinda-id.js.map +0 -1
  49. package/dist/match-detection/features/bib/melinda-identifier-factory.js +0 -100
  50. package/dist/match-detection/features/bib/melinda-identifier-factory.js.map +0 -1
  51. package/dist/match-detection/features/bib/other-standard-identifier.js +0 -55
  52. package/dist/match-detection/features/bib/other-standard-identifier.js.map +0 -1
  53. package/dist/match-detection/features/bib/publication-time.js +0 -47
  54. package/dist/match-detection/features/bib/publication-time.js.map +0 -1
  55. package/dist/match-detection/features/bib/record-type.js +0 -42
  56. package/dist/match-detection/features/bib/record-type.js.map +0 -1
  57. package/dist/match-detection/features/bib/standard-identifier-factory.js +0 -125
  58. package/dist/match-detection/features/bib/standard-identifier-factory.js.map +0 -1
  59. package/dist/match-detection/features/bib/title.js +0 -91
  60. package/dist/match-detection/features/bib/title.js.map +0 -1
  61. package/dist/match-detection/features/index.js +0 -15
  62. package/dist/match-detection/features/index.js.map +0 -1
  63. package/dist/match-detection/index.js +0 -178
  64. package/dist/match-detection/index.js.map +0 -1
  65. package/dist/match-detection/index.spec.js +0 -81
  66. package/dist/match-detection/index.spec.js.map +0 -1
  67. package/dist/matching-utils.js +0 -95
  68. package/dist/matching-utils.js.map +0 -1
@@ -1,42 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- /**
9
- *
10
- * @licstart The following is the entire license notice for the JavaScript code in this file.
11
- *
12
- * Melinda record matching modules for Javascript
13
- *
14
- * Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
15
- *
16
- * This file is part of melinda-record-matching-js
17
- *
18
- * melinda-record-matching-js program is free software: you can redistribute it and/or modify
19
- * it under the terms of the GNU Lesser General Public License as
20
- * published by the Free Software Foundation, either version 3 of the
21
- * License, or (at your option) any later version.
22
- *
23
- * melinda-record-matching-js is distributed in the hope that it will be useful,
24
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
25
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
- * GNU Lesser General Public License for more details.
27
- *
28
- * You should have received a copy of the GNU Affero General Public License
29
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
30
- *
31
- * @licend The above is the entire license notice
32
- * for the JavaScript code in this file.
33
- *
34
- */
35
- var _default = () => ({
36
- name: 'Record type',
37
- extract: r => r.leader[6] ? [r.leader[6]] : [],
38
- compare: (a, b) => a[0] === b[0] ? 0.1 : -0.5
39
- });
40
-
41
- exports.default = _default;
42
- //# sourceMappingURL=record-type.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/match-detection/features/bib/record-type.js"],"names":["name","extract","r","leader","compare","a","b"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;eAEe,OAAO;AACpBA,EAAAA,IAAI,EAAE,aADc;AAEpBC,EAAAA,OAAO,EAAEC,CAAC,IAAIA,CAAC,CAACC,MAAF,CAAS,CAAT,IAAc,CAACD,CAAC,CAACC,MAAF,CAAS,CAAT,CAAD,CAAd,GAA8B,EAFxB;AAGpBC,EAAAA,OAAO,EAAE,CAACC,CAAD,EAAIC,CAAJ,KAAUD,CAAC,CAAC,CAAD,CAAD,KAASC,CAAC,CAAC,CAAD,CAAV,GAAgB,GAAhB,GAAsB,CAAC;AAHtB,CAAP,C","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\nexport default () => ({\n name: 'Record type',\n extract: r => r.leader[6] ? [r.leader[6]] : [],\n compare: (a, b) => a[0] === b[0] ? 0.1 : -0.5\n});\n"],"file":"record-type.js"}
@@ -1,125 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _debug = _interopRequireDefault(require("debug"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
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 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
- const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:match-detection:features:standard-identifiers');
40
- const debugData = debug.extend('data');
41
-
42
- var _default = ({
43
- pattern,
44
- subfieldCodes
45
- }) => {
46
- return {
47
- extract,
48
- compare
49
- };
50
-
51
- function extract(record) {
52
- const [field] = record.get(pattern);
53
-
54
- if (field) {
55
- return field.subfields.filter(({
56
- code
57
- }) => subfieldCodes.includes(code)).map(({
58
- code,
59
- value
60
- }) => ({
61
- code,
62
- value: value.replace(/-/ug, '')
63
- }));
64
- }
65
-
66
- return [];
67
- }
68
-
69
- function compare(a, b) {
70
- if (a.length === 0 || b.length === 0) {
71
- debugData(`No standardidentifiers to compare`);
72
- return 0;
73
- }
74
-
75
- if (bothHaveValidIdentifiers()) {
76
- const {
77
- maxValues,
78
- matchingValues
79
- } = getValueCount(true);
80
- return matchingValues / maxValues * 0.75;
81
- }
82
-
83
- const {
84
- maxValues,
85
- matchingValues
86
- } = getValueCount();
87
- return matchingValues / maxValues * 0.2;
88
-
89
- function bothHaveValidIdentifiers() {
90
- const aValues = a.filter(({
91
- code
92
- }) => code === 'a');
93
- const bValues = a.filter(({
94
- code
95
- }) => code === 'a');
96
- return aValues.length > 0 && bValues.length > 0;
97
- }
98
-
99
- function getValueCount(validOnly = false) {
100
- const aValues = getIdentifiers(a);
101
- const bValues = getIdentifiers(b);
102
- return {
103
- maxValues: aValues.length > bValues.length ? aValues.length : bValues.length,
104
- matchingValues: aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length
105
- };
106
-
107
- function getIdentifiers(values) {
108
- if (validOnly) {
109
- return values.filter(({
110
- code
111
- }) => code === 'a').map(({
112
- value
113
- }) => value);
114
- }
115
-
116
- return values.map(({
117
- value
118
- }) => value);
119
- }
120
- }
121
- }
122
- };
123
-
124
- exports.default = _default;
125
- //# sourceMappingURL=standard-identifier-factory.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/match-detection/features/bib/standard-identifier-factory.js"],"names":["debug","debugData","extend","pattern","subfieldCodes","extract","compare","record","field","get","subfields","filter","code","includes","map","value","replace","a","b","length","bothHaveValidIdentifiers","maxValues","matchingValues","getValueCount","aValues","bValues","validOnly","getIdentifiers","aValue","some","bValue","values"],"mappings":";;;;;;;AA4BA;;;;AA5BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAIA,MAAMA,KAAK,GAAG,oBAAkB,iFAAlB,CAAd;AACA,MAAMC,SAAS,GAAGD,KAAK,CAACE,MAAN,CAAa,MAAb,CAAlB;;eAEe,CAAC;AAACC,EAAAA,OAAD;AAAUC,EAAAA;AAAV,CAAD,KAA8B;AAC3C,SAAO;AAACC,IAAAA,OAAD;AAAUC,IAAAA;AAAV,GAAP;;AAEA,WAASD,OAAT,CAAiBE,MAAjB,EAAyB;AACvB,UAAM,CAACC,KAAD,IAAUD,MAAM,CAACE,GAAP,CAAWN,OAAX,CAAhB;;AAEA,QAAIK,KAAJ,EAAW;AACT,aAAOA,KAAK,CAACE,SAAN,CACJC,MADI,CACG,CAAC;AAACC,QAAAA;AAAD,OAAD,KAAYR,aAAa,CAACS,QAAd,CAAuBD,IAAvB,CADf,EAEJE,GAFI,CAEA,CAAC;AAACF,QAAAA,IAAD;AAAOG,QAAAA;AAAP,OAAD,MAAoB;AAACH,QAAAA,IAAD;AAAOG,QAAAA,KAAK,EAAEA,KAAK,CAACC,OAAN,CAAc,KAAd,EAAqB,EAAr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AACb,MAAR,CAAeiB,MAAM,IAAIH,OAAO,CAACI,IAAR,CAAaC,MAAM,IAAIF,MAAM,KAAKE,MAAlC,CAAzB,EAAoEX;AAF/E,OAAP;;AAKA,eAASQ,cAAT,CAAwBI,MAAxB,EAAgC;AAC9B,YAAIL,SAAJ,EAAe;AACb,iBAAOK,MAAM,CACVpB,MADI,CACG,CAAC;AAACC,YAAAA;AAAD,WAAD,KAAYA,IAAI,KAAK,GADxB,EAEJE,GAFI,CAEA,CAAC;AAACC,YAAAA;AAAD,WAAD,KAAaA,KAFb,CAAP;AAGD;;AAED,eAAOgB,MAAM,CAACjB,GAAP,CAAW,CAAC;AAACC,UAAAA;AAAD,SAAD,KAAaA,KAAxB,CAAP;AACD;AACF;AACF;AACF,C","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 createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features:standard-identifiers');\nconst debugData = debug.extend('data');\n\nexport default ({pattern, subfieldCodes}) => {\n return {extract, compare};\n\n function extract(record) {\n const [field] = record.get(pattern);\n\n if (field) {\n return field.subfields\n .filter(({code}) => subfieldCodes.includes(code))\n .map(({code, value}) => ({code, value: value.replace(/-/ug, '')}));\n }\n\n return [];\n }\n\n function compare(a, b) {\n if (a.length === 0 || b.length === 0) {\n debugData(`No standardidentifiers to compare`);\n return 0;\n }\n\n if (bothHaveValidIdentifiers()) {\n const {maxValues, matchingValues} = getValueCount(true);\n return matchingValues / maxValues * 0.75;\n }\n\n const {maxValues, matchingValues} = getValueCount();\n return matchingValues / maxValues * 0.2;\n\n function bothHaveValidIdentifiers() {\n const aValues = a.filter(({code}) => code === 'a');\n const bValues = a.filter(({code}) => code === 'a');\n return aValues.length > 0 && bValues.length > 0;\n }\n\n function getValueCount(validOnly = false) {\n const aValues = getIdentifiers(a);\n const bValues = getIdentifiers(b);\n\n return {\n maxValues: aValues.length > bValues.length ? aValues.length : bValues.length,\n matchingValues: aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length\n };\n\n function getIdentifiers(values) {\n if (validOnly) {\n return values\n .filter(({code}) => code === 'a')\n .map(({value}) => value);\n }\n\n return values.map(({value}) => value);\n }\n }\n }\n};\n"],"file":"standard-identifier-factory.js"}
@@ -1,91 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _debug = _interopRequireDefault(require("debug"));
9
-
10
- var _natural = require("natural");
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- /**
15
- *
16
- * @licstart The following is the entire license notice for the JavaScript code in this file.
17
- *
18
- * Melinda record matching modules for Javascript
19
- *
20
- * Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
21
- *
22
- * This file is part of melinda-record-matching-js
23
- *
24
- * melinda-record-matching-js program is free software: you can redistribute it and/or modify
25
- * it under the terms of the GNU Lesser General Public License as
26
- * published by the Free Software Foundation, either version 3 of the
27
- * License, or (at your option) any later version.
28
- *
29
- * melinda-record-matching-js is distributed in the hope that it will be useful,
30
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
31
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32
- * GNU Lesser General Public License for more details.
33
- *
34
- * You should have received a copy of the GNU Affero General Public License
35
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
36
- *
37
- * @licend The above is the entire license notice
38
- * for the JavaScript code in this file.
39
- *
40
- */
41
- var _default = ({
42
- treshold = 10
43
- } = {}) => ({
44
- name: 'Title',
45
- extract: record => {
46
- const title = getTitle();
47
-
48
- if (title) {
49
- return [title.replace(/[^\p{Letter}\p{Number}]/gu, '').toLowerCase()];
50
- }
51
-
52
- return [];
53
-
54
- function getTitle() {
55
- const [field] = record.get(/^245$/u);
56
-
57
- if (field) {
58
- return field.subfields.filter(({
59
- code
60
- }) => ['a', 'b'].includes(code)).map(({
61
- value
62
- }) => value).join('');
63
- }
64
- }
65
- },
66
- compare: (a, b) => {
67
- const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:match-detection:features/bib/title');
68
- const distance = (0, _natural.LevenshteinDistance)(a[0], b[0]);
69
-
70
- if (distance === 0) {
71
- return 0.5;
72
- }
73
-
74
- const maxLength = getMaxLength();
75
- const percentage = distance / maxLength * 100;
76
- debug(`'${a}' vs '${b}': Max length = ${maxLength}, distance = ${distance}, percentage = ${percentage}`);
77
-
78
- if (percentage <= treshold) {
79
- return 0.3;
80
- }
81
-
82
- return -0.5;
83
-
84
- function getMaxLength() {
85
- return a[0].length > b[0].length ? a[0].length : b[0].length;
86
- }
87
- }
88
- });
89
-
90
- exports.default = _default;
91
- //# sourceMappingURL=title.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/match-detection/features/bib/title.js"],"names":["treshold","name","extract","record","title","getTitle","replace","toLowerCase","field","get","subfields","filter","code","includes","map","value","join","compare","a","b","debug","distance","maxLength","getMaxLength","percentage","length"],"mappings":";;;;;;;AA4BA;;AACA;;;;AA7BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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AIxB,QAAlB,EAA4B;AAC1B,aAAO,GAAP;AACD;;AAED,WAAO,CAAC,GAAR;;AAEA,aAASuB,YAAT,GAAwB;AACtB,aAAOL,CAAC,CAAC,CAAD,CAAD,CAAKO,MAAL,GAAcN,CAAC,CAAC,CAAD,CAAD,CAAKM,MAAnB,GAA4BP,CAAC,CAAC,CAAD,CAAD,CAAKO,MAAjC,GAA0CN,CAAC,CAAC,CAAD,CAAD,CAAKM,MAAtD;AACD;AAEF;AA7CuC,CAA3B,C","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 createDebugLogger from 'debug';\nimport {LevenshteinDistance as leven} from 'natural';\n\nexport default ({treshold = 10} = {}) => ({\n name: 'Title',\n extract: record => {\n const title = getTitle();\n\n if (title) {\n return [title.replace(/[^\\p{Letter}\\p{Number}]/gu, '').toLowerCase()];\n }\n\n return [];\n\n function getTitle() {\n const [field] = record.get(/^245$/u);\n\n if (field) {\n return field.subfields\n .filter(({code}) => ['a', 'b'].includes(code))\n .map(({value}) => value)\n .join('');\n }\n }\n },\n compare: (a, b) => {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib/title');\n const distance = leven(a[0], b[0]);\n\n if (distance === 0) {\n return 0.5;\n }\n\n const maxLength = getMaxLength();\n const percentage = distance / maxLength * 100;\n\n debug(`'${a}' vs '${b}': Max length = ${maxLength}, distance = ${distance}, percentage = ${percentage}`);\n\n if (percentage <= treshold) {\n return 0.3;\n }\n\n return -0.5;\n\n function getMaxLength() {\n return a[0].length > b[0].length ? a[0].length : b[0].length;\n }\n\n }\n});\n"],"file":"title.js"}
@@ -1,15 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.bib = void 0;
7
-
8
- var bib = _interopRequireWildcard(require("./bib"));
9
-
10
- exports.bib = bib;
11
-
12
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
-
14
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/match-detection/features/index.js"],"names":[],"mappings":";;;;;;;AA4BA","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 * as bib from './bib';\nexport {bib};\n"],"file":"index.js"}
@@ -1,178 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.features = exports.default = void 0;
7
-
8
- var _debug = _interopRequireDefault(require("debug"));
9
-
10
- var features = _interopRequireWildcard(require("./features"));
11
-
12
- exports.features = features;
13
-
14
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
-
16
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
-
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
- /* eslint-disable no-console */
21
-
22
- /**
23
- *
24
- * @licstart The following is the entire license notice for the JavaScript code in this file.
25
- *
26
- * Melinda record matching modules for Javascript
27
- *
28
- * Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
29
- *
30
- * This file is part of melinda-record-matching-js
31
- *
32
- * melinda-record-matching-js program is free software: you can redistribute it and/or modify
33
- * it under the terms of the GNU Lesser General Public License as
34
- * published by the Free Software Foundation, either version 3 of the
35
- * License, or (at your option) any later version.
36
- *
37
- * melinda-record-matching-js is distributed in the hope that it will be useful,
38
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
39
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40
- * GNU Lesser General Public License for more details.
41
- *
42
- * You should have received a copy of the GNU Affero General Public License
43
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
44
- *
45
- * @licend The above is the entire license notice
46
- * for the JavaScript code in this file.
47
- *
48
- */
49
- // eslint-disable-next-line max-statements
50
- var _default = ({
51
- strategy,
52
- treshold = 0.9
53
- }, returnStrategy = false) => (recordA, recordB) => {
54
- const minProbabilityQuantifier = 0.5;
55
- const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:match-detection');
56
- const debugData = debug.extend('data');
57
- debugData(`Strategy: ${JSON.stringify(strategy)}`);
58
- debugData(`Treshold: ${JSON.stringify(treshold)}`);
59
- debugData(`ReturnStrategy: ${JSON.stringify(returnStrategy)}`);
60
- const featuresA = extractFeatures(recordA);
61
- const featuresB = extractFeatures(recordB);
62
- debugData(`Features (a): ${JSON.stringify(featuresA)}`);
63
- debugData(`Features (b): ${JSON.stringify(featuresB)}`);
64
- const featurePairs = generateFeaturePairs();
65
- const similarityVector = generateSimilarityVector();
66
-
67
- if (similarityVector.some(v => v >= minProbabilityQuantifier)) {
68
- const probability = calculateprobability();
69
- debug(`probability: ${probability} (Treshold: ${treshold})`);
70
- return returnResult({
71
- match: probability >= treshold,
72
- probability
73
- });
74
- }
75
-
76
- debugData(`No feature yielded minimum probability amount of points (${minProbabilityQuantifier})`);
77
- return returnResult({
78
- match: false,
79
- probability: 0.0
80
- });
81
-
82
- function returnResult(result) {
83
- if (returnStrategy) {
84
- debug(`Returning detection strategy with the result`);
85
- const resultWithStrategy = {
86
- match: result.match,
87
- probability: result.probability,
88
- strategy: formatStrategy(strategy),
89
- treshold
90
- };
91
- debugData(`${JSON.stringify(resultWithStrategy)}`);
92
- return resultWithStrategy;
93
- }
94
-
95
- return result;
96
- }
97
-
98
- function formatStrategy(strategy) {
99
- const strategyNames = strategy.map(element => element.name);
100
- return strategyNames || [];
101
- }
102
-
103
- function calculateprobability() {
104
- const probability = similarityVector.reduce((acc, v) => acc + v, 0.0);
105
- return probability > 1.0 ? 1.0 : probability;
106
- }
107
-
108
- function extractFeatures(record) {
109
- return strategy.reduce((acc, {
110
- name,
111
- extract
112
- }) => acc.concat({
113
- name,
114
- value: extract(record)
115
- }), []);
116
- }
117
-
118
- function generateSimilarityVector() {
119
- const compared = featurePairs.map(({
120
- name,
121
- a,
122
- b
123
- }) => {
124
- const {
125
- compare
126
- } = strategy.find(({
127
- name: featureName
128
- }) => name === featureName);
129
- const points = compare(a, b);
130
- return {
131
- name,
132
- points
133
- };
134
- });
135
- debugData(`Points: ${JSON.stringify(compared)}`);
136
- return compared.map(({
137
- points
138
- }) => points);
139
- }
140
-
141
- function generateFeaturePairs() {
142
- const pairs = generatePairs();
143
- const missingFeatures = findMissing();
144
- debug(`Not comparing the following features because one, or both records are missing features: ${JSON.stringify(missingFeatures)}`);
145
- return pairs;
146
-
147
- function generatePairs() {
148
- return featuresA.reduce((acc, {
149
- name,
150
- value
151
- }, index) => acc.concat({
152
- name,
153
- a: value,
154
- b: featuresB[index].value
155
- }), []).filter(({
156
- a,
157
- b
158
- }) => {
159
- if (a.length === 0 || b.length === 0) {
160
- return false;
161
- }
162
-
163
- return true;
164
- });
165
- }
166
-
167
- function findMissing() {
168
- return featuresA.map(({
169
- name
170
- }) => name).filter(v => pairs.some(({
171
- name
172
- }) => name === v) === false);
173
- }
174
- }
175
- };
176
-
177
- exports.default = _default;
178
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/match-detection/index.js"],"names":["strategy","treshold","returnStrategy","recordA","recordB","minProbabilityQuantifier","debug","debugData","extend","JSON","stringify","featuresA","extractFeatures","featuresB","featurePairs","generateFeaturePairs","similarityVector","generateSimilarityVector","some","v","probability","calculateprobability","returnResult","match","result","resultWithStrategy","formatStrategy","strategyNames","map","element","name","reduce","acc","record","extract","concat","value","compared","a","b","compare","find","featureName","points","pairs","generatePairs","missingFeatures","findMissing","index","filter","length"],"mappings":";;;;;;;AA6BA;;AACA;;;;;;;;;;AA9BA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAOA;eACe,CAAC;AAACA,EAAAA,QAAD;AAAWC,EAAAA,QAAQ,GAAG;AAAtB,CAAD,EAA6BC,cAAc,GAAG,KAA9C,KAAwD,CAACC,OAAD,EAAUC,OAAV,KAAsB;AAC3F,QAAMC,wBAAwB,GAAG,GAAjC;AAEA,QAAMC,KAAK,GAAG,oBAAkB,mDAAlB,CAAd;AACA,QAAMC,SAAS,GAAGD,KAAK,CAACE,MAAN,CAAa,MAAb,CAAlB;AAEAD,EAAAA,SAAS,CAAE,aAAYE,IAAI,CAACC,SAAL,CAAeV,QAAf,CAAyB,EAAvC,CAAT;AACAO,EAAAA,SAAS,CAAE,aAAYE,IAAI,CAACC,SAAL,CAAeT,QAAf,CAAyB,EAAvC,CAAT;AACAM,EAAAA,SAAS,CAAE,mBAAkBE,IAAI,CAACC,SAAL,CAAeR,cAAf,CAA+B,EAAnD,CAAT;AAEA,QAAMS,SAAS,GAAGC,eAAe,CAACT,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,CAAyB,EAArC,CAAT;AACA,WAAOA,QAAQ,CAACT,GAAT,CAAa,CAAC;AAACe,MAAAA;AAAD,KAAD,KAAcA,MAA3B,CAAP;AACD;;AAED,WAAS5B,oBAAT,GAAgC;AAC9B,UAAM6B,KAAK,GAAGC,aAAa,EAA3B;AACA,UAAMC,eAAe,GAAGC,WAAW,EAAnC;AAEAzC,IAAAA,KAAK,CAAE,2FAA0FG,IAAI,CAACC,SAAL,CAAeoC,eAAf,CAAgC,EAA5H,CAAL;AACA,WAAOF,KAAP;;AAEA,aAASC,aAAT,GAAyB;AACvB,aAAOlC,SAAS,CACboB,MADI,CACG,CAACC,GAAD,EAAM;AAACF,QAAAA,IAAD;AAAOM,QAAAA;AAAP,OAAN,EAAqBY,KAArB,KAA+BhB,GAAG,CAACG,MAAJ,CAAW;AAChDL,QAAAA,IADgD;AAEhDQ,QAAAA,CAAC,EAAEF,KAF6C;AAGhDG,QAAAA,CAAC,EAAE1B,SAAS,CAACmC,KAAD,CAAT,CAAiBZ;AAH4B,OAAX,CADlC,EAKD,EALC,EAMJa,MANI,CAMG,CAAC;AAACX,QAAAA,CAAD;AAAIC,QAAAA;AAAJ,OAAD,KAAY;AAClB,YAAID,CAAC,CAACY,MAAF,KAAa,CAAb,IAAkBX,CAAC,CAACW,MAAF,KAAa,CAAnC,EAAsC;AACpC,iBAAO,KAAP;AACD;;AAED,eAAO,IAAP;AACD,OAZI,CAAP;AAaD;;AAED,aAASH,WAAT,GAAuB;AACrB,aAAOpC,SAAS,CACbiB,GADI,CACA,CAAC;AAACE,QAAAA;AAAD,OAAD,KAAYA,IADZ,EAEJmB,MAFI,CAEG9B,CAAC,IAAIyB,KAAK,CAAC1B,IAAN,CAAW,CAAC;AAACY,QAAAA;AAAD,OAAD,KAAYA,IAAI,KAAKX,CAAhC,MAAuC,KAF/C,CAAP;AAGD;AACF;AACF,C","sourcesContent":["/* eslint-disable no-console */\n/**\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 createDebugLogger from 'debug';\nimport * as features from './features';\n\nexport {features};\n\n// eslint-disable-next-line max-statements\nexport default ({strategy, treshold = 0.9}, returnStrategy = false) => (recordA, recordB) => {\n const minProbabilityQuantifier = 0.5;\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection');\n const debugData = debug.extend('data');\n\n debugData(`Strategy: ${JSON.stringify(strategy)}`);\n debugData(`Treshold: ${JSON.stringify(treshold)}`);\n debugData(`ReturnStrategy: ${JSON.stringify(returnStrategy)}`);\n\n const featuresA = extractFeatures(recordA);\n const featuresB = extractFeatures(recordB);\n\n debugData(`Features (a): ${JSON.stringify(featuresA)}`);\n debugData(`Features (b): ${JSON.stringify(featuresB)}`);\n\n const featurePairs = generateFeaturePairs();\n const similarityVector = generateSimilarityVector();\n\n if (similarityVector.some(v => v >= minProbabilityQuantifier)) {\n const probability = calculateprobability();\n debug(`probability: ${probability} (Treshold: ${treshold})`);\n return returnResult({match: probability >= treshold, probability});\n }\n\n debugData(`No feature yielded minimum probability amount of points (${minProbabilityQuantifier})`);\n return returnResult({match: false, probability: 0.0});\n\n function returnResult(result) {\n if (returnStrategy) {\n debug(`Returning detection strategy with the result`);\n const resultWithStrategy = {match: result.match, probability: result.probability, strategy: formatStrategy(strategy), treshold};\n debugData(`${JSON.stringify(resultWithStrategy)}`);\n return resultWithStrategy;\n }\n return result;\n }\n\n function formatStrategy(strategy) {\n const strategyNames = strategy.map(element => element.name);\n return strategyNames || [];\n }\n\n function calculateprobability() {\n const probability = similarityVector.reduce((acc, v) => acc + v, 0.0);\n return probability > 1.0 ? 1.0 : probability;\n }\n\n function extractFeatures(record) {\n return strategy.reduce((acc, {name, extract}) => acc.concat({name, value: extract(record)}), []);\n }\n\n function generateSimilarityVector() {\n const compared = featurePairs.map(({name, a, b}) => {\n const {compare} = strategy.find(({name: featureName}) => name === featureName);\n const points = compare(a, b);\n return {name, points};\n });\n\n debugData(`Points: ${JSON.stringify(compared)}`);\n return compared.map(({points}) => points);\n }\n\n function generateFeaturePairs() {\n const pairs = generatePairs();\n const missingFeatures = findMissing();\n\n debug(`Not comparing the following features because one, or both records are missing features: ${JSON.stringify(missingFeatures)}`);\n return pairs;\n\n function generatePairs() {\n return featuresA\n .reduce((acc, {name, value}, index) => acc.concat({\n name,\n a: value,\n b: featuresB[index].value\n }), [])\n .filter(({a, b}) => {\n if (a.length === 0 || b.length === 0) {\n return false;\n }\n\n return true;\n });\n }\n\n function findMissing() {\n return featuresA\n .map(({name}) => name)\n .filter(v => pairs.some(({name}) => name === v) === false);\n }\n }\n};\n"],"file":"index.js"}
@@ -1,81 +0,0 @@
1
- "use strict";
2
-
3
- var _fixugen = _interopRequireDefault(require("@natlibfi/fixugen"));
4
-
5
- var _fixura = require("@natlibfi/fixura");
6
-
7
- var _chai = require("chai");
8
-
9
- var _marcRecord = require("@natlibfi/marc-record");
10
-
11
- var features = _interopRequireWildcard(require("./features"));
12
-
13
- var _ = _interopRequireDefault(require("."));
14
-
15
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
16
-
17
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
18
-
19
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
-
21
- /**
22
- *
23
- * @licstart The following is the entire license notice for the JavaScript code in this file.
24
- *
25
- * Melinda record matching modules for Javascript
26
- *
27
- * Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
28
- *
29
- * This file is part of melinda-record-matching-js
30
- *
31
- * melinda-record-matching-js program is free software: you can redistribute it and/or modify
32
- * it under the terms of the GNU Lesser General Public License as
33
- * published by the Free Software Foundation, either version 3 of the
34
- * License, or (at your option) any later version.
35
- *
36
- * melinda-record-matching-js is distributed in the hope that it will be useful,
37
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
38
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39
- * GNU Lesser General Public License for more details.
40
- *
41
- * You should have received a copy of the GNU Affero General Public License
42
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
43
- *
44
- * @licend The above is the entire license notice
45
- * for the JavaScript code in this file.
46
- *
47
- */
48
- describe('match-detection', () => {
49
- (0, _fixugen.default)({
50
- path: [__dirname, '..', '..', 'test-fixtures', 'match-detection', 'index'],
51
- useMetadataFile: true,
52
- recurse: false,
53
- fixura: {
54
- reader: _fixura.READERS.JSON
55
- },
56
- callback: ({
57
- getFixture,
58
- options,
59
- expectedResults,
60
- enabled = true
61
- }) => {
62
- if (!enabled) {
63
- return;
64
- }
65
-
66
- const detect = (0, _.default)(formatOptions());
67
- const recordA = new _marcRecord.MarcRecord(getFixture('recordA.json'));
68
- const recordB = new _marcRecord.MarcRecord(getFixture('recordB.json'));
69
- const results = detect(recordA, recordB);
70
- (0, _chai.expect)(results).to.eql(expectedResults);
71
-
72
- function formatOptions() {
73
- const contextFeatures = features[options.strategy.type];
74
- return { ...options,
75
- strategy: options.strategy.features.map(v => contextFeatures[v]())
76
- };
77
- }
78
- }
79
- });
80
- });
81
- //# sourceMappingURL=index.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/match-detection/index.spec.js"],"names":["describe","path","__dirname","useMetadataFile","recurse","fixura","reader","READERS","JSON","callback","getFixture","options","expectedResults","enabled","detect","formatOptions","recordA","MarcRecord","recordB","results","to","eql","contextFeatures","features","strategy","type","map","v"],"mappings":";;AA4BA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAjCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AASAA,QAAQ,CAAC,iBAAD,EAAoB,MAAM;AAChC,wBAAc;AACZC,IAAAA,IAAI,EAAE,CAACC,SAAD,EAAY,IAAZ,EAAkB,IAAlB,EAAwB,eAAxB,EAAyC,iBAAzC,EAA4D,OAA5D,CADM;AAEZC,IAAAA,eAAe,EAAE,IAFL;AAGZC,IAAAA,OAAO,EAAE,KAHG;AAIZC,IAAAA,MAAM,EAAE;AACNC,MAAAA,MAAM,EAAEC,gBAAQC;AADV,KAJI;AAOZC,IAAAA,QAAQ,EAAE,CAAC;AAACC,MAAAA,UAAD;AAAaC,MAAAA,OAAb;AAAsBC,MAAAA,eAAtB;AAAuCC,MAAAA,OAAO,GAAG;AAAjD,KAAD,KAA4D;AAEpE,UAAI,CAACA,OAAL,EAAc;AACZ;AACD;;AAED,YAAMC,MAAM,GAAG,eAAyBC,aAAa,EAAtC,CAAf;AACA,YAAMC,OAAO,GAAG,IAAIC,sBAAJ,CAAeP,UAAU,CAAC,cAAD,CAAzB,CAAhB;AACA,YAAMQ,OAAO,GAAG,IAAID,sBAAJ,CAAeP,UAAU,CAAC,cAAD,CAAzB,CAAhB;AACA,YAAMS,OAAO,GAAGL,MAAM,CAACE,OAAD,EAAUE,OAAV,CAAtB;AAEA,wBAAOC,OAAP,EAAgBC,EAAhB,CAAmBC,GAAnB,CAAuBT,eAAvB;;AAEA,eAASG,aAAT,GAAyB;AACvB,cAAMO,eAAe,GAAGC,QAAQ,CAACZ,OAAO,CAACa,QAAR,CAAiBC,IAAlB,CAAhC;AAEA,eAAO,EACL,GAAGd,OADE;AAELa,UAAAA,QAAQ,EAAEb,OAAO,CAACa,QAAR,CAAiBD,QAAjB,CAA0BG,GAA1B,CAA8BC,CAAC,IAAIL,eAAe,CAACK,CAAD,CAAf,EAAnC;AAFL,SAAP;AAID;AACF;AA5BW,GAAd;AA8BD,CA/BO,CAAR","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 features from './features';\nimport createDetectionInterface from '.';\n\ndescribe('match-detection', () => {\n generateTests({\n path: [__dirname, '..', '..', 'test-fixtures', 'match-detection', 'index'],\n useMetadataFile: true,\n recurse: false,\n fixura: {\n reader: READERS.JSON\n },\n callback: ({getFixture, options, expectedResults, enabled = true}) => {\n\n if (!enabled) {\n return;\n }\n\n const detect = createDetectionInterface(formatOptions());\n const recordA = new MarcRecord(getFixture('recordA.json'));\n const recordB = new MarcRecord(getFixture('recordB.json'));\n const results = detect(recordA, recordB);\n\n expect(results).to.eql(expectedResults);\n\n function formatOptions() {\n const contextFeatures = features[options.strategy.type];\n\n return {\n ...options,\n strategy: options.strategy.features.map(v => contextFeatures[v]())\n };\n }\n }\n });\n});\n"],"file":"index.spec.js"}