@natlibfi/melinda-record-matching 2.2.0-alpha.4 → 2.2.1-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/.github/CODEOWNERS +10 -0
- package/.github/dependabot.yml +40 -0
- package/.github/workflows/melinda-node-tests.yml +70 -0
- package/package.json +1 -1
- package/dist/candidate-search/candidate-search-utils.js +0 -58
- package/dist/candidate-search/candidate-search-utils.js.map +0 -1
- package/dist/candidate-search/index.js +0 -273
- package/dist/candidate-search/index.js.map +0 -1
- package/dist/candidate-search/index.spec.js +0 -161
- package/dist/candidate-search/index.spec.js.map +0 -1
- package/dist/candidate-search/query-list/bib.js +0 -252
- package/dist/candidate-search/query-list/bib.js.map +0 -1
- package/dist/candidate-search/query-list/bib.spec.js +0 -72
- package/dist/candidate-search/query-list/bib.spec.js.map +0 -1
- package/dist/candidate-search/query-list/index.js +0 -67
- package/dist/candidate-search/query-list/index.js.map +0 -1
- package/dist/index.js +0 -578
- package/dist/index.js.map +0 -1
- package/dist/index.spec.js +0 -133
- package/dist/index.spec.js.map +0 -1
- package/dist/match-detection/features/bib/all-source-ids.js +0 -122
- package/dist/match-detection/features/bib/all-source-ids.js.map +0 -1
- package/dist/match-detection/features/bib/authors.js +0 -117
- package/dist/match-detection/features/bib/authors.js.map +0 -1
- package/dist/match-detection/features/bib/bibliographic-level.js +0 -42
- package/dist/match-detection/features/bib/bibliographic-level.js.map +0 -1
- package/dist/match-detection/features/bib/host-component.js +0 -42
- package/dist/match-detection/features/bib/host-component.js.map +0 -1
- package/dist/match-detection/features/bib/index.js +0 -104
- package/dist/match-detection/features/bib/index.js.map +0 -1
- package/dist/match-detection/features/bib/index.spec.js +0 -97
- package/dist/match-detection/features/bib/index.spec.js.map +0 -1
- package/dist/match-detection/features/bib/isbn.js +0 -55
- package/dist/match-detection/features/bib/isbn.js.map +0 -1
- package/dist/match-detection/features/bib/issn.js +0 -55
- package/dist/match-detection/features/bib/issn.js.map +0 -1
- package/dist/match-detection/features/bib/language.js +0 -113
- package/dist/match-detection/features/bib/language.js.map +0 -1
- package/dist/match-detection/features/bib/melinda-id.js +0 -52
- package/dist/match-detection/features/bib/melinda-id.js.map +0 -1
- package/dist/match-detection/features/bib/melinda-identifier-factory.js +0 -100
- package/dist/match-detection/features/bib/melinda-identifier-factory.js.map +0 -1
- package/dist/match-detection/features/bib/other-standard-identifier.js +0 -55
- package/dist/match-detection/features/bib/other-standard-identifier.js.map +0 -1
- package/dist/match-detection/features/bib/publication-time.js +0 -47
- package/dist/match-detection/features/bib/publication-time.js.map +0 -1
- package/dist/match-detection/features/bib/record-type.js +0 -42
- package/dist/match-detection/features/bib/record-type.js.map +0 -1
- package/dist/match-detection/features/bib/standard-identifier-factory.js +0 -126
- package/dist/match-detection/features/bib/standard-identifier-factory.js.map +0 -1
- package/dist/match-detection/features/bib/title.js +0 -91
- package/dist/match-detection/features/bib/title.js.map +0 -1
- package/dist/match-detection/features/index.js +0 -15
- package/dist/match-detection/features/index.js.map +0 -1
- package/dist/match-detection/index.js +0 -184
- package/dist/match-detection/index.js.map +0 -1
- package/dist/match-detection/index.spec.js +0 -99
- package/dist/match-detection/index.spec.js.map +0 -1
- package/dist/matching-utils.js +0 -95
- package/dist/matching-utils.js.map +0 -1
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _standardIdentifierFactory = _interopRequireDefault(require("./standard-identifier-factory"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
15
|
-
*
|
|
16
|
-
* Melinda record matching modules for Javascript
|
|
17
|
-
*
|
|
18
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
19
|
-
*
|
|
20
|
-
* This file is part of melinda-record-matching-js
|
|
21
|
-
*
|
|
22
|
-
* melinda-record-matching-js program is free software: you can redistribute it and/or modify
|
|
23
|
-
* it under the terms of the GNU Lesser General Public License as
|
|
24
|
-
* published by the Free Software Foundation, either version 3 of the
|
|
25
|
-
* License, or (at your option) any later version.
|
|
26
|
-
*
|
|
27
|
-
* melinda-record-matching-js is distributed in the hope that it will be useful,
|
|
28
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
29
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
30
|
-
* GNU Lesser General Public License for more details.
|
|
31
|
-
*
|
|
32
|
-
* You should have received a copy of the GNU Affero General Public License
|
|
33
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
34
|
-
*
|
|
35
|
-
* @licend The above is the entire license notice
|
|
36
|
-
* for the JavaScript code in this file.
|
|
37
|
-
*
|
|
38
|
-
*/
|
|
39
|
-
var _default = () => {
|
|
40
|
-
const {
|
|
41
|
-
extract,
|
|
42
|
-
compare
|
|
43
|
-
} = (0, _standardIdentifierFactory.default)({
|
|
44
|
-
pattern: /^024$/u,
|
|
45
|
-
subfieldCodes: ['a', 'z']
|
|
46
|
-
});
|
|
47
|
-
return {
|
|
48
|
-
extract,
|
|
49
|
-
compare,
|
|
50
|
-
name: 'Other standard identifier'
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
exports.default = _default;
|
|
55
|
-
//# sourceMappingURL=other-standard-identifier.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"other-standard-identifier.js","names":["extract","compare","createInterface","pattern","subfieldCodes","name"],"sources":["../../../../src/match-detection/features/bib/other-standard-identifier.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 createInterface from './standard-identifier-factory';\n\nexport default () => {\n const {extract, compare} = createInterface({pattern: /^024$/u, subfieldCodes: ['a', 'z']});\n return {extract, compare, name: 'Other standard identifier'};\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;eAIe,MAAM;EACnB,MAAM;IAACA,OAAD;IAAUC;EAAV,IAAqB,IAAAC,kCAAA,EAAgB;IAACC,OAAO,EAAE,QAAV;IAAoBC,aAAa,EAAE,CAAC,GAAD,EAAM,GAAN;EAAnC,CAAhB,CAA3B;EACA,OAAO;IAACJ,OAAD;IAAUC,OAAV;IAAmBI,IAAI,EAAE;EAAzB,CAAP;AACD,C"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
10
|
-
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
11
|
-
*
|
|
12
|
-
* Melinda record matching modules for Javascript
|
|
13
|
-
*
|
|
14
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
15
|
-
*
|
|
16
|
-
* This file is part of melinda-record-matching-js
|
|
17
|
-
*
|
|
18
|
-
* melinda-record-matching-js program is free software: you can redistribute it and/or modify
|
|
19
|
-
* it under the terms of the GNU Lesser General Public License as
|
|
20
|
-
* published by the Free Software Foundation, either version 3 of the
|
|
21
|
-
* License, or (at your option) any later version.
|
|
22
|
-
*
|
|
23
|
-
* melinda-record-matching-js is distributed in the hope that it will be useful,
|
|
24
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
25
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
26
|
-
* GNU Lesser General Public License for more details.
|
|
27
|
-
*
|
|
28
|
-
* You should have received a copy of the GNU Affero General Public License
|
|
29
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
30
|
-
*
|
|
31
|
-
* @licend The above is the entire license notice
|
|
32
|
-
* for the JavaScript code in this file.
|
|
33
|
-
*
|
|
34
|
-
*/
|
|
35
|
-
var _default = () => ({
|
|
36
|
-
name: 'Publication time',
|
|
37
|
-
extract: record => {
|
|
38
|
-
var _record$get, _record$get$;
|
|
39
|
-
|
|
40
|
-
const value = ((_record$get = record.get(/^008$/u)) === null || _record$get === void 0 ? void 0 : (_record$get$ = _record$get[0]) === null || _record$get$ === void 0 ? void 0 : _record$get$.value) || '';
|
|
41
|
-
return value ? [value.slice(7, 11)] : [];
|
|
42
|
-
},
|
|
43
|
-
compare: (a, b) => a[0] === b[0] ? 0.1 : -1.0
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
exports.default = _default;
|
|
47
|
-
//# sourceMappingURL=publication-time.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"publication-time.js","names":["name","extract","record","value","get","slice","compare","a","b"],"sources":["../../../../src/match-detection/features/bib/publication-time.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\nexport default () => ({\n name: 'Publication time',\n extract: record => {\n const value = record.get(/^008$/u)?.[0]?.value || '';\n return value ? [value.slice(7, 11)] : [];\n },\n compare: (a, b) => a[0] === b[0] ? 0.1 : -1.0\n});\n"],"mappings":";;;;;;;AAAA;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;eAEe,OAAO;EACpBA,IAAI,EAAE,kBADc;EAEpBC,OAAO,EAAEC,MAAM,IAAI;IAAA;;IACjB,MAAMC,KAAK,GAAG,gBAAAD,MAAM,CAACE,GAAP,CAAW,QAAX,6EAAuB,CAAvB,+DAA2BD,KAA3B,KAAoC,EAAlD;IACA,OAAOA,KAAK,GAAG,CAACA,KAAK,CAACE,KAAN,CAAY,CAAZ,EAAe,EAAf,CAAD,CAAH,GAA0B,EAAtC;EACD,CALmB;EAMpBC,OAAO,EAAE,CAACC,CAAD,EAAIC,CAAJ,KAAUD,CAAC,CAAC,CAAD,CAAD,KAASC,CAAC,CAAC,CAAD,CAAV,GAAgB,GAAhB,GAAsB,CAAC;AANtB,CAAP,C"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
10
|
-
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
11
|
-
*
|
|
12
|
-
* Melinda record matching modules for Javascript
|
|
13
|
-
*
|
|
14
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
15
|
-
*
|
|
16
|
-
* This file is part of melinda-record-matching-js
|
|
17
|
-
*
|
|
18
|
-
* melinda-record-matching-js program is free software: you can redistribute it and/or modify
|
|
19
|
-
* it under the terms of the GNU Lesser General Public License as
|
|
20
|
-
* published by the Free Software Foundation, either version 3 of the
|
|
21
|
-
* License, or (at your option) any later version.
|
|
22
|
-
*
|
|
23
|
-
* melinda-record-matching-js is distributed in the hope that it will be useful,
|
|
24
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
25
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
26
|
-
* GNU Lesser General Public License for more details.
|
|
27
|
-
*
|
|
28
|
-
* You should have received a copy of the GNU Affero General Public License
|
|
29
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
30
|
-
*
|
|
31
|
-
* @licend The above is the entire license notice
|
|
32
|
-
* for the JavaScript code in this file.
|
|
33
|
-
*
|
|
34
|
-
*/
|
|
35
|
-
var _default = () => ({
|
|
36
|
-
name: 'Record type',
|
|
37
|
-
extract: r => r.leader[6] ? [r.leader[6]] : [],
|
|
38
|
-
compare: (a, b) => a[0] === b[0] ? 0.1 : -0.5
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
exports.default = _default;
|
|
42
|
-
//# sourceMappingURL=record-type.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"record-type.js","names":["name","extract","r","leader","compare","a","b"],"sources":["../../../../src/match-detection/features/bib/record-type.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\nexport default () => ({\n name: 'Record type',\n extract: r => r.leader[6] ? [r.leader[6]] : [],\n compare: (a, b) => a[0] === b[0] ? 0.1 : -0.5\n});\n"],"mappings":";;;;;;;AAAA;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;eAEe,OAAO;EACpBA,IAAI,EAAE,aADc;EAEpBC,OAAO,EAAEC,CAAC,IAAIA,CAAC,CAACC,MAAF,CAAS,CAAT,IAAc,CAACD,CAAC,CAACC,MAAF,CAAS,CAAT,CAAD,CAAd,GAA8B,EAFxB;EAGpBC,OAAO,EAAE,CAACC,CAAD,EAAIC,CAAJ,KAAUD,CAAC,CAAC,CAAD,CAAD,KAASC,CAAC,CAAC,CAAD,CAAV,GAAgB,GAAhB,GAAsB,CAAC;AAHtB,CAAP,C"}
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
15
|
-
*
|
|
16
|
-
* Melinda record matching modules for Javascript
|
|
17
|
-
*
|
|
18
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
19
|
-
*
|
|
20
|
-
* This file is part of melinda-record-matching-js
|
|
21
|
-
*
|
|
22
|
-
* melinda-record-matching-js program is free software: you can redistribute it and/or modify
|
|
23
|
-
* it under the terms of the GNU Lesser General Public License as
|
|
24
|
-
* published by the Free Software Foundation, either version 3 of the
|
|
25
|
-
* License, or (at your option) any later version.
|
|
26
|
-
*
|
|
27
|
-
* melinda-record-matching-js is distributed in the hope that it will be useful,
|
|
28
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
29
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
30
|
-
* GNU Lesser General Public License for more details.
|
|
31
|
-
*
|
|
32
|
-
* You should have received a copy of the GNU Affero General Public License
|
|
33
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
34
|
-
*
|
|
35
|
-
* @licend The above is the entire license notice
|
|
36
|
-
* for the JavaScript code in this file.
|
|
37
|
-
*
|
|
38
|
-
*/
|
|
39
|
-
const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:match-detection:features:standard-identifiers');
|
|
40
|
-
const debugData = debug.extend('data');
|
|
41
|
-
|
|
42
|
-
var _default = ({
|
|
43
|
-
pattern,
|
|
44
|
-
subfieldCodes
|
|
45
|
-
}) => {
|
|
46
|
-
return {
|
|
47
|
-
extract,
|
|
48
|
-
compare
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
function extract(record) {
|
|
52
|
-
const [field] = record.get(pattern);
|
|
53
|
-
|
|
54
|
-
if (field) {
|
|
55
|
-
return field.subfields.filter(({
|
|
56
|
-
code
|
|
57
|
-
}) => subfieldCodes.includes(code)) // .map(({code, value}) => ({code, value: value.replace(/-/ug, '')}));
|
|
58
|
-
.map(({
|
|
59
|
-
code,
|
|
60
|
-
value
|
|
61
|
-
}) => ({
|
|
62
|
-
code,
|
|
63
|
-
value: value ? value.replace(/-/ug, '') : ''
|
|
64
|
-
}));
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return [];
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function compare(a, b) {
|
|
71
|
-
if (a.length === 0 || b.length === 0) {
|
|
72
|
-
debugData(`No standardidentifiers to compare`);
|
|
73
|
-
return 0;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (bothHaveValidIdentifiers()) {
|
|
77
|
-
const {
|
|
78
|
-
maxValues,
|
|
79
|
-
matchingValues
|
|
80
|
-
} = getValueCount(true);
|
|
81
|
-
return matchingValues / maxValues * 0.75;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const {
|
|
85
|
-
maxValues,
|
|
86
|
-
matchingValues
|
|
87
|
-
} = getValueCount();
|
|
88
|
-
return matchingValues / maxValues * 0.2;
|
|
89
|
-
|
|
90
|
-
function bothHaveValidIdentifiers() {
|
|
91
|
-
const aValues = a.filter(({
|
|
92
|
-
code
|
|
93
|
-
}) => code === 'a');
|
|
94
|
-
const bValues = a.filter(({
|
|
95
|
-
code
|
|
96
|
-
}) => code === 'a');
|
|
97
|
-
return aValues.length > 0 && bValues.length > 0;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function getValueCount(validOnly = false) {
|
|
101
|
-
const aValues = getIdentifiers(a);
|
|
102
|
-
const bValues = getIdentifiers(b);
|
|
103
|
-
return {
|
|
104
|
-
maxValues: aValues.length > bValues.length ? aValues.length : bValues.length,
|
|
105
|
-
matchingValues: aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
function getIdentifiers(values) {
|
|
109
|
-
if (validOnly) {
|
|
110
|
-
return values.filter(({
|
|
111
|
-
code
|
|
112
|
-
}) => code === 'a').map(({
|
|
113
|
-
value
|
|
114
|
-
}) => value);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return values.map(({
|
|
118
|
-
value
|
|
119
|
-
}) => value);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
exports.default = _default;
|
|
126
|
-
//# sourceMappingURL=standard-identifier-factory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"standard-identifier-factory.js","names":["debug","createDebugLogger","debugData","extend","pattern","subfieldCodes","extract","compare","record","field","get","subfields","filter","code","includes","map","value","replace","a","b","length","bothHaveValidIdentifiers","maxValues","matchingValues","getValueCount","aValues","bValues","validOnly","getIdentifiers","aValue","some","bValue","values"],"sources":["../../../../src/match-detection/features/bib/standard-identifier-factory.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 createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features:standard-identifiers');\nconst debugData = debug.extend('data');\n\nexport default ({pattern, subfieldCodes}) => {\n return {extract, compare};\n\n function extract(record) {\n const [field] = record.get(pattern);\n\n if (field) {\n return field.subfields\n .filter(({code}) => subfieldCodes.includes(code))\n // .map(({code, value}) => ({code, value: value.replace(/-/ug, '')}));\n .map(({code, value}) => ({code, value: value ? value.replace(/-/ug, '') : ''}));\n }\n\n return [];\n }\n\n function compare(a, b) {\n if (a.length === 0 || b.length === 0) {\n debugData(`No standardidentifiers to compare`);\n return 0;\n }\n\n if (bothHaveValidIdentifiers()) {\n const {maxValues, matchingValues} = getValueCount(true);\n return matchingValues / maxValues * 0.75;\n }\n\n const {maxValues, matchingValues} = getValueCount();\n return matchingValues / maxValues * 0.2;\n\n function bothHaveValidIdentifiers() {\n const aValues = a.filter(({code}) => code === 'a');\n const bValues = a.filter(({code}) => code === 'a');\n return aValues.length > 0 && bValues.length > 0;\n }\n\n function getValueCount(validOnly = false) {\n const aValues = getIdentifiers(a);\n const bValues = getIdentifiers(b);\n\n return {\n maxValues: aValues.length > bValues.length ? aValues.length : bValues.length,\n matchingValues: aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length\n };\n\n function getIdentifiers(values) {\n if (validOnly) {\n return values\n .filter(({code}) => code === 'a')\n .map(({value}) => value);\n }\n\n return values.map(({value}) => value);\n }\n }\n }\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,iFAAlB,CAAd;AACA,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAN,CAAa,MAAb,CAAlB;;eAEe,CAAC;EAACC,OAAD;EAAU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,IAAI,KAAK,GAA9B,CAAhB;MACA,OAAOY,OAAO,CAACL,MAAR,GAAiB,CAAjB,IAAsBM,OAAO,CAACN,MAAR,GAAiB,CAA9C;IACD;;IAED,SAASI,aAAT,CAAuBG,SAAS,GAAG,KAAnC,EAA0C;MACxC,MAAMF,OAAO,GAAGG,cAAc,CAACV,CAAD,CAA9B;MACA,MAAMQ,OAAO,GAAGE,cAAc,CAACT,CAAD,CAA9B;MAEA,OAAO;QACLG,SAAS,EAAEG,OAAO,CAACL,MAAR,GAAiBM,OAAO,CAACN,MAAzB,GAAkCK,OAAO,CAACL,MAA1C,GAAmDM,OAAO,CAACN,MADjE;QAELG,cAAc,EAAEE,OAAO,CAACb,MAAR,CAAeiB,MAAM,IAAIH,OAAO,CAACI,IAAR,CAAaC,MAAM,IAAIF,MAAM,KAAKE,MAAlC,CAAzB,EAAoEX;MAF/E,CAAP;;MAKA,SAASQ,cAAT,CAAwBI,MAAxB,EAAgC;QAC9B,IAAIL,SAAJ,EAAe;UACb,OAAOK,MAAM,CACVpB,MADI,CACG,CAAC;YAACC;UAAD,CAAD,KAAYA,IAAI,KAAK,GADxB,EAEJE,GAFI,CAEA,CAAC;YAACC;UAAD,CAAD,KAAaA,KAFb,CAAP;QAGD;;QAED,OAAOgB,MAAM,CAACjB,GAAP,CAAW,CAAC;UAACC;QAAD,CAAD,KAAaA,KAAxB,CAAP;MACD;IACF;EACF;AACF,C"}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
9
|
-
|
|
10
|
-
var _natural = require("natural");
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
16
|
-
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
17
|
-
*
|
|
18
|
-
* Melinda record matching modules for Javascript
|
|
19
|
-
*
|
|
20
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
21
|
-
*
|
|
22
|
-
* This file is part of melinda-record-matching-js
|
|
23
|
-
*
|
|
24
|
-
* melinda-record-matching-js program is free software: you can redistribute it and/or modify
|
|
25
|
-
* it under the terms of the GNU Lesser General Public License as
|
|
26
|
-
* published by the Free Software Foundation, either version 3 of the
|
|
27
|
-
* License, or (at your option) any later version.
|
|
28
|
-
*
|
|
29
|
-
* melinda-record-matching-js is distributed in the hope that it will be useful,
|
|
30
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
31
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
32
|
-
* GNU Lesser General Public License for more details.
|
|
33
|
-
*
|
|
34
|
-
* You should have received a copy of the GNU Affero General Public License
|
|
35
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
36
|
-
*
|
|
37
|
-
* @licend The above is the entire license notice
|
|
38
|
-
* for the JavaScript code in this file.
|
|
39
|
-
*
|
|
40
|
-
*/
|
|
41
|
-
var _default = ({
|
|
42
|
-
treshold = 10
|
|
43
|
-
} = {}) => ({
|
|
44
|
-
name: 'Title',
|
|
45
|
-
extract: record => {
|
|
46
|
-
const title = getTitle();
|
|
47
|
-
|
|
48
|
-
if (title) {
|
|
49
|
-
return [title.replace(/[^\p{Letter}\p{Number}]/gu, '').toLowerCase()];
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return [];
|
|
53
|
-
|
|
54
|
-
function getTitle() {
|
|
55
|
-
const [field] = record.get(/^245$/u);
|
|
56
|
-
|
|
57
|
-
if (field) {
|
|
58
|
-
return field.subfields.filter(({
|
|
59
|
-
code
|
|
60
|
-
}) => ['a', 'b'].includes(code)).map(({
|
|
61
|
-
value
|
|
62
|
-
}) => value).join('');
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
compare: (a, b) => {
|
|
67
|
-
const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:match-detection:features/bib/title');
|
|
68
|
-
const distance = (0, _natural.LevenshteinDistance)(a[0], b[0]);
|
|
69
|
-
|
|
70
|
-
if (distance === 0) {
|
|
71
|
-
return 0.5;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const maxLength = getMaxLength();
|
|
75
|
-
const percentage = distance / maxLength * 100;
|
|
76
|
-
debug(`'${a}' vs '${b}': Max length = ${maxLength}, distance = ${distance}, percentage = ${percentage}`);
|
|
77
|
-
|
|
78
|
-
if (percentage <= treshold) {
|
|
79
|
-
return 0.3;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return -0.5;
|
|
83
|
-
|
|
84
|
-
function getMaxLength() {
|
|
85
|
-
return a[0].length > b[0].length ? a[0].length : b[0].length;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
exports.default = _default;
|
|
91
|
-
//# sourceMappingURL=title.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"title.js","names":["treshold","name","extract","record","title","getTitle","replace","toLowerCase","field","get","subfields","filter","code","includes","map","value","join","compare","a","b","debug","createDebugLogger","distance","leven","maxLength","getMaxLength","percentage","length"],"sources":["../../../../src/match-detection/features/bib/title.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 createDebugLogger from 'debug';\nimport {LevenshteinDistance as leven} from 'natural';\n\nexport default ({treshold = 10} = {}) => ({\n name: 'Title',\n extract: record => {\n const title = getTitle();\n\n if (title) {\n return [title.replace(/[^\\p{Letter}\\p{Number}]/gu, '').toLowerCase()];\n }\n\n return [];\n\n function getTitle() {\n const [field] = record.get(/^245$/u);\n\n if (field) {\n return field.subfields\n .filter(({code}) => ['a', 'b'].includes(code))\n .map(({value}) => value)\n .join('');\n }\n }\n },\n compare: (a, b) => {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib/title');\n const distance = leven(a[0], b[0]);\n\n if (distance === 0) {\n return 0.5;\n }\n\n const maxLength = getMaxLength();\n const percentage = distance / maxLength * 100;\n\n debug(`'${a}' vs '${b}': Max length = ${maxLength}, distance = ${distance}, percentage = ${percentage}`);\n\n if (percentage <= treshold) {\n return 0.3;\n }\n\n return -0.5;\n\n function getMaxLength() {\n return a[0].length > b[0].length ? a[0].length : b[0].length;\n }\n\n }\n});\n"],"mappings":";;;;;;;AA4BA;;AACA;;;;AA7BA;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;eAKe,CAAC;EAACA,QAAQ,GAAG;AAAZ,IAAkB,EAAnB,MAA2B;EACxCC,IAAI,EAAE,OADkC;EAExCC,OAAO,EAAEC,MAAM,IAAI;IACjB,MAAMC,KAAK,GAAGC,QAAQ,EAAtB;;IAEA,IAAID,KAAJ,EAAW;MACT,OAAO,CAACA,KAAK,CAACE,OAAN,CAAc,2BAAd,EAA2C,EAA3C,E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CuC,CAA3B,C"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.bib = void 0;
|
|
7
|
-
|
|
8
|
-
var bib = _interopRequireWildcard(require("./bib"));
|
|
9
|
-
|
|
10
|
-
exports.bib = bib;
|
|
11
|
-
|
|
12
|
-
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); }
|
|
13
|
-
|
|
14
|
-
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; }
|
|
15
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/match-detection/features/index.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 * as bib from './bib';\nexport {bib};\n"],"mappings":";;;;;;;AA4BA"}
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.features = exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
9
|
-
|
|
10
|
-
var features = _interopRequireWildcard(require("./features"));
|
|
11
|
-
|
|
12
|
-
exports.features = features;
|
|
13
|
-
|
|
14
|
-
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); }
|
|
15
|
-
|
|
16
|
-
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; }
|
|
17
|
-
|
|
18
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
|
-
/* eslint-disable no-console */
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
*
|
|
24
|
-
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
25
|
-
*
|
|
26
|
-
* Melinda record matching modules for Javascript
|
|
27
|
-
*
|
|
28
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
29
|
-
*
|
|
30
|
-
* This file is part of melinda-record-matching-js
|
|
31
|
-
*
|
|
32
|
-
* melinda-record-matching-js program is free software: you can redistribute it and/or modify
|
|
33
|
-
* it under the terms of the GNU Lesser General Public License as
|
|
34
|
-
* published by the Free Software Foundation, either version 3 of the
|
|
35
|
-
* License, or (at your option) any later version.
|
|
36
|
-
*
|
|
37
|
-
* melinda-record-matching-js is distributed in the hope that it will be useful,
|
|
38
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
39
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
40
|
-
* GNU Lesser General Public License for more details.
|
|
41
|
-
*
|
|
42
|
-
* You should have received a copy of the GNU Affero General Public License
|
|
43
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
44
|
-
*
|
|
45
|
-
* @licend The above is the entire license notice
|
|
46
|
-
* for the JavaScript code in this file.
|
|
47
|
-
*
|
|
48
|
-
*/
|
|
49
|
-
var _default = ({
|
|
50
|
-
strategy,
|
|
51
|
-
treshold = 0.9
|
|
52
|
-
}, returnStrategy = false) => (recordA, recordB) => {
|
|
53
|
-
const minProbabilityQuantifier = 0.5;
|
|
54
|
-
const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:match-detection');
|
|
55
|
-
const debugData = debug.extend('data');
|
|
56
|
-
debugData(`Strategy: ${JSON.stringify(strategy)}`);
|
|
57
|
-
debugData(`Treshold: ${JSON.stringify(treshold)}`);
|
|
58
|
-
debugData(`ReturnStrategy: ${JSON.stringify(returnStrategy)}`);
|
|
59
|
-
const featuresA = extractFeatures(recordA);
|
|
60
|
-
debug(`We got an array of records: ${Array.isArray(recordB)}`);
|
|
61
|
-
const recordsB = Array.isArray(recordB) ? recordB : [recordB];
|
|
62
|
-
const detectionResults = recordsB.map(record => actualDetection(featuresA, record));
|
|
63
|
-
return Array.isArray(recordB) ? detectionResults : detectionResults[0];
|
|
64
|
-
|
|
65
|
-
function actualDetection(featuresA, record) {
|
|
66
|
-
const featuresB = extractFeatures(record);
|
|
67
|
-
debugData(`Features (a): ${JSON.stringify(featuresA)}`);
|
|
68
|
-
debugData(`Features (b): ${JSON.stringify(featuresB)}`);
|
|
69
|
-
const featurePairs = generateFeaturePairs(featuresA, featuresB);
|
|
70
|
-
const similarityVector = generateSimilarityVector(featurePairs);
|
|
71
|
-
|
|
72
|
-
if (similarityVector.some(v => v >= minProbabilityQuantifier)) {
|
|
73
|
-
const probability = calculateprobability(similarityVector);
|
|
74
|
-
debug(`probability: ${probability} (Treshold: ${treshold})`);
|
|
75
|
-
return returnResult({
|
|
76
|
-
match: probability >= treshold,
|
|
77
|
-
probability
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
debugData(`No feature yielded minimum probability amount of points (${minProbabilityQuantifier})`);
|
|
82
|
-
return returnResult({
|
|
83
|
-
match: false,
|
|
84
|
-
probability: 0.0
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function extractFeatures(record) {
|
|
89
|
-
return strategy.reduce((acc, {
|
|
90
|
-
name,
|
|
91
|
-
extract
|
|
92
|
-
}) => acc.concat({
|
|
93
|
-
name,
|
|
94
|
-
value: extract(record)
|
|
95
|
-
}), []);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function returnResult(result) {
|
|
99
|
-
if (returnStrategy) {
|
|
100
|
-
debug(`Returning detection strategy with the result`);
|
|
101
|
-
const resultWithStrategy = {
|
|
102
|
-
match: result.match,
|
|
103
|
-
probability: result.probability,
|
|
104
|
-
strategy: formatStrategy(strategy),
|
|
105
|
-
treshold
|
|
106
|
-
};
|
|
107
|
-
debugData(`${JSON.stringify(resultWithStrategy)}`);
|
|
108
|
-
return resultWithStrategy;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return result;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function formatStrategy(strategy) {
|
|
115
|
-
const strategyNames = strategy.map(element => element.name);
|
|
116
|
-
return strategyNames || [];
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function calculateprobability(similarityVector) {
|
|
120
|
-
const probability = similarityVector.reduce((acc, v) => acc + v, 0.0);
|
|
121
|
-
return probability > 1.0 ? 1.0 : probability;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function generateSimilarityVector(featurePairs) {
|
|
125
|
-
const compared = featurePairs.map(({
|
|
126
|
-
name,
|
|
127
|
-
a,
|
|
128
|
-
b
|
|
129
|
-
}) => {
|
|
130
|
-
const {
|
|
131
|
-
compare
|
|
132
|
-
} = strategy.find(({
|
|
133
|
-
name: featureName
|
|
134
|
-
}) => name === featureName);
|
|
135
|
-
const points = compare(a, b);
|
|
136
|
-
return {
|
|
137
|
-
name,
|
|
138
|
-
points
|
|
139
|
-
};
|
|
140
|
-
});
|
|
141
|
-
debugData(`Points: ${JSON.stringify(compared)}`);
|
|
142
|
-
return compared.map(({
|
|
143
|
-
points
|
|
144
|
-
}) => points);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function generateFeaturePairs(featuresA, featuresB) {
|
|
148
|
-
const pairs = generatePairs();
|
|
149
|
-
const missingFeatures = findMissing();
|
|
150
|
-
debug(`Not comparing the following features because one, or both records are missing features: ${JSON.stringify(missingFeatures)}`);
|
|
151
|
-
return pairs;
|
|
152
|
-
|
|
153
|
-
function generatePairs() {
|
|
154
|
-
return featuresA.reduce((acc, {
|
|
155
|
-
name,
|
|
156
|
-
value
|
|
157
|
-
}, index) => acc.concat({
|
|
158
|
-
name,
|
|
159
|
-
a: value,
|
|
160
|
-
b: featuresB[index].value
|
|
161
|
-
}), []).filter(({
|
|
162
|
-
a,
|
|
163
|
-
b
|
|
164
|
-
}) => {
|
|
165
|
-
if (a.length === 0 || b.length === 0) {
|
|
166
|
-
return false;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
return true;
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
function findMissing() {
|
|
174
|
-
return featuresA.map(({
|
|
175
|
-
name
|
|
176
|
-
}) => name).filter(v => pairs.some(({
|
|
177
|
-
name
|
|
178
|
-
}) => name === v) === false);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
exports.default = _default;
|
|
184
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["strategy","treshold","returnStrategy","recordA","recordB","minProbabilityQuantifier","debug","createDebugLogger","debugData","extend","JSON","stringify","featuresA","extractFeatures","Array","isArray","recordsB","detectionResults","map","record","actualDetection","featuresB","featurePairs","generateFeaturePairs","similarityVector","generateSimilarityVector","some","v","probability","calculateprobability","returnResult","match","reduce","acc","name","extract","concat","value","result","resultWithStrategy","formatStrategy","strategyNames","element","compared","a","b","compare","find","featureName","points","pairs","generatePairs","missingFeatures","findMissing","index","filter","length"],"sources":["../../src/match-detection/index.js"],"sourcesContent":["/* eslint-disable no-console */\n/**\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 createDebugLogger from 'debug';\nimport * as features from './features';\n\nexport {features};\n\nexport default ({strategy, treshold = 0.9}, returnStrategy = false) => (recordA, recordB) => {\n const minProbabilityQuantifier = 0.5;\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection');\n const debugData = debug.extend('data');\n\n debugData(`Strategy: ${JSON.stringify(strategy)}`);\n debugData(`Treshold: ${JSON.stringify(treshold)}`);\n debugData(`ReturnStrategy: ${JSON.stringify(returnStrategy)}`);\n\n const featuresA = extractFeatures(recordA);\n\n debug(`We got an array of records: ${Array.isArray(recordB)}`);\n const recordsB = Array.isArray(recordB) ? recordB : [recordB];\n const detectionResults = recordsB.map(record => actualDetection(featuresA, record));\n\n return Array.isArray(recordB) ? detectionResults : detectionResults[0];\n\n function actualDetection(featuresA, record) {\n\n const featuresB = extractFeatures(record);\n\n debugData(`Features (a): ${JSON.stringify(featuresA)}`);\n debugData(`Features (b): ${JSON.stringify(featuresB)}`);\n\n const featurePairs = generateFeaturePairs(featuresA, featuresB);\n const similarityVector = generateSimilarityVector(featurePairs);\n\n if (similarityVector.some(v => v >= minProbabilityQuantifier)) {\n const probability = calculateprobability(similarityVector);\n debug(`probability: ${probability} (Treshold: ${treshold})`);\n return returnResult({match: probability >= treshold, probability});\n }\n\n debugData(`No feature yielded minimum probability amount of points (${minProbabilityQuantifier})`);\n return returnResult({match: false, probability: 0.0});\n }\n\n function extractFeatures(record) {\n return strategy.reduce((acc, {name, extract}) => acc.concat({name, value: extract(record)}), []);\n }\n\n function returnResult(result) {\n if (returnStrategy) {\n debug(`Returning detection strategy with the result`);\n const resultWithStrategy = {match: result.match, probability: result.probability, strategy: formatStrategy(strategy), treshold};\n debugData(`${JSON.stringify(resultWithStrategy)}`);\n return resultWithStrategy;\n }\n return result;\n }\n\n function formatStrategy(strategy) {\n const strategyNames = strategy.map(element => element.name);\n return strategyNames || [];\n }\n\n function calculateprobability(similarityVector) {\n const probability = similarityVector.reduce((acc, v) => acc + v, 0.0);\n return probability > 1.0 ? 1.0 : probability;\n }\n\n function generateSimilarityVector(featurePairs) {\n const compared = featurePairs.map(({name, a, b}) => {\n const {compare} = strategy.find(({name: featureName}) => name === featureName);\n const points = compare(a, b);\n return {name, points};\n });\n\n debugData(`Points: ${JSON.stringify(compared)}`);\n return compared.map(({points}) => points);\n }\n\n function generateFeaturePairs(featuresA, featuresB) {\n const pairs = generatePairs();\n const missingFeatures = findMissing();\n\n debug(`Not comparing the following features because one, or both records are missing features: ${JSON.stringify(missingFeatures)}`);\n return pairs;\n\n function generatePairs() {\n return featuresA\n .reduce((acc, {name, value}, index) => acc.concat({\n name,\n a: value,\n b: featuresB[index].value\n }), [])\n .filter(({a, b}) => {\n if (a.length === 0 || b.length === 0) {\n return false;\n }\n\n return true;\n });\n }\n\n function findMissing() {\n return featuresA\n .map(({name}) => name)\n .filter(v => pairs.some(({name}) => name === v) === false);\n }\n }\n\n};\n"],"mappings":";;;;;;;AA6BA;;AACA;;;;;;;;;;AA9BA;;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;AACA;eAOe,CAAC;EAACA,QAAD;EAAWC,QAAQ,GAAG;AAAtB,CAAD,EAA6BC,cAAc,GAAG,KAA9C,KAAwD,CAACC,OAAD,EAAUC,OAAV,KAAsB;EAC3F,MAAMC,wBAAwB,GAAG,GAAjC;EAEA,MAAMC,KAAK,GAAG,IAAAC,cAAA,EAAkB,mDAAlB,CAAd;EACA,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