@natlibfi/melinda-record-matching 2.2.2 → 3.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/dist/index.js +20 -3
- package/dist/index.js.map +1 -1
- package/dist/index.spec.js +3 -1
- package/dist/index.spec.js.map +1 -1
- package/dist/match-detection/features/bib/all-source-ids.js +6 -2
- package/dist/match-detection/features/bib/all-source-ids.js.map +1 -1
- package/dist/match-detection/features/bib/authors.js +28 -22
- package/dist/match-detection/features/bib/authors.js.map +1 -1
- package/dist/match-detection/features/bib/bibliographic-level.js +3 -1
- package/dist/match-detection/features/bib/bibliographic-level.js.map +1 -1
- package/dist/match-detection/features/bib/host-component.js +3 -1
- package/dist/match-detection/features/bib/host-component.js.map +1 -1
- package/dist/match-detection/features/bib/index.spec.js +3 -1
- package/dist/match-detection/features/bib/index.spec.js.map +1 -1
- package/dist/match-detection/features/bib/language.js +6 -2
- package/dist/match-detection/features/bib/language.js.map +1 -1
- package/dist/match-detection/features/bib/melinda-identifier-factory.js +5 -2
- package/dist/match-detection/features/bib/melinda-identifier-factory.js.map +1 -1
- package/dist/match-detection/features/bib/publication-time.js +3 -1
- package/dist/match-detection/features/bib/publication-time.js.map +1 -1
- package/dist/match-detection/features/bib/record-type.js +3 -1
- package/dist/match-detection/features/bib/record-type.js.map +1 -1
- package/dist/match-detection/features/bib/standard-identifier-factory.js +3 -1
- package/dist/match-detection/features/bib/standard-identifier-factory.js.map +1 -1
- package/dist/match-detection/features/bib/title.js +3 -1
- package/dist/match-detection/features/bib/title.js.map +1 -1
- package/dist/match-detection/index.js +47 -12
- package/dist/match-detection/index.js.map +1 -1
- package/dist/match-detection/index.spec.js +4 -1
- package/dist/match-detection/index.spec.js.map +1 -1
- package/package.json +1 -1
- package/src/index.js +5 -3
- package/src/index.spec.js +1 -1
- package/src/match-detection/features/bib/all-source-ids.js +3 -2
- package/src/match-detection/features/bib/authors.js +19 -15
- package/src/match-detection/features/bib/bibliographic-level.js +1 -1
- package/src/match-detection/features/bib/host-component.js +1 -1
- package/src/match-detection/features/bib/index.spec.js +1 -1
- package/src/match-detection/features/bib/language.js +4 -2
- package/src/match-detection/features/bib/melinda-identifier-factory.js +2 -2
- package/src/match-detection/features/bib/publication-time.js +1 -1
- package/src/match-detection/features/bib/record-type.js +1 -1
- package/src/match-detection/features/bib/standard-identifier-factory.js +1 -1
- package/src/match-detection/features/bib/title.js +1 -1
- package/src/match-detection/index.js +20 -12
- package/src/match-detection/index.spec.js +1 -1
|
@@ -32,30 +32,38 @@ import * as features from './features';
|
|
|
32
32
|
|
|
33
33
|
export {features};
|
|
34
34
|
|
|
35
|
-
export default ({strategy, treshold = 0.9}, returnStrategy = false) => (recordA, recordB) => {
|
|
35
|
+
export default ({strategy, treshold = 0.9}, returnStrategy = false) => ({recordA, recordB, recordAExternal = {}, recordBExternal = {}}) => {
|
|
36
36
|
const minProbabilityQuantifier = 0.5;
|
|
37
37
|
|
|
38
38
|
const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection');
|
|
39
39
|
const debugData = debug.extend('data');
|
|
40
40
|
|
|
41
|
-
debugData(`Strategy: ${JSON.stringify(strategy)}`);
|
|
42
|
-
debugData(`
|
|
43
|
-
|
|
41
|
+
debugData(`Strategy: ${JSON.stringify(strategy)}, Treshold: ${JSON.stringify(treshold)}, ReturnStrategy: ${JSON.stringify(returnStrategy)}`);
|
|
42
|
+
debugData(`Records: A: ${recordA}\nB: ${recordB}`);
|
|
43
|
+
debug(`Externals: A: ${JSON.stringify(recordAExternal)}, B: ${JSON.stringify(recordBExternal)}`);
|
|
44
44
|
|
|
45
|
-
const featuresA = extractFeatures(recordA);
|
|
45
|
+
const featuresA = extractFeatures({record: recordA, recordExternal: recordAExternal});
|
|
46
46
|
|
|
47
47
|
debug(`We got an array of records: ${Array.isArray(recordB)}`);
|
|
48
48
|
const recordsB = Array.isArray(recordB) ? recordB : [recordB];
|
|
49
|
-
const
|
|
49
|
+
const recordsBExternal = Array.isArray(recordB) ? recordBExternal : [recordBExternal];
|
|
50
50
|
|
|
51
|
+
const detectionResults = recordsB.map((record, index) => actualDetection({featuresA, recordAExternal, record, recordExternal: recordsBExternal[index], index}));
|
|
52
|
+
|
|
53
|
+
// if we got array of records, we return an array of result
|
|
54
|
+
// if we got a singular record, we return a singular result
|
|
51
55
|
return Array.isArray(recordB) ? detectionResults : detectionResults[0];
|
|
52
56
|
|
|
53
|
-
function actualDetection(featuresA, record) {
|
|
57
|
+
function actualDetection({featuresA, record, recordExternal, index}) {
|
|
58
|
+
const labelA = recordAExternal && recordAExternal.label ? recordAExternal.label : 'a';
|
|
59
|
+
const labelB = recordExternal && recordExternal.label ? recordExternal.label : 'b';
|
|
60
|
+
|
|
54
61
|
|
|
55
|
-
|
|
62
|
+
debug(`Actual detection for record ${index + 1} ${labelB}`);
|
|
63
|
+
const featuresB = extractFeatures({record, recordExternal});
|
|
56
64
|
|
|
57
|
-
debugData(`Features (a): ${JSON.stringify(featuresA)}`);
|
|
58
|
-
debugData(`Features (b): ${JSON.stringify(featuresB)}`);
|
|
65
|
+
debugData(`Features (a: ${labelA}): ${JSON.stringify(featuresA)}`);
|
|
66
|
+
debugData(`Features (b: ${labelB}): ${JSON.stringify(featuresB)}`);
|
|
59
67
|
|
|
60
68
|
const featurePairs = generateFeaturePairs(featuresA, featuresB);
|
|
61
69
|
const similarityVector = generateSimilarityVector(featurePairs);
|
|
@@ -70,8 +78,8 @@ export default ({strategy, treshold = 0.9}, returnStrategy = false) => (recordA,
|
|
|
70
78
|
return returnResult({match: false, probability: 0.0});
|
|
71
79
|
}
|
|
72
80
|
|
|
73
|
-
function extractFeatures(record) {
|
|
74
|
-
return strategy.reduce((acc, {name, extract}) => acc.concat({name, value: extract(record)}), []);
|
|
81
|
+
function extractFeatures({record, recordExternal}) {
|
|
82
|
+
return strategy.reduce((acc, {name, extract}) => acc.concat({name, value: extract({record, recordExternal})}), []);
|
|
75
83
|
}
|
|
76
84
|
|
|
77
85
|
function returnResult(result) {
|
|
@@ -63,7 +63,7 @@ describe('match-detection', () => {
|
|
|
63
63
|
: new MarcRecord(getFixture('recordB.json'), {subfieldValues: false});
|
|
64
64
|
debugData(inspect(recordB));
|
|
65
65
|
|
|
66
|
-
const results = detect(recordA, recordB);
|
|
66
|
+
const results = detect({recordA, recordB});
|
|
67
67
|
debugData(`${JSON.stringify(results)}`);
|
|
68
68
|
|
|
69
69
|
expect(results).to.eql(expectedResults);
|