@natlibfi/melinda-record-matching 4.4.0-alpha.1 → 5.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/melinda-node-tests.yml +13 -9
- package/LICENSE.txt +21 -165
- package/README.md +2 -2
- package/eslint.config.js +52 -0
- package/example.env +4 -0
- package/package.json +29 -79
- package/src/candidate-search/candidate-search-utils.js +1 -28
- package/src/candidate-search/choose-queries.js +93 -0
- package/src/candidate-search/index.js +85 -119
- package/src/candidate-search/{index.spec.js → index.test.js} +30 -43
- package/src/candidate-search/query-list/bib.js +54 -55
- package/src/candidate-search/query-list/bib.test.js +38 -0
- package/src/candidate-search/query-list/component.js +127 -0
- package/src/candidate-search/query-list/index.js +31 -35
- package/src/cli.js +177 -0
- package/src/index.js +27 -68
- package/src/{index.spec.js → index.test.js} +11 -42
- package/src/match-detection/features/bib/all-source-ids.js +2 -29
- package/src/match-detection/features/bib/authors.js +5 -30
- package/src/match-detection/features/bib/bibliographic-level.js +0 -27
- package/src/match-detection/features/bib/host-component.js +0 -27
- package/src/match-detection/features/bib/index.js +16 -43
- package/src/match-detection/features/bib/index.test.js +52 -0
- package/src/match-detection/features/bib/isbn.js +2 -29
- package/src/match-detection/features/bib/issn.js +1 -28
- package/src/match-detection/features/bib/language.js +5 -32
- package/src/match-detection/features/bib/media-type.js +2 -28
- package/src/match-detection/features/bib/melinda-id.js +1 -28
- package/src/match-detection/features/bib/melinda-identifier-factory.js +5 -32
- package/src/match-detection/features/bib/other-standard-identifier.js +1 -28
- package/src/match-detection/features/bib/publication-time-allow-cons-years-multi.js +7 -34
- package/src/match-detection/features/bib/publication-time-allow-cons-years.js +1 -28
- package/src/match-detection/features/bib/publication-time.js +2 -28
- package/src/match-detection/features/bib/record-type.js +0 -27
- package/src/match-detection/features/bib/standard-identifier-factory.js +1 -28
- package/src/match-detection/features/bib/title-version-original.js +2 -28
- package/src/match-detection/features/bib/title.js +6 -34
- package/src/match-detection/features/index.js +1 -28
- package/src/match-detection/index.js +1 -28
- package/src/match-detection/{index.spec.js → index.test.js} +9 -35
- package/src/matching-utils.js +8 -37
- package/dist/candidate-search/candidate-search-utils.js +0 -55
- package/dist/candidate-search/candidate-search-utils.js.map +0 -1
- package/dist/candidate-search/index.js +0 -254
- package/dist/candidate-search/index.js.map +0 -1
- package/dist/candidate-search/index.spec.js +0 -144
- package/dist/candidate-search/index.spec.js.map +0 -1
- package/dist/candidate-search/query-list/bib.js +0 -439
- package/dist/candidate-search/query-list/bib.js.map +0 -1
- package/dist/candidate-search/query-list/bib.spec.js +0 -64
- package/dist/candidate-search/query-list/bib.spec.js.map +0 -1
- package/dist/candidate-search/query-list/index.js +0 -66
- package/dist/candidate-search/query-list/index.js.map +0 -1
- package/dist/index.js +0 -579
- package/dist/index.js.map +0 -1
- package/dist/index.spec.js +0 -127
- package/dist/index.spec.js.map +0 -1
- package/dist/match-detection/features/bib/all-source-ids.js +0 -119
- package/dist/match-detection/features/bib/all-source-ids.js.map +0 -1
- package/dist/match-detection/features/bib/authors.js +0 -113
- package/dist/match-detection/features/bib/authors.js.map +0 -1
- package/dist/match-detection/features/bib/bibliographic-level.js +0 -42
- package/dist/match-detection/features/bib/bibliographic-level.js.map +0 -1
- package/dist/match-detection/features/bib/host-component.js +0 -42
- package/dist/match-detection/features/bib/host-component.js.map +0 -1
- package/dist/match-detection/features/bib/index.js +0 -119
- package/dist/match-detection/features/bib/index.js.map +0 -1
- package/dist/match-detection/features/bib/index.spec.js +0 -93
- package/dist/match-detection/features/bib/index.spec.js.map +0 -1
- package/dist/match-detection/features/bib/isbn.js +0 -77
- package/dist/match-detection/features/bib/isbn.js.map +0 -1
- package/dist/match-detection/features/bib/issn.js +0 -51
- package/dist/match-detection/features/bib/issn.js.map +0 -1
- package/dist/match-detection/features/bib/language.js +0 -141
- package/dist/match-detection/features/bib/language.js.map +0 -1
- package/dist/match-detection/features/bib/media-type.js +0 -83
- package/dist/match-detection/features/bib/media-type.js.map +0 -1
- package/dist/match-detection/features/bib/melinda-id.js +0 -48
- package/dist/match-detection/features/bib/melinda-id.js.map +0 -1
- package/dist/match-detection/features/bib/melinda-identifier-factory.js +0 -89
- package/dist/match-detection/features/bib/melinda-identifier-factory.js.map +0 -1
- package/dist/match-detection/features/bib/other-standard-identifier.js +0 -52
- package/dist/match-detection/features/bib/other-standard-identifier.js.map +0 -1
- package/dist/match-detection/features/bib/publication-time-allow-cons-years-multi.js +0 -256
- package/dist/match-detection/features/bib/publication-time-allow-cons-years-multi.js.map +0 -1
- package/dist/match-detection/features/bib/publication-time-allow-cons-years.js +0 -71
- package/dist/match-detection/features/bib/publication-time-allow-cons-years.js.map +0 -1
- package/dist/match-detection/features/bib/publication-time.js +0 -48
- package/dist/match-detection/features/bib/publication-time.js.map +0 -1
- package/dist/match-detection/features/bib/record-type.js +0 -45
- package/dist/match-detection/features/bib/record-type.js.map +0 -1
- package/dist/match-detection/features/bib/standard-identifier-factory.js +0 -215
- package/dist/match-detection/features/bib/standard-identifier-factory.js.map +0 -1
- package/dist/match-detection/features/bib/title-version-original.js +0 -79
- package/dist/match-detection/features/bib/title-version-original.js.map +0 -1
- package/dist/match-detection/features/bib/title.js +0 -98
- package/dist/match-detection/features/bib/title.js.map +0 -1
- package/dist/match-detection/features/index.js +0 -11
- package/dist/match-detection/features/index.js.map +0 -1
- package/dist/match-detection/index.js +0 -201
- package/dist/match-detection/index.js.map +0 -1
- package/dist/match-detection/index.spec.js +0 -91
- package/dist/match-detection/index.spec.js.map +0 -1
- package/dist/matching-utils.js +0 -143
- package/dist/matching-utils.js.map +0 -1
- package/src/candidate-search/query-list/bib.spec.js +0 -54
- package/src/match-detection/features/bib/index.spec.js +0 -78
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.features = exports.default = void 0;
|
|
7
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
8
|
-
var features = _interopRequireWildcard(require("./features"));
|
|
9
|
-
exports.features = features;
|
|
10
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
11
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
/**
|
|
14
|
-
*
|
|
15
|
-
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
16
|
-
*
|
|
17
|
-
* Melinda record matching modules for Javascript
|
|
18
|
-
*
|
|
19
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
20
|
-
*
|
|
21
|
-
* This file is part of melinda-record-matching-js
|
|
22
|
-
*
|
|
23
|
-
* melinda-record-matching-js program is free software: you can redistribute it and/or modify
|
|
24
|
-
* it under the terms of the GNU Lesser General Public License as
|
|
25
|
-
* published by the Free Software Foundation, either version 3 of the
|
|
26
|
-
* License, or (at your option) any later version.
|
|
27
|
-
*
|
|
28
|
-
* melinda-record-matching-js is distributed in the hope that it will be useful,
|
|
29
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
30
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
31
|
-
* GNU Lesser General Public License for more details.
|
|
32
|
-
*
|
|
33
|
-
* You should have received a copy of the GNU Affero General Public License
|
|
34
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
35
|
-
*
|
|
36
|
-
* @licend The above is the entire license notice
|
|
37
|
-
* for the JavaScript code in this file.
|
|
38
|
-
*
|
|
39
|
-
*/
|
|
40
|
-
var _default = ({
|
|
41
|
-
strategy,
|
|
42
|
-
treshold = 0.9
|
|
43
|
-
}, returnStrategy = false, localSettings = {}) => ({
|
|
44
|
-
recordA,
|
|
45
|
-
recordB,
|
|
46
|
-
recordAExternal = {},
|
|
47
|
-
recordBExternal = {}
|
|
48
|
-
}) => {
|
|
49
|
-
const minProbabilityQuantifier = 0.5;
|
|
50
|
-
const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:match-detection');
|
|
51
|
-
const debugData = debug.extend('data');
|
|
52
|
-
debugData(`Strategy: ${JSON.stringify(strategy)}, Treshold: ${JSON.stringify(treshold)}, ReturnStrategy: ${JSON.stringify(returnStrategy)}`);
|
|
53
|
-
debugData(`Records: A: ${recordA}\nB: ${recordB}`);
|
|
54
|
-
debug(`Externals: A: ${JSON.stringify(recordAExternal)}, B: ${JSON.stringify(recordBExternal)}`);
|
|
55
|
-
// We could add here labels for records if we didn't get external labels
|
|
56
|
-
|
|
57
|
-
const featuresA = extractFeatures({
|
|
58
|
-
record: recordA,
|
|
59
|
-
recordExternal: recordAExternal,
|
|
60
|
-
localSettings
|
|
61
|
-
});
|
|
62
|
-
debug(`We got an array of records: ${Array.isArray(recordB)}`);
|
|
63
|
-
const recordsB = Array.isArray(recordB) ? recordB : [recordB];
|
|
64
|
-
const recordsBExternal = Array.isArray(recordB) ? recordBExternal : [recordBExternal];
|
|
65
|
-
const detectionResults = recordsB.map((record, index) => actualDetection({
|
|
66
|
-
featuresA,
|
|
67
|
-
recordAExternal,
|
|
68
|
-
record,
|
|
69
|
-
recordExternal: recordsBExternal[index],
|
|
70
|
-
index
|
|
71
|
-
}));
|
|
72
|
-
|
|
73
|
-
// if we got array of records, we return an array of result
|
|
74
|
-
// if we got a singular record, we return a singular result
|
|
75
|
-
return Array.isArray(recordB) ? detectionResults : detectionResults[0];
|
|
76
|
-
function actualDetection({
|
|
77
|
-
featuresA,
|
|
78
|
-
record,
|
|
79
|
-
recordExternal,
|
|
80
|
-
index,
|
|
81
|
-
localSettings
|
|
82
|
-
}) {
|
|
83
|
-
const labelA = recordAExternal && recordAExternal.label ? recordAExternal.label : 'a';
|
|
84
|
-
const labelB = recordExternal && recordExternal.label ? recordExternal.label : 'b';
|
|
85
|
-
debug(`Actual detection for record ${index + 1} ${labelB}`);
|
|
86
|
-
const featuresB = extractFeatures({
|
|
87
|
-
record,
|
|
88
|
-
recordExternal,
|
|
89
|
-
localSettings
|
|
90
|
-
});
|
|
91
|
-
debugData(`Features (a: ${labelA}): ${JSON.stringify(featuresA)}`);
|
|
92
|
-
debugData(`Features (b: ${labelB}): ${JSON.stringify(featuresB)}`);
|
|
93
|
-
const featurePairs = generateFeaturePairs(featuresA, featuresB);
|
|
94
|
-
const similarityVector = generateSimilarityVector(featurePairs);
|
|
95
|
-
if (similarityVector.some(v => v >= minProbabilityQuantifier)) {
|
|
96
|
-
const probability = calculateProbability(similarityVector);
|
|
97
|
-
debug(`probability: ${probability} (Treshold: ${treshold})`);
|
|
98
|
-
return returnResult({
|
|
99
|
-
match: probability >= treshold,
|
|
100
|
-
probability
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
debugData(`No feature yielded minimum probability amount of points (${minProbabilityQuantifier})`);
|
|
104
|
-
return returnResult({
|
|
105
|
-
match: false,
|
|
106
|
-
probability: 0.0
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
function extractFeatures({
|
|
110
|
-
record,
|
|
111
|
-
recordExternal
|
|
112
|
-
}) {
|
|
113
|
-
return strategy.reduce((acc, {
|
|
114
|
-
name,
|
|
115
|
-
extract
|
|
116
|
-
}) => acc.concat({
|
|
117
|
-
name,
|
|
118
|
-
value: extract({
|
|
119
|
-
record,
|
|
120
|
-
recordExternal
|
|
121
|
-
})
|
|
122
|
-
}), []);
|
|
123
|
-
}
|
|
124
|
-
function returnResult(result) {
|
|
125
|
-
if (returnStrategy) {
|
|
126
|
-
debug(`Returning detection strategy with the result`);
|
|
127
|
-
const resultWithStrategy = {
|
|
128
|
-
match: result.match,
|
|
129
|
-
probability: result.probability,
|
|
130
|
-
strategy: formatStrategy(strategy),
|
|
131
|
-
treshold
|
|
132
|
-
};
|
|
133
|
-
debugData(`${JSON.stringify(resultWithStrategy)}`);
|
|
134
|
-
return resultWithStrategy;
|
|
135
|
-
}
|
|
136
|
-
return result;
|
|
137
|
-
}
|
|
138
|
-
function formatStrategy(strategy) {
|
|
139
|
-
const strategyNames = strategy.map(element => element.name);
|
|
140
|
-
return strategyNames || [];
|
|
141
|
-
}
|
|
142
|
-
function calculateProbability(similarityVector) {
|
|
143
|
-
const probability = similarityVector.reduce((acc, v) => acc + v, 0.0);
|
|
144
|
-
return probability > 1.0 ? 1.0 : probability;
|
|
145
|
-
}
|
|
146
|
-
function generateSimilarityVector(featurePairs) {
|
|
147
|
-
const compared = featurePairs.map(({
|
|
148
|
-
name,
|
|
149
|
-
a,
|
|
150
|
-
b
|
|
151
|
-
}) => {
|
|
152
|
-
const {
|
|
153
|
-
compare
|
|
154
|
-
} = strategy.find(({
|
|
155
|
-
name: featureName
|
|
156
|
-
}) => name === featureName);
|
|
157
|
-
const points = compare(a, b);
|
|
158
|
-
return {
|
|
159
|
-
name,
|
|
160
|
-
points
|
|
161
|
-
};
|
|
162
|
-
});
|
|
163
|
-
debugData(`Points: ${JSON.stringify(compared)}`);
|
|
164
|
-
return compared.map(({
|
|
165
|
-
points
|
|
166
|
-
}) => points);
|
|
167
|
-
}
|
|
168
|
-
function generateFeaturePairs(featuresA, featuresB) {
|
|
169
|
-
const pairs = generatePairs();
|
|
170
|
-
const missingFeatures = findMissing();
|
|
171
|
-
debug(`Not comparing the following features because one, or both records are missing features: ${JSON.stringify(missingFeatures)}`);
|
|
172
|
-
return pairs;
|
|
173
|
-
function generatePairs() {
|
|
174
|
-
return featuresA.reduce((acc, {
|
|
175
|
-
name,
|
|
176
|
-
value
|
|
177
|
-
}, index) => acc.concat({
|
|
178
|
-
name,
|
|
179
|
-
a: value,
|
|
180
|
-
b: featuresB[index].value
|
|
181
|
-
}), []).filter(({
|
|
182
|
-
a,
|
|
183
|
-
b
|
|
184
|
-
}) => {
|
|
185
|
-
if (a.length === 0 || b.length === 0) {
|
|
186
|
-
return false;
|
|
187
|
-
}
|
|
188
|
-
return true;
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
function findMissing() {
|
|
192
|
-
return featuresA.map(({
|
|
193
|
-
name
|
|
194
|
-
}) => name).filter(v => pairs.some(({
|
|
195
|
-
name
|
|
196
|
-
}) => name === v) === false);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
exports.default = _default;
|
|
201
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_debug","_interopRequireDefault","require","features","_interopRequireWildcard","exports","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","obj","_default","strategy","treshold","returnStrategy","localSettings","recordA","recordB","recordAExternal","recordBExternal","minProbabilityQuantifier","debug","createDebugLogger","debugData","extend","JSON","stringify","featuresA","extractFeatures","record","recordExternal","Array","isArray","recordsB","recordsBExternal","detectionResults","map","index","actualDetection","labelA","label","labelB","featuresB","featurePairs","generateFeaturePairs","similarityVector","generateSimilarityVector","some","v","probability","calculateProbability","returnResult","match","reduce","acc","name","extract","concat","value","result","resultWithStrategy","formatStrategy","strategyNames","element","compared","b","compare","find","featureName","points","pairs","generatePairs","missingFeatures","findMissing","filter","length"],"sources":["../../src/match-detection/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 createDebugLogger from 'debug';\nimport * as features from './features';\n\nexport {features};\n\nexport default ({strategy, treshold = 0.9}, returnStrategy = false, localSettings = {}) => ({recordA, recordB, recordAExternal = {}, recordBExternal = {}}) => {\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)}, Treshold: ${JSON.stringify(treshold)}, ReturnStrategy: ${JSON.stringify(returnStrategy)}`);\n debugData(`Records: A: ${recordA}\\nB: ${recordB}`);\n debug(`Externals: A: ${JSON.stringify(recordAExternal)}, B: ${JSON.stringify(recordBExternal)}`);\n // We could add here labels for records if we didn't get external labels\n\n const featuresA = extractFeatures({record: recordA, recordExternal: recordAExternal, localSettings});\n\n debug(`We got an array of records: ${Array.isArray(recordB)}`);\n const recordsB = Array.isArray(recordB) ? recordB : [recordB];\n const recordsBExternal = Array.isArray(recordB) ? recordBExternal : [recordBExternal];\n\n const detectionResults = recordsB.map((record, index) => actualDetection({featuresA, recordAExternal, record, recordExternal: recordsBExternal[index], index}));\n\n // if we got array of records, we return an array of result\n // if we got a singular record, we return a singular result\n return Array.isArray(recordB) ? detectionResults : detectionResults[0];\n\n function actualDetection({featuresA, record, recordExternal, index, localSettings}) {\n const labelA = recordAExternal && recordAExternal.label ? recordAExternal.label : 'a';\n const labelB = recordExternal && recordExternal.label ? recordExternal.label : 'b';\n\n\n debug(`Actual detection for record ${index + 1} ${labelB}`);\n const featuresB = extractFeatures({record, recordExternal, localSettings});\n\n debugData(`Features (a: ${labelA}): ${JSON.stringify(featuresA)}`);\n debugData(`Features (b: ${labelB}): ${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, recordExternal}) {\n return strategy.reduce((acc, {name, extract}) => acc.concat({name, value: extract({record, recordExternal})}), []);\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":";;;;;;AA4BA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAC,uBAAA,CAAAF,OAAA;AAAuCG,OAAA,CAAAF,QAAA,GAAAA,QAAA;AAAA,SAAAG,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAH,wBAAAG,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAjB,CAAA,EAAAc,CAAA,SAAAI,CAAA,GAAAR,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAI,CAAA,KAAAA,CAAA,CAAAX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
-
var _fixura = require("@natlibfi/fixura");
|
|
5
|
-
var _chai = require("chai");
|
|
6
|
-
var _marcRecord = require("@natlibfi/marc-record");
|
|
7
|
-
var features = _interopRequireWildcard(require("./features"));
|
|
8
|
-
var _ = _interopRequireDefault(require("."));
|
|
9
|
-
var _util = require("util");
|
|
10
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
11
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
12
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
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
|
-
|
|
42
|
-
const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:match-detection:test');
|
|
43
|
-
const debugData = debug.extend('data');
|
|
44
|
-
describe('match-detection', () => {
|
|
45
|
-
(0, _fixugen.default)({
|
|
46
|
-
path: [__dirname, '..', '..', 'test-fixtures', 'match-detection', 'index'],
|
|
47
|
-
useMetadataFile: true,
|
|
48
|
-
recurse: false,
|
|
49
|
-
fixura: {
|
|
50
|
-
reader: _fixura.READERS.JSON
|
|
51
|
-
},
|
|
52
|
-
callback: ({
|
|
53
|
-
getFixture,
|
|
54
|
-
options,
|
|
55
|
-
expectedResults,
|
|
56
|
-
array,
|
|
57
|
-
enabled = true
|
|
58
|
-
}) => {
|
|
59
|
-
if (!enabled) {
|
|
60
|
-
debug(`*** DISABLED TEST! ***`);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
const detect = (0, _.default)(formatOptions());
|
|
64
|
-
const recordA = new _marcRecord.MarcRecord(getFixture('recordA.json'), {
|
|
65
|
-
subfieldValues: false
|
|
66
|
-
});
|
|
67
|
-
debugData((0, _util.inspect)(recordA));
|
|
68
|
-
debug(`Our recordB is an array of records: ${array}`);
|
|
69
|
-
const recordB = array ? getFixture('recordB.json').map(recordJson => new _marcRecord.MarcRecord(recordJson, {
|
|
70
|
-
subfieldValues: false
|
|
71
|
-
})) : new _marcRecord.MarcRecord(getFixture('recordB.json'), {
|
|
72
|
-
subfieldValues: false
|
|
73
|
-
});
|
|
74
|
-
debugData((0, _util.inspect)(recordB));
|
|
75
|
-
const results = detect({
|
|
76
|
-
recordA,
|
|
77
|
-
recordB
|
|
78
|
-
});
|
|
79
|
-
debugData(`${JSON.stringify(results)}`);
|
|
80
|
-
(0, _chai.expect)(results).to.eql(expectedResults);
|
|
81
|
-
function formatOptions() {
|
|
82
|
-
const contextFeatures = features[options.strategy.type];
|
|
83
|
-
return {
|
|
84
|
-
...options,
|
|
85
|
-
strategy: options.strategy.features.map(v => contextFeatures[v]())
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
//# sourceMappingURL=index.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.spec.js","names":["_fixugen","_interopRequireDefault","require","_fixura","_chai","_marcRecord","features","_interopRequireWildcard","_","_util","_debug","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","obj","debug","createDebugLogger","debugData","extend","describe","generateTests","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","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,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAC,uBAAA,CAAAL,OAAA;AACA,IAAAM,CAAA,G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AAE;QAACJ,cAAc,EAAE;MAAK,CAAC,CAAC,CAAC,GACjG,IAAID,sBAAU,CAACT,UAAU,CAAC,cAAc,CAAC,EAAE;QAACU,cAAc,EAAE;MAAK,CAAC,CAAC;MACvEvB,SAAS,CAAC,IAAAwB,aAAO,EAACC,OAAO,CAAC,CAAC;MAE3B,MAAMG,OAAO,GAAGV,MAAM,CAAC;QAACG,OAAO;QAAEI;MAAO,CAAC,CAAC;MAC1CzB,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,aAAaA,CAAA,EAAG;QACvB,MAAMa,eAAe,GAAG9D,QAAQ,CAAC2C,OAAO,CAACoB,QAAQ,CAACC,IAAI,CAAC;QAEvD,OAAO;UACL,GAAGrB,OAAO;UACVoB,QAAQ,EAAEpB,OAAO,CAACoB,QAAQ,CAAC/D,QAAQ,CAACuD,GAAG,CAACU,CAAC,IAAIH,eAAe,CAACG,CAAC,CAAC,CAAC,CAAC;QACnE,CAAC;MACH;IACF;EACF,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/matching-utils.js
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.extractSubfieldsFromField = extractSubfieldsFromField;
|
|
7
|
-
exports.getMatchCounts = getMatchCounts;
|
|
8
|
-
exports.getMelindaIdsF035 = getMelindaIdsF035;
|
|
9
|
-
exports.getSubfieldValues = getSubfieldValues;
|
|
10
|
-
exports.testStringOrNumber = testStringOrNumber;
|
|
11
|
-
exports.uniqueSubfields = uniqueSubfields;
|
|
12
|
-
exports.validateSidFieldSubfieldCounts = validateSidFieldSubfieldCounts;
|
|
13
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
/**
|
|
16
|
-
*
|
|
17
|
-
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
18
|
-
*
|
|
19
|
-
* Melinda record matching modules for Javascript
|
|
20
|
-
*
|
|
21
|
-
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
22
|
-
*
|
|
23
|
-
* This file is part of melinda-record-matching-js
|
|
24
|
-
*
|
|
25
|
-
* melinda-record-matching-js program is free software: you can redistribute it and/or modify
|
|
26
|
-
* it under the terms of the GNU Lesser General Public License as
|
|
27
|
-
* published by the Free Software Foundation, either version 3 of the
|
|
28
|
-
* License, or (at your option) any later version.
|
|
29
|
-
*
|
|
30
|
-
* melinda-record-matching-js is distributed in the hope that it will be useful,
|
|
31
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
32
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
33
|
-
* GNU Lesser General Public License for more details.
|
|
34
|
-
*
|
|
35
|
-
* You should have received a copy of the GNU Affero General Public License
|
|
36
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
37
|
-
*
|
|
38
|
-
* @licend The above is the entire license notice
|
|
39
|
-
* for the JavaScript code in this file.
|
|
40
|
-
*
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:utils');
|
|
44
|
-
const debugData = debug.extend('data');
|
|
45
|
-
function getMelindaIdsF035(record) {
|
|
46
|
-
const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:melinda-id');
|
|
47
|
-
const debugData = debug.extend('data');
|
|
48
|
-
const f035s = record.getFields('035');
|
|
49
|
-
if (f035s.length < 1) {
|
|
50
|
-
debug(`No f035s found.`);
|
|
51
|
-
return [];
|
|
52
|
-
}
|
|
53
|
-
const allF035MelindaIds = [].concat(...f035s.map(toMelindaIds));
|
|
54
|
-
const f035MelindaIds = [...new Set(allF035MelindaIds)];
|
|
55
|
-
debugData(`Fields (${f035s.length}): ${JSON.stringify(f035s)}`);
|
|
56
|
-
debugData(`Ids (${allF035MelindaIds.length}): ${JSON.stringify(allF035MelindaIds)}`);
|
|
57
|
-
debugData(`Unique ids (${f035MelindaIds.length}): ${JSON.stringify(f035MelindaIds)}`);
|
|
58
|
-
return f035MelindaIds;
|
|
59
|
-
function toMelindaIds({
|
|
60
|
-
subfields
|
|
61
|
-
}) {
|
|
62
|
-
const melindaIdRegExp = /^(?<prefix>\(FI-MELINDA\)|FCC)(?<id>\d{9})$/u;
|
|
63
|
-
return subfields.filter(sub => ['a', 'z'].includes(sub.code)).filter(sub => testStringOrNumber(sub.value) && melindaIdRegExp.test(String(sub.value))).map(({
|
|
64
|
-
value
|
|
65
|
-
}) => testStringOrNumber(value) ? String(value).replace(melindaIdRegExp, '$<id>') : '');
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
function validateSidFieldSubfieldCounts(field) {
|
|
69
|
-
// Valid SID-fields have just one $c and one $b
|
|
70
|
-
debugData(`Validating SID field ${JSON.stringify(field)}`);
|
|
71
|
-
const countC = countSubfields(field, 'c');
|
|
72
|
-
const countB = countSubfields(field, 'b');
|
|
73
|
-
debug(`Found ${countC} sf $cs and ${countB} sf $bs. IsValid: ${countC === 1 && countB === 1}`);
|
|
74
|
-
return countC === 1 && countB === 1;
|
|
75
|
-
}
|
|
76
|
-
function countSubfields(field, subfieldCode) {
|
|
77
|
-
// debug(`Counting subfields ${subfieldCode}`);
|
|
78
|
-
return field.subfields.filter(({
|
|
79
|
-
code
|
|
80
|
-
}) => code === subfieldCode).length;
|
|
81
|
-
}
|
|
82
|
-
function getSubfieldValues(field, subfieldCode) {
|
|
83
|
-
debugData(`Get subfield(s) $${subfieldCode} from ${JSON.stringify(field)}`);
|
|
84
|
-
return field.subfields.filter(({
|
|
85
|
-
code
|
|
86
|
-
}) => code === subfieldCode).map(({
|
|
87
|
-
value
|
|
88
|
-
}) => testStringOrNumber(value) ? String(value) : '').filter(value => value);
|
|
89
|
-
}
|
|
90
|
-
function testStringOrNumber(value) {
|
|
91
|
-
if (typeof value === 'string' || typeof value === 'number') {
|
|
92
|
-
return true;
|
|
93
|
-
}
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
function extractSubfieldsFromField(field, subfieldCodes) {
|
|
97
|
-
if (field === undefined || field.subfields === undefined) {
|
|
98
|
-
return [];
|
|
99
|
-
}
|
|
100
|
-
const resultSubfields = field.subfields.filter(({
|
|
101
|
-
code
|
|
102
|
-
}) => subfieldCodes.includes(code)).map(({
|
|
103
|
-
code,
|
|
104
|
-
value
|
|
105
|
-
}) => ({
|
|
106
|
-
code,
|
|
107
|
-
value: testStringOrNumber(value) ? String(value) : ''
|
|
108
|
-
})).filter(value => value);
|
|
109
|
-
return resultSubfields;
|
|
110
|
-
}
|
|
111
|
-
function uniqueSubfields(subfields) {
|
|
112
|
-
return subfields.reduce((arr, e) => {
|
|
113
|
-
if (!arr.find(item => item.code === e.code && item.value === e.value)) {
|
|
114
|
-
const newArr = arr.concat(e);
|
|
115
|
-
return newArr;
|
|
116
|
-
}
|
|
117
|
-
return arr;
|
|
118
|
-
}, []);
|
|
119
|
-
}
|
|
120
|
-
function getMatchCounts(aValues, bValues) {
|
|
121
|
-
const matchingValues = getMatchingValuesAmount(aValues, bValues);
|
|
122
|
-
return {
|
|
123
|
-
maxValues: aValues.length > bValues.length ? aValues.length : bValues.length,
|
|
124
|
-
// possibleMatchingValues: amount of identifiers in set of less identifiers (we cannot more values than these)
|
|
125
|
-
possibleMatchValues: aValues.length > bValues.length ? bValues.length : aValues.length,
|
|
126
|
-
matchingValues
|
|
127
|
-
};
|
|
128
|
-
function getMatchingValuesAmount(aValues, bValues) {
|
|
129
|
-
if (bValues.length > aValues.length) {
|
|
130
|
-
return aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length;
|
|
131
|
-
}
|
|
132
|
-
if (aValues.length > bValues.length) {
|
|
133
|
-
return bValues.filter(bValue => aValues.some(aValue => bValue === aValue)).length;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// If we have same amount of values, we'll check matches both ways, to avoid mixups in cases
|
|
137
|
-
// there would be duplicate values
|
|
138
|
-
const aToB = aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length;
|
|
139
|
-
const bToA = bValues.filter(bValue => aValues.some(aValue => bValue === aValue)).length;
|
|
140
|
-
return aToB < bToA ? aToB : bToA;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
//# sourceMappingURL=matching-utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"matching-utils.js","names":["_debug","_interopRequireDefault","require","obj","__esModule","default","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","extractSubfieldsFromField","subfieldCodes","undefined","resultSubfields","uniqueSubfields","reduce","arr","e","find","item","newArr","getMatchCounts","aValues","bValues","matchingValues","getMatchingValuesAmount","maxValues","possibleMatchValues","aValue","some","bValue","aToB","bToA"],"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\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\nexport function extractSubfieldsFromField(field, subfieldCodes) {\n if (field === undefined || field.subfields === undefined) {\n return [];\n }\n const resultSubfields = field.subfields\n .filter(({code}) => subfieldCodes.includes(code))\n .map(({code, value}) => ({code, value: testStringOrNumber(value) ? String(value) : ''}))\n .filter(value => value);\n return resultSubfields;\n}\n\nexport function uniqueSubfields(subfields) {\n return subfields.reduce((arr, e) => {\n if (!arr.find(item => item.code === e.code && item.value === e.value)) {\n const newArr = arr.concat(e);\n return newArr;\n }\n return arr;\n }, []);\n}\n\nexport function getMatchCounts(aValues, bValues) {\n\n const matchingValues = getMatchingValuesAmount(aValues, bValues);\n\n return {\n maxValues: aValues.length > bValues.length ? aValues.length : bValues.length,\n // possibleMatchingValues: amount of identifiers in set of less identifiers (we cannot more values than these)\n possibleMatchValues: aValues.length > bValues.length ? bValues.length : aValues.length,\n matchingValues\n };\n\n function getMatchingValuesAmount(aValues, bValues) {\n if (bValues.length > aValues.length) {\n return aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length;\n }\n if (aValues.length > bValues.length) {\n return bValues.filter(bValue => aValues.some(aValue => bValue === aValue)).length;\n }\n\n // If we have same amount of values, we'll check matches both ways, to avoid mixups in cases\n // there would be duplicate values\n const aToB = aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length;\n const bToA = bValues.filter(bValue => aValues.some(aValue => bValue === aValue)).length;\n\n return aToB < bToA ? aToB : bToA;\n }\n}\n"],"mappings":";;;;;;;;;;;;AA4BA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAsC,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,G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ACvF,MAAMiD,IAAI,GAAGT,OAAO,CAAC7B,MAAM,CAACoC,MAAM,IAAIR,OAAO,CAACO,IAAI,CAACD,MAAM,IAAIE,MAAM,KAAKF,MAAM,CAAC,CAAC,CAAC7C,MAAM;IAEvF,OAAOgD,IAAI,GAAGC,IAAI,GAAGD,IAAI,GAAGC,IAAI;EAClC;AACF"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
4
|
-
*
|
|
5
|
-
* Melinda record matching modules for Javascript
|
|
6
|
-
*
|
|
7
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
8
|
-
*
|
|
9
|
-
* This file is part of melinda-record-matching-js
|
|
10
|
-
*
|
|
11
|
-
* melinda-record-matching-js program is free software: you can redistribute it and/or modify
|
|
12
|
-
* it under the terms of the GNU Lesser General Public License as
|
|
13
|
-
* published by the Free Software Foundation, either version 3 of the
|
|
14
|
-
* License, or (at your option) any later version.
|
|
15
|
-
*
|
|
16
|
-
* melinda-record-matching-js is distributed in the hope that it will be useful,
|
|
17
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19
|
-
* GNU Lesser General Public License for more details.
|
|
20
|
-
*
|
|
21
|
-
* You should have received a copy of the GNU Affero General Public License
|
|
22
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
23
|
-
*
|
|
24
|
-
* @licend The above is the entire license notice
|
|
25
|
-
* for the JavaScript code in this file.
|
|
26
|
-
*
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
import generateTests from '@natlibfi/fixugen';
|
|
30
|
-
import {READERS} from '@natlibfi/fixura';
|
|
31
|
-
import {expect} from 'chai';
|
|
32
|
-
import {MarcRecord} from '@natlibfi/marc-record';
|
|
33
|
-
import * as generators from './bib';
|
|
34
|
-
|
|
35
|
-
describe('candidate-search/query-list/bib/', () => {
|
|
36
|
-
generateTests({
|
|
37
|
-
path: [__dirname, '..', '..', '..', 'test-fixtures', 'candidate-search', 'query-list', 'bib'],
|
|
38
|
-
useMetadataFile: true,
|
|
39
|
-
fixura: {
|
|
40
|
-
reader: READERS.JSON
|
|
41
|
-
},
|
|
42
|
-
callback: ({type, inputRecord, expectedQuery, enabled = true}) => {
|
|
43
|
-
const generate = generators[type];
|
|
44
|
-
const record = new MarcRecord(inputRecord, {subfieldValues: false});
|
|
45
|
-
|
|
46
|
-
if (!enabled) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const queryList = generate(record);
|
|
51
|
-
expect(queryList).to.eql(expectedQuery);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
});
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
4
|
-
*
|
|
5
|
-
* Melinda record matching modules for Javascript
|
|
6
|
-
*
|
|
7
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
8
|
-
*
|
|
9
|
-
* This file is part of melinda-record-matching-js
|
|
10
|
-
*
|
|
11
|
-
* melinda-record-matching-js program is free software: you can redistribute it and/or modify
|
|
12
|
-
* it under the terms of the GNU Lesser General Public License as
|
|
13
|
-
* published by the Free Software Foundation, either version 3 of the
|
|
14
|
-
* License, or (at your option) any later version.
|
|
15
|
-
*
|
|
16
|
-
* melinda-record-matching-js is distributed in the hope that it will be useful,
|
|
17
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19
|
-
* GNU Lesser General Public License for more details.
|
|
20
|
-
*
|
|
21
|
-
* You should have received a copy of the GNU Affero General Public License
|
|
22
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
23
|
-
*
|
|
24
|
-
* @licend The above is the entire license notice
|
|
25
|
-
* for the JavaScript code in this file.
|
|
26
|
-
*
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
import generateTests from '@natlibfi/fixugen';
|
|
30
|
-
import {READERS} from '@natlibfi/fixura';
|
|
31
|
-
import {expect} from 'chai';
|
|
32
|
-
import {MarcRecord} from '@natlibfi/marc-record';
|
|
33
|
-
import * as features from '.';
|
|
34
|
-
import createDebugLogger from 'debug';
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib:test');
|
|
38
|
-
const debugData = debug.extend('data');
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
describe('match-detection/features/bib/', () => {
|
|
42
|
-
generateTests({
|
|
43
|
-
path: [__dirname, '..', '..', '..', '..', 'test-fixtures', 'match-detection', 'features', 'bib'],
|
|
44
|
-
useMetadataFile: true,
|
|
45
|
-
fixura: {
|
|
46
|
-
reader: READERS.JSON
|
|
47
|
-
},
|
|
48
|
-
|
|
49
|
-
callback: ({enabled = true, feature, options, type, ...expectations}) => {
|
|
50
|
-
|
|
51
|
-
if (!enabled) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
debug(`Testing: ${feature} ${type}`);
|
|
56
|
-
|
|
57
|
-
if (type === 'extract') {
|
|
58
|
-
const {expectedFeatures, inputRecord} = expectations;
|
|
59
|
-
const record = new MarcRecord(inputRecord, {subfieldValues: false});
|
|
60
|
-
debugData(`Record: ${record}`);
|
|
61
|
-
const {extract} = features[feature](options);
|
|
62
|
-
|
|
63
|
-
expect(extract({record})).to.eql(expectedFeatures);
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (type === 'compare') {
|
|
68
|
-
const {featuresA, featuresB, expectedPoints} = expectations;
|
|
69
|
-
const {compare} = features[feature](options);
|
|
70
|
-
|
|
71
|
-
expect(compare(featuresA, featuresB)).to.equal(expectedPoints);
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
throw new Error(`Invalid type ${type}`);
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
});
|