@natlibfi/melinda-record-matching 1.0.9 → 2.0.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/candidate-search/candidate-search-utils.js +58 -0
- package/dist/candidate-search/candidate-search-utils.js.map +1 -0
- package/dist/candidate-search/index.js +16 -5
- package/dist/candidate-search/index.js.map +1 -1
- package/dist/candidate-search/index.spec.js +94 -86
- package/dist/candidate-search/index.spec.js.map +1 -1
- package/dist/candidate-search/query-list/bib.js +113 -23
- package/dist/candidate-search/query-list/bib.js.map +1 -1
- package/dist/candidate-search/query-list/bib.spec.js +25 -23
- package/dist/candidate-search/query-list/bib.spec.js.map +1 -1
- package/dist/candidate-search/query-list/index.js +6 -4
- package/dist/candidate-search/query-list/index.js.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/index.spec.js +53 -46
- package/dist/index.spec.js.map +1 -1
- package/dist/match-detection/features/bib/all-source-ids.js +122 -0
- package/dist/match-detection/features/bib/all-source-ids.js.map +1 -0
- package/dist/match-detection/features/bib/authors.js.map +1 -1
- package/dist/match-detection/features/bib/bibliographic-level.js.map +1 -1
- package/dist/match-detection/features/bib/host-component.js.map +1 -1
- package/dist/match-detection/features/bib/index.js +32 -16
- package/dist/match-detection/features/bib/index.js.map +1 -1
- package/dist/match-detection/features/bib/index.spec.js +50 -42
- package/dist/match-detection/features/bib/index.spec.js.map +1 -1
- package/dist/match-detection/features/bib/isbn.js.map +1 -1
- package/dist/match-detection/features/bib/issn.js.map +1 -1
- package/dist/match-detection/features/bib/language.js.map +1 -1
- package/dist/match-detection/features/bib/melinda-id.js +52 -0
- package/dist/match-detection/features/bib/melinda-id.js.map +1 -0
- package/dist/match-detection/features/bib/melinda-identifier-factory.js +100 -0
- package/dist/match-detection/features/bib/melinda-identifier-factory.js.map +1 -0
- package/dist/match-detection/features/bib/other-standard-identifier.js.map +1 -1
- package/dist/match-detection/features/bib/publication-time.js.map +1 -1
- package/dist/match-detection/features/bib/record-type.js.map +1 -1
- package/dist/match-detection/features/bib/standard-identifier-factory.js.map +1 -1
- package/dist/match-detection/features/bib/title.js.map +1 -1
- package/dist/match-detection/features/index.js +2 -2
- package/dist/match-detection/index.js +10 -6
- package/dist/match-detection/index.js.map +1 -1
- package/dist/match-detection/index.spec.js +32 -25
- package/dist/match-detection/index.spec.js.map +1 -1
- package/dist/matching-utils.js +95 -0
- package/dist/matching-utils.js.map +1 -0
- package/package.json +26 -29
- package/src/candidate-search/candidate-search-utils.js +53 -0
- package/src/candidate-search/index.js +11 -1
- package/src/candidate-search/index.spec.js +64 -58
- package/src/candidate-search/query-list/bib.js +130 -20
- package/src/candidate-search/query-list/bib.spec.js +16 -14
- package/src/candidate-search/query-list/index.js +3 -1
- package/src/index.spec.js +46 -39
- package/src/match-detection/features/bib/all-source-ids.js +122 -0
- package/src/match-detection/features/bib/index.js +2 -0
- package/src/match-detection/features/bib/index.spec.js +32 -23
- package/src/match-detection/features/bib/melinda-id.js +34 -0
- package/src/match-detection/features/bib/melinda-identifier-factory.js +94 -0
- package/src/match-detection/index.js +7 -4
- package/src/match-detection/index.spec.js +27 -20
- package/src/matching-utils.js +86 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
1
2
|
/**
|
|
2
3
|
*
|
|
3
4
|
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
@@ -31,15 +32,17 @@ import * as features from './features';
|
|
|
31
32
|
|
|
32
33
|
export {features};
|
|
33
34
|
|
|
35
|
+
// eslint-disable-next-line max-statements
|
|
34
36
|
export default ({strategy, treshold = 0.9}) => (recordA, recordB) => {
|
|
35
37
|
const minProbabilityQuantifier = 0.5;
|
|
36
38
|
|
|
37
39
|
const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection');
|
|
40
|
+
const debugData = debug.extend('data');
|
|
38
41
|
const featuresA = extractFeatures(recordA);
|
|
39
42
|
const featuresB = extractFeatures(recordB);
|
|
40
43
|
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
debugData(`Features (a): ${JSON.stringify(featuresA)}`);
|
|
45
|
+
debugData(`Features (b): ${JSON.stringify(featuresB)}`);
|
|
43
46
|
|
|
44
47
|
const featurePairs = generateFeaturePairs();
|
|
45
48
|
const similarityVector = generateSimilarityVector();
|
|
@@ -50,7 +53,7 @@ export default ({strategy, treshold = 0.9}) => (recordA, recordB) => {
|
|
|
50
53
|
return {match: probability >= treshold, probability};
|
|
51
54
|
}
|
|
52
55
|
|
|
53
|
-
|
|
56
|
+
debugData(`No feature yielded minimum probability amount of points (${minProbabilityQuantifier})`);
|
|
54
57
|
return {match: false, probability: 0.0};
|
|
55
58
|
|
|
56
59
|
function calculateprobability() {
|
|
@@ -69,7 +72,7 @@ export default ({strategy, treshold = 0.9}) => (recordA, recordB) => {
|
|
|
69
72
|
return {name, points};
|
|
70
73
|
});
|
|
71
74
|
|
|
72
|
-
|
|
75
|
+
debugData(`Points: ${JSON.stringify(compared)}`);
|
|
73
76
|
return compared.map(({points}) => points);
|
|
74
77
|
}
|
|
75
78
|
|
|
@@ -33,28 +33,35 @@ import {MarcRecord} from '@natlibfi/marc-record';
|
|
|
33
33
|
import * as features from './features';
|
|
34
34
|
import createDetectionInterface from '.';
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const recordA = new MarcRecord(getFixture('recordA.json'));
|
|
46
|
-
const recordB = new MarcRecord(getFixture('recordB.json'));
|
|
47
|
-
const results = detect(recordA, recordB);
|
|
36
|
+
describe('match-detection', () => {
|
|
37
|
+
generateTests({
|
|
38
|
+
path: [__dirname, '..', '..', 'test-fixtures', 'match-detection', 'index'],
|
|
39
|
+
useMetadataFile: true,
|
|
40
|
+
recurse: false,
|
|
41
|
+
fixura: {
|
|
42
|
+
reader: READERS.JSON
|
|
43
|
+
},
|
|
44
|
+
callback: ({getFixture, options, expectedResults, enabled = true}) => {
|
|
48
45
|
|
|
49
|
-
|
|
46
|
+
if (!enabled) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
50
49
|
|
|
51
|
-
|
|
52
|
-
const
|
|
50
|
+
const detect = createDetectionInterface(formatOptions());
|
|
51
|
+
const recordA = new MarcRecord(getFixture('recordA.json'));
|
|
52
|
+
const recordB = new MarcRecord(getFixture('recordB.json'));
|
|
53
|
+
const results = detect(recordA, recordB);
|
|
53
54
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
expect(results).to.eql(expectedResults);
|
|
56
|
+
|
|
57
|
+
function formatOptions() {
|
|
58
|
+
const contextFeatures = features[options.strategy.type];
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
...options,
|
|
62
|
+
strategy: options.strategy.features.map(v => contextFeatures[v]())
|
|
63
|
+
};
|
|
64
|
+
}
|
|
58
65
|
}
|
|
59
|
-
}
|
|
66
|
+
});
|
|
60
67
|
});
|
|
@@ -0,0 +1,86 @@
|
|
|
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 createDebugLogger from 'debug';
|
|
30
|
+
|
|
31
|
+
const debug = createDebugLogger('@natlibfi/melinda-record-matching:utils');
|
|
32
|
+
const debugData = debug.extend('data');
|
|
33
|
+
|
|
34
|
+
// eslint-disable-next-line max-statements
|
|
35
|
+
export function getMelindaIdsF035(record) {
|
|
36
|
+
|
|
37
|
+
const debug = createDebugLogger('@natlibfi/melinda-record-matching:melinda-id');
|
|
38
|
+
const debugData = debug.extend('data');
|
|
39
|
+
|
|
40
|
+
const f035s = record.getFields('035');
|
|
41
|
+
|
|
42
|
+
if (f035s.length < 1) {
|
|
43
|
+
debug(`No f035s found.`);
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const allF035MelindaIds = [].concat(...f035s.map(toMelindaIds));
|
|
48
|
+
const f035MelindaIds = [...new Set(allF035MelindaIds)];
|
|
49
|
+
|
|
50
|
+
debugData(`Fields (${f035s.length}): ${JSON.stringify(f035s)}`);
|
|
51
|
+
debugData(`Ids (${allF035MelindaIds.length}): ${JSON.stringify(allF035MelindaIds)}`);
|
|
52
|
+
debugData(`Unique ids (${f035MelindaIds.length}): ${JSON.stringify(f035MelindaIds)}`);
|
|
53
|
+
|
|
54
|
+
return f035MelindaIds;
|
|
55
|
+
|
|
56
|
+
function toMelindaIds({subfields}) {
|
|
57
|
+
const melindaIdRegExp = /^(?<prefix>\(FI-MELINDA\)|FCC)(?<id>\d{9})$/u;
|
|
58
|
+
|
|
59
|
+
return subfields
|
|
60
|
+
.filter(sub => ['a', 'z'].includes(sub.code))
|
|
61
|
+
.filter(sub => melindaIdRegExp.test(sub.value))
|
|
62
|
+
.map(({value}) => value.replace(melindaIdRegExp, '$<id>'));
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function validateSidFieldSubfieldCounts(field) {
|
|
68
|
+
// Valid SID-fields have just one $c and one $b
|
|
69
|
+
debugData(`Validating SID field ${JSON.stringify(field)}`);
|
|
70
|
+
const countC = countSubfields(field, 'c');
|
|
71
|
+
const countB = countSubfields(field, 'b');
|
|
72
|
+
debug(`Found ${countC} sf $cs and ${countB} sf $bs. IsValid: ${countC === 1 && countB === 1}`);
|
|
73
|
+
|
|
74
|
+
return countC === 1 && countB === 1;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function countSubfields(field, subfieldCode) {
|
|
78
|
+
// debug(`Counting subfields ${subfieldCode}`);
|
|
79
|
+
return field.subfields.filter(({code}) => code === subfieldCode).length;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function getSubfieldValues(field, subfieldCode) {
|
|
83
|
+
debugData(`Get subfield(s) $${subfieldCode} from ${JSON.stringify(field)}`);
|
|
84
|
+
return field.subfields.filter(({code}) => code === subfieldCode).map(({value}) => value);
|
|
85
|
+
}
|
|
86
|
+
|