@natlibfi/melinda-record-matching 3.0.0-alpha.1 → 3.0.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/index.js +0 -4
- package/dist/candidate-search/index.js.map +1 -1
- package/dist/candidate-search/index.spec.js +1 -5
- package/dist/candidate-search/index.spec.js.map +1 -1
- package/dist/candidate-search/query-list/bib.js +0 -2
- package/dist/candidate-search/query-list/bib.js.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/match-detection/features/bib/all-source-ids.js +0 -1
- package/dist/match-detection/features/bib/all-source-ids.js.map +1 -1
- package/dist/match-detection/features/bib/bibliographic-level.js +2 -1
- package/dist/match-detection/features/bib/bibliographic-level.js.map +1 -1
- package/dist/match-detection/features/bib/host-component.js +2 -1
- package/dist/match-detection/features/bib/host-component.js.map +1 -1
- package/dist/match-detection/features/bib/index.js +7 -0
- package/dist/match-detection/features/bib/index.js.map +1 -1
- package/dist/match-detection/features/bib/index.spec.js +0 -1
- package/dist/match-detection/features/bib/index.spec.js.map +1 -1
- package/dist/match-detection/features/bib/isbn.js +2 -1
- package/dist/match-detection/features/bib/isbn.js.map +1 -1
- package/dist/match-detection/features/bib/issn.js +2 -1
- package/dist/match-detection/features/bib/issn.js.map +1 -1
- package/dist/match-detection/features/bib/language.js +6 -6
- package/dist/match-detection/features/bib/language.js.map +1 -1
- package/dist/match-detection/features/bib/melinda-id.js +2 -1
- package/dist/match-detection/features/bib/melinda-id.js.map +1 -1
- package/dist/match-detection/features/bib/melinda-identifier-factory.js +0 -2
- package/dist/match-detection/features/bib/melinda-identifier-factory.js.map +1 -1
- package/dist/match-detection/features/bib/other-standard-identifier.js +2 -1
- package/dist/match-detection/features/bib/other-standard-identifier.js.map +1 -1
- package/dist/match-detection/features/bib/title-version-original.js +79 -0
- package/dist/match-detection/features/bib/title-version-original.js.map +1 -0
- package/dist/match-detection/features/bib/title.js +24 -6
- package/dist/match-detection/features/bib/title.js.map +1 -1
- package/dist/match-detection/index.js +11 -7
- package/dist/match-detection/index.js.map +1 -1
- package/dist/matching-utils.js +0 -2
- package/dist/matching-utils.js.map +1 -1
- package/package.json +8 -8
- package/src/candidate-search/index.js +1 -3
- package/src/candidate-search/index.spec.js +1 -3
- package/src/candidate-search/query-list/bib.js +0 -1
- package/src/index.js +0 -1
- package/src/match-detection/features/bib/all-source-ids.js +0 -1
- package/src/match-detection/features/bib/index.js +1 -0
- package/src/match-detection/features/bib/index.spec.js +1 -1
- package/src/match-detection/features/bib/language.js +6 -6
- package/src/match-detection/features/bib/melinda-identifier-factory.js +0 -1
- package/src/match-detection/features/bib/title-version-original.js +78 -0
- package/src/match-detection/features/bib/title.js +22 -4
- package/src/match-detection/index.js +7 -7
- package/src/matching-utils.js +0 -1
|
@@ -1 +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\
|
|
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\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;AAAsC;AA5BtC;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,cAAiB,EA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,MAAM,CAACK,KAAK,IAAIA,KAAK,CAAC;AAC3B;AAEO,SAASD,kBAAkB,CAACC,KAAK,EAAE;EACxC,IAAI,OAAOA,KAAK,KAAK,QAAQ,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IAC1D,OAAO,IAAI;EACb;EACA,OAAO,KAAK;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": "3.0.
|
|
17
|
+
"version": "3.0.1-alpha.2",
|
|
18
18
|
"main": "./dist/index.js",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=14"
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"watch:test": "cross-env DEBUG=1 NODE_ENV=test nodemon -w src -w test-fixtures --exec 'npm run test:dev'"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@natlibfi/marc-record": "^7.2.
|
|
40
|
-
"@natlibfi/marc-record-serializers": "^9.0.
|
|
41
|
-
"@natlibfi/melinda-commons": "^12.0.
|
|
39
|
+
"@natlibfi/marc-record": "^7.2.2",
|
|
40
|
+
"@natlibfi/marc-record-serializers": "^9.0.2",
|
|
41
|
+
"@natlibfi/melinda-commons": "^12.0.6",
|
|
42
42
|
"@natlibfi/sru-client": "^5.0.3",
|
|
43
43
|
"debug": "^4.3.4",
|
|
44
44
|
"moment": "^2.29.4",
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@babel/cli": "^7.19.3",
|
|
51
|
-
"@babel/core": "^7.19.
|
|
51
|
+
"@babel/core": "^7.19.6",
|
|
52
52
|
"@babel/eslint-parser": "^7.19.1",
|
|
53
|
-
"@babel/node": "^7.
|
|
53
|
+
"@babel/node": "^7.20.0",
|
|
54
54
|
"@babel/preset-env": "^7.19.4",
|
|
55
55
|
"@babel/register": "^7.18.9",
|
|
56
56
|
"@natlibfi/eslint-config-melinda-backend": "^2.0.1",
|
|
@@ -62,8 +62,8 @@
|
|
|
62
62
|
"chai": "^4.3.6",
|
|
63
63
|
"chai-as-promised": "^7.1.1",
|
|
64
64
|
"cross-env": "^7.0.3",
|
|
65
|
-
"eslint": "^8.
|
|
66
|
-
"mocha": "^10.
|
|
65
|
+
"eslint": "^8.26.0",
|
|
66
|
+
"mocha": "^10.1.0",
|
|
67
67
|
"nodemon": "^2.0.20",
|
|
68
68
|
"nyc": "^15.1.0"
|
|
69
69
|
},
|
|
@@ -39,7 +39,6 @@ export class CandidateSearchError extends Error {}
|
|
|
39
39
|
|
|
40
40
|
// serverMaxResults : maximum size of total search result available from the server, defaults to Aleph's 20000
|
|
41
41
|
|
|
42
|
-
// eslint-disable-next-line max-statements
|
|
43
42
|
export default ({record, searchSpec, url, maxCandidates, maxRecordsPerRequest = 50, serverMaxResult = 20000}) => {
|
|
44
43
|
MarcRecord.setValidationOptions({subfieldValues: false});
|
|
45
44
|
|
|
@@ -69,7 +68,7 @@ export default ({record, searchSpec, url, maxCandidates, maxRecordsPerRequest =
|
|
|
69
68
|
|
|
70
69
|
// if generateQueryList errored we should throw 422
|
|
71
70
|
|
|
72
|
-
if (queryList.length === 0) {
|
|
71
|
+
if (queryList.length === 0) {
|
|
73
72
|
throw new CandidateSearchError(`Generated query list contains no queries`);
|
|
74
73
|
}
|
|
75
74
|
|
|
@@ -175,7 +174,6 @@ export default ({record, searchSpec, url, maxCandidates, maxRecordsPerRequest =
|
|
|
175
174
|
};
|
|
176
175
|
|
|
177
176
|
function checkMaxedQuery(query, total, serverMaxResult) {
|
|
178
|
-
// eslint-disable-next-line functional/no-conditional-statement
|
|
179
177
|
if (total >= serverMaxResult) {
|
|
180
178
|
debug(`WARNING: Query ${query} resulted in ${total} hits which meets the serverMaxResult (${serverMaxResult}) `);
|
|
181
179
|
return query;
|
|
@@ -46,7 +46,6 @@ describe('candidate-search', () => {
|
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
48
|
|
|
49
|
-
// eslint-disable-next-line max-statements
|
|
50
49
|
async function callback({getFixture, factoryOptions, searchOptions, expectedFactoryError = false, expectedSearchError = false, enabled = true}) {
|
|
51
50
|
const url = 'http://foo.bar';
|
|
52
51
|
|
|
@@ -77,7 +76,6 @@ describe('candidate-search', () => {
|
|
|
77
76
|
};
|
|
78
77
|
}
|
|
79
78
|
|
|
80
|
-
// eslint-disable-next-line max-statements
|
|
81
79
|
async function iterate({searchOptions, expectedSearchError, expectedErrorStatus, count = 1}) {
|
|
82
80
|
const expectedResults = getFixture(`expectedResults${count}.json`);
|
|
83
81
|
|
|
@@ -108,7 +106,7 @@ describe('candidate-search', () => {
|
|
|
108
106
|
}
|
|
109
107
|
|
|
110
108
|
function formatResults(results) {
|
|
111
|
-
debug(results);
|
|
109
|
+
debug(results);
|
|
112
110
|
return {
|
|
113
111
|
...results,
|
|
114
112
|
records: results.records.map(({record, id}) => ({id, record: record.toObject()}))
|
|
@@ -217,7 +217,6 @@ export function bibTitle(record) {
|
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
-
// eslint-disable-next-line max-statements
|
|
221
220
|
export function bibStandardIdentifiers(record) {
|
|
222
221
|
|
|
223
222
|
const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibStandardIdentifiers');
|
package/src/index.js
CHANGED
|
@@ -235,7 +235,6 @@ export default ({detection: detectionOptions, search: searchOptions, maxMatches
|
|
|
235
235
|
// - if creating the featureSet for the incoming record fails we have an unprocessable entity
|
|
236
236
|
// - if creating the featureSet for a candidate record fails we could skip that candidate - but list the case as a detectionFailure, same as conversionFailures
|
|
237
237
|
|
|
238
|
-
// eslint-disable-next-line max-statements
|
|
239
238
|
function iterateRecords({records, recordSetSize, maxMatches, matches = [], nonMatches = [], recordMatches = [], recordNonMatches = [], recordCount = 0, recordDuplicateCount = 0, recordNonMatchCount = 0, recordMatchErrors = []}) {
|
|
240
239
|
|
|
241
240
|
// recordSetSize : total amount of records in the current record set
|
|
@@ -31,6 +31,7 @@ export {default as isbn} from './isbn';
|
|
|
31
31
|
export {default as issn} from './issn';
|
|
32
32
|
export {default as otherStandardIdentifier} from './other-standard-identifier';
|
|
33
33
|
export {default as title} from './title';
|
|
34
|
+
export {default as titleVersionOriginal} from './title-version-original';
|
|
34
35
|
export {default as authors} from './authors';
|
|
35
36
|
export {default as recordType} from './record-type';
|
|
36
37
|
export {default as publicationTime} from './publication-time';
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable max-statements */
|
|
2
1
|
/**
|
|
3
2
|
*
|
|
4
3
|
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
@@ -42,14 +41,14 @@ export default () => ({
|
|
|
42
41
|
debugData(`${label} 008: ${JSON.stringify(value008)}, 041: ${JSON.stringify(values041)}`);
|
|
43
42
|
|
|
44
43
|
if (value008 && values041.length > 0) {
|
|
45
|
-
debugData(
|
|
44
|
+
debugData(`${label} There's both 008 and 041, searching for value in both`);
|
|
46
45
|
const correspondingValue = values041.find(v => v === value008);
|
|
47
|
-
debugData(
|
|
46
|
+
debugData(`${label} Corresponding value: ${correspondingValue}`);
|
|
48
47
|
return correspondingValue ? [correspondingValue] : [];
|
|
49
48
|
}
|
|
50
49
|
|
|
51
50
|
if (!value008 && values041.length < 1) {
|
|
52
|
-
debugData(`No actual values found`);
|
|
51
|
+
debugData(`{$label} No actual values found`);
|
|
53
52
|
return [];
|
|
54
53
|
}
|
|
55
54
|
|
|
@@ -57,18 +56,19 @@ export default () => ({
|
|
|
57
56
|
|
|
58
57
|
function get008Value() {
|
|
59
58
|
const value = record.get(/^008$/u)?.[0]?.value || undefined;
|
|
60
|
-
debugData(
|
|
59
|
+
debugData(`${label} 008 value: ${value}`);
|
|
61
60
|
|
|
62
61
|
if (!value) {
|
|
63
62
|
return undefined;
|
|
64
63
|
}
|
|
65
64
|
|
|
66
65
|
const code = value.slice(35, 38);
|
|
67
|
-
debugData(
|
|
66
|
+
debugData(`${label} 008 code: ${code}`);
|
|
68
67
|
return code === '|||' || code === ' ' || code === '^^^' ? undefined : code;
|
|
69
68
|
}
|
|
70
69
|
|
|
71
70
|
// Main language for the resource: in the first f041 $a or f041 $d
|
|
71
|
+
// Should we get all $a or $d languages instead of just the first?
|
|
72
72
|
// Uses only f041s that have 2nd ind ' ', which means that the codes used are MARC 21 language codes
|
|
73
73
|
|
|
74
74
|
function get041Values() {
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
4
|
+
*
|
|
5
|
+
* Melinda record matching modules for Javascript
|
|
6
|
+
*
|
|
7
|
+
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
8
|
+
*
|
|
9
|
+
* This file is part of melinda-record-matching-js
|
|
10
|
+
*
|
|
11
|
+
* melinda-record-matching-js program is free software: you can redistribute it and/or modify
|
|
12
|
+
* it under the terms of the GNU Lesser General Public License as
|
|
13
|
+
* published by the Free Software Foundation, either version 3 of the
|
|
14
|
+
* License, or (at your option) any later version.
|
|
15
|
+
*
|
|
16
|
+
* melinda-record-matching-js is distributed in the hope that it will be useful,
|
|
17
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19
|
+
* GNU Lesser General Public License for more details.
|
|
20
|
+
*
|
|
21
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
22
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
23
|
+
*
|
|
24
|
+
* @licend The above is the entire license notice
|
|
25
|
+
* for the JavaScript code in this file.
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import createDebugLogger from 'debug';
|
|
30
|
+
import {LevenshteinDistance as leven} from 'natural';
|
|
31
|
+
|
|
32
|
+
export default ({treshold = 10} = {}) => ({
|
|
33
|
+
name: 'titleVersionOriginal',
|
|
34
|
+
extract: ({record}) => {
|
|
35
|
+
const title = getTitle();
|
|
36
|
+
|
|
37
|
+
if (title) {
|
|
38
|
+
return [title.replace(/[^\p{Letter}\p{Number}]/gu, '').toLowerCase()];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return [];
|
|
42
|
+
|
|
43
|
+
function getTitle() {
|
|
44
|
+
const [field] = record.get(/^245$/u);
|
|
45
|
+
|
|
46
|
+
if (field) {
|
|
47
|
+
return field.subfields
|
|
48
|
+
.filter(({code}) => ['a', 'b'].includes(code))
|
|
49
|
+
.map(({value}) => value)
|
|
50
|
+
.join('');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
compare: (a, b) => {
|
|
55
|
+
const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib/title-version-original');
|
|
56
|
+
const distance = leven(a[0], b[0]);
|
|
57
|
+
|
|
58
|
+
if (distance === 0) {
|
|
59
|
+
return 0.5;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const maxLength = getMaxLength();
|
|
63
|
+
const percentage = distance / maxLength * 100;
|
|
64
|
+
|
|
65
|
+
debug(`'${a}' vs '${b}': Max length = ${maxLength}, distance = ${distance}, percentage = ${percentage}`);
|
|
66
|
+
|
|
67
|
+
if (percentage <= treshold) {
|
|
68
|
+
return 0.3;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return -0.5;
|
|
72
|
+
|
|
73
|
+
function getMaxLength() {
|
|
74
|
+
return a[0].length > b[0].length ? a[0].length : b[0].length;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
}
|
|
78
|
+
});
|
|
@@ -26,27 +26,45 @@
|
|
|
26
26
|
*
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
import {LevenshteinDistance as leven} from 'natural';
|
|
31
31
|
import {testStringOrNumber} from '../../../matching-utils';
|
|
32
|
+
import createDebugLogger from 'debug';
|
|
33
|
+
|
|
34
|
+
const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features:title');
|
|
35
|
+
const debugData = debug.extend('data');
|
|
36
|
+
|
|
32
37
|
|
|
33
38
|
export default ({treshold = 10} = {}) => ({
|
|
34
39
|
name: 'Title',
|
|
35
|
-
extract: ({record}) => {
|
|
40
|
+
extract: ({record, recordExternal}) => {
|
|
41
|
+
const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';
|
|
36
42
|
const title = getTitle();
|
|
43
|
+
debug(`${label} title: ${title}`);
|
|
37
44
|
|
|
38
45
|
if (testStringOrNumber(title)) {
|
|
39
|
-
|
|
46
|
+
const titleAsNormalizedString = String(title)
|
|
47
|
+
// decompose unicode diacritics
|
|
48
|
+
.normalize('NFD')
|
|
49
|
+
// strip non-letters/numbers
|
|
50
|
+
// - note: combined with decomposing unicode diactics this normalizes both 'saa' and 'sää' as 'saa'
|
|
51
|
+
// - we could precompose the finnish letters back to avoid this
|
|
52
|
+
.replace(/[^\p{Letter}\p{Number}]/gu, '')
|
|
53
|
+
.toLowerCase();
|
|
54
|
+
debug(`${label} titleString: ${titleAsNormalizedString}`);
|
|
55
|
+
return [titleAsNormalizedString];
|
|
40
56
|
}
|
|
41
57
|
|
|
42
58
|
return [];
|
|
43
59
|
|
|
44
60
|
function getTitle() {
|
|
45
61
|
const [field] = record.get(/^245$/u);
|
|
62
|
+
debugData(`${label} titleField: ${JSON.stringify(field)}`);
|
|
46
63
|
|
|
47
64
|
if (field) {
|
|
48
65
|
return field.subfields
|
|
49
|
-
|
|
66
|
+
// get also $n:s and $p:s here
|
|
67
|
+
.filter(({code}) => ['a', 'b', 'n', 'p'].includes(code))
|
|
50
68
|
.map(({value}) => testStringOrNumber(value) ? String(value) : '')
|
|
51
69
|
.join('');
|
|
52
70
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
1
|
/**
|
|
3
2
|
*
|
|
4
3
|
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
@@ -32,7 +31,7 @@ import * as features from './features';
|
|
|
32
31
|
|
|
33
32
|
export {features};
|
|
34
33
|
|
|
35
|
-
export default ({strategy, treshold = 0.9}, returnStrategy = false) => ({recordA, recordB, recordAExternal = {}, recordBExternal = {}}) => {
|
|
34
|
+
export default ({strategy, treshold = 0.9}, returnStrategy = false, localSettings = {}) => ({recordA, recordB, recordAExternal = {}, recordBExternal = {}}) => {
|
|
36
35
|
const minProbabilityQuantifier = 0.5;
|
|
37
36
|
|
|
38
37
|
const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection');
|
|
@@ -41,8 +40,9 @@ export default ({strategy, treshold = 0.9}, returnStrategy = false) => ({recordA
|
|
|
41
40
|
debugData(`Strategy: ${JSON.stringify(strategy)}, Treshold: ${JSON.stringify(treshold)}, ReturnStrategy: ${JSON.stringify(returnStrategy)}`);
|
|
42
41
|
debugData(`Records: A: ${recordA}\nB: ${recordB}`);
|
|
43
42
|
debug(`Externals: A: ${JSON.stringify(recordAExternal)}, B: ${JSON.stringify(recordBExternal)}`);
|
|
43
|
+
// We could add here labels for records if we didn't get external labels
|
|
44
44
|
|
|
45
|
-
const featuresA = extractFeatures({record: recordA, recordExternal: recordAExternal});
|
|
45
|
+
const featuresA = extractFeatures({record: recordA, recordExternal: recordAExternal, localSettings});
|
|
46
46
|
|
|
47
47
|
debug(`We got an array of records: ${Array.isArray(recordB)}`);
|
|
48
48
|
const recordsB = Array.isArray(recordB) ? recordB : [recordB];
|
|
@@ -54,13 +54,13 @@ export default ({strategy, treshold = 0.9}, returnStrategy = false) => ({recordA
|
|
|
54
54
|
// if we got a singular record, we return a singular result
|
|
55
55
|
return Array.isArray(recordB) ? detectionResults : detectionResults[0];
|
|
56
56
|
|
|
57
|
-
function actualDetection({featuresA, record, recordExternal, index}) {
|
|
57
|
+
function actualDetection({featuresA, record, recordExternal, index, localSettings}) {
|
|
58
58
|
const labelA = recordAExternal && recordAExternal.label ? recordAExternal.label : 'a';
|
|
59
59
|
const labelB = recordExternal && recordExternal.label ? recordExternal.label : 'b';
|
|
60
60
|
|
|
61
61
|
|
|
62
62
|
debug(`Actual detection for record ${index + 1} ${labelB}`);
|
|
63
|
-
const featuresB = extractFeatures({record, recordExternal});
|
|
63
|
+
const featuresB = extractFeatures({record, recordExternal, localSettings});
|
|
64
64
|
|
|
65
65
|
debugData(`Features (a: ${labelA}): ${JSON.stringify(featuresA)}`);
|
|
66
66
|
debugData(`Features (b: ${labelB}): ${JSON.stringify(featuresB)}`);
|
|
@@ -69,7 +69,7 @@ export default ({strategy, treshold = 0.9}, returnStrategy = false) => ({recordA
|
|
|
69
69
|
const similarityVector = generateSimilarityVector(featurePairs);
|
|
70
70
|
|
|
71
71
|
if (similarityVector.some(v => v >= minProbabilityQuantifier)) {
|
|
72
|
-
const probability =
|
|
72
|
+
const probability = calculateProbability(similarityVector);
|
|
73
73
|
debug(`probability: ${probability} (Treshold: ${treshold})`);
|
|
74
74
|
return returnResult({match: probability >= treshold, probability});
|
|
75
75
|
}
|
|
@@ -97,7 +97,7 @@ export default ({strategy, treshold = 0.9}, returnStrategy = false) => ({recordA
|
|
|
97
97
|
return strategyNames || [];
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
function
|
|
100
|
+
function calculateProbability(similarityVector) {
|
|
101
101
|
const probability = similarityVector.reduce((acc, v) => acc + v, 0.0);
|
|
102
102
|
return probability > 1.0 ? 1.0 : probability;
|
|
103
103
|
}
|
package/src/matching-utils.js
CHANGED
|
@@ -31,7 +31,6 @@ import createDebugLogger from 'debug';
|
|
|
31
31
|
const debug = createDebugLogger('@natlibfi/melinda-record-matching:utils');
|
|
32
32
|
const debugData = debug.extend('data');
|
|
33
33
|
|
|
34
|
-
// eslint-disable-next-line max-statements
|
|
35
34
|
export function getMelindaIdsF035(record) {
|
|
36
35
|
|
|
37
36
|
const debug = createDebugLogger('@natlibfi/melinda-record-matching:melinda-id');
|