@natlibfi/melinda-record-match-validator
Version:
Validates if two records matched by melinda-record-matching can be merged and sets merge priority
52 lines (51 loc) • 2.45 kB
JavaScript
import createDebugLogger from "debug";
import * as features from "@natlibfi/melinda-record-matching/src/match-detection/features/bib/index.js";
export function getCheckFeature({ featureName, threshold = 0 }) {
const debug = createDebugLogger(`@natlibfi/melinda-record-match-validator:matching-feature-checks:${featureName}`);
const debugDev = debug.extend("dev");
debug(`Using matcher feature (bib): ${featureName}`);
return checkFeature;
function getFeatures(featureName2, record, recordExternal = {}) {
const { extract } = features[featureName2]();
return { [featureName2]: extract({ record, recordExternal }) };
}
function compareFeatures({ features1, features2 }) {
debugDev(JSON.stringify(features1));
debugDev(JSON.stringify(features2));
const { compare } = features[featureName]();
const compareResult = compare(features1[featureName], features2[featureName]);
debug(`CompareResult: ${compareResult}`);
return convertPointsToBoolean(compareResult, threshold);
}
function checkFeature({ record1, record2 }) {
debugDev(`=== Running checkFeature for ${featureName} ===`);
const features1 = getFeatures(featureName, record1);
const features2 = getFeatures(featureName, record2);
return compareFeatures({ features1, features2 });
}
function convertPointsToBoolean(points, threshold2) {
if (points < threshold2) {
debugDev(`Returning false for less points (${points}) than threshold ${threshold2}`);
return false;
}
debugDev(`Returning true for equal or more points (${points}) than threshold ${threshold2}`);
return true;
}
}
export function checkAllFeatures({ record1, record2 }) {
const debug = createDebugLogger(`@natlibfi/melinda-record-match-validator:matching-feature-checks:all-features`);
const debugDev = debug.extend("dev");
debugDev(`=== Running allFeatures check ==== `);
let result = [];
Object.keys(features).forEach((feature) => {
const { name } = features[feature]();
debugDev(`---- ${feature} : ${name} -----`);
const checkFeature = getCheckFeature({ featureName: feature });
result.push({ feature: checkFeature({ record1, record2 }) });
});
debugDev(JSON.stringify(result));
const filteredResult = result.filter((feature) => feature === false);
debugDev(JSON.stringify(filteredResult));
return filteredResult.length > 0 ? filteredResult : false;
}
//# sourceMappingURL=matchingFeatureChecks.js.map