@natlibfi/melinda-record-matching 2.2.1-alpha.2 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/candidate-search/candidate-search-utils.js +3 -6
- package/dist/candidate-search/candidate-search-utils.js.map +1 -1
- package/dist/candidate-search/index.js +18 -33
- package/dist/candidate-search/index.js.map +1 -1
- package/dist/candidate-search/index.spec.js +17 -30
- package/dist/candidate-search/index.spec.js.map +1 -1
- package/dist/candidate-search/query-list/bib.js +27 -49
- package/dist/candidate-search/query-list/bib.js.map +1 -1
- package/dist/candidate-search/query-list/bib.spec.js +1 -10
- package/dist/candidate-search/query-list/bib.spec.js.map +1 -1
- package/dist/candidate-search/query-list/index.js +3 -9
- package/dist/candidate-search/query-list/index.js.map +1 -1
- package/dist/index.js +46 -65
- package/dist/index.js.map +1 -1
- package/dist/index.spec.js +13 -21
- package/dist/index.spec.js.map +1 -1
- package/dist/match-detection/features/bib/all-source-ids.js +10 -16
- package/dist/match-detection/features/bib/all-source-ids.js.map +1 -1
- package/dist/match-detection/features/bib/authors.js +2 -15
- package/dist/match-detection/features/bib/authors.js.map +1 -1
- package/dist/match-detection/features/bib/bibliographic-level.js +1 -4
- package/dist/match-detection/features/bib/bibliographic-level.js.map +1 -1
- package/dist/match-detection/features/bib/host-component.js +1 -4
- package/dist/match-detection/features/bib/host-component.js.map +1 -1
- package/dist/match-detection/features/bib/index.js +0 -13
- package/dist/match-detection/features/bib/index.js.map +1 -1
- package/dist/match-detection/features/bib/index.spec.js +1 -11
- package/dist/match-detection/features/bib/index.spec.js.map +1 -1
- package/dist/match-detection/features/bib/isbn.js +1 -6
- package/dist/match-detection/features/bib/isbn.js.map +1 -1
- package/dist/match-detection/features/bib/issn.js +1 -6
- package/dist/match-detection/features/bib/issn.js.map +1 -1
- package/dist/match-detection/features/bib/language.js +4 -19
- package/dist/match-detection/features/bib/language.js.map +1 -1
- package/dist/match-detection/features/bib/melinda-id.js +1 -6
- package/dist/match-detection/features/bib/melinda-id.js.map +1 -1
- package/dist/match-detection/features/bib/melinda-identifier-factory.js +2 -14
- package/dist/match-detection/features/bib/melinda-identifier-factory.js.map +1 -1
- package/dist/match-detection/features/bib/other-standard-identifier.js +1 -6
- package/dist/match-detection/features/bib/other-standard-identifier.js.map +1 -1
- package/dist/match-detection/features/bib/publication-time.js +0 -4
- package/dist/match-detection/features/bib/publication-time.js.map +1 -1
- package/dist/match-detection/features/bib/record-type.js +0 -2
- package/dist/match-detection/features/bib/record-type.js.map +1 -1
- package/dist/match-detection/features/bib/standard-identifier-factory.js +1 -16
- package/dist/match-detection/features/bib/standard-identifier-factory.js.map +1 -1
- package/dist/match-detection/features/bib/title.js +1 -18
- package/dist/match-detection/features/bib/title.js.map +1 -1
- package/dist/match-detection/features/index.js +0 -4
- package/dist/match-detection/features/index.js.map +1 -1
- package/dist/match-detection/index.js +0 -22
- package/dist/match-detection/index.js.map +1 -1
- package/dist/match-detection/index.spec.js +3 -14
- package/dist/match-detection/index.spec.js.map +1 -1
- package/dist/matching-utils.js +3 -12
- package/dist/matching-utils.js.map +1 -1
- package/package.json +17 -17
|
@@ -4,15 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _debug = _interopRequireDefault(require("debug"));
|
|
9
|
-
|
|
10
8
|
var _natural = require("natural");
|
|
11
|
-
|
|
12
9
|
var _matchingUtils = require("../../../matching-utils");
|
|
13
|
-
|
|
14
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
11
|
/**
|
|
17
12
|
*
|
|
18
13
|
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
@@ -39,23 +34,18 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
39
34
|
* @licend The above is the entire license notice
|
|
40
35
|
* for the JavaScript code in this file.
|
|
41
36
|
*
|
|
42
|
-
*/
|
|
43
|
-
var _default = ({
|
|
37
|
+
*/var _default = ({
|
|
44
38
|
treshold = 10
|
|
45
39
|
} = {}) => ({
|
|
46
40
|
name: 'Title',
|
|
47
41
|
extract: record => {
|
|
48
42
|
const title = getTitle();
|
|
49
|
-
|
|
50
43
|
if ((0, _matchingUtils.testStringOrNumber)(title)) {
|
|
51
44
|
return [String(title).replace(/[^\p{Letter}\p{Number}]/gu, '').toLowerCase()];
|
|
52
45
|
}
|
|
53
|
-
|
|
54
46
|
return [];
|
|
55
|
-
|
|
56
47
|
function getTitle() {
|
|
57
48
|
const [field] = record.get(/^245$/u);
|
|
58
|
-
|
|
59
49
|
if (field) {
|
|
60
50
|
return field.subfields.filter(({
|
|
61
51
|
code
|
|
@@ -63,33 +53,26 @@ var _default = ({
|
|
|
63
53
|
value
|
|
64
54
|
}) => (0, _matchingUtils.testStringOrNumber)(value) ? String(value) : '').join('');
|
|
65
55
|
}
|
|
66
|
-
|
|
67
56
|
return false;
|
|
68
57
|
}
|
|
69
58
|
},
|
|
70
59
|
compare: (a, b) => {
|
|
71
60
|
const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:match-detection:features/bib/title');
|
|
72
61
|
const distance = (0, _natural.LevenshteinDistance)(a[0], b[0]);
|
|
73
|
-
|
|
74
62
|
if (distance === 0) {
|
|
75
63
|
return 0.5;
|
|
76
64
|
}
|
|
77
|
-
|
|
78
65
|
const maxLength = getMaxLength();
|
|
79
66
|
const percentage = distance / maxLength * 100;
|
|
80
67
|
debug(`'${a}' vs '${b}': Max length = ${maxLength}, distance = ${distance}, percentage = ${percentage}`);
|
|
81
|
-
|
|
82
68
|
if (percentage <= treshold) {
|
|
83
69
|
return 0.3;
|
|
84
70
|
}
|
|
85
|
-
|
|
86
71
|
return -0.5;
|
|
87
|
-
|
|
88
72
|
function getMaxLength() {
|
|
89
73
|
return a[0].length > b[0].length ? a[0].length : b[0].length;
|
|
90
74
|
}
|
|
91
75
|
}
|
|
92
76
|
});
|
|
93
|
-
|
|
94
77
|
exports.default = _default;
|
|
95
78
|
//# sourceMappingURL=title.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"title.js","names":["treshold","name","extract","record","title","getTitle","testStringOrNumber","String","replace","toLowerCase","field","get","subfields","filter","code","includes","map","value","join","compare","a","b","debug","createDebugLogger","distance","leven","maxLength","getMaxLength","percentage","length"],"sources":["../../../../src/match-detection/features/bib/title.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 createDebugLogger from 'debug';\nimport {LevenshteinDistance as leven} from 'natural';\nimport {testStringOrNumber} from '../../../matching-utils';\n\nexport default ({treshold = 10} = {}) => ({\n name: 'Title',\n extract: record => {\n const title = getTitle();\n\n if (testStringOrNumber(title)) {\n return [String(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}) => testStringOrNumber(value) ? String(value) : '')\n .join('');\n }\n return false;\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"],"mappings":"
|
|
1
|
+
{"version":3,"file":"title.js","names":["treshold","name","extract","record","title","getTitle","testStringOrNumber","String","replace","toLowerCase","field","get","subfields","filter","code","includes","map","value","join","compare","a","b","debug","createDebugLogger","distance","leven","maxLength","getMaxLength","percentage","length"],"sources":["../../../../src/match-detection/features/bib/title.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 createDebugLogger from 'debug';\nimport {LevenshteinDistance as leven} from 'natural';\nimport {testStringOrNumber} from '../../../matching-utils';\n\nexport default ({treshold = 10} = {}) => ({\n name: 'Title',\n extract: record => {\n const title = getTitle();\n\n if (testStringOrNumber(title)) {\n return [String(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}) => testStringOrNumber(value) ? String(value) : '')\n .join('');\n }\n return false;\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"],"mappings":";;;;;;AA4BA;AACA;AACA;AAA2D;AA9B3D;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,EA1BA,eAgCe,CAAC;EAACA,QAAQ,GAAG;AAAE,CAAC,GAAG,CAAC,CAAC,MAAM;EACxCC,IAAI,EAAE,OAAO;EACbC,OAAO,EAAEC,MAAM,IAAI;IACjB,MAAMC,KAAK,GAAGC,QAAQ,EAAE;IAExB,IAAI,IAAAC,iCAAkB,EAACF,KAAK,CAAC,EAAE;MAC7B,OAAO,CAACG,MAAM,CAACH,KAAK,CAAC,CAACI,OAAO,CAAC,2BAA2B,EAAE,EAAE,CAAC,CAACC,WAAW,EAAE,CAAC;IAC/E;IAEA,OAAO,EAAE;IAET,SAASJ,QAAQ,GAAG;MAClB,MAAM,CAACK,KAAK,CAAC,GAAGP,MAAM,CAACQ,GAAG,CAAC,QAAQ,CAAC;MAEpC,IAAID,KAAK,EAAE;QACT,OAAOA,KAAK,CAACE,SAAS,CACnBC,MAAM,CAAC,CAAC;UAACC;QAAI,CAAC,KAAK,CAAC,GAAG,EAAE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|
|
9
|
-
|
|
10
8
|
exports.bib = bib;
|
|
11
|
-
|
|
12
9
|
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
10
|
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
11
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/match-detection/features/index.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 * as bib from './bib';\nexport {bib};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/match-detection/features/index.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 * as bib from './bib';\nexport {bib};\n"],"mappings":";;;;;;AA4BA;AAA6B;AAAA;AAAA"}
|
|
@@ -4,21 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.features = exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _debug = _interopRequireDefault(require("debug"));
|
|
9
|
-
|
|
10
8
|
var features = _interopRequireWildcard(require("./features"));
|
|
11
|
-
|
|
12
9
|
exports.features = features;
|
|
13
|
-
|
|
14
10
|
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
11
|
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
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
13
|
/* eslint-disable no-console */
|
|
21
|
-
|
|
22
14
|
/**
|
|
23
15
|
*
|
|
24
16
|
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
@@ -61,14 +53,12 @@ var _default = ({
|
|
|
61
53
|
const recordsB = Array.isArray(recordB) ? recordB : [recordB];
|
|
62
54
|
const detectionResults = recordsB.map(record => actualDetection(featuresA, record));
|
|
63
55
|
return Array.isArray(recordB) ? detectionResults : detectionResults[0];
|
|
64
|
-
|
|
65
56
|
function actualDetection(featuresA, record) {
|
|
66
57
|
const featuresB = extractFeatures(record);
|
|
67
58
|
debugData(`Features (a): ${JSON.stringify(featuresA)}`);
|
|
68
59
|
debugData(`Features (b): ${JSON.stringify(featuresB)}`);
|
|
69
60
|
const featurePairs = generateFeaturePairs(featuresA, featuresB);
|
|
70
61
|
const similarityVector = generateSimilarityVector(featurePairs);
|
|
71
|
-
|
|
72
62
|
if (similarityVector.some(v => v >= minProbabilityQuantifier)) {
|
|
73
63
|
const probability = calculateprobability(similarityVector);
|
|
74
64
|
debug(`probability: ${probability} (Treshold: ${treshold})`);
|
|
@@ -77,14 +67,12 @@ var _default = ({
|
|
|
77
67
|
probability
|
|
78
68
|
});
|
|
79
69
|
}
|
|
80
|
-
|
|
81
70
|
debugData(`No feature yielded minimum probability amount of points (${minProbabilityQuantifier})`);
|
|
82
71
|
return returnResult({
|
|
83
72
|
match: false,
|
|
84
73
|
probability: 0.0
|
|
85
74
|
});
|
|
86
75
|
}
|
|
87
|
-
|
|
88
76
|
function extractFeatures(record) {
|
|
89
77
|
return strategy.reduce((acc, {
|
|
90
78
|
name,
|
|
@@ -94,7 +82,6 @@ var _default = ({
|
|
|
94
82
|
value: extract(record)
|
|
95
83
|
}), []);
|
|
96
84
|
}
|
|
97
|
-
|
|
98
85
|
function returnResult(result) {
|
|
99
86
|
if (returnStrategy) {
|
|
100
87
|
debug(`Returning detection strategy with the result`);
|
|
@@ -107,20 +94,16 @@ var _default = ({
|
|
|
107
94
|
debugData(`${JSON.stringify(resultWithStrategy)}`);
|
|
108
95
|
return resultWithStrategy;
|
|
109
96
|
}
|
|
110
|
-
|
|
111
97
|
return result;
|
|
112
98
|
}
|
|
113
|
-
|
|
114
99
|
function formatStrategy(strategy) {
|
|
115
100
|
const strategyNames = strategy.map(element => element.name);
|
|
116
101
|
return strategyNames || [];
|
|
117
102
|
}
|
|
118
|
-
|
|
119
103
|
function calculateprobability(similarityVector) {
|
|
120
104
|
const probability = similarityVector.reduce((acc, v) => acc + v, 0.0);
|
|
121
105
|
return probability > 1.0 ? 1.0 : probability;
|
|
122
106
|
}
|
|
123
|
-
|
|
124
107
|
function generateSimilarityVector(featurePairs) {
|
|
125
108
|
const compared = featurePairs.map(({
|
|
126
109
|
name,
|
|
@@ -143,13 +126,11 @@ var _default = ({
|
|
|
143
126
|
points
|
|
144
127
|
}) => points);
|
|
145
128
|
}
|
|
146
|
-
|
|
147
129
|
function generateFeaturePairs(featuresA, featuresB) {
|
|
148
130
|
const pairs = generatePairs();
|
|
149
131
|
const missingFeatures = findMissing();
|
|
150
132
|
debug(`Not comparing the following features because one, or both records are missing features: ${JSON.stringify(missingFeatures)}`);
|
|
151
133
|
return pairs;
|
|
152
|
-
|
|
153
134
|
function generatePairs() {
|
|
154
135
|
return featuresA.reduce((acc, {
|
|
155
136
|
name,
|
|
@@ -165,11 +146,9 @@ var _default = ({
|
|
|
165
146
|
if (a.length === 0 || b.length === 0) {
|
|
166
147
|
return false;
|
|
167
148
|
}
|
|
168
|
-
|
|
169
149
|
return true;
|
|
170
150
|
});
|
|
171
151
|
}
|
|
172
|
-
|
|
173
152
|
function findMissing() {
|
|
174
153
|
return featuresA.map(({
|
|
175
154
|
name
|
|
@@ -179,6 +158,5 @@ var _default = ({
|
|
|
179
158
|
}
|
|
180
159
|
}
|
|
181
160
|
};
|
|
182
|
-
|
|
183
161
|
exports.default = _default;
|
|
184
162
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["strategy","treshold","returnStrategy","recordA","recordB","minProbabilityQuantifier","debug","createDebugLogger","debugData","extend","JSON","stringify","featuresA","extractFeatures","Array","isArray","recordsB","detectionResults","map","record","actualDetection","featuresB","featurePairs","generateFeaturePairs","similarityVector","generateSimilarityVector","some","v","probability","calculateprobability","returnResult","match","reduce","acc","name","extract","concat","value","result","resultWithStrategy","formatStrategy","strategyNames","element","compared","a","b","compare","find","featureName","points","pairs","generatePairs","missingFeatures","findMissing","index","filter","length"],"sources":["../../src/match-detection/index.js"],"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\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\n debug(`We got an array of records: ${Array.isArray(recordB)}`);\n const recordsB = Array.isArray(recordB) ? recordB : [recordB];\n const detectionResults = recordsB.map(record => actualDetection(featuresA, record));\n\n return Array.isArray(recordB) ? detectionResults : detectionResults[0];\n\n function actualDetection(featuresA, record) {\n\n const featuresB = extractFeatures(record);\n\n debugData(`Features (a): ${JSON.stringify(featuresA)}`);\n debugData(`Features (b): ${JSON.stringify(featuresB)}`);\n\n const featurePairs = generateFeaturePairs(featuresA, featuresB);\n const similarityVector = generateSimilarityVector(featurePairs);\n\n if (similarityVector.some(v => v >= minProbabilityQuantifier)) {\n const probability = calculateprobability(similarityVector);\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\n function extractFeatures(record) {\n return strategy.reduce((acc, {name, extract}) => acc.concat({name, value: extract(record)}), []);\n }\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(similarityVector) {\n const probability = similarityVector.reduce((acc, v) => acc + v, 0.0);\n return probability > 1.0 ? 1.0 : probability;\n }\n\n function generateSimilarityVector(featurePairs) {\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(featuresA, featuresB) {\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};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["strategy","treshold","returnStrategy","recordA","recordB","minProbabilityQuantifier","debug","createDebugLogger","debugData","extend","JSON","stringify","featuresA","extractFeatures","Array","isArray","recordsB","detectionResults","map","record","actualDetection","featuresB","featurePairs","generateFeaturePairs","similarityVector","generateSimilarityVector","some","v","probability","calculateprobability","returnResult","match","reduce","acc","name","extract","concat","value","result","resultWithStrategy","formatStrategy","strategyNames","element","compared","a","b","compare","find","featureName","points","pairs","generatePairs","missingFeatures","findMissing","index","filter","length"],"sources":["../../src/match-detection/index.js"],"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\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\n debug(`We got an array of records: ${Array.isArray(recordB)}`);\n const recordsB = Array.isArray(recordB) ? recordB : [recordB];\n const detectionResults = recordsB.map(record => actualDetection(featuresA, record));\n\n return Array.isArray(recordB) ? detectionResults : detectionResults[0];\n\n function actualDetection(featuresA, record) {\n\n const featuresB = extractFeatures(record);\n\n debugData(`Features (a): ${JSON.stringify(featuresA)}`);\n debugData(`Features (b): ${JSON.stringify(featuresB)}`);\n\n const featurePairs = generateFeaturePairs(featuresA, featuresB);\n const similarityVector = generateSimilarityVector(featurePairs);\n\n if (similarityVector.some(v => v >= minProbabilityQuantifier)) {\n const probability = calculateprobability(similarityVector);\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\n function extractFeatures(record) {\n return strategy.reduce((acc, {name, extract}) => acc.concat({name, value: extract(record)}), []);\n }\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(similarityVector) {\n const probability = similarityVector.reduce((acc, v) => acc + v, 0.0);\n return probability > 1.0 ? 1.0 : probability;\n }\n\n function generateSimilarityVector(featurePairs) {\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(featuresA, featuresB) {\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};\n"],"mappings":";;;;;;AA6BA;AACA;AAAuC;AAAA;AAAA;AAAA;AA9BvC;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;AA1BA,eAiCe,CAAC;EAACA,QAAQ;EAAEC,QAAQ,GAAG;AAAG,CAAC,EAAEC,cAAc,GAAG,KAAK,KAAK,CAACC,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KAAK,KAAKrB,GAAG,CAACG,MAAM,CAAC;QAChDF,IAAI;QACJU,CAAC,EAAEP,KAAK;QACRQ,CAAC,EAAExB,SAAS,CAACiC,KAAK,CAAC,CAACjB;MACtB,CAAC,CAAC,EAAE,EAAE,CAAC,CACNkB,MAAM,CAAC,CAAC;QAACX,CAAC;QAAEC;MAAC,CAAC,KAAK;QAClB,IAAID,CAAC,CAACY,MAAM,KAAK,CAAC,IAAIX,CAAC,CAACW,MAAM,KAAK,CAAC,EAAE;UACpC,OAAO,KAAK;QACd;QAEA,OAAO,IAAI;MACb,CAAC,CAAC;IACN;IAEA,SAASH,WAAW,GAAG;MACrB,OAAOzC,SAAS,CACbM,GAAG,CAAC,CAAC;QAACgB;MAAI,CAAC,KAAKA,IAAI,CAAC,CACrBqB,MAAM,CAAC5B,CAAC,IAAIuB,KAAK,CAACxB,IAAI,CAAC,CAAC;QAACQ;MAAI,CAAC,KAAKA,IAAI,KAAKP,CAAC,CAAC,KAAK,KAAK,CAAC;IAC9D;EACF;AAEF,CAAC;AAAA"}
|
|
@@ -1,27 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _fixugen = _interopRequireDefault(require("@natlibfi/fixugen"));
|
|
4
|
-
|
|
5
4
|
var _fixura = require("@natlibfi/fixura");
|
|
6
|
-
|
|
7
5
|
var _chai = require("chai");
|
|
8
|
-
|
|
9
6
|
var _marcRecord = require("@natlibfi/marc-record");
|
|
10
|
-
|
|
11
7
|
var features = _interopRequireWildcard(require("./features"));
|
|
12
|
-
|
|
13
8
|
var _ = _interopRequireDefault(require("."));
|
|
14
|
-
|
|
15
9
|
var _util = require("util");
|
|
16
|
-
|
|
17
10
|
var _debug = _interopRequireDefault(require("debug"));
|
|
18
|
-
|
|
19
11
|
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); }
|
|
20
|
-
|
|
21
12
|
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; }
|
|
22
|
-
|
|
23
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
24
|
-
|
|
25
14
|
/**
|
|
26
15
|
*
|
|
27
16
|
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
@@ -49,6 +38,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
49
38
|
* for the JavaScript code in this file.
|
|
50
39
|
*
|
|
51
40
|
*/
|
|
41
|
+
|
|
52
42
|
const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:match-detection:test');
|
|
53
43
|
const debugData = debug.extend('data');
|
|
54
44
|
describe('match-detection', () => {
|
|
@@ -70,7 +60,6 @@ describe('match-detection', () => {
|
|
|
70
60
|
debug(`*** DISABLED TEST! ***`);
|
|
71
61
|
return;
|
|
72
62
|
}
|
|
73
|
-
|
|
74
63
|
const detect = (0, _.default)(formatOptions());
|
|
75
64
|
const recordA = new _marcRecord.MarcRecord(getFixture('recordA.json'), {
|
|
76
65
|
subfieldValues: false
|
|
@@ -86,10 +75,10 @@ describe('match-detection', () => {
|
|
|
86
75
|
const results = detect(recordA, recordB);
|
|
87
76
|
debugData(`${JSON.stringify(results)}`);
|
|
88
77
|
(0, _chai.expect)(results).to.eql(expectedResults);
|
|
89
|
-
|
|
90
78
|
function formatOptions() {
|
|
91
79
|
const contextFeatures = features[options.strategy.type];
|
|
92
|
-
return {
|
|
80
|
+
return {
|
|
81
|
+
...options,
|
|
93
82
|
strategy: options.strategy.features.map(v => contextFeatures[v]())
|
|
94
83
|
};
|
|
95
84
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.spec.js","names":["debug","createDebugLogger","debugData","extend","describe","generateTests","path","__dirname","useMetadataFile","recurse","fixura","reader","READERS","JSON","callback","getFixture","options","expectedResults","array","enabled","detect","createDetectionInterface","formatOptions","recordA","MarcRecord","subfieldValues","inspect","recordB","map","recordJson","results","stringify","expect","to","eql","contextFeatures","features","strategy","type","v"],"sources":["../../src/match-detection/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 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 '.';\nimport {inspect} from 'util';\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:test');\nconst debugData = debug.extend('data');\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, array, enabled = true}) => {\n\n if (!enabled) {\n debug(`*** DISABLED TEST! ***`);\n return;\n }\n\n const detect = createDetectionInterface(formatOptions());\n const recordA = new MarcRecord(getFixture('recordA.json'), {subfieldValues: false});\n debugData(inspect(recordA));\n\n debug(`Our recordB is an array of records: ${array}`);\n const recordB = array\n ? getFixture('recordB.json').map(recordJson => new MarcRecord(recordJson, {subfieldValues: false}))\n : new MarcRecord(getFixture('recordB.json'), {subfieldValues: false});\n debugData(inspect(recordB));\n\n const results = detect(recordA, recordB);\n debugData(`${JSON.stringify(results)}`);\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"],"mappings":";;AA4BA
|
|
1
|
+
{"version":3,"file":"index.spec.js","names":["debug","createDebugLogger","debugData","extend","describe","generateTests","path","__dirname","useMetadataFile","recurse","fixura","reader","READERS","JSON","callback","getFixture","options","expectedResults","array","enabled","detect","createDetectionInterface","formatOptions","recordA","MarcRecord","subfieldValues","inspect","recordB","map","recordJson","results","stringify","expect","to","eql","contextFeatures","features","strategy","type","v"],"sources":["../../src/match-detection/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 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 '.';\nimport {inspect} from 'util';\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:test');\nconst debugData = debug.extend('data');\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, array, enabled = true}) => {\n\n if (!enabled) {\n debug(`*** DISABLED TEST! ***`);\n return;\n }\n\n const detect = createDetectionInterface(formatOptions());\n const recordA = new MarcRecord(getFixture('recordA.json'), {subfieldValues: false});\n debugData(inspect(recordA));\n\n debug(`Our recordB is an array of records: ${array}`);\n const recordB = array\n ? getFixture('recordB.json').map(recordJson => new MarcRecord(recordJson, {subfieldValues: false}))\n : new MarcRecord(getFixture('recordB.json'), {subfieldValues: false});\n debugData(inspect(recordB));\n\n const results = detect(recordA, recordB);\n debugData(`${JSON.stringify(results)}`);\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"],"mappings":";;AA4BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAsC;AAAA;AAAA;AAnCtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A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C,IAAAwB,aAAO,EAACC,OAAO,CAAC,CAAC;MAE3B,MAAMG,OAAO,GAAGV,MAAM,CAACG,OAAO,EAAEI,OAAO,CAAC;MACxCzB,SAAS,CAAE,GAAEW,IAAI,CAACkB,SAAS,CAACD,OAAO,CAAE,EAAC,CAAC;MAEvC,IAAAE,YAAM,EAACF,OAAO,CAAC,CAACG,EAAE,CAACC,GAAG,CAACjB,eAAe,CAAC;MAEvC,SAASK,aAAa,GAAG;QACvB,MAAMa,eAAe,GAAGC,QAAQ,CAACpB,OAAO,CAACqB,QAAQ,CAACC,IAAI,CAAC;QAEvD,OAAO;UACL,GAAGtB,OAAO;UACVqB,QAAQ,EAAErB,OAAO,CAACqB,QAAQ,CAACD,QAAQ,CAACR,GAAG,CAACW,CAAC,IAAIJ,eAAe,CAACI,CAAC,CAAC,EAAE;QACnE,CAAC;MACH;IACF;EACF,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/matching-utils.js
CHANGED
|
@@ -7,11 +7,8 @@ exports.getMelindaIdsF035 = getMelindaIdsF035;
|
|
|
7
7
|
exports.getSubfieldValues = getSubfieldValues;
|
|
8
8
|
exports.testStringOrNumber = testStringOrNumber;
|
|
9
9
|
exports.validateSidFieldSubfieldCounts = validateSidFieldSubfieldCounts;
|
|
10
|
-
|
|
11
10
|
var _debug = _interopRequireDefault(require("debug"));
|
|
12
|
-
|
|
13
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
12
|
/**
|
|
16
13
|
*
|
|
17
14
|
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
@@ -39,26 +36,25 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
39
36
|
* for the JavaScript code in this file.
|
|
40
37
|
*
|
|
41
38
|
*/
|
|
39
|
+
|
|
42
40
|
const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:utils');
|
|
43
|
-
const debugData = debug.extend('data');
|
|
41
|
+
const debugData = debug.extend('data');
|
|
44
42
|
|
|
43
|
+
// eslint-disable-next-line max-statements
|
|
45
44
|
function getMelindaIdsF035(record) {
|
|
46
45
|
const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:melinda-id');
|
|
47
46
|
const debugData = debug.extend('data');
|
|
48
47
|
const f035s = record.getFields('035');
|
|
49
|
-
|
|
50
48
|
if (f035s.length < 1) {
|
|
51
49
|
debug(`No f035s found.`);
|
|
52
50
|
return [];
|
|
53
51
|
}
|
|
54
|
-
|
|
55
52
|
const allF035MelindaIds = [].concat(...f035s.map(toMelindaIds));
|
|
56
53
|
const f035MelindaIds = [...new Set(allF035MelindaIds)];
|
|
57
54
|
debugData(`Fields (${f035s.length}): ${JSON.stringify(f035s)}`);
|
|
58
55
|
debugData(`Ids (${allF035MelindaIds.length}): ${JSON.stringify(allF035MelindaIds)}`);
|
|
59
56
|
debugData(`Unique ids (${f035MelindaIds.length}): ${JSON.stringify(f035MelindaIds)}`);
|
|
60
57
|
return f035MelindaIds;
|
|
61
|
-
|
|
62
58
|
function toMelindaIds({
|
|
63
59
|
subfields
|
|
64
60
|
}) {
|
|
@@ -68,7 +64,6 @@ function getMelindaIdsF035(record) {
|
|
|
68
64
|
}) => testStringOrNumber(value) ? String(value).replace(melindaIdRegExp, '$<id>') : '');
|
|
69
65
|
}
|
|
70
66
|
}
|
|
71
|
-
|
|
72
67
|
function validateSidFieldSubfieldCounts(field) {
|
|
73
68
|
// Valid SID-fields have just one $c and one $b
|
|
74
69
|
debugData(`Validating SID field ${JSON.stringify(field)}`);
|
|
@@ -77,14 +72,12 @@ function validateSidFieldSubfieldCounts(field) {
|
|
|
77
72
|
debug(`Found ${countC} sf $cs and ${countB} sf $bs. IsValid: ${countC === 1 && countB === 1}`);
|
|
78
73
|
return countC === 1 && countB === 1;
|
|
79
74
|
}
|
|
80
|
-
|
|
81
75
|
function countSubfields(field, subfieldCode) {
|
|
82
76
|
// debug(`Counting subfields ${subfieldCode}`);
|
|
83
77
|
return field.subfields.filter(({
|
|
84
78
|
code
|
|
85
79
|
}) => code === subfieldCode).length;
|
|
86
80
|
}
|
|
87
|
-
|
|
88
81
|
function getSubfieldValues(field, subfieldCode) {
|
|
89
82
|
debugData(`Get subfield(s) $${subfieldCode} from ${JSON.stringify(field)}`);
|
|
90
83
|
return field.subfields.filter(({
|
|
@@ -93,12 +86,10 @@ function getSubfieldValues(field, subfieldCode) {
|
|
|
93
86
|
value
|
|
94
87
|
}) => testStringOrNumber(value) ? String(value) : '').filter(value => value);
|
|
95
88
|
}
|
|
96
|
-
|
|
97
89
|
function testStringOrNumber(value) {
|
|
98
90
|
if (typeof value === 'string' || typeof value === 'number') {
|
|
99
91
|
return true;
|
|
100
92
|
}
|
|
101
|
-
|
|
102
93
|
return false;
|
|
103
94
|
}
|
|
104
95
|
//# sourceMappingURL=matching-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matching-utils.js","names":["debug","createDebugLogger","debugData","extend","getMelindaIdsF035","record","f035s","getFields","length","allF035MelindaIds","concat","map","toMelindaIds","f035MelindaIds","Set","JSON","stringify","subfields","melindaIdRegExp","filter","sub","includes","code","testStringOrNumber","value","test","String","replace","validateSidFieldSubfieldCounts","field","countC","countSubfields","countB","subfieldCode","getSubfieldValues"],"sources":["../src/matching-utils.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 createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:utils');\nconst debugData = debug.extend('data');\n\n// eslint-disable-next-line max-statements\nexport function getMelindaIdsF035(record) {\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:melinda-id');\n const debugData = debug.extend('data');\n\n const f035s = record.getFields('035');\n\n if (f035s.length < 1) {\n debug(`No f035s found.`);\n return [];\n }\n\n const allF035MelindaIds = [].concat(...f035s.map(toMelindaIds));\n const f035MelindaIds = [...new Set(allF035MelindaIds)];\n\n debugData(`Fields (${f035s.length}): ${JSON.stringify(f035s)}`);\n debugData(`Ids (${allF035MelindaIds.length}): ${JSON.stringify(allF035MelindaIds)}`);\n debugData(`Unique ids (${f035MelindaIds.length}): ${JSON.stringify(f035MelindaIds)}`);\n\n return f035MelindaIds;\n\n function toMelindaIds({subfields}) {\n const melindaIdRegExp = /^(?<prefix>\\(FI-MELINDA\\)|FCC)(?<id>\\d{9})$/u;\n\n return subfields\n .filter(sub => ['a', 'z'].includes(sub.code))\n .filter(sub => testStringOrNumber(sub.value) && melindaIdRegExp.test(String(sub.value)))\n .map(({value}) => testStringOrNumber(value) ? String(value).replace(melindaIdRegExp, '$<id>') : '');\n\n }\n}\n\nexport function validateSidFieldSubfieldCounts(field) {\n // Valid SID-fields have just one $c and one $b\n debugData(`Validating SID field ${JSON.stringify(field)}`);\n const countC = countSubfields(field, 'c');\n const countB = countSubfields(field, 'b');\n debug(`Found ${countC} sf $cs and ${countB} sf $bs. IsValid: ${countC === 1 && countB === 1}`);\n\n return countC === 1 && countB === 1;\n}\n\nfunction countSubfields(field, subfieldCode) {\n // debug(`Counting subfields ${subfieldCode}`);\n return field.subfields.filter(({code}) => code === subfieldCode).length;\n}\n\nexport function getSubfieldValues(field, subfieldCode) {\n debugData(`Get subfield(s) $${subfieldCode} from ${JSON.stringify(field)}`);\n return field.subfields\n .filter(({code}) => code === subfieldCode)\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .filter(value => value);\n}\n\nexport function testStringOrNumber(value) {\n if (typeof value === 'string' || typeof value === 'number') {\n return true;\n }\n return false;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"matching-utils.js","names":["debug","createDebugLogger","debugData","extend","getMelindaIdsF035","record","f035s","getFields","length","allF035MelindaIds","concat","map","toMelindaIds","f035MelindaIds","Set","JSON","stringify","subfields","melindaIdRegExp","filter","sub","includes","code","testStringOrNumber","value","test","String","replace","validateSidFieldSubfieldCounts","field","countC","countSubfields","countB","subfieldCode","getSubfieldValues"],"sources":["../src/matching-utils.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 createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:utils');\nconst debugData = debug.extend('data');\n\n// eslint-disable-next-line max-statements\nexport function getMelindaIdsF035(record) {\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:melinda-id');\n const debugData = debug.extend('data');\n\n const f035s = record.getFields('035');\n\n if (f035s.length < 1) {\n debug(`No f035s found.`);\n return [];\n }\n\n const allF035MelindaIds = [].concat(...f035s.map(toMelindaIds));\n const f035MelindaIds = [...new Set(allF035MelindaIds)];\n\n debugData(`Fields (${f035s.length}): ${JSON.stringify(f035s)}`);\n debugData(`Ids (${allF035MelindaIds.length}): ${JSON.stringify(allF035MelindaIds)}`);\n debugData(`Unique ids (${f035MelindaIds.length}): ${JSON.stringify(f035MelindaIds)}`);\n\n return f035MelindaIds;\n\n function toMelindaIds({subfields}) {\n const melindaIdRegExp = /^(?<prefix>\\(FI-MELINDA\\)|FCC)(?<id>\\d{9})$/u;\n\n return subfields\n .filter(sub => ['a', 'z'].includes(sub.code))\n .filter(sub => testStringOrNumber(sub.value) && melindaIdRegExp.test(String(sub.value)))\n .map(({value}) => testStringOrNumber(value) ? String(value).replace(melindaIdRegExp, '$<id>') : '');\n\n }\n}\n\nexport function validateSidFieldSubfieldCounts(field) {\n // Valid SID-fields have just one $c and one $b\n debugData(`Validating SID field ${JSON.stringify(field)}`);\n const countC = countSubfields(field, 'c');\n const countB = countSubfields(field, 'b');\n debug(`Found ${countC} sf $cs and ${countB} sf $bs. IsValid: ${countC === 1 && countB === 1}`);\n\n return countC === 1 && countB === 1;\n}\n\nfunction countSubfields(field, subfieldCode) {\n // debug(`Counting subfields ${subfieldCode}`);\n return field.subfields.filter(({code}) => code === subfieldCode).length;\n}\n\nexport function getSubfieldValues(field, subfieldCode) {\n debugData(`Get subfield(s) $${subfieldCode} from ${JSON.stringify(field)}`);\n return field.subfields\n .filter(({code}) => code === subfieldCode)\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .filter(value => value);\n}\n\nexport function testStringOrNumber(value) {\n if (typeof value === 'string' || typeof value === 'number') {\n return true;\n }\n return false;\n}\n"],"mappings":";;;;;;;;;AA4BA;AAAsC;AA5BtC;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;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AAGE,MAAM,CAACF,KAAK,CAAC,GAAG,EAAE,CAAC,CAChEL,MAAM,CAACK,KAAK,IAAIA,KAAK,CAAC;AAC3B;AAEO,SAASD,kBAAkB,CAACC,KAAK,EAAE;EACxC,IAAI,OAAOA,KAAK,KAAK,QAAQ,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IAC1D,OAAO,IAAI;EACb;EACA,OAAO,KAAK;AACd"}
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"url": "git@github.com:natlibfi/melinda-record-matching-js.git"
|
|
15
15
|
},
|
|
16
16
|
"license": "LGPL-3.0+",
|
|
17
|
-
"version": "2.2.1
|
|
17
|
+
"version": "2.2.1",
|
|
18
18
|
"main": "./dist/index.js",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=14"
|
|
@@ -36,35 +36,35 @@
|
|
|
36
36
|
"watch:test": "cross-env DEBUG=1 NODE_ENV=test nodemon -w src -w test-fixtures --exec 'npm run test:dev'"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@natlibfi/marc-record": "^7.
|
|
40
|
-
"@natlibfi/marc-record-serializers": "^
|
|
41
|
-
"@natlibfi/melinda-commons": "^12.0.
|
|
42
|
-
"@natlibfi/sru-client": "^5.0.
|
|
39
|
+
"@natlibfi/marc-record": "^7.2.1",
|
|
40
|
+
"@natlibfi/marc-record-serializers": "^9.0.0",
|
|
41
|
+
"@natlibfi/melinda-commons": "^12.0.4",
|
|
42
|
+
"@natlibfi/sru-client": "^5.0.3",
|
|
43
43
|
"debug": "^4.3.4",
|
|
44
44
|
"moment": "^2.29.4",
|
|
45
45
|
"natural": "^5.2.3",
|
|
46
|
-
"uuid": "^
|
|
47
|
-
"winston": "^3.8.
|
|
46
|
+
"uuid": "^9.0.0",
|
|
47
|
+
"winston": "^3.8.2"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@babel/cli": "^7.
|
|
51
|
-
"@babel/core": "^7.
|
|
52
|
-
"@babel/eslint-parser": "^7.
|
|
53
|
-
"@babel/node": "^7.
|
|
54
|
-
"@babel/preset-env": "^7.
|
|
50
|
+
"@babel/cli": "^7.19.3",
|
|
51
|
+
"@babel/core": "^7.19.3",
|
|
52
|
+
"@babel/eslint-parser": "^7.19.1",
|
|
53
|
+
"@babel/node": "^7.19.1",
|
|
54
|
+
"@babel/preset-env": "^7.19.4",
|
|
55
55
|
"@babel/register": "^7.18.9",
|
|
56
|
-
"@natlibfi/eslint-config-melinda-backend": "^2.0.
|
|
56
|
+
"@natlibfi/eslint-config-melinda-backend": "^2.0.1",
|
|
57
57
|
"@natlibfi/fixugen": "^1.1.0",
|
|
58
58
|
"@natlibfi/fixugen-http-client": "^2.0.1",
|
|
59
|
-
"@natlibfi/fixura": "^2.2.
|
|
59
|
+
"@natlibfi/fixura": "^2.2.5",
|
|
60
60
|
"babel-plugin-istanbul": "^6.1.1",
|
|
61
61
|
"babel-plugin-rewire": "^1.2.0",
|
|
62
62
|
"chai": "^4.3.6",
|
|
63
63
|
"chai-as-promised": "^7.1.1",
|
|
64
64
|
"cross-env": "^7.0.3",
|
|
65
|
-
"eslint": "^8.
|
|
66
|
-
"mocha": "^
|
|
67
|
-
"nodemon": "^2.0.
|
|
65
|
+
"eslint": "^8.25.0",
|
|
66
|
+
"mocha": "^10.0.0",
|
|
67
|
+
"nodemon": "^2.0.20",
|
|
68
68
|
"nyc": "^15.1.0"
|
|
69
69
|
},
|
|
70
70
|
"eslintConfig": {
|