@natlibfi/melinda-record-matching 2.2.1 → 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/candidate-search/index.js +4 -4
- package/dist/candidate-search/index.js.map +1 -1
- package/dist/index.js +21 -4
- 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/candidate-search/index.js +4 -4
- package/src/index.js +6 -4
- 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
|
@@ -33,22 +33,26 @@ import {testStringOrNumber} from '../../../matching-utils';
|
|
|
33
33
|
|
|
34
34
|
export default ({nameTreshold = 10} = {}) => ({
|
|
35
35
|
name: 'Authors',
|
|
36
|
-
extract: record =>
|
|
37
|
-
.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
36
|
+
extract: ({record}) => {
|
|
37
|
+
//const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';
|
|
38
|
+
const authors = record.get(/^(?<def>100|700)$/u)
|
|
39
|
+
.map(({subfields}) => {
|
|
40
|
+
return subfields
|
|
41
|
+
.filter(({code, value}) => code && value)
|
|
42
|
+
.filter(({code}) => ['a', '0'].includes(code))
|
|
43
|
+
.map(toObj)
|
|
44
|
+
.reduce((acc, v) => ({...acc, ...v}), {});
|
|
45
|
+
|
|
46
|
+
function toObj({code, value}) {
|
|
47
|
+
if (code === 'a') {
|
|
48
|
+
return {name: testStringOrNumber(value) ? String(value).replace(/[^\p{Letter}\p{Number}]/gu, '').toLowerCase() : ''};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return {id: value};
|
|
47
52
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}),
|
|
53
|
+
});
|
|
54
|
+
return authors;
|
|
55
|
+
},
|
|
52
56
|
compare: (a, b) => {
|
|
53
57
|
const maxAuthors = a.length > b.length ? a.length : b.length;
|
|
54
58
|
const matchingIds = findMatchingIds();
|
|
@@ -28,6 +28,6 @@
|
|
|
28
28
|
|
|
29
29
|
export default () => ({
|
|
30
30
|
name: 'Host/Component record',
|
|
31
|
-
extract:
|
|
31
|
+
extract: ({record}) => record.get(/^773$/u).length > 0 ? ['component'] : ['host'],
|
|
32
32
|
compare: (a, b) => a[0] === b[0] ? 0.0 : -1.0
|
|
33
33
|
});
|
|
@@ -52,7 +52,7 @@ describe('match-detection/features/bib/', () => {
|
|
|
52
52
|
const record = new MarcRecord(inputRecord, {subfieldValues: false});
|
|
53
53
|
const {extract} = features[feature](options);
|
|
54
54
|
|
|
55
|
-
expect(extract(record)).to.eql(expectedFeatures);
|
|
55
|
+
expect(extract({record})).to.eql(expectedFeatures);
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
58
|
|
|
@@ -34,10 +34,12 @@ const debugData = debug.extend('data');
|
|
|
34
34
|
|
|
35
35
|
export default () => ({
|
|
36
36
|
name: 'Language',
|
|
37
|
-
extract: record => {
|
|
37
|
+
extract: ({record, recordExternal}) => {
|
|
38
|
+
const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';
|
|
39
|
+
|
|
38
40
|
const value008 = get008Value();
|
|
39
41
|
const values041 = get041Values();
|
|
40
|
-
debugData(
|
|
42
|
+
debugData(`${label} 008: ${JSON.stringify(value008)}, 041: ${JSON.stringify(values041)}`);
|
|
41
43
|
|
|
42
44
|
if (value008 && values041.length > 0) {
|
|
43
45
|
debugData(`There's both 008 and 041, searching for value in both`);
|
|
@@ -43,7 +43,7 @@ export default () => {
|
|
|
43
43
|
|
|
44
44
|
return {extract, compare};
|
|
45
45
|
|
|
46
|
-
function extract(record) {
|
|
46
|
+
function extract({record, recordExternal}) {
|
|
47
47
|
|
|
48
48
|
const isMelindaRecord = record.get('003').some(f003 => f003.value === 'FI-MELINDA');
|
|
49
49
|
const [f001] = record.get('001').map(field => field.value);
|
|
@@ -54,7 +54,7 @@ export default () => {
|
|
|
54
54
|
f001 === undefined &&
|
|
55
55
|
f035MelindaIds.length < 1) {
|
|
56
56
|
|
|
57
|
-
debug(
|
|
57
|
+
debug(`${recordExternal.label} No Melinda-IDs found`);
|
|
58
58
|
return {};
|
|
59
59
|
}
|
|
60
60
|
|
|
@@ -33,7 +33,7 @@ import {testStringOrNumber} from '../../../matching-utils';
|
|
|
33
33
|
|
|
34
34
|
export default () => ({
|
|
35
35
|
name: 'Publication time',
|
|
36
|
-
extract: record => {
|
|
36
|
+
extract: ({record}) => {
|
|
37
37
|
const value = record.get(/^008$/u)?.[0]?.value || undefined;
|
|
38
38
|
return testStringOrNumber(value) ? [String(value).slice(7, 11)] : [];
|
|
39
39
|
},
|
|
@@ -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);
|