UNPKG

@natlibfi/melinda-record-match-validator

Version:

Validates if two records matched by melinda-record-matching can be merged and sets merge priority

100 lines (93 loc) 3.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.check336 = check336; exports.check337 = check337; exports.check338 = check338; exports.compare336ContentType = compare336ContentType; exports.compare337MediaType = compare337MediaType; exports.compare338CarrierType = compare338CarrierType; exports.get336bContentType = get336bContentType; exports.get337bMediaType = get337bMediaType; exports.get338bCarrierType = get338bCarrierType; var _debug = _interopRequireDefault(require("debug")); var _utils = require("./utils"); var _collectUtils = require("./collectFunctions/collectUtils"); var _compareUtils = require("./compareFunctions/compareUtils"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } // Handle fields 336, 337 and 338. const debug = (0, _debug.default)('@natlibfi/melinda-record-match-validator:field33X'); const debugDev = debug.extend('dev'); //const debugData = debug.extend('data'); // COLLECT: function get33Xb(record, tag) { const types = (0, _collectUtils.hasFields)(tag, record, _collectUtils.getSubfield, 'b'); debugDev('Field %s types: %o', tag, types); (0, _utils.nvdebug)(`NV Field ${tag} has types: ${types.join(', ')}`, debugDev); return { types }; } function get336bContentType(record) { // Test-only return get33Xb(record, '336'); } function get337bMediaType(record) { // Test-only return get33Xb(record, '337'); } function get338bCarrierType(record) { // Test-only // A component part should not have a 338 field. However, I don't think we need this sanity check... return get33Xb(record, '338'); } /* 336, 337, 338 $b:t automaatiolla pitää miettiä jotain parempaa logiikkaa - mut tekstiaineistoissa jos toinen tietue on 337 $b c ja toinen on 337 $b n niin yhdistämistä ei saa tehdä. (Tietokonekäyttöinen teksti ja fyysinen teksti) */ function compare33XType(recordValuesA, recordValuesB, tag) { const f33XA = recordValuesA[tag]; const f33XB = recordValuesB[tag]; debugDev('%s type(s): %o vs %o', tag, f33XA, f33XB); return (0, _compareUtils.compareArrayContent)(f33XA.types, f33XB.types); } // COMPARE TESTS: function compare336ContentType(recordValuesA, recordValuesB) { return compare33XType(recordValuesA, recordValuesB, '336'); } function compare337MediaType(recordValuesA, recordValuesB) { return compare33XType(recordValuesA, recordValuesB, '337'); } function compare338CarrierType(recordValuesA, recordValuesB) { return compare33XType(recordValuesA, recordValuesB, '338'); } /// BOTH: function check33X(record1, record2, tag) { const data1 = get33Xb(record1, tag); const data2 = get33Xb(record2, tag); debugDev('CC Field %s types: %o vs %o', tag, data1, data2); return (0, _compareUtils.compareArrayContent)(data1.types, data2.types); //return compare336ContentType(data1, data2); } function check336({ record1, record2 }) { // return check33X(record1, record2, '336'); } function check337({ record1, record2 }) { return check33X(record1, record2, '337'); } function check338({ record1, record2 }) { return check33X(record1, record2, '338'); } //# sourceMappingURL=field33X.js.map