@natlibfi/melinda-record-matching 2.2.1-alpha.1 → 2.2.1-alpha.2
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 +273 -0
- package/dist/candidate-search/index.js.map +1 -0
- package/dist/candidate-search/index.spec.js +161 -0
- package/dist/candidate-search/index.spec.js.map +1 -0
- package/dist/candidate-search/query-list/bib.js +252 -0
- package/dist/candidate-search/query-list/bib.js.map +1 -0
- package/dist/candidate-search/query-list/bib.spec.js +72 -0
- package/dist/candidate-search/query-list/bib.spec.js.map +1 -0
- package/dist/candidate-search/query-list/index.js +67 -0
- package/dist/candidate-search/query-list/index.js.map +1 -0
- package/dist/index.js +578 -0
- package/dist/index.js.map +1 -0
- package/dist/index.spec.js +133 -0
- package/dist/index.spec.js.map +1 -0
- 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 +120 -0
- package/dist/match-detection/features/bib/authors.js.map +1 -0
- package/dist/match-detection/features/bib/bibliographic-level.js +42 -0
- package/dist/match-detection/features/bib/bibliographic-level.js.map +1 -0
- package/dist/match-detection/features/bib/host-component.js +42 -0
- package/dist/match-detection/features/bib/host-component.js.map +1 -0
- package/dist/match-detection/features/bib/index.js +104 -0
- package/dist/match-detection/features/bib/index.js.map +1 -0
- package/dist/match-detection/features/bib/index.spec.js +97 -0
- package/dist/match-detection/features/bib/index.spec.js.map +1 -0
- package/dist/match-detection/features/bib/isbn.js +55 -0
- package/dist/match-detection/features/bib/isbn.js.map +1 -0
- package/dist/match-detection/features/bib/issn.js +55 -0
- package/dist/match-detection/features/bib/issn.js.map +1 -0
- package/dist/match-detection/features/bib/language.js +113 -0
- package/dist/match-detection/features/bib/language.js.map +1 -0
- 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 +55 -0
- package/dist/match-detection/features/bib/other-standard-identifier.js.map +1 -0
- package/dist/match-detection/features/bib/publication-time.js +51 -0
- package/dist/match-detection/features/bib/publication-time.js.map +1 -0
- package/dist/match-detection/features/bib/record-type.js +43 -0
- package/dist/match-detection/features/bib/record-type.js.map +1 -0
- package/dist/match-detection/features/bib/standard-identifier-factory.js +127 -0
- package/dist/match-detection/features/bib/standard-identifier-factory.js.map +1 -0
- package/dist/match-detection/features/bib/title.js +95 -0
- package/dist/match-detection/features/bib/title.js.map +1 -0
- package/dist/match-detection/features/index.js +15 -0
- package/dist/match-detection/features/index.js.map +1 -0
- package/dist/match-detection/index.js +184 -0
- package/dist/match-detection/index.js.map +1 -0
- package/dist/match-detection/index.spec.js +99 -0
- package/dist/match-detection/index.spec.js.map +1 -0
- package/dist/matching-utils.js +104 -0
- package/dist/matching-utils.js.map +1 -0
- package/package.json +2 -1
- package/src/candidate-search/query-list/bib.js +19 -18
- package/src/candidate-search/query-list/index.js +1 -1
- package/src/match-detection/features/bib/authors.js +5 -2
- package/src/match-detection/features/bib/language.js +2 -2
- package/src/match-detection/features/bib/publication-time.js +8 -3
- package/src/match-detection/features/bib/record-type.js +2 -0
- package/src/match-detection/features/bib/standard-identifier-factory.js +4 -3
- package/src/match-detection/features/bib/title.js +6 -4
- package/src/matching-utils.js +13 -4
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _fixugen = _interopRequireDefault(require("@natlibfi/fixugen"));
|
|
4
|
+
|
|
5
|
+
var _fixura = require("@natlibfi/fixura");
|
|
6
|
+
|
|
7
|
+
var _chai = require("chai");
|
|
8
|
+
|
|
9
|
+
var _marcRecord = require("@natlibfi/marc-record");
|
|
10
|
+
|
|
11
|
+
var features = _interopRequireWildcard(require("./features"));
|
|
12
|
+
|
|
13
|
+
var _ = _interopRequireDefault(require("."));
|
|
14
|
+
|
|
15
|
+
var _util = require("util");
|
|
16
|
+
|
|
17
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
18
|
+
|
|
19
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
20
|
+
|
|
21
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
22
|
+
|
|
23
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
28
|
+
*
|
|
29
|
+
* Melinda record matching modules for Javascript
|
|
30
|
+
*
|
|
31
|
+
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
32
|
+
*
|
|
33
|
+
* This file is part of melinda-record-matching-js
|
|
34
|
+
*
|
|
35
|
+
* melinda-record-matching-js program is free software: you can redistribute it and/or modify
|
|
36
|
+
* it under the terms of the GNU Lesser General Public License as
|
|
37
|
+
* published by the Free Software Foundation, either version 3 of the
|
|
38
|
+
* License, or (at your option) any later version.
|
|
39
|
+
*
|
|
40
|
+
* melinda-record-matching-js is distributed in the hope that it will be useful,
|
|
41
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
42
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
43
|
+
* GNU Lesser General Public License for more details.
|
|
44
|
+
*
|
|
45
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
46
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
47
|
+
*
|
|
48
|
+
* @licend The above is the entire license notice
|
|
49
|
+
* for the JavaScript code in this file.
|
|
50
|
+
*
|
|
51
|
+
*/
|
|
52
|
+
const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:match-detection:test');
|
|
53
|
+
const debugData = debug.extend('data');
|
|
54
|
+
describe('match-detection', () => {
|
|
55
|
+
(0, _fixugen.default)({
|
|
56
|
+
path: [__dirname, '..', '..', 'test-fixtures', 'match-detection', 'index'],
|
|
57
|
+
useMetadataFile: true,
|
|
58
|
+
recurse: false,
|
|
59
|
+
fixura: {
|
|
60
|
+
reader: _fixura.READERS.JSON
|
|
61
|
+
},
|
|
62
|
+
callback: ({
|
|
63
|
+
getFixture,
|
|
64
|
+
options,
|
|
65
|
+
expectedResults,
|
|
66
|
+
array,
|
|
67
|
+
enabled = true
|
|
68
|
+
}) => {
|
|
69
|
+
if (!enabled) {
|
|
70
|
+
debug(`*** DISABLED TEST! ***`);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const detect = (0, _.default)(formatOptions());
|
|
75
|
+
const recordA = new _marcRecord.MarcRecord(getFixture('recordA.json'), {
|
|
76
|
+
subfieldValues: false
|
|
77
|
+
});
|
|
78
|
+
debugData((0, _util.inspect)(recordA));
|
|
79
|
+
debug(`Our recordB is an array of records: ${array}`);
|
|
80
|
+
const recordB = array ? getFixture('recordB.json').map(recordJson => new _marcRecord.MarcRecord(recordJson, {
|
|
81
|
+
subfieldValues: false
|
|
82
|
+
})) : new _marcRecord.MarcRecord(getFixture('recordB.json'), {
|
|
83
|
+
subfieldValues: false
|
|
84
|
+
});
|
|
85
|
+
debugData((0, _util.inspect)(recordB));
|
|
86
|
+
const results = detect(recordA, recordB);
|
|
87
|
+
debugData(`${JSON.stringify(results)}`);
|
|
88
|
+
(0, _chai.expect)(results).to.eql(expectedResults);
|
|
89
|
+
|
|
90
|
+
function formatOptions() {
|
|
91
|
+
const contextFeatures = features[options.strategy.type];
|
|
92
|
+
return { ...options,
|
|
93
|
+
strategy: options.strategy.features.map(v => contextFeatures[v]())
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
//# sourceMappingURL=index.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.spec.js","names":["debug","createDebugLogger","debugData","extend","describe","generateTests","path","__dirname","useMetadataFile","recurse","fixura","reader","READERS","JSON","callback","getFixture","options","expectedResults","array","enabled","detect","createDetectionInterface","formatOptions","recordA","MarcRecord","subfieldValues","inspect","recordB","map","recordJson","results","stringify","expect","to","eql","contextFeatures","features","strategy","type","v"],"sources":["../../src/match-detection/index.spec.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-record-matching-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport generateTests from '@natlibfi/fixugen';\nimport {READERS} from '@natlibfi/fixura';\nimport {expect} from 'chai';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport * as features from './features';\nimport createDetectionInterface from '.';\nimport {inspect} from 'util';\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:test');\nconst debugData = debug.extend('data');\n\ndescribe('match-detection', () => {\n generateTests({\n path: [__dirname, '..', '..', 'test-fixtures', 'match-detection', 'index'],\n useMetadataFile: true,\n recurse: false,\n fixura: {\n reader: READERS.JSON\n },\n callback: ({getFixture, options, expectedResults, array, enabled = true}) => {\n\n if (!enabled) {\n debug(`*** DISABLED TEST! ***`);\n return;\n }\n\n const detect = createDetectionInterface(formatOptions());\n const recordA = new MarcRecord(getFixture('recordA.json'), {subfieldValues: false});\n debugData(inspect(recordA));\n\n debug(`Our recordB is an array of records: ${array}`);\n const recordB = array\n ? getFixture('recordB.json').map(recordJson => new MarcRecord(recordJson, {subfieldValues: false}))\n : new MarcRecord(getFixture('recordB.json'), {subfieldValues: false});\n debugData(inspect(recordB));\n\n const results = detect(recordA, recordB);\n debugData(`${JSON.stringify(results)}`);\n\n expect(results).to.eql(expectedResults);\n\n function formatOptions() {\n const contextFeatures = features[options.strategy.type];\n\n return {\n ...options,\n strategy: options.strategy.features.map(v => contextFeatures[v]())\n };\n }\n }\n });\n});\n"],"mappings":";;AA4BA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAnCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAWA,MAAMA,KAAK,GAAG,IAAAC,cAAA,EAAkB,wDAAlB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,OAAD,EAAUI,OAAV,CAAtB;MACAzB,SAAS,CAAE,GAAEW,IAAI,CAACkB,SAAL,CAAeD,OAAf,CAAwB,EAA5B,CAAT;MAEA,IAAAE,YAAA,EAAOF,OAAP,EAAgBG,EAAhB,CAAmBC,GAAnB,CAAuBjB,eAAvB;;MAEA,SAASK,aAAT,GAAyB;QACvB,MAAMa,eAAe,GAAGC,QAAQ,CAACpB,OAAO,CAACqB,QAAR,CAAiBC,IAAlB,CAAhC;QAEA,OAAO,EACL,GAAGtB,OADE;UAELqB,QAAQ,EAAErB,OAAO,CAACqB,QAAR,CAAiBD,QAAjB,CAA0BR,GAA1B,CAA8BW,CAAC,IAAIJ,eAAe,CAACI,CAAD,CAAf,EAAnC;QAFL,CAAP;MAID;IACF;EArCW,CAAd;AAuCD,CAxCO,CAAR"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getMelindaIdsF035 = getMelindaIdsF035;
|
|
7
|
+
exports.getSubfieldValues = getSubfieldValues;
|
|
8
|
+
exports.testStringOrNumber = testStringOrNumber;
|
|
9
|
+
exports.validateSidFieldSubfieldCounts = validateSidFieldSubfieldCounts;
|
|
10
|
+
|
|
11
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
12
|
+
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
18
|
+
*
|
|
19
|
+
* Melinda record matching modules for Javascript
|
|
20
|
+
*
|
|
21
|
+
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
22
|
+
*
|
|
23
|
+
* This file is part of melinda-record-matching-js
|
|
24
|
+
*
|
|
25
|
+
* melinda-record-matching-js program is free software: you can redistribute it and/or modify
|
|
26
|
+
* it under the terms of the GNU Lesser General Public License as
|
|
27
|
+
* published by the Free Software Foundation, either version 3 of the
|
|
28
|
+
* License, or (at your option) any later version.
|
|
29
|
+
*
|
|
30
|
+
* melinda-record-matching-js is distributed in the hope that it will be useful,
|
|
31
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
32
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
33
|
+
* GNU Lesser General Public License for more details.
|
|
34
|
+
*
|
|
35
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
36
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
37
|
+
*
|
|
38
|
+
* @licend The above is the entire license notice
|
|
39
|
+
* for the JavaScript code in this file.
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
42
|
+
const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:utils');
|
|
43
|
+
const debugData = debug.extend('data'); // eslint-disable-next-line max-statements
|
|
44
|
+
|
|
45
|
+
function getMelindaIdsF035(record) {
|
|
46
|
+
const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:melinda-id');
|
|
47
|
+
const debugData = debug.extend('data');
|
|
48
|
+
const f035s = record.getFields('035');
|
|
49
|
+
|
|
50
|
+
if (f035s.length < 1) {
|
|
51
|
+
debug(`No f035s found.`);
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const allF035MelindaIds = [].concat(...f035s.map(toMelindaIds));
|
|
56
|
+
const f035MelindaIds = [...new Set(allF035MelindaIds)];
|
|
57
|
+
debugData(`Fields (${f035s.length}): ${JSON.stringify(f035s)}`);
|
|
58
|
+
debugData(`Ids (${allF035MelindaIds.length}): ${JSON.stringify(allF035MelindaIds)}`);
|
|
59
|
+
debugData(`Unique ids (${f035MelindaIds.length}): ${JSON.stringify(f035MelindaIds)}`);
|
|
60
|
+
return f035MelindaIds;
|
|
61
|
+
|
|
62
|
+
function toMelindaIds({
|
|
63
|
+
subfields
|
|
64
|
+
}) {
|
|
65
|
+
const melindaIdRegExp = /^(?<prefix>\(FI-MELINDA\)|FCC)(?<id>\d{9})$/u;
|
|
66
|
+
return subfields.filter(sub => ['a', 'z'].includes(sub.code)).filter(sub => testStringOrNumber(sub.value) && melindaIdRegExp.test(String(sub.value))).map(({
|
|
67
|
+
value
|
|
68
|
+
}) => testStringOrNumber(value) ? String(value).replace(melindaIdRegExp, '$<id>') : '');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function validateSidFieldSubfieldCounts(field) {
|
|
73
|
+
// Valid SID-fields have just one $c and one $b
|
|
74
|
+
debugData(`Validating SID field ${JSON.stringify(field)}`);
|
|
75
|
+
const countC = countSubfields(field, 'c');
|
|
76
|
+
const countB = countSubfields(field, 'b');
|
|
77
|
+
debug(`Found ${countC} sf $cs and ${countB} sf $bs. IsValid: ${countC === 1 && countB === 1}`);
|
|
78
|
+
return countC === 1 && countB === 1;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function countSubfields(field, subfieldCode) {
|
|
82
|
+
// debug(`Counting subfields ${subfieldCode}`);
|
|
83
|
+
return field.subfields.filter(({
|
|
84
|
+
code
|
|
85
|
+
}) => code === subfieldCode).length;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function getSubfieldValues(field, subfieldCode) {
|
|
89
|
+
debugData(`Get subfield(s) $${subfieldCode} from ${JSON.stringify(field)}`);
|
|
90
|
+
return field.subfields.filter(({
|
|
91
|
+
code
|
|
92
|
+
}) => code === subfieldCode).map(({
|
|
93
|
+
value
|
|
94
|
+
}) => testStringOrNumber(value) ? String(value) : '').filter(value => value);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function testStringOrNumber(value) {
|
|
98
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=matching-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matching-utils.js","names":["debug","createDebugLogger","debugData","extend","getMelindaIdsF035","record","f035s","getFields","length","allF035MelindaIds","concat","map","toMelindaIds","f035MelindaIds","Set","JSON","stringify","subfields","melindaIdRegExp","filter","sub","includes","code","testStringOrNumber","value","test","String","replace","validateSidFieldSubfieldCounts","field","countC","countSubfields","countB","subfieldCode","getSubfieldValues"],"sources":["../src/matching-utils.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-record-matching-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:utils');\nconst debugData = debug.extend('data');\n\n// eslint-disable-next-line max-statements\nexport function getMelindaIdsF035(record) {\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:melinda-id');\n const debugData = debug.extend('data');\n\n const f035s = record.getFields('035');\n\n if (f035s.length < 1) {\n debug(`No f035s found.`);\n return [];\n }\n\n const allF035MelindaIds = [].concat(...f035s.map(toMelindaIds));\n const f035MelindaIds = [...new Set(allF035MelindaIds)];\n\n debugData(`Fields (${f035s.length}): ${JSON.stringify(f035s)}`);\n debugData(`Ids (${allF035MelindaIds.length}): ${JSON.stringify(allF035MelindaIds)}`);\n debugData(`Unique ids (${f035MelindaIds.length}): ${JSON.stringify(f035MelindaIds)}`);\n\n return f035MelindaIds;\n\n function toMelindaIds({subfields}) {\n const melindaIdRegExp = /^(?<prefix>\\(FI-MELINDA\\)|FCC)(?<id>\\d{9})$/u;\n\n return subfields\n .filter(sub => ['a', 'z'].includes(sub.code))\n .filter(sub => testStringOrNumber(sub.value) && melindaIdRegExp.test(String(sub.value)))\n .map(({value}) => testStringOrNumber(value) ? String(value).replace(melindaIdRegExp, '$<id>') : '');\n\n }\n}\n\nexport function validateSidFieldSubfieldCounts(field) {\n // Valid SID-fields have just one $c and one $b\n debugData(`Validating SID field ${JSON.stringify(field)}`);\n const countC = countSubfields(field, 'c');\n const countB = countSubfields(field, 'b');\n debug(`Found ${countC} sf $cs and ${countB} sf $bs. IsValid: ${countC === 1 && countB === 1}`);\n\n return countC === 1 && countB === 1;\n}\n\nfunction countSubfields(field, subfieldCode) {\n // debug(`Counting subfields ${subfieldCode}`);\n return field.subfields.filter(({code}) => code === subfieldCode).length;\n}\n\nexport function getSubfieldValues(field, subfieldCode) {\n debugData(`Get subfield(s) $${subfieldCode} from ${JSON.stringify(field)}`);\n return field.subfields\n .filter(({code}) => code === subfieldCode)\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .filter(value => value);\n}\n\nexport function testStringOrNumber(value) {\n if (typeof value === 'string' || typeof value === 'number') {\n return true;\n }\n return false;\n}\n"],"mappings":";;;;;;;;;;AA4BA;;;;AA5BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAIA,MAAMA,KAAK,GAAG,IAAAC,cAAA,EAAkB,yCAAlB,CAAd;AACA,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAN,CAAa,MAAb,CAAlB,C,CAEA;;AACO,SAASC,iBAAT,CAA2BC,MAA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AAmC;EACxC,IAAI,OAAOA,KAAP,KAAiB,QAAjB,IAA6B,OAAOA,KAAP,KAAiB,QAAlD,EAA4D;IAC1D,OAAO,IAAP;EACD;;EACD,OAAO,KAAP;AACD"}
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"url": "git@github.com:natlibfi/melinda-record-matching-js.git"
|
|
15
15
|
},
|
|
16
16
|
"license": "LGPL-3.0+",
|
|
17
|
-
"version": "2.2.1-alpha.
|
|
17
|
+
"version": "2.2.1-alpha.2",
|
|
18
18
|
"main": "./dist/index.js",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=14"
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
|
+
"prepare": "npm run build",
|
|
26
27
|
"start": "node dist/index.js",
|
|
27
28
|
"cli": "node dist/cli.js",
|
|
28
29
|
"lint": "eslint src",
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Melinda record matching modules for Javascript
|
|
7
7
|
*
|
|
8
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
8
|
+
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
9
9
|
*
|
|
10
10
|
* This file is part of melinda-record-matching-js
|
|
11
11
|
*
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
*/
|
|
29
29
|
import createDebugLogger from 'debug';
|
|
30
30
|
import {toQueries} from '../candidate-search-utils';
|
|
31
|
-
import {getMelindaIdsF035, validateSidFieldSubfieldCounts, getSubfieldValues} from '../../matching-utils';
|
|
31
|
+
import {getMelindaIdsF035, validateSidFieldSubfieldCounts, getSubfieldValues, testStringOrNumber} from '../../matching-utils';
|
|
32
32
|
|
|
33
33
|
|
|
34
34
|
export function bibSourceIds(record) {
|
|
@@ -108,7 +108,7 @@ export function bibSourceIds(record) {
|
|
|
108
108
|
|
|
109
109
|
function removeSourcePrefix(subfieldValue) {
|
|
110
110
|
const sourcePrefixRegex = (/^(?<sourcePrefix>\([A-Za-z0-9-]+\))(?<id>.+)$/u);
|
|
111
|
-
const normalizedValue = subfieldValue ? subfieldValue.replace(sourcePrefixRegex, '$<id>') : '';
|
|
111
|
+
const normalizedValue = testStringOrNumber(subfieldValue) ? String(subfieldValue).replace(sourcePrefixRegex, '$<id>') : '';
|
|
112
112
|
debugData(`Normalized ${subfieldValue} to ${normalizedValue}`);
|
|
113
113
|
return normalizedValue;
|
|
114
114
|
}
|
|
@@ -116,7 +116,7 @@ export function bibSourceIds(record) {
|
|
|
116
116
|
function normalizeSidSubfieldValue(subfieldValue) {
|
|
117
117
|
debugData(`Normalizing ${subfieldValue}`);
|
|
118
118
|
const normalizeAwayRegex = (/[- ]/u);
|
|
119
|
-
return subfieldValue ? subfieldValue.replace(normalizeAwayRegex, '') : '';
|
|
119
|
+
return testStringOrNumber(subfieldValue) ? String(subfieldValue).replace(normalizeAwayRegex, '') : '';
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
}
|
|
@@ -151,7 +151,7 @@ export function bibMelindaIds(record) {
|
|
|
151
151
|
// bibHostComponents should search all 773 $ws for possible host id, but what should it do in case of multiple host ids?
|
|
152
152
|
export function bibHostComponents(record) {
|
|
153
153
|
const id = getHostId();
|
|
154
|
-
return id ? [`melinda.partsofhost=${id}`] : [];
|
|
154
|
+
return testStringOrNumber(id) ? [`melinda.partsofhost=${id}`] : [];
|
|
155
155
|
|
|
156
156
|
function getHostId() {
|
|
157
157
|
const [field] = record.get(/^773$/u);
|
|
@@ -159,12 +159,12 @@ export function bibHostComponents(record) {
|
|
|
159
159
|
if (field) {
|
|
160
160
|
const {value} = field.subfields.find(({code}) => code === 'w') || {};
|
|
161
161
|
|
|
162
|
-
if (value && (/^\(FI-MELINDA\)/u).test(value)) {
|
|
163
|
-
return value.replace(/^\(FI-MELINDA\)/u, '');
|
|
162
|
+
if (testStringOrNumber(value) && (/^\(FI-MELINDA\)/u).test(String(value))) {
|
|
163
|
+
return String(value).replace(/^\(FI-MELINDA\)/u, '');
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
if (value && (/^\(FIN01\)/u).test(value)) {
|
|
167
|
-
return value.replace(/^\(FIN01\)/u, '');
|
|
166
|
+
if (testStringOrNumber(value) && (/^\(FIN01\)/u).test(String(value))) {
|
|
167
|
+
return String(value).replace(/^\(FIN01\)/u, '');
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
return false;
|
|
@@ -185,8 +185,8 @@ export function bibTitle(record) {
|
|
|
185
185
|
const title = getTitle();
|
|
186
186
|
const booleanStartWords = ['and', 'or', 'nor', 'not'];
|
|
187
187
|
|
|
188
|
-
if (title) {
|
|
189
|
-
const formatted = title
|
|
188
|
+
if (testStringOrNumber(title)) {
|
|
189
|
+
const formatted = String(title)
|
|
190
190
|
.replace(/[^\w\s\p{Alphabetic}]/gu, '')
|
|
191
191
|
// Clean up concurrent spaces from fe. subfield changes
|
|
192
192
|
.replace(/ +/gu, ' ')
|
|
@@ -208,7 +208,8 @@ export function bibTitle(record) {
|
|
|
208
208
|
if (field) {
|
|
209
209
|
return field.subfields
|
|
210
210
|
.filter(({code}) => ['a', 'b'].includes(code))
|
|
211
|
-
.map(({value}) => value)
|
|
211
|
+
.map(({value}) => testStringOrNumber(value) ? String(value) : '')
|
|
212
|
+
.filter(value => value)
|
|
212
213
|
// In Melinda's index subfield separators are indexed as ' '
|
|
213
214
|
.join(' ');
|
|
214
215
|
}
|
|
@@ -244,18 +245,18 @@ export function bibStandardIdentifiers(record) {
|
|
|
244
245
|
|
|
245
246
|
if (tag === '022') {
|
|
246
247
|
return subfields
|
|
247
|
-
.filter(sub => ['a', 'z', 'y'].includes(sub.code) &&
|
|
248
|
-
.map(({value}) => value);
|
|
248
|
+
.filter(sub => ['a', 'z', 'y'].includes(sub.code) && testStringOrNumber(sub.value) && issnIsbnReqExp.test(String(sub.value)))
|
|
249
|
+
.map(({value}) => String(value));
|
|
249
250
|
}
|
|
250
251
|
|
|
251
252
|
if (tag === '020') {
|
|
252
253
|
return subfields
|
|
253
|
-
.filter(sub => ['a', 'z'].includes(sub.code) &&
|
|
254
|
-
.map(({value}) => value);
|
|
254
|
+
.filter(sub => ['a', 'z'].includes(sub.code) && testStringOrNumber(sub.value) && issnIsbnReqExp.test(String(sub.value)))
|
|
255
|
+
.map(({value}) => String(value));
|
|
255
256
|
}
|
|
256
257
|
|
|
257
258
|
return subfields
|
|
258
|
-
.filter(sub => ['a', 'z'].includes(sub.code) &&
|
|
259
|
-
.map(({value}) => value);
|
|
259
|
+
.filter(sub => ['a', 'z'].includes(sub.code) && testStringOrNumber(sub.value) && otherIdReqExp.test(String(sub.value)))
|
|
260
|
+
.map(({value}) => String(value));
|
|
260
261
|
}
|
|
261
262
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Melinda record matching modules for Javascript
|
|
6
6
|
*
|
|
7
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
7
|
+
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
8
8
|
*
|
|
9
9
|
* This file is part of melinda-record-matching-js
|
|
10
10
|
*
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Melinda record matching modules for Javascript
|
|
6
6
|
*
|
|
7
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
7
|
+
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
8
8
|
*
|
|
9
9
|
* This file is part of melinda-record-matching-js
|
|
10
10
|
*
|
|
@@ -27,6 +27,9 @@
|
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
29
|
import {LevenshteinDistance as leven} from 'natural';
|
|
30
|
+
import {testStringOrNumber} from '../../../matching-utils';
|
|
31
|
+
|
|
32
|
+
// We should extract also organisational authors (110/710)
|
|
30
33
|
|
|
31
34
|
export default ({nameTreshold = 10} = {}) => ({
|
|
32
35
|
name: 'Authors',
|
|
@@ -40,7 +43,7 @@ export default ({nameTreshold = 10} = {}) => ({
|
|
|
40
43
|
|
|
41
44
|
function toObj({code, value}) {
|
|
42
45
|
if (code === 'a') {
|
|
43
|
-
return {name: value ? value.replace(/[^\p{Letter}\p{Number}]/gu, '').toLowerCase() : ''};
|
|
46
|
+
return {name: testStringOrNumber(value) ? String(value).replace(/[^\p{Letter}\p{Number}]/gu, '').toLowerCase() : ''};
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
return {id: value};
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Melinda record matching modules for Javascript
|
|
7
7
|
*
|
|
8
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
8
|
+
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
9
9
|
*
|
|
10
10
|
* This file is part of melinda-record-matching-js
|
|
11
11
|
*
|
|
@@ -86,7 +86,7 @@ export default () => ({
|
|
|
86
86
|
return 0;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
debugData(`There
|
|
89
|
+
debugData(`There are languages to compare`);
|
|
90
90
|
|
|
91
91
|
if (a[0] === b[0]) {
|
|
92
92
|
return 0.1;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Melinda record matching modules for Javascript
|
|
6
6
|
*
|
|
7
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
7
|
+
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
8
8
|
*
|
|
9
9
|
* This file is part of melinda-record-matching-js
|
|
10
10
|
*
|
|
@@ -26,11 +26,16 @@
|
|
|
26
26
|
*
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
|
+
import {testStringOrNumber} from '../../../matching-utils';
|
|
30
|
+
|
|
31
|
+
// We should also get copyright time and copyright/publication times from 26x
|
|
32
|
+
// We could also enable matching of records which have consequent publication years
|
|
33
|
+
|
|
29
34
|
export default () => ({
|
|
30
35
|
name: 'Publication time',
|
|
31
36
|
extract: record => {
|
|
32
|
-
const value = record.get(/^008$/u)?.[0]?.value ||
|
|
33
|
-
return value ? [value.slice(7, 11)] : [];
|
|
37
|
+
const value = record.get(/^008$/u)?.[0]?.value || undefined;
|
|
38
|
+
return testStringOrNumber(value) ? [String(value).slice(7, 11)] : [];
|
|
34
39
|
},
|
|
35
40
|
compare: (a, b) => a[0] === b[0] ? 0.1 : -1.0
|
|
36
41
|
});
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Melinda record matching modules for Javascript
|
|
6
6
|
*
|
|
7
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
7
|
+
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
8
8
|
*
|
|
9
9
|
* This file is part of melinda-record-matching-js
|
|
10
10
|
*
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
29
|
import createDebugLogger from 'debug';
|
|
30
|
+
import {testStringOrNumber} from '../../../matching-utils';
|
|
30
31
|
|
|
31
32
|
const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features:standard-identifiers');
|
|
32
33
|
const debugData = debug.extend('data');
|
|
@@ -40,8 +41,8 @@ export default ({pattern, subfieldCodes}) => {
|
|
|
40
41
|
if (field) {
|
|
41
42
|
return field.subfields
|
|
42
43
|
.filter(({code}) => subfieldCodes.includes(code))
|
|
43
|
-
|
|
44
|
-
.
|
|
44
|
+
.map(({code, value}) => ({code, value: testStringOrNumber(value) ? String(value).replace(/-/ug, '') : ''}))
|
|
45
|
+
.filter(value => value);
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
return [];
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Melinda record matching modules for Javascript
|
|
6
6
|
*
|
|
7
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
7
|
+
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
8
8
|
*
|
|
9
9
|
* This file is part of melinda-record-matching-js
|
|
10
10
|
*
|
|
@@ -28,14 +28,15 @@
|
|
|
28
28
|
|
|
29
29
|
import createDebugLogger from 'debug';
|
|
30
30
|
import {LevenshteinDistance as leven} from 'natural';
|
|
31
|
+
import {testStringOrNumber} from '../../../matching-utils';
|
|
31
32
|
|
|
32
33
|
export default ({treshold = 10} = {}) => ({
|
|
33
34
|
name: 'Title',
|
|
34
35
|
extract: record => {
|
|
35
36
|
const title = getTitle();
|
|
36
37
|
|
|
37
|
-
if (title) {
|
|
38
|
-
return [title.replace(/[^\p{Letter}\p{Number}]/gu, '').toLowerCase()];
|
|
38
|
+
if (testStringOrNumber(title)) {
|
|
39
|
+
return [String(title).replace(/[^\p{Letter}\p{Number}]/gu, '').toLowerCase()];
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
return [];
|
|
@@ -46,9 +47,10 @@ export default ({treshold = 10} = {}) => ({
|
|
|
46
47
|
if (field) {
|
|
47
48
|
return field.subfields
|
|
48
49
|
.filter(({code}) => ['a', 'b'].includes(code))
|
|
49
|
-
.map(({value}) => value)
|
|
50
|
+
.map(({value}) => testStringOrNumber(value) ? String(value) : '')
|
|
50
51
|
.join('');
|
|
51
52
|
}
|
|
53
|
+
return false;
|
|
52
54
|
}
|
|
53
55
|
},
|
|
54
56
|
compare: (a, b) => {
|
package/src/matching-utils.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Melinda record matching modules for Javascript
|
|
6
6
|
*
|
|
7
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
7
|
+
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
8
8
|
*
|
|
9
9
|
* This file is part of melinda-record-matching-js
|
|
10
10
|
*
|
|
@@ -58,8 +58,8 @@ export function getMelindaIdsF035(record) {
|
|
|
58
58
|
|
|
59
59
|
return subfields
|
|
60
60
|
.filter(sub => ['a', 'z'].includes(sub.code))
|
|
61
|
-
.filter(sub => melindaIdRegExp.test(sub.value))
|
|
62
|
-
.map(({value}) => value ? value.replace(melindaIdRegExp, '$<id>') : '');
|
|
61
|
+
.filter(sub => testStringOrNumber(sub.value) && melindaIdRegExp.test(String(sub.value)))
|
|
62
|
+
.map(({value}) => testStringOrNumber(value) ? String(value).replace(melindaIdRegExp, '$<id>') : '');
|
|
63
63
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -81,6 +81,15 @@ function countSubfields(field, subfieldCode) {
|
|
|
81
81
|
|
|
82
82
|
export function getSubfieldValues(field, subfieldCode) {
|
|
83
83
|
debugData(`Get subfield(s) $${subfieldCode} from ${JSON.stringify(field)}`);
|
|
84
|
-
return field.subfields
|
|
84
|
+
return field.subfields
|
|
85
|
+
.filter(({code}) => code === subfieldCode)
|
|
86
|
+
.map(({value}) => testStringOrNumber(value) ? String(value) : '')
|
|
87
|
+
.filter(value => value);
|
|
85
88
|
}
|
|
86
89
|
|
|
90
|
+
export function testStringOrNumber(value) {
|
|
91
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
}
|