@natlibfi/melinda-record-matching 4.4.0-alpha.1 → 5.0.0-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/workflows/melinda-node-tests.yml +13 -9
- package/LICENSE.txt +21 -165
- package/README.md +2 -2
- package/eslint.config.js +52 -0
- package/example.env +4 -0
- package/package.json +29 -79
- package/src/candidate-search/candidate-search-utils.js +1 -28
- package/src/candidate-search/choose-queries.js +93 -0
- package/src/candidate-search/index.js +85 -119
- package/src/candidate-search/{index.spec.js → index.test.js} +30 -43
- package/src/candidate-search/query-list/bib.js +54 -55
- package/src/candidate-search/query-list/bib.test.js +38 -0
- package/src/candidate-search/query-list/component.js +127 -0
- package/src/candidate-search/query-list/index.js +31 -35
- package/src/cli.js +177 -0
- package/src/index.js +27 -68
- package/src/{index.spec.js → index.test.js} +11 -42
- package/src/match-detection/features/bib/all-source-ids.js +2 -29
- package/src/match-detection/features/bib/authors.js +5 -30
- package/src/match-detection/features/bib/bibliographic-level.js +0 -27
- package/src/match-detection/features/bib/host-component.js +0 -27
- package/src/match-detection/features/bib/index.js +16 -43
- package/src/match-detection/features/bib/index.test.js +52 -0
- package/src/match-detection/features/bib/isbn.js +2 -29
- package/src/match-detection/features/bib/issn.js +1 -28
- package/src/match-detection/features/bib/language.js +5 -32
- package/src/match-detection/features/bib/media-type.js +2 -28
- package/src/match-detection/features/bib/melinda-id.js +1 -28
- package/src/match-detection/features/bib/melinda-identifier-factory.js +5 -32
- package/src/match-detection/features/bib/other-standard-identifier.js +1 -28
- package/src/match-detection/features/bib/publication-time-allow-cons-years-multi.js +7 -34
- package/src/match-detection/features/bib/publication-time-allow-cons-years.js +1 -28
- package/src/match-detection/features/bib/publication-time.js +2 -28
- package/src/match-detection/features/bib/record-type.js +0 -27
- package/src/match-detection/features/bib/standard-identifier-factory.js +1 -28
- package/src/match-detection/features/bib/title-version-original.js +2 -28
- package/src/match-detection/features/bib/title.js +6 -34
- package/src/match-detection/features/index.js +1 -28
- package/src/match-detection/index.js +1 -28
- package/src/match-detection/{index.spec.js → index.test.js} +9 -35
- package/src/matching-utils.js +8 -37
- package/dist/candidate-search/candidate-search-utils.js +0 -55
- package/dist/candidate-search/candidate-search-utils.js.map +0 -1
- package/dist/candidate-search/index.js +0 -254
- package/dist/candidate-search/index.js.map +0 -1
- package/dist/candidate-search/index.spec.js +0 -144
- package/dist/candidate-search/index.spec.js.map +0 -1
- package/dist/candidate-search/query-list/bib.js +0 -439
- package/dist/candidate-search/query-list/bib.js.map +0 -1
- package/dist/candidate-search/query-list/bib.spec.js +0 -64
- package/dist/candidate-search/query-list/bib.spec.js.map +0 -1
- package/dist/candidate-search/query-list/index.js +0 -66
- package/dist/candidate-search/query-list/index.js.map +0 -1
- package/dist/index.js +0 -579
- package/dist/index.js.map +0 -1
- package/dist/index.spec.js +0 -127
- package/dist/index.spec.js.map +0 -1
- package/dist/match-detection/features/bib/all-source-ids.js +0 -119
- package/dist/match-detection/features/bib/all-source-ids.js.map +0 -1
- package/dist/match-detection/features/bib/authors.js +0 -113
- 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 -119
- package/dist/match-detection/features/bib/index.js.map +0 -1
- package/dist/match-detection/features/bib/index.spec.js +0 -93
- package/dist/match-detection/features/bib/index.spec.js.map +0 -1
- package/dist/match-detection/features/bib/isbn.js +0 -77
- package/dist/match-detection/features/bib/isbn.js.map +0 -1
- package/dist/match-detection/features/bib/issn.js +0 -51
- package/dist/match-detection/features/bib/issn.js.map +0 -1
- package/dist/match-detection/features/bib/language.js +0 -141
- package/dist/match-detection/features/bib/language.js.map +0 -1
- package/dist/match-detection/features/bib/media-type.js +0 -83
- package/dist/match-detection/features/bib/media-type.js.map +0 -1
- package/dist/match-detection/features/bib/melinda-id.js +0 -48
- package/dist/match-detection/features/bib/melinda-id.js.map +0 -1
- package/dist/match-detection/features/bib/melinda-identifier-factory.js +0 -89
- package/dist/match-detection/features/bib/melinda-identifier-factory.js.map +0 -1
- package/dist/match-detection/features/bib/other-standard-identifier.js +0 -52
- package/dist/match-detection/features/bib/other-standard-identifier.js.map +0 -1
- package/dist/match-detection/features/bib/publication-time-allow-cons-years-multi.js +0 -256
- package/dist/match-detection/features/bib/publication-time-allow-cons-years-multi.js.map +0 -1
- package/dist/match-detection/features/bib/publication-time-allow-cons-years.js +0 -71
- package/dist/match-detection/features/bib/publication-time-allow-cons-years.js.map +0 -1
- package/dist/match-detection/features/bib/publication-time.js +0 -48
- package/dist/match-detection/features/bib/publication-time.js.map +0 -1
- package/dist/match-detection/features/bib/record-type.js +0 -45
- package/dist/match-detection/features/bib/record-type.js.map +0 -1
- package/dist/match-detection/features/bib/standard-identifier-factory.js +0 -215
- package/dist/match-detection/features/bib/standard-identifier-factory.js.map +0 -1
- package/dist/match-detection/features/bib/title-version-original.js +0 -79
- package/dist/match-detection/features/bib/title-version-original.js.map +0 -1
- package/dist/match-detection/features/bib/title.js +0 -98
- package/dist/match-detection/features/bib/title.js.map +0 -1
- package/dist/match-detection/features/index.js +0 -11
- package/dist/match-detection/features/index.js.map +0 -1
- package/dist/match-detection/index.js +0 -201
- package/dist/match-detection/index.js.map +0 -1
- package/dist/match-detection/index.spec.js +0 -91
- package/dist/match-detection/index.spec.js.map +0 -1
- package/dist/matching-utils.js +0 -143
- package/dist/matching-utils.js.map +0 -1
- package/src/candidate-search/query-list/bib.spec.js +0 -54
- package/src/match-detection/features/bib/index.spec.js +0 -78
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _matchingUtils = require("../../../matching-utils");
|
|
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-2022 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
|
-
// We should also get copyright time and copyright/publication times from 26x
|
|
36
|
-
// see publication-time-allow-cons-years for a version allowing consequent years to match
|
|
37
|
-
var _default = () => ({
|
|
38
|
-
name: 'Publication time',
|
|
39
|
-
extract: ({
|
|
40
|
-
record
|
|
41
|
-
}) => {
|
|
42
|
-
const value = record.get(/^008$/u)?.[0]?.value || undefined;
|
|
43
|
-
return (0, _matchingUtils.testStringOrNumber)(value) ? [String(value).slice(7, 11)] : [];
|
|
44
|
-
},
|
|
45
|
-
compare: (a, b) => a[0] === b[0] ? 0.1 : -1.0
|
|
46
|
-
});
|
|
47
|
-
exports.default = _default;
|
|
48
|
-
//# sourceMappingURL=publication-time.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"publication-time.js","names":["_matchingUtils","require","_default","name","extract","record","value","get","undefined","testStringOrNumber","String","slice","compare","a","b","exports","default"],"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-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 {testStringOrNumber} from '../../../matching-utils';\n\n// We should also get copyright time and copyright/publication times from 26x\n// see publication-time-allow-cons-years for a version allowing consequent years to match\n\nexport default () => ({\n name: 'Publication time',\n extract: ({record}) => {\n const value = record.get(/^008$/u)?.[0]?.value || undefined;\n return testStringOrNumber(value) ? [String(value).slice(7, 11)] : [];\n },\n compare: (a, b) => a[0] === b[0] ? 0.1 : -1.0\n});\n"],"mappings":";;;;;;AA4BA,IAAAA,cAAA,GAAAC,OAAA;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;AACA;AAAA,IAAAC,QAAA,GAEeA,CAAA,MAAO;EACpBC,IAAI,EAAE,kBAAkB;EACxBC,OAAO,EAAEA,CAAC;IAACC;EAAM,CAAC,KAAK;IACrB,MAAMC,KAAK,GAAGD,MAAM,CAACE,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAED,KAAK,IAAIE,SAAS;IAC3D,OAAO,IAAAC,iCAAkB,EAACH,KAAK,CAAC,GAAG,CAACI,MAAM,CAACJ,KAAK,CAAC,CAACK,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE;EACtE,CAAC;EACDC,OAAO,EAAEA,CAACC,CAAC,EAAEC,CAAC,KAAKD,CAAC,CAAC,CAAC,CAAC,KAAKC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC;AAC5C,CAAC,CAAC;AAAAC,OAAA,CAAAC,OAAA,GAAAd,QAAA"}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
/**
|
|
8
|
-
*
|
|
9
|
-
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
10
|
-
*
|
|
11
|
-
* Melinda record matching modules for Javascript
|
|
12
|
-
*
|
|
13
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
14
|
-
*
|
|
15
|
-
* This file is part of melinda-record-matching-js
|
|
16
|
-
*
|
|
17
|
-
* melinda-record-matching-js program is free software: you can redistribute it and/or modify
|
|
18
|
-
* it under the terms of the GNU Lesser General Public License as
|
|
19
|
-
* published by the Free Software Foundation, either version 3 of the
|
|
20
|
-
* License, or (at your option) any later version.
|
|
21
|
-
*
|
|
22
|
-
* melinda-record-matching-js is distributed in the hope that it will be useful,
|
|
23
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
24
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
25
|
-
* GNU Lesser General Public License for more details.
|
|
26
|
-
*
|
|
27
|
-
* You should have received a copy of the GNU Affero General Public License
|
|
28
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
29
|
-
*
|
|
30
|
-
* @licend The above is the entire license notice
|
|
31
|
-
* for the JavaScript code in this file.
|
|
32
|
-
*
|
|
33
|
-
*/
|
|
34
|
-
// we could handle the case of books/notes
|
|
35
|
-
// Recordtype: LDR/06 - Type of Record
|
|
36
|
-
// Note: currently matchValidator fails all mismatching recordTypes, so this won't actually do much
|
|
37
|
-
var _default = () => ({
|
|
38
|
-
name: 'Record type',
|
|
39
|
-
extract: ({
|
|
40
|
-
record
|
|
41
|
-
}) => record.leader[6] ? [record.leader[6]] : [],
|
|
42
|
-
compare: (a, b) => a[0] === b[0] ? 0.1 : -0.5
|
|
43
|
-
});
|
|
44
|
-
exports.default = _default;
|
|
45
|
-
//# sourceMappingURL=record-type.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"record-type.js","names":["_default","name","extract","record","leader","compare","a","b","exports","default"],"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\n// we could handle the case of books/notes\n// Recordtype: LDR/06 - Type of Record\n// Note: currently matchValidator fails all mismatching recordTypes, so this won't actually do much\n\nexport default () => ({\n name: 'Record type',\n extract: ({record}) => record.leader[6] ? [record.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;AAEA;AACA;AACA;AAAA,IAAAA,QAAA,GAEeA,CAAA,MAAO;EACpBC,IAAI,EAAE,aAAa;EACnBC,OAAO,EAAEA,CAAC;IAACC;EAAM,CAAC,KAAKA,MAAM,CAACC,MAAM,CAAC,CAAC,CAAC,GAAG,CAACD,MAAM,CAACC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE;EACjEC,OAAO,EAAEA,CAACC,CAAC,EAAEC,CAAC,KAAKD,CAAC,CAAC,CAAC,CAAC,KAAKC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC;AAC5C,CAAC,CAAC;AAAAC,OAAA,CAAAC,OAAA,GAAAT,QAAA"}
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
8
|
-
var _matchingUtils = require("../../../matching-utils");
|
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
/* eslint-disable max-statements */
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
14
|
-
*
|
|
15
|
-
* Melinda record matching modules for Javascript
|
|
16
|
-
*
|
|
17
|
-
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
18
|
-
*
|
|
19
|
-
* This file is part of melinda-record-matching-js
|
|
20
|
-
*
|
|
21
|
-
* melinda-record-matching-js program is free software: you can redistribute it and/or modify
|
|
22
|
-
* it under the terms of the GNU Lesser General Public License as
|
|
23
|
-
* published by the Free Software Foundation, either version 3 of the
|
|
24
|
-
* License, or (at your option) any later version.
|
|
25
|
-
*
|
|
26
|
-
* melinda-record-matching-js is distributed in the hope that it will be useful,
|
|
27
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
28
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
29
|
-
* GNU Lesser General Public License for more details.
|
|
30
|
-
*
|
|
31
|
-
* You should have received a copy of the GNU Affero General Public License
|
|
32
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
33
|
-
*
|
|
34
|
-
* @licend The above is the entire license notice
|
|
35
|
-
* for the JavaScript code in this file.
|
|
36
|
-
*
|
|
37
|
-
*/
|
|
38
|
-
// Note about validity of standardIdentifiers:
|
|
39
|
-
// We have three types of invalid standardIdentifiers:
|
|
40
|
-
// 1. Formally invalid standardIdentifiers (ie. typos either in the resource or the record)
|
|
41
|
-
// 2. Formally valid standardIdentifiers that are used in a wrong resource
|
|
42
|
-
// 3. Canceled standardIdentifiers
|
|
43
|
-
// Matcher could and should check that a standardIdentifier found in a subfield for a valid identifier is formally valid, and if it's not formally valid, handle it as an invalid standardIdentifier
|
|
44
|
-
// Formally valid standardIdentifiers found in subfield for invalid identifier cannot be handled as valid standardIdentifiers, because they can be a case of type 2) or 3) invalid standardIdentifiers
|
|
45
|
-
// We could also do a separate handling for formally valid an formally invalid standardIdentifiers
|
|
46
|
-
var _default = ({
|
|
47
|
-
pattern,
|
|
48
|
-
subfieldCodes,
|
|
49
|
-
identifier,
|
|
50
|
-
validIdentifierSubfieldCodes = ['a'],
|
|
51
|
-
invalidIdentifierSubfieldCodes = ['z'],
|
|
52
|
-
validatorAndNormalizer = undefined
|
|
53
|
-
}) => {
|
|
54
|
-
const debug = (0, _debug.default)(`@natlibfi/melinda-record-matching:match-detection:features:standard-identifiers:${identifier}`);
|
|
55
|
-
const debugData = debug.extend('data');
|
|
56
|
-
return {
|
|
57
|
-
extract,
|
|
58
|
-
compare
|
|
59
|
-
};
|
|
60
|
-
function extract({
|
|
61
|
-
record,
|
|
62
|
-
recordExternal
|
|
63
|
-
}) {
|
|
64
|
-
const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';
|
|
65
|
-
const fields = record.get(pattern);
|
|
66
|
-
debugData(`${label}: ${fields.length} ${identifier}-fields `);
|
|
67
|
-
|
|
68
|
-
// extractIdentifierSubfield normalizes hyphens away from the subfield values
|
|
69
|
-
const identifiersFromFields = fields.map(field => (0, _matchingUtils.extractSubfieldsFromField)(field, subfieldCodes));
|
|
70
|
-
debugData(`${label}: IDs from fields (${identifiersFromFields.length}): ${JSON.stringify(identifiersFromFields)}`);
|
|
71
|
-
const allIdentifiers = identifiersFromFields.flat();
|
|
72
|
-
debugData(`${label}: Flat IDs from fields (${allIdentifiers.length}): ${JSON.stringify(allIdentifiers)}`);
|
|
73
|
-
const validatedAndNormalizedIdentifiers = validateAndNormalizeIdentifiers({
|
|
74
|
-
identifierSubs: allIdentifiers,
|
|
75
|
-
validatorAndNormalizer,
|
|
76
|
-
validIdentifierSubfieldCodes,
|
|
77
|
-
invalidIdentifierSubfieldCodes
|
|
78
|
-
});
|
|
79
|
-
const identifiers = (0, _matchingUtils.uniqueSubfields)(validatedAndNormalizedIdentifiers);
|
|
80
|
-
debugData(`${label}: Unique IDs from fields (${identifiers.length}): ${JSON.stringify(identifiers)}`);
|
|
81
|
-
return identifiers;
|
|
82
|
-
function validateAndNormalizeIdentifiers({
|
|
83
|
-
identifierSubs,
|
|
84
|
-
validatorAndNormalizer,
|
|
85
|
-
validIdentifierSubfieldCodes,
|
|
86
|
-
invalidIdentifierSubfieldCodes
|
|
87
|
-
}) {
|
|
88
|
-
if (validatorAndNormalizer) {
|
|
89
|
-
return identifierSubs.map(idSub => validateAndNormalizeIdentifier({
|
|
90
|
-
idSub,
|
|
91
|
-
validatorAndNormalizer,
|
|
92
|
-
validIdentifierSubfieldCodes,
|
|
93
|
-
invalidIdentifierSubfieldCodes
|
|
94
|
-
}));
|
|
95
|
-
}
|
|
96
|
-
return identifierSubs.map(idSub => normalizeHyphens(idSub));
|
|
97
|
-
}
|
|
98
|
-
function validateAndNormalizeIdentifier({
|
|
99
|
-
idSub,
|
|
100
|
-
validatorAndNormalizer,
|
|
101
|
-
validIdentifierSubfieldCodes,
|
|
102
|
-
invalidIdentifierSubfieldCodes
|
|
103
|
-
}) {
|
|
104
|
-
const {
|
|
105
|
-
valid,
|
|
106
|
-
value
|
|
107
|
-
} = validatorAndNormalizer(idSub.value);
|
|
108
|
-
if (validIdentifierSubfieldCodes.includes(idSub.code) && valid === false) {
|
|
109
|
-
const [code] = invalidIdentifierSubfieldCodes;
|
|
110
|
-
return {
|
|
111
|
-
code,
|
|
112
|
-
value
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
return {
|
|
116
|
-
code: idSub.code,
|
|
117
|
-
value
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
function normalizeHyphens(idSub) {
|
|
121
|
-
return {
|
|
122
|
-
code: idSub.code,
|
|
123
|
-
value: idSub.value.replace(/-/ug, '')
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
function compare(a, b) {
|
|
128
|
-
debug(`Comparing A and B`);
|
|
129
|
-
if (a.length === 0 || b.length === 0) {
|
|
130
|
-
debugData(`No standardidentifiers (${identifier}) to compare`);
|
|
131
|
-
return 0;
|
|
132
|
-
}
|
|
133
|
-
debugData(`A: ${JSON.stringify(a)}`);
|
|
134
|
-
debugData(`B: ${JSON.stringify(b)}`);
|
|
135
|
-
if (bothHaveValidIdentifiers()) {
|
|
136
|
-
// Compare only valid identifiers, if both have valid idenfiers
|
|
137
|
-
const {
|
|
138
|
-
maxValues,
|
|
139
|
-
possibleMatchValues,
|
|
140
|
-
matchingValues
|
|
141
|
-
} = getValueCount(true);
|
|
142
|
-
if (matchingValues < 1) {
|
|
143
|
-
debug(`Both have valid standardidentifiers (${identifier}), but none of these match.`);
|
|
144
|
-
return -0.75;
|
|
145
|
-
}
|
|
146
|
-
debug(`Both have valid standardidentifiers (${identifier}), ${matchingValues}/${possibleMatchValues} valid identifiers match.`);
|
|
147
|
-
// ignore non-matches if there is mismatching amount of values
|
|
148
|
-
debug(`Possible matches: ${possibleMatchValues}/${maxValues}`);
|
|
149
|
-
//we give some kind of penalty for mismatching amount of values instead of simple divide?
|
|
150
|
-
const penaltyForMissing = 0.1 * (maxValues - possibleMatchValues);
|
|
151
|
-
const penaltyForMisMatch = 0.2 * (possibleMatchValues - matchingValues);
|
|
152
|
-
debug(`\t points: penaltyForMissing: ${penaltyForMissing}`);
|
|
153
|
-
debug(`\t points: penaltyForMisMatch: ${penaltyForMisMatch}`);
|
|
154
|
-
return 0.75 - penaltyForMisMatch - penaltyForMissing;
|
|
155
|
-
//return matchingValues / possibleMatchValues * 0.75;
|
|
156
|
-
}
|
|
157
|
-
// If both do not have valid identifiers, compare all identifiers
|
|
158
|
-
const {
|
|
159
|
-
maxValues,
|
|
160
|
-
matchingValues
|
|
161
|
-
} = getValueCount();
|
|
162
|
-
debug(`Both do NOT have valid standardidentifiers (${identifier}), ${matchingValues}/${maxValues} valid/invalid identifiers match.`);
|
|
163
|
-
return matchingValues / maxValues * 0.2;
|
|
164
|
-
function bothHaveValidIdentifiers() {
|
|
165
|
-
const aValues = a.filter(({
|
|
166
|
-
code
|
|
167
|
-
}) => validIdentifierSubfieldCodes.includes(code));
|
|
168
|
-
const bValues = a.filter(({
|
|
169
|
-
code
|
|
170
|
-
}) => validIdentifierSubfieldCodes.includes(code));
|
|
171
|
-
debug(`A: ${aValues.length} valid ${identifier} identifiers`);
|
|
172
|
-
debug(`B: ${bValues.length} valid ${identifier} identifiers`);
|
|
173
|
-
return aValues.length > 0 && bValues.length > 0;
|
|
174
|
-
}
|
|
175
|
-
function getValueCount(validOnly = false) {
|
|
176
|
-
const aValues = getIdentifiers(a, validOnly);
|
|
177
|
-
const bValues = getIdentifiers(b, validOnly);
|
|
178
|
-
const matchingValues = getMatchingValuesAmount(aValues, bValues);
|
|
179
|
-
return {
|
|
180
|
-
maxValues: aValues.length > bValues.length ? aValues.length : bValues.length,
|
|
181
|
-
// possibleMatchingValues: amount of identifiers in set of less identifiers (we cannot more values than these)
|
|
182
|
-
possibleMatchValues: aValues.length > bValues.length ? bValues.length : aValues.length,
|
|
183
|
-
matchingValues
|
|
184
|
-
};
|
|
185
|
-
function getMatchingValuesAmount(aValues, bValues) {
|
|
186
|
-
if (bValues.length > aValues.length) {
|
|
187
|
-
return aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length;
|
|
188
|
-
}
|
|
189
|
-
if (aValues.length > bValues.length) {
|
|
190
|
-
return bValues.filter(bValue => aValues.some(aValue => bValue === aValue)).length;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// If we have same amount of values, we'll check matches both ways, to avoid mixups in cases
|
|
194
|
-
// there would be duplicate values
|
|
195
|
-
const aToB = aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length;
|
|
196
|
-
const bToA = bValues.filter(bValue => aValues.some(aValue => bValue === aValue)).length;
|
|
197
|
-
return aToB < bToA ? aToB : bToA;
|
|
198
|
-
}
|
|
199
|
-
function getIdentifiers(values, validOnly) {
|
|
200
|
-
if (validOnly) {
|
|
201
|
-
return values.filter(({
|
|
202
|
-
code
|
|
203
|
-
}) => validIdentifierSubfieldCodes.includes(code)).map(({
|
|
204
|
-
value
|
|
205
|
-
}) => value);
|
|
206
|
-
}
|
|
207
|
-
return values.map(({
|
|
208
|
-
value
|
|
209
|
-
}) => value);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
};
|
|
214
|
-
exports.default = _default;
|
|
215
|
-
//# sourceMappingURL=standard-identifier-factory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"standard-identifier-factory.js","names":["_debug","_interopRequireDefault","require","_matchingUtils","obj","__esModule","default","_default","pattern","subfieldCodes","identifier","validIdentifierSubfieldCodes","invalidIdentifierSubfieldCodes","validatorAndNormalizer","undefined","debug","createDebugLogger","debugData","extend","extract","compare","record","recordExternal","label","fields","get","length","identifiersFromFields","map","field","extractSubfieldsFromField","JSON","stringify","allIdentifiers","flat","validatedAndNormalizedIdentifiers","validateAndNormalizeIdentifiers","identifierSubs","identifiers","uniqueSubfields","idSub","validateAndNormalizeIdentifier","normalizeHyphens","valid","value","includes","code","replace","a","b","bothHaveValidIdentifiers","maxValues","possibleMatchValues","matchingValues","getValueCount","penaltyForMissing","penaltyForMisMatch","aValues","filter","bValues","validOnly","getIdentifiers","getMatchingValuesAmount","aValue","some","bValue","aToB","bToA","values","exports"],"sources":["../../../../src/match-detection/features/bib/standard-identifier-factory.js"],"sourcesContent":["/* eslint-disable max-statements */\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-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';\nimport {extractSubfieldsFromField, uniqueSubfields} from '../../../matching-utils';\n\n// Note about validity of standardIdentifiers:\n// We have three types of invalid standardIdentifiers:\n// 1. Formally invalid standardIdentifiers (ie. typos either in the resource or the record)\n// 2. Formally valid standardIdentifiers that are used in a wrong resource\n// 3. Canceled standardIdentifiers\n\n// Matcher could and should check that a standardIdentifier found in a subfield for a valid identifier is formally valid, and if it's not formally valid, handle it as an invalid standardIdentifier\n// Formally valid standardIdentifiers found in subfield for invalid identifier cannot be handled as valid standardIdentifiers, because they can be a case of type 2) or 3) invalid standardIdentifiers\n// We could also do a separate handling for formally valid an formally invalid standardIdentifiers\n\nexport default ({pattern, subfieldCodes, identifier, validIdentifierSubfieldCodes = ['a'], invalidIdentifierSubfieldCodes = ['z'], validatorAndNormalizer = undefined}) => {\n const debug = createDebugLogger(`@natlibfi/melinda-record-matching:match-detection:features:standard-identifiers:${identifier}`);\n const debugData = debug.extend('data');\n\n return {extract, compare};\n\n function extract({record, recordExternal}) {\n const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';\n const fields = record.get(pattern);\n debugData(`${label}: ${fields.length} ${identifier}-fields `);\n\n // extractIdentifierSubfield normalizes hyphens away from the subfield values\n const identifiersFromFields = fields.map(field => extractSubfieldsFromField(field, subfieldCodes));\n debugData(`${label}: IDs from fields (${identifiersFromFields.length}): ${JSON.stringify(identifiersFromFields)}`);\n const allIdentifiers = identifiersFromFields.flat();\n debugData(`${label}: Flat IDs from fields (${allIdentifiers.length}): ${JSON.stringify(allIdentifiers)}`);\n\n const validatedAndNormalizedIdentifiers = validateAndNormalizeIdentifiers({identifierSubs: allIdentifiers, validatorAndNormalizer, validIdentifierSubfieldCodes, invalidIdentifierSubfieldCodes});\n\n const identifiers = uniqueSubfields(validatedAndNormalizedIdentifiers);\n\n debugData(`${label}: Unique IDs from fields (${identifiers.length}): ${JSON.stringify(identifiers)}`);\n return identifiers;\n\n function validateAndNormalizeIdentifiers({identifierSubs, validatorAndNormalizer, validIdentifierSubfieldCodes, invalidIdentifierSubfieldCodes}) {\n if (validatorAndNormalizer) {\n return identifierSubs.map((idSub) => validateAndNormalizeIdentifier({idSub, validatorAndNormalizer, validIdentifierSubfieldCodes, invalidIdentifierSubfieldCodes}));\n }\n return identifierSubs.map((idSub) => normalizeHyphens(idSub));\n }\n\n function validateAndNormalizeIdentifier({idSub, validatorAndNormalizer, validIdentifierSubfieldCodes, invalidIdentifierSubfieldCodes}) {\n const {valid, value} = validatorAndNormalizer(idSub.value);\n if (validIdentifierSubfieldCodes.includes(idSub.code) && valid === false) {\n const [code] = invalidIdentifierSubfieldCodes;\n return {code, value};\n }\n return {code: idSub.code, value};\n }\n\n function normalizeHyphens(idSub) {\n return {code: idSub.code, value: idSub.value.replace(/-/ug, '')};\n }\n\n\n }\n\n function compare(a, b) {\n debug(`Comparing A and B`);\n if (a.length === 0 || b.length === 0) {\n debugData(`No standardidentifiers (${identifier}) to compare`);\n return 0;\n }\n\n debugData(`A: ${JSON.stringify(a)}`);\n debugData(`B: ${JSON.stringify(b)}`);\n\n\n if (bothHaveValidIdentifiers()) {\n // Compare only valid identifiers, if both have valid idenfiers\n const {maxValues, possibleMatchValues, matchingValues} = getValueCount(true);\n if (matchingValues < 1) {\n debug(`Both have valid standardidentifiers (${identifier}), but none of these match.`);\n return -0.75;\n }\n debug(`Both have valid standardidentifiers (${identifier}), ${matchingValues}/${possibleMatchValues} valid identifiers match.`);\n // ignore non-matches if there is mismatching amount of values\n debug(`Possible matches: ${possibleMatchValues}/${maxValues}`);\n //we give some kind of penalty for mismatching amount of values instead of simple divide?\n const penaltyForMissing = 0.1 * (maxValues - possibleMatchValues);\n const penaltyForMisMatch = 0.2 * (possibleMatchValues - matchingValues);\n debug(`\\t points: penaltyForMissing: ${penaltyForMissing}`);\n debug(`\\t points: penaltyForMisMatch: ${penaltyForMisMatch}`);\n\n return 0.75 - penaltyForMisMatch - penaltyForMissing;\n //return matchingValues / possibleMatchValues * 0.75;\n }\n // If both do not have valid identifiers, compare all identifiers\n const {maxValues, matchingValues} = getValueCount();\n debug(`Both do NOT have valid standardidentifiers (${identifier}), ${matchingValues}/${maxValues} valid/invalid identifiers match.`);\n\n return matchingValues / maxValues * 0.2;\n\n function bothHaveValidIdentifiers() {\n const aValues = a.filter(({code}) => validIdentifierSubfieldCodes.includes(code));\n const bValues = a.filter(({code}) => validIdentifierSubfieldCodes.includes(code));\n debug(`A: ${aValues.length} valid ${identifier} identifiers`);\n debug(`B: ${bValues.length} valid ${identifier} identifiers`);\n return aValues.length > 0 && bValues.length > 0;\n }\n\n function getValueCount(validOnly = false) {\n const aValues = getIdentifiers(a, validOnly);\n const bValues = getIdentifiers(b, validOnly);\n\n const matchingValues = getMatchingValuesAmount(aValues, bValues);\n\n return {\n maxValues: aValues.length > bValues.length ? aValues.length : bValues.length,\n // possibleMatchingValues: amount of identifiers in set of less identifiers (we cannot more values than these)\n possibleMatchValues: aValues.length > bValues.length ? bValues.length : aValues.length,\n matchingValues\n };\n\n function getMatchingValuesAmount(aValues, bValues) {\n if (bValues.length > aValues.length) {\n return aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length;\n }\n if (aValues.length > bValues.length) {\n return bValues.filter(bValue => aValues.some(aValue => bValue === aValue)).length;\n }\n\n // If we have same amount of values, we'll check matches both ways, to avoid mixups in cases\n // there would be duplicate values\n const aToB = aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length;\n const bToA = bValues.filter(bValue => aValues.some(aValue => bValue === aValue)).length;\n\n return aToB < bToA ? aToB : bToA;\n }\n\n function getIdentifiers(values, validOnly) {\n if (validOnly) {\n return values\n .filter(({code}) => validIdentifierSubfieldCodes.includes(code))\n .map(({value}) => value);\n }\n\n return values.map(({value}) => value);\n }\n }\n }\n};\n"],"mappings":";;;;;;AA6BA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AAAmF,SAAAD,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AA9BnF;AACA;AACA;AACA;AAC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;UAACgB;QAAK,CAAC,KAAKA,KAAK,CAAC;MACvC;IACF;EACF;AACF,CAAC;AAAAyB,OAAA,CAAA/D,OAAA,GAAAC,QAAA"}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
8
|
-
var _natural = require("natural");
|
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
/**
|
|
11
|
-
*
|
|
12
|
-
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
13
|
-
*
|
|
14
|
-
* Melinda record matching modules for Javascript
|
|
15
|
-
*
|
|
16
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
17
|
-
*
|
|
18
|
-
* This file is part of melinda-record-matching-js
|
|
19
|
-
*
|
|
20
|
-
* melinda-record-matching-js program is free software: you can redistribute it and/or modify
|
|
21
|
-
* it under the terms of the GNU Lesser General Public License as
|
|
22
|
-
* published by the Free Software Foundation, either version 3 of the
|
|
23
|
-
* License, or (at your option) any later version.
|
|
24
|
-
*
|
|
25
|
-
* melinda-record-matching-js is distributed in the hope that it will be useful,
|
|
26
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
27
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
28
|
-
* GNU Lesser General Public License for more details.
|
|
29
|
-
*
|
|
30
|
-
* You should have received a copy of the GNU Affero General Public License
|
|
31
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
32
|
-
*
|
|
33
|
-
* @licend The above is the entire license notice
|
|
34
|
-
* for the JavaScript code in this file.
|
|
35
|
-
*
|
|
36
|
-
*/
|
|
37
|
-
var _default = ({
|
|
38
|
-
treshold = 10
|
|
39
|
-
} = {}) => ({
|
|
40
|
-
name: 'titleVersionOriginal',
|
|
41
|
-
extract: ({
|
|
42
|
-
record
|
|
43
|
-
}) => {
|
|
44
|
-
const title = getTitle();
|
|
45
|
-
if (title) {
|
|
46
|
-
return [title.replace(/[^\p{Letter}\p{Number}]/gu, '').toLowerCase()];
|
|
47
|
-
}
|
|
48
|
-
return [];
|
|
49
|
-
function getTitle() {
|
|
50
|
-
const [field] = record.get(/^245$/u);
|
|
51
|
-
if (field) {
|
|
52
|
-
return field.subfields.filter(({
|
|
53
|
-
code
|
|
54
|
-
}) => ['a', 'b'].includes(code)).map(({
|
|
55
|
-
value
|
|
56
|
-
}) => value).join('');
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
compare: (a, b) => {
|
|
61
|
-
const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:match-detection:features/bib/title-version-original');
|
|
62
|
-
const distance = (0, _natural.LevenshteinDistance)(a[0], b[0]);
|
|
63
|
-
if (distance === 0) {
|
|
64
|
-
return 0.5;
|
|
65
|
-
}
|
|
66
|
-
const maxLength = getMaxLength();
|
|
67
|
-
const percentage = distance / maxLength * 100;
|
|
68
|
-
debug(`'${a}' vs '${b}': Max length = ${maxLength}, distance = ${distance}, percentage = ${percentage}`);
|
|
69
|
-
if (percentage <= treshold) {
|
|
70
|
-
return 0.3;
|
|
71
|
-
}
|
|
72
|
-
return -0.5;
|
|
73
|
-
function getMaxLength() {
|
|
74
|
-
return a[0].length > b[0].length ? a[0].length : b[0].length;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
exports.default = _default;
|
|
79
|
-
//# sourceMappingURL=title-version-original.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"title-version-original.js","names":["_debug","_interopRequireDefault","require","_natural","obj","__esModule","default","_default","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","exports"],"sources":["../../../../src/match-detection/features/bib/title-version-original.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: 'titleVersionOriginal',\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-version-original');\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"],"m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AAK,EAACL,CAAC,CAAC,CAAC,CAAC,EAAEC,CAAC,CAAC,CAAC,CAAC,CAAC;IAElC,IAAIG,QAAQ,KAAK,CAAC,EAAE;MAClB,OAAO,GAAG;IACZ;IAEA,MAAME,SAAS,GAAGC,YAAY,CAAC,CAAC;IAChC,MAAMC,UAAU,GAAGJ,QAAQ,GAAGE,SAAS,GAAG,GAAG;IAE7CJ,KAAK,CAAE,IAAGF,CAAE,SAAQC,CAAE,mBAAkBK,SAAU,gBAAeF,QAAS,kBAAiBI,UAAW,EAAC,CAAC;IAExG,IAAIA,UAAU,IAAI1B,QAAQ,EAAE;MAC1B,OAAO,GAAG;IACZ;IAEA,OAAO,CAAC,GAAG;IAEX,SAASyB,YAAYA,CAAA,EAAG;MACtB,OAAOP,CAAC,CAAC,CAAC,CAAC,CAACS,MAAM,GAAGR,CAAC,CAAC,CAAC,CAAC,CAACQ,MAAM,GAAGT,CAAC,CAAC,CAAC,CAAC,CAACS,MAAM,GAAGR,CAAC,CAAC,CAAC,CAAC,CAACQ,MAAM;IAC9D;EAEF;AACF,CAAC,CAAC;AAAAC,OAAA,CAAA9B,OAAA,GAAAC,QAAA"}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _natural = require("natural");
|
|
8
|
-
var _matchingUtils = require("../../../matching-utils");
|
|
9
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
14
|
-
*
|
|
15
|
-
* Melinda record matching modules for Javascript
|
|
16
|
-
*
|
|
17
|
-
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
18
|
-
*
|
|
19
|
-
* This file is part of melinda-record-matching-js
|
|
20
|
-
*
|
|
21
|
-
* melinda-record-matching-js program is free software: you can redistribute it and/or modify
|
|
22
|
-
* it under the terms of the GNU Lesser General Public License as
|
|
23
|
-
* published by the Free Software Foundation, either version 3 of the
|
|
24
|
-
* License, or (at your option) any later version.
|
|
25
|
-
*
|
|
26
|
-
* melinda-record-matching-js is distributed in the hope that it will be useful,
|
|
27
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
28
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
29
|
-
* GNU Lesser General Public License for more details.
|
|
30
|
-
*
|
|
31
|
-
* You should have received a copy of the GNU Affero General Public License
|
|
32
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
33
|
-
*
|
|
34
|
-
* @licend The above is the entire license notice
|
|
35
|
-
* for the JavaScript code in this file.
|
|
36
|
-
*
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:match-detection:features:title');
|
|
40
|
-
const debugData = debug.extend('data');
|
|
41
|
-
var _default = ({
|
|
42
|
-
treshold = 10
|
|
43
|
-
} = {}) => ({
|
|
44
|
-
name: 'Title',
|
|
45
|
-
extract: ({
|
|
46
|
-
record,
|
|
47
|
-
recordExternal
|
|
48
|
-
}) => {
|
|
49
|
-
const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';
|
|
50
|
-
const title = getTitle();
|
|
51
|
-
debug(`${label} title: ${title}`);
|
|
52
|
-
if ((0, _matchingUtils.testStringOrNumber)(title)) {
|
|
53
|
-
const titleAsNormalizedString = String(title)
|
|
54
|
-
// decompose unicode diacritics
|
|
55
|
-
.normalize('NFD')
|
|
56
|
-
// strip non-letters/numbers
|
|
57
|
-
// - note: combined with decomposing unicode diactics this normalizes both 'saa' and 'sää' as 'saa'
|
|
58
|
-
// - we could precompose the finnish letters back to avoid this
|
|
59
|
-
.replace(/[^\p{Letter}\p{Number}]/gu, '').toLowerCase();
|
|
60
|
-
debug(`${label} titleString: ${titleAsNormalizedString}`);
|
|
61
|
-
return [titleAsNormalizedString];
|
|
62
|
-
}
|
|
63
|
-
return [];
|
|
64
|
-
function getTitle() {
|
|
65
|
-
const [field] = record.get(/^245$/u);
|
|
66
|
-
debugData(`${label} titleField: ${JSON.stringify(field)}`);
|
|
67
|
-
if (field) {
|
|
68
|
-
return field.subfields
|
|
69
|
-
// get also $n:s and $p:s here
|
|
70
|
-
.filter(({
|
|
71
|
-
code
|
|
72
|
-
}) => ['a', 'b', 'n', 'p'].includes(code)).map(({
|
|
73
|
-
value
|
|
74
|
-
}) => (0, _matchingUtils.testStringOrNumber)(value) ? String(value) : '').join('');
|
|
75
|
-
}
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
compare: (a, b) => {
|
|
80
|
-
const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:match-detection:features/bib/title');
|
|
81
|
-
const distance = (0, _natural.LevenshteinDistance)(a[0], b[0]);
|
|
82
|
-
if (distance === 0) {
|
|
83
|
-
return 0.5;
|
|
84
|
-
}
|
|
85
|
-
const maxLength = getMaxLength();
|
|
86
|
-
const percentage = distance / maxLength * 100;
|
|
87
|
-
debug(`'${a}' vs '${b}': Max length = ${maxLength}, distance = ${distance}, percentage = ${percentage}`);
|
|
88
|
-
if (percentage <= treshold) {
|
|
89
|
-
return 0.3;
|
|
90
|
-
}
|
|
91
|
-
return -0.5;
|
|
92
|
-
function getMaxLength() {
|
|
93
|
-
return a[0].length > b[0].length ? a[0].length : b[0].length;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
exports.default = _default;
|
|
98
|
-
//# sourceMappingURL=title.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"title.js","names":["_natural","require","_matchingUtils","_debug","_interopRequireDefault","obj","__esModule","default","debug","createDebugLogger","debugData","extend","_default","treshold","name","extract","record","recordExternal","label","title","getTitle","testStringOrNumber","titleAsNormalizedString","String","normalize","replace","toLowerCase","field","get","JSON","stringify","subfields","filter","code","includes","map","value","join","compare","a","b","distance","leven","maxLength","getMaxLength","percentage","length","exports"],"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-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\n\nimport {LevenshteinDistance as leven} from 'natural';\nimport {testStringOrNumber} from '../../../matching-utils';\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features:title');\nconst debugData = debug.extend('data');\n\n\nexport default ({treshold = 10} = {}) => ({\n name: 'Title',\n extract: ({record, recordExternal}) => {\n const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';\n const title = getTitle();\n debug(`${label} title: ${title}`);\n\n if (testStringOrNumber(title)) {\n const titleAsNormalizedString = String(title)\n // decompose unicode diacritics\n .normalize('NFD')\n // strip non-letters/numbers\n // - note: combined with decomposing unicode diactics this normalizes both 'saa' and 'sää' as 'saa'\n // - we could precompose the finnish letters back to avoid this\n .replace(/[^\\p{Letter}\\p{Number}]/gu, '')\n .toLowerCase();\n debug(`${label} titleString: ${titleAsNormalizedString}`);\n return [titleAsNormalizedString];\n }\n\n return [];\n\n function getTitle() {\n const [field] = record.get(/^245$/u);\n debugData(`${label} titleField: ${JSON.stringify(field)}`);\n\n if (field) {\n return field.subfields\n // get also $n:s and $p:s here\n .filter(({code}) => ['a', 'b', 'n', 'p'].includes(code))\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .join('');\n }\n return false;\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":";;;;;;AA6BA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AAAsC,SAAAG,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AA/BtC;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;;AAOA,MAAMG,KAAK,GAAG,IAAAC,cAAiB,EAAC,kEAAkE,CAAC;AACnG,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAM,CAAC,MAAM,CAAC;AAAC,IAAAC,QAAA,GAGxBA,CAAC;EAACC,QAAQ,GAAG;AAAE,CAAC,GAAG,CAAC,CAAC,MAAM;EACxCC,IAAI,EAAE,OAAO;EACbC,OAAO,EAAEA,CAAC;IAACC,MAAM;IAAEC;EAAc,CAAC,KA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AAC,cAAiB,EAAC,sEAAsE,CAAC;IACvG,MAAMgC,QAAQ,GAAG,IAAAC,4BAAK,EAACH,CAAC,CAAC,CAAC,CAAC,EAAEC,CAAC,CAAC,CAAC,CAAC,CAAC;IAElC,IAAIC,QAAQ,KAAK,CAAC,EAAE;MAClB,OAAO,GAAG;IACZ;IAEA,MAAME,SAAS,GAAGC,YAAY,CAAC,CAAC;IAChC,MAAMC,UAAU,GAAGJ,QAAQ,GAAGE,SAAS,GAAG,GAAG;IAE7CnC,KAAK,CAAE,IAAG+B,CAAE,SAAQC,CAAE,mBAAkBG,SAAU,gBAAeF,QAAS,kBAAiBI,UAAW,EAAC,CAAC;IAExG,IAAIA,UAAU,IAAIhC,QAAQ,EAAE;MAC1B,OAAO,GAAG;IACZ;IAEA,OAAO,CAAC,GAAG;IAEX,SAAS+B,YAAYA,CAAA,EAAG;MACtB,OAAOL,CAAC,CAAC,CAAC,CAAC,CAACO,MAAM,GAAGN,CAAC,CAAC,CAAC,CAAC,CAACM,MAAM,GAAGP,CAAC,CAAC,CAAC,CAAC,CAACO,MAAM,GAAGN,CAAC,CAAC,CAAC,CAAC,CAACM,MAAM;IAC9D;EAEF;AACF,CAAC,CAAC;AAAAC,OAAA,CAAAxC,OAAA,GAAAK,QAAA"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.bib = void 0;
|
|
7
|
-
var bib = _interopRequireWildcard(require("./bib"));
|
|
8
|
-
exports.bib = bib;
|
|
9
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
10
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["bib","_interopRequireWildcard","require","exports","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set"],"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,IAAAA,GAAA,GAAAC,uBAAA,CAAAC,OAAA;AAA6BC,OAAA,CAAAH,GAAA,GAAAA,GAAA;AAAA,SAAAI,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAA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