@natlibfi/melinda-record-matching 2.0.1-alpha.1 → 2.0.7-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 +2 -0
- package/.github/dependabot.yml +40 -0
- package/.github/workflows/melinda-node-tests.yml +70 -0
- package/README.md +1 -1
- package/dist/candidate-search/candidate-search-utils.js +3 -6
- package/dist/candidate-search/candidate-search-utils.js.map +1 -1
- package/dist/candidate-search/index.js +115 -50
- package/dist/candidate-search/index.js.map +1 -1
- package/dist/candidate-search/index.spec.js +41 -48
- package/dist/candidate-search/index.spec.js.map +1 -1
- package/dist/candidate-search/query-list/bib.js +154 -64
- package/dist/candidate-search/query-list/bib.js.map +1 -1
- package/dist/candidate-search/query-list/bib.spec.js +1 -10
- package/dist/candidate-search/query-list/bib.spec.js.map +1 -1
- package/dist/candidate-search/query-list/index.js +4 -10
- package/dist/candidate-search/query-list/index.js.map +1 -1
- package/dist/index.js +498 -50
- package/dist/index.js.map +1 -1
- package/dist/index.spec.js +60 -34
- package/dist/index.spec.js.map +1 -1
- package/dist/match-detection/features/bib/all-source-ids.js +16 -19
- package/dist/match-detection/features/bib/all-source-ids.js.map +1 -1
- package/dist/match-detection/features/bib/authors.js +31 -35
- package/dist/match-detection/features/bib/authors.js.map +1 -1
- package/dist/match-detection/features/bib/bibliographic-level.js +3 -3
- package/dist/match-detection/features/bib/bibliographic-level.js.map +1 -1
- package/dist/match-detection/features/bib/host-component.js +3 -3
- package/dist/match-detection/features/bib/host-component.js.map +1 -1
- package/dist/match-detection/features/bib/index.js +28 -13
- package/dist/match-detection/features/bib/index.js.map +1 -1
- package/dist/match-detection/features/bib/index.spec.js +9 -13
- package/dist/match-detection/features/bib/index.spec.js.map +1 -1
- package/dist/match-detection/features/bib/isbn.js +28 -6
- package/dist/match-detection/features/bib/isbn.js.map +1 -1
- package/dist/match-detection/features/bib/issn.js +0 -4
- package/dist/match-detection/features/bib/issn.js.map +1 -1
- package/dist/match-detection/features/bib/language.js +69 -41
- package/dist/match-detection/features/bib/language.js.map +1 -1
- package/dist/match-detection/features/bib/media-type.js +83 -0
- package/dist/match-detection/features/bib/media-type.js.map +1 -0
- package/dist/match-detection/features/bib/melinda-id.js +0 -4
- package/dist/match-detection/features/bib/melinda-id.js.map +1 -1
- package/dist/match-detection/features/bib/melinda-identifier-factory.js +6 -17
- package/dist/match-detection/features/bib/melinda-identifier-factory.js.map +1 -1
- package/dist/match-detection/features/bib/other-standard-identifier.js +1 -4
- package/dist/match-detection/features/bib/other-standard-identifier.js.map +1 -1
- package/dist/match-detection/features/bib/publication-time-allow-cons-years-multi.js +256 -0
- package/dist/match-detection/features/bib/publication-time-allow-cons-years-multi.js.map +1 -0
- package/dist/match-detection/features/bib/publication-time-allow-cons-years.js +71 -0
- package/dist/match-detection/features/bib/publication-time-allow-cons-years.js.map +1 -0
- package/dist/match-detection/features/bib/publication-time.js +9 -8
- package/dist/match-detection/features/bib/publication-time.js.map +1 -1
- package/dist/match-detection/features/bib/record-type.js +6 -3
- package/dist/match-detection/features/bib/record-type.js.map +1 -1
- package/dist/match-detection/features/bib/standard-identifier-factory.js +129 -39
- package/dist/match-detection/features/bib/standard-identifier-factory.js.map +1 -1
- package/dist/match-detection/features/bib/title-version-original.js +79 -0
- package/dist/match-detection/features/bib/title-version-original.js.map +1 -0
- package/dist/match-detection/features/bib/title.js +29 -22
- package/dist/match-detection/features/bib/title.js.map +1 -1
- package/dist/match-detection/features/index.js +0 -4
- package/dist/match-detection/features/index.js.map +1 -1
- package/dist/match-detection/index.js +94 -47
- package/dist/match-detection/index.js.map +1 -1
- package/dist/match-detection/index.spec.js +25 -15
- package/dist/match-detection/index.spec.js.map +1 -1
- package/dist/matching-utils.js +63 -15
- package/dist/matching-utils.js.map +1 -1
- package/package.json +27 -24
- package/src/candidate-search/index.js +93 -31
- package/src/candidate-search/index.spec.js +27 -24
- package/src/candidate-search/query-list/bib.js +149 -22
- package/src/candidate-search/query-list/index.js +1 -1
- package/src/index.js +310 -38
- package/src/index.spec.js +49 -21
- package/src/match-detection/features/bib/all-source-ids.js +3 -3
- package/src/match-detection/features/bib/authors.js +23 -16
- package/src/match-detection/features/bib/bibliographic-level.js +1 -1
- package/src/match-detection/features/bib/host-component.js +1 -1
- package/src/match-detection/features/bib/index.js +4 -0
- package/src/match-detection/features/bib/index.spec.js +10 -2
- package/src/match-detection/features/bib/isbn.js +21 -2
- package/src/match-detection/features/bib/language.js +63 -22
- package/src/match-detection/features/bib/media-type.js +77 -0
- package/src/match-detection/features/bib/melinda-identifier-factory.js +2 -3
- package/src/match-detection/features/bib/other-standard-identifier.js +2 -0
- package/src/match-detection/features/bib/publication-time-allow-cons-years-multi.js +268 -0
- package/src/match-detection/features/bib/publication-time-allow-cons-years.js +67 -0
- package/src/match-detection/features/bib/publication-time.js +9 -4
- package/src/match-detection/features/bib/record-type.js +5 -1
- package/src/match-detection/features/bib/standard-identifier-factory.js +107 -22
- package/src/match-detection/features/bib/title-version-original.js +78 -0
- package/src/match-detection/features/bib/title.js +27 -7
- package/src/match-detection/index.js +60 -22
- package/src/match-detection/index.spec.js +18 -4
- package/src/matching-utils.js +62 -5
|
@@ -27,8 +27,27 @@
|
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
29
|
import createInterface from './standard-identifier-factory';
|
|
30
|
+
import {parse as isbnParse} from 'isbn3';
|
|
31
|
+
import createDebugLogger from 'debug';
|
|
32
|
+
|
|
33
|
+
const debug = createDebugLogger(`@natlibfi/melinda-record-matching:match-detection:features:standard-identifiers:ISBN`);
|
|
34
|
+
const debugData = debug.extend('data');
|
|
30
35
|
|
|
31
36
|
export default () => {
|
|
32
|
-
const
|
|
33
|
-
|
|
37
|
+
const IDENTIFIER_NAME = 'ISBN';
|
|
38
|
+
|
|
39
|
+
function validatorAndNormalizer(string) {
|
|
40
|
+
const isbnParseResult = isbnParse(string);
|
|
41
|
+
debugData(`isbnParseResult: ${JSON.stringify(isbnParseResult)}`);
|
|
42
|
+
if (isbnParseResult === null) {
|
|
43
|
+
debug(`Not parseable ISBN, just removing hyphens`);
|
|
44
|
+
return {valid: false, value: string.replace(/-/ug, '')};
|
|
45
|
+
}
|
|
46
|
+
debug(`Parseable ISBN, normalizing to ISBN-13`);
|
|
47
|
+
return {valid: true, value: isbnParseResult.isbn13};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const {extract, compare} = createInterface({identifier: IDENTIFIER_NAME, pattern: /^020$/u, subfieldCodes: ['a', 'z'], validIdentifierSubfieldCodes: ['a'], invalidIdentifierSubfieldCodes: ['z'], validatorAndNormalizer});
|
|
51
|
+
return {extract, compare, name: IDENTIFIER_NAME};
|
|
34
52
|
};
|
|
53
|
+
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
/* eslint-disable max-statements */
|
|
2
1
|
/**
|
|
3
2
|
*
|
|
4
3
|
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
5
4
|
*
|
|
6
5
|
* Melinda record matching modules for Javascript
|
|
7
6
|
*
|
|
8
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
7
|
+
* Copyright (C) 2020-2023 University Of Helsinki (The National Library Of Finland)
|
|
9
8
|
*
|
|
10
9
|
* This file is part of melinda-record-matching-js
|
|
11
10
|
*
|
|
@@ -28,45 +27,43 @@
|
|
|
28
27
|
*/
|
|
29
28
|
|
|
30
29
|
import createDebugLogger from 'debug';
|
|
30
|
+
import {getMatchCounts} from '../../../matching-utils';
|
|
31
31
|
|
|
32
32
|
const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features:language');
|
|
33
33
|
const debugData = debug.extend('data');
|
|
34
34
|
|
|
35
35
|
export default () => ({
|
|
36
36
|
name: 'Language',
|
|
37
|
-
extract: record => {
|
|
37
|
+
extract: ({record, recordExternal}) => {
|
|
38
|
+
const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';
|
|
39
|
+
|
|
38
40
|
const value008 = get008Value();
|
|
39
41
|
const values041 = get041Values();
|
|
40
|
-
debugData(
|
|
41
|
-
|
|
42
|
-
if (value008 && values041.length > 0) {
|
|
43
|
-
debugData(`There's both 008 and 041, searching for value in both`);
|
|
44
|
-
const correspondingValue = values041.find(v => v === value008);
|
|
45
|
-
debugData(`Corresponding value: ${correspondingValue}`);
|
|
46
|
-
return correspondingValue ? [correspondingValue] : [];
|
|
47
|
-
}
|
|
42
|
+
debugData(`${label} 008: ${JSON.stringify(value008)}, 041: ${JSON.stringify(values041)}`);
|
|
48
43
|
|
|
49
44
|
if (!value008 && values041.length < 1) {
|
|
50
|
-
debugData(`No actual values found`);
|
|
45
|
+
debugData(`{$label} No actual values found`);
|
|
51
46
|
return [];
|
|
52
47
|
}
|
|
53
48
|
|
|
54
|
-
|
|
49
|
+
const allValues = value008 === undefined ? values041 : values041.concat(value008);
|
|
50
|
+
const uniqueSortedValues = [...new Set(allValues)].sort();
|
|
51
|
+
|
|
52
|
+
return uniqueSortedValues;
|
|
55
53
|
|
|
56
54
|
function get008Value() {
|
|
57
55
|
const value = record.get(/^008$/u)?.[0]?.value || undefined;
|
|
58
|
-
debugData(
|
|
56
|
+
debugData(`${label} 008 value: ${value}`);
|
|
59
57
|
|
|
60
58
|
if (!value) {
|
|
61
59
|
return undefined;
|
|
62
60
|
}
|
|
63
61
|
|
|
64
62
|
const code = value.slice(35, 38);
|
|
65
|
-
debugData(
|
|
66
|
-
return code
|
|
63
|
+
debugData(`${label} 008 code: ${code}`);
|
|
64
|
+
return isLangCodeForALanguage(code) ? code : undefined;
|
|
67
65
|
}
|
|
68
66
|
|
|
69
|
-
// Main language for the resource: in the first f041 $a or f041 $d
|
|
70
67
|
// Uses only f041s that have 2nd ind ' ', which means that the codes used are MARC 21 language codes
|
|
71
68
|
|
|
72
69
|
function get041Values() {
|
|
@@ -75,23 +72,67 @@ export default () => ({
|
|
|
75
72
|
.map(({subfields}) => subfields)
|
|
76
73
|
.flat()
|
|
77
74
|
.filter(({code}) => code === 'a' || code === 'd')
|
|
75
|
+
.filter(({value}) => value && isLangCodeForALanguage(value))
|
|
78
76
|
.map(({value}) => value);
|
|
79
77
|
}
|
|
78
|
+
|
|
79
|
+
// Check if a string is a possible, validly formed language code for a single language
|
|
80
|
+
// Currently accept also codes in capitals
|
|
81
|
+
function isLangCodeForALanguage(code) {
|
|
82
|
+
if (code.length !== 3) {
|
|
83
|
+
debugData(`Code ${code} is not correct length (3) for a language code.`);
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
if (code === '|||' || code === ' ' || code === '^^^' || code === 'mul' || code === 'zxx') {
|
|
87
|
+
debugData(`Code ${code} is not code for a spesific language.`);
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
const langCodePattern = /^[a-z][a-z][a-z]$/ui;
|
|
91
|
+
if (!langCodePattern.test(code)) {
|
|
92
|
+
debugData(`Code ${code} is not valid as a language code`);
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
|
|
80
98
|
},
|
|
99
|
+
// eslint-disable-next-line max-statements
|
|
81
100
|
compare: (a, b) => {
|
|
82
|
-
debugData(`Comparing ${JSON.stringify(a
|
|
101
|
+
debugData(`Comparing ${JSON.stringify(a)} and ${JSON.stringify(b)}`);
|
|
83
102
|
|
|
84
103
|
if (a.length === 0 || b.length === 0) {
|
|
85
104
|
debugData(`No language to compare`);
|
|
86
105
|
return 0;
|
|
87
106
|
}
|
|
88
107
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (a[0] === b[0]) {
|
|
108
|
+
if (a.length === b.length && a.every((element, index) => element === b[index])) {
|
|
109
|
+
debugData(`All languages match`);
|
|
92
110
|
return 0.1;
|
|
93
111
|
}
|
|
94
112
|
|
|
95
|
-
|
|
113
|
+
const {matchingValues, possibleMatchValues, maxValues} = getMatchCounts(a, b);
|
|
114
|
+
|
|
115
|
+
if (matchingValues < 1) {
|
|
116
|
+
debug(`Both have languages, but none of these match.`);
|
|
117
|
+
return -1.0;
|
|
118
|
+
}
|
|
119
|
+
debug(`Both have languages, ${matchingValues}/${possibleMatchValues} valid languages match.`);
|
|
120
|
+
// ignore non-matches if there is mismatching amount of values
|
|
121
|
+
debug(`Possible matches: ${possibleMatchValues}/${maxValues}`);
|
|
122
|
+
//we give some kind of penalty for mismatching amount of values instead of simple divide?
|
|
123
|
+
const missingCount = maxValues - possibleMatchValues;
|
|
124
|
+
const misMatchCount = possibleMatchValues - matchingValues;
|
|
125
|
+
debug(`\t missing: ${missingCount}`);
|
|
126
|
+
debug(`\t mismatches: ${misMatchCount}`);
|
|
127
|
+
|
|
128
|
+
const penaltyForMissing = 0.02 * (maxValues - possibleMatchValues);
|
|
129
|
+
const penaltyForMisMatch = 0.05 * (possibleMatchValues - matchingValues);
|
|
130
|
+
debug(`\t points: penaltyForMissing: ${penaltyForMissing}`);
|
|
131
|
+
debug(`\t points: penaltyForMisMatch: ${penaltyForMisMatch}`);
|
|
132
|
+
|
|
133
|
+
const points = Number(Number(0.1 - penaltyForMisMatch - penaltyForMissing).toFixed(2));
|
|
134
|
+
debug(`Total points: ${points}`);
|
|
135
|
+
|
|
136
|
+
return points;
|
|
96
137
|
}
|
|
97
138
|
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/* eslint-disable max-statements */
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
5
|
+
*
|
|
6
|
+
* Melinda record matching modules for Javascript
|
|
7
|
+
*
|
|
8
|
+
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
9
|
+
*
|
|
10
|
+
* This file is part of melinda-record-matching-js
|
|
11
|
+
*
|
|
12
|
+
* melinda-record-matching-js program is free software: you can redistribute it and/or modify
|
|
13
|
+
* it under the terms of the GNU Lesser General Public License as
|
|
14
|
+
* published by the Free Software Foundation, either version 3 of the
|
|
15
|
+
* License, or (at your option) any later version.
|
|
16
|
+
*
|
|
17
|
+
* melinda-record-matching-js is distributed in the hope that it will be useful,
|
|
18
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20
|
+
* GNU Lesser General Public License for more details.
|
|
21
|
+
*
|
|
22
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
23
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
24
|
+
*
|
|
25
|
+
* @licend The above is the entire license notice
|
|
26
|
+
* for the JavaScript code in this file.
|
|
27
|
+
*
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
import createDebugLogger from 'debug';
|
|
31
|
+
|
|
32
|
+
const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features:media-type');
|
|
33
|
+
const debugData = debug.extend('data');
|
|
34
|
+
|
|
35
|
+
export default () => ({
|
|
36
|
+
name: 'Media type',
|
|
37
|
+
extract: ({record, recordExternal}) => {
|
|
38
|
+
const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';
|
|
39
|
+
debugData(`Record (${label}): ${JSON.stringify(record)}`);
|
|
40
|
+
debugData(`RecordExternal: ${JSON.stringify(recordExternal)}`);
|
|
41
|
+
const values337 = get337Values();
|
|
42
|
+
debug(`${label} 337 $b values: ${JSON.stringify(values337)}`);
|
|
43
|
+
|
|
44
|
+
return values337;
|
|
45
|
+
|
|
46
|
+
function get337Values() {
|
|
47
|
+
return record.get(/^337$/u)
|
|
48
|
+
.filter(f => f.subfields.some((subfield) => subfield.code === '2' && subfield.value === 'rdamedia'))
|
|
49
|
+
.map(({subfields}) => subfields)
|
|
50
|
+
.flat()
|
|
51
|
+
.filter(({code}) => code === 'b')
|
|
52
|
+
.map(({value}) => value);
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
compare: (a, b) => {
|
|
56
|
+
debugData(`Comparing ${JSON.stringify(a)} and ${JSON.stringify(b)}`);
|
|
57
|
+
|
|
58
|
+
// Should we give extra good points if all mediaTypes match?
|
|
59
|
+
// Should we give partial points for partially matching mediaTypes?
|
|
60
|
+
// Should we check whether recordType is 'mixedMaterials'
|
|
61
|
+
// Should we okay typical cases of not totally matching mediaTypes? What would these be?
|
|
62
|
+
|
|
63
|
+
if (a.every(elem => b.includes(elem))) {
|
|
64
|
+
debug(`All mediaTypes from A are in B`);
|
|
65
|
+
return 1;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (b.every(elem => a.includes(elem))) {
|
|
69
|
+
debug(`All mediaTypes from B are in A`);
|
|
70
|
+
return 1;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
debug(`Mismatch in mediaTypes between A and B`);
|
|
74
|
+
return -1;
|
|
75
|
+
|
|
76
|
+
}
|
|
77
|
+
});
|
|
@@ -43,7 +43,7 @@ export default () => {
|
|
|
43
43
|
|
|
44
44
|
return {extract, compare};
|
|
45
45
|
|
|
46
|
-
function extract(record) {
|
|
46
|
+
function extract({record, recordExternal}) {
|
|
47
47
|
|
|
48
48
|
const isMelindaRecord = record.get('003').some(f003 => f003.value === 'FI-MELINDA');
|
|
49
49
|
const [f001] = record.get('001').map(field => field.value);
|
|
@@ -54,7 +54,7 @@ export default () => {
|
|
|
54
54
|
f001 === undefined &&
|
|
55
55
|
f035MelindaIds.length < 1) {
|
|
56
56
|
|
|
57
|
-
debug(
|
|
57
|
+
debug(`${recordExternal.label} No Melinda-IDs found`);
|
|
58
58
|
return {};
|
|
59
59
|
}
|
|
60
60
|
|
|
@@ -62,7 +62,6 @@ export default () => {
|
|
|
62
62
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
// eslint-disable-next-line max-statements
|
|
66
65
|
function compare(a, b) {
|
|
67
66
|
|
|
68
67
|
if (a.isMelindaRecord && b.isMelindaRecord &&
|
|
@@ -28,6 +28,8 @@
|
|
|
28
28
|
|
|
29
29
|
import createInterface from './standard-identifier-factory';
|
|
30
30
|
|
|
31
|
+
// DEVELOP: we should compare indicators and sf2 for f024
|
|
32
|
+
|
|
31
33
|
export default () => {
|
|
32
34
|
const {extract, compare} = createInterface({pattern: /^024$/u, subfieldCodes: ['a', 'z']});
|
|
33
35
|
return {extract, compare, name: 'Other standard identifier'};
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
4
|
+
*
|
|
5
|
+
* Melinda record matching modules for Javascript
|
|
6
|
+
*
|
|
7
|
+
* Copyright (C) 2020-2023 University Of Helsinki (The National Library Of Finland)
|
|
8
|
+
*
|
|
9
|
+
* This file is part of melinda-record-matching-js
|
|
10
|
+
*
|
|
11
|
+
* melinda-record-matching-js program is free software: you can redistribute it and/or modify
|
|
12
|
+
* it under the terms of the GNU Lesser General Public License as
|
|
13
|
+
* published by the Free Software Foundation, either version 3 of the
|
|
14
|
+
* License, or (at your option) any later version.
|
|
15
|
+
*
|
|
16
|
+
* melinda-record-matching-js is distributed in the hope that it will be useful,
|
|
17
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19
|
+
* GNU Lesser General Public License for more details.
|
|
20
|
+
*
|
|
21
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
22
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
23
|
+
*
|
|
24
|
+
* @licend The above is the entire license notice
|
|
25
|
+
* for the JavaScript code in this file.
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import {testStringOrNumber} from '../../../matching-utils';
|
|
30
|
+
import createDebugLogger from 'debug';
|
|
31
|
+
|
|
32
|
+
// We should also get copyright time and copyright/publication times from 26x
|
|
33
|
+
// We should also get publishing time type from f008
|
|
34
|
+
// We should get reprint times from f500 $a "Lisäpainos/Lisäpainokset:"
|
|
35
|
+
|
|
36
|
+
export default () => ({
|
|
37
|
+
name: 'Publication time, allow consequent years, years from multiple sources',
|
|
38
|
+
extract: ({record, recordExternal}) => {
|
|
39
|
+
const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib/publication-time-allow-cons-years-multi');
|
|
40
|
+
const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';
|
|
41
|
+
|
|
42
|
+
const f008Values = extractF008Values(record);
|
|
43
|
+
debug(`${label} f008: ${JSON.stringify(f008Values)}`);
|
|
44
|
+
|
|
45
|
+
const f26xValues = extractF26xValues(record);
|
|
46
|
+
debug(`${label} f26x: ${JSON.stringify(f26xValues)}`);
|
|
47
|
+
|
|
48
|
+
const f500Values = extractF500Years(record);
|
|
49
|
+
debug(`${label} f500: ${JSON.stringify(f500Values)}`);
|
|
50
|
+
|
|
51
|
+
// We should get copyrightYear from f008Date2 to copyrightYears when f008YearType = 'r'
|
|
52
|
+
// Is the original year (f008Date2) in f008YearType === 'r' comparable to copyrightYear?
|
|
53
|
+
// We should handle unknown years (here or comparison?)
|
|
54
|
+
// We should handle year ranges for continuing resources / collections
|
|
55
|
+
|
|
56
|
+
const normalYears = [...new Set(f26xValues.normalYears.concat(f008Values.f008Date1).filter(value => value && value !== ' ' && value !== '||||'))].sort();
|
|
57
|
+
const copyrightYears = [...new Set(f26xValues.copyrightYears)].sort();
|
|
58
|
+
const reprintYears = [...new Set(f500Values)].sort();
|
|
59
|
+
|
|
60
|
+
const combined = {normalYears, copyrightYears, reprintYears};
|
|
61
|
+
|
|
62
|
+
debug(`Combined: ${JSON.stringify(combined)}`);
|
|
63
|
+
|
|
64
|
+
return combined;
|
|
65
|
+
|
|
66
|
+
function extractF008Values(record) {
|
|
67
|
+
// Record should have only one f008 - in case of several, we handle the first one
|
|
68
|
+
const value = record.get(/^008$/u)?.[0]?.value || undefined;
|
|
69
|
+
if (value && testStringOrNumber(value)) {
|
|
70
|
+
const f008Date1 = extractF008Date1(value);
|
|
71
|
+
const f008Date2 = extractF008Date2(value);
|
|
72
|
+
const f008YearType = extractF008YearType(value);
|
|
73
|
+
return {f008Date1, f008Date2, f008YearType};
|
|
74
|
+
}
|
|
75
|
+
return {f008Date1: undefined, f008Date2: undefined, f008YearType: undefined};
|
|
76
|
+
|
|
77
|
+
function extractF008Date1(value) {
|
|
78
|
+
return String(value).slice(7, 11);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function extractF008Date2(value) {
|
|
82
|
+
return String(value).slice(11, 15);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function extractF008YearType(value) {
|
|
86
|
+
return String(value).slice(6, 7);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function extractF26xValues(record) {
|
|
91
|
+
const copyrightRegex = /^(?<copyrightPrefix>cop|cop.|c|©|p|℗)/u;
|
|
92
|
+
|
|
93
|
+
const pubNormalSubFieldValues = extractPubNormalSubfieldValues(record, copyrightRegex);
|
|
94
|
+
debug(`Normal years: ${JSON.stringify(pubNormalSubFieldValues)}`);
|
|
95
|
+
|
|
96
|
+
const pubF264CopySubFieldValues = extractPubF264CopySubfieldValues(record);
|
|
97
|
+
debug(`F264 copyright years: ${JSON.stringify(pubF264CopySubFieldValues)}`);
|
|
98
|
+
|
|
99
|
+
const pubF260CopySubFieldValues = extractPubF260CopySubfieldValues(record, copyrightRegex);
|
|
100
|
+
debug(`F260 copyright years: ${JSON.stringify(pubF260CopySubFieldValues)}`);
|
|
101
|
+
|
|
102
|
+
return {normalYears: pubNormalSubFieldValues, copyrightYears: [...pubF260CopySubFieldValues, ...pubF264CopySubFieldValues]};
|
|
103
|
+
|
|
104
|
+
function extractPubNormalSubfieldValues(record, copyrightRegex) {
|
|
105
|
+
return record.get(/^26[04]$/u)
|
|
106
|
+
.filter((field) => !(field.tag === '264' && field.ind2 === '4'))
|
|
107
|
+
.map(({subfields}) => subfields)
|
|
108
|
+
.flat()
|
|
109
|
+
.filter(({code}) => code && code === 'c')
|
|
110
|
+
.filter(({value}) => value && !copyrightRegex.test(value))
|
|
111
|
+
.map(({value}) => value)
|
|
112
|
+
.map((value) => removeNonAlphaNumeric(value));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function extractPubF264CopySubfieldValues(record, copyrightRegex) {
|
|
116
|
+
return record.get(/^264$/u)
|
|
117
|
+
.filter((field) => field.ind2 === '4')
|
|
118
|
+
.map(({subfields}) => subfields)
|
|
119
|
+
.flat()
|
|
120
|
+
.filter(({code}) => code && code === 'c')
|
|
121
|
+
.filter(({value}) => value)
|
|
122
|
+
.map(({value}) => value)
|
|
123
|
+
.map((value) => value.replace(copyrightRegex, ''))
|
|
124
|
+
.map((value) => removeNonAlphaNumeric(value));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function extractPubF260CopySubfieldValues(record, copyrightRegex) {
|
|
128
|
+
return record.get(/^260$/u)
|
|
129
|
+
.map(({subfields}) => subfields)
|
|
130
|
+
.flat()
|
|
131
|
+
.filter(({code}) => code && code === 'c')
|
|
132
|
+
.filter(({value}) => value && copyrightRegex.test(value))
|
|
133
|
+
.map(({value}) => value)
|
|
134
|
+
.map((value) => value.replace(copyrightRegex, ''))
|
|
135
|
+
.map((value) => removeNonAlphaNumeric(value));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function removeNonAlphaNumeric(value) {
|
|
139
|
+
debug(`Cleaning: ${JSON.stringify(value)}`);
|
|
140
|
+
const nonAlphaNumericRegex = /[^A-Za-z0-9]/ug;
|
|
141
|
+
return value ? value.replace(nonAlphaNumericRegex, '') : value;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function extractF500Years(record) {
|
|
146
|
+
|
|
147
|
+
const reprintRegex = /(?<reprint>Lisäpainokset:|Lisäpainos:)/u;
|
|
148
|
+
const reprintFieldContents = record.get(/^500$/u)
|
|
149
|
+
.map(({subfields}) => subfields)
|
|
150
|
+
.flat()
|
|
151
|
+
.filter(({code}) => code === 'a')
|
|
152
|
+
.map(({value}) => value);
|
|
153
|
+
//.filter(value => value.test(reprintRegex));
|
|
154
|
+
|
|
155
|
+
debug(`f500 reprint field contents: ${JSON.stringify(reprintFieldContents)}`);
|
|
156
|
+
|
|
157
|
+
const filteredF500 = reprintFieldContents.filter((content) => content && content.match(reprintRegex));
|
|
158
|
+
|
|
159
|
+
debug(`f500 reprint field contents (filtered): ${JSON.stringify(filteredF500)}`);
|
|
160
|
+
|
|
161
|
+
const reprintYears = extractReprintYears(filteredF500);
|
|
162
|
+
|
|
163
|
+
return reprintYears;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function extractReprintYears(contents) {
|
|
167
|
+
const yearRegex = /[0-9][0-9][0-9][0-9]/gu;
|
|
168
|
+
const years = contents.map(content => content.match(yearRegex))
|
|
169
|
+
.flat();
|
|
170
|
+
debug(`${JSON.stringify(years)}`);
|
|
171
|
+
const uniqYears = [...new Set(years)].sort();
|
|
172
|
+
debug(`${JSON.stringify(uniqYears)}`);
|
|
173
|
+
return uniqYears;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
},
|
|
177
|
+
// eslint-disable-next-line max-statements
|
|
178
|
+
compare: (a, b) => {
|
|
179
|
+
const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib/publication-time-allow-cons-years-multi');
|
|
180
|
+
debug(`Comparing ${JSON.stringify(a)} to ${JSON.stringify(b)}`);
|
|
181
|
+
|
|
182
|
+
const [firstA] = a.normalYears ? a.normalYears : a;
|
|
183
|
+
const [firstB] = b.normalYears ? b.normalYears : b;
|
|
184
|
+
|
|
185
|
+
debug(`Comparing ${JSON.stringify(firstA)} to ${JSON.stringify(firstB)}`);
|
|
186
|
+
|
|
187
|
+
if (firstA === firstB) {
|
|
188
|
+
return 0.1;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// If either of years is a non string/number, values are not comparable
|
|
192
|
+
if (!testStringOrNumber(firstA) || !testStringOrNumber(firstB)) {
|
|
193
|
+
return 0;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const firstANumber = parseInt(firstA, 10);
|
|
197
|
+
const firstBNumber = parseInt(firstB, 10);
|
|
198
|
+
|
|
199
|
+
// Handle consequent years as a match
|
|
200
|
+
// see publication-time for a version that does not handle consequent years as a match
|
|
201
|
+
if (!(isNaN(firstANumber) || isNaN(firstBNumber)) &&
|
|
202
|
+
(firstANumber + 1 === firstBNumber || firstANumber - 1 === firstBNumber)) {
|
|
203
|
+
return 0.1;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// We should do something with copyrightYears, too
|
|
207
|
+
|
|
208
|
+
// Do not give minus points if a normal publishing year is found in normal years
|
|
209
|
+
const bNormalInANormal = a.normalYears.filter(aValue => b.normalYears.some(bValue => aValue === bValue));
|
|
210
|
+
const aNormalInBNormal = b.normalYears.filter(bValue => a.normalYears.some(aValue => bValue === aValue));
|
|
211
|
+
debug(`BNorm in ANorm: ${JSON.stringify(bNormalInANormal)}`);
|
|
212
|
+
debug(`ANorm in BNorm: ${JSON.stringify(aNormalInBNormal)}`);
|
|
213
|
+
|
|
214
|
+
if (bNormalInANormal > 0 || aNormalInBNormal > 0) {
|
|
215
|
+
return 0;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Do not give minus points if a normal publishing year is found in reprint years
|
|
219
|
+
const bNormalInAReprint = a.reprintYears.filter(aValue => b.normalYears.some(bValue => aValue === bValue));
|
|
220
|
+
const aNormalInBReprint = b.reprintYears.filter(bValue => a.normalYears.some(aValue => bValue === aValue));
|
|
221
|
+
debug(`BNorm in AReprint: ${JSON.stringify(bNormalInAReprint)}`);
|
|
222
|
+
debug(`ANorm in BReprint: ${JSON.stringify(aNormalInBReprint)}`);
|
|
223
|
+
|
|
224
|
+
if (bNormalInAReprint > 0 || aNormalInBReprint > 0) {
|
|
225
|
+
return 0;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return -1;
|
|
229
|
+
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
// https://www.loc.gov/marc/bibliographic/bd008.html
|
|
234
|
+
// field 008
|
|
235
|
+
// 06 - Type of date/Publication status
|
|
236
|
+
// 07-10 - Date 1
|
|
237
|
+
// 11-14 - Date 2
|
|
238
|
+
//
|
|
239
|
+
// 06 - Type of date/Publication status
|
|
240
|
+
// b - No dates given; B.C. date involved
|
|
241
|
+
// c - Continuing resource currently published
|
|
242
|
+
// d - Continuing resource ceased publication
|
|
243
|
+
// e - Detailed date
|
|
244
|
+
// i - Inclusive dates of collection
|
|
245
|
+
// k - Range of years of bulk of collection
|
|
246
|
+
// m - Multiple dates
|
|
247
|
+
// n - Dates unknown
|
|
248
|
+
// p - Date of distribution/release/issue and production/recording session when different
|
|
249
|
+
// q - Questionable date
|
|
250
|
+
// r - Reprint/reissue date and original date
|
|
251
|
+
// s - Single known date/probable date
|
|
252
|
+
// t - Publication date and copyright date
|
|
253
|
+
// u - Continuing resource status unknown
|
|
254
|
+
// | - No attempt to code
|
|
255
|
+
//
|
|
256
|
+
// 07-10 - Date 1
|
|
257
|
+
// 1-9 - Date digit
|
|
258
|
+
// # - Date element is not applicable
|
|
259
|
+
// u - Date element is totally or partially unknown
|
|
260
|
+
// |||| - No attempt to code
|
|
261
|
+
//
|
|
262
|
+
// 11-14 - Date 2
|
|
263
|
+
// 1-9 - Date digit
|
|
264
|
+
// # - Date element is not applicable
|
|
265
|
+
// u - Date element is totally or partially unknown
|
|
266
|
+
// |||| - No attempt to code
|
|
267
|
+
//
|
|
268
|
+
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
4
|
+
*
|
|
5
|
+
* Melinda record matching modules for Javascript
|
|
6
|
+
*
|
|
7
|
+
* Copyright (C) 2020-2023 University Of Helsinki (The National Library Of Finland)
|
|
8
|
+
*
|
|
9
|
+
* This file is part of melinda-record-matching-js
|
|
10
|
+
*
|
|
11
|
+
* melinda-record-matching-js program is free software: you can redistribute it and/or modify
|
|
12
|
+
* it under the terms of the GNU Lesser General Public License as
|
|
13
|
+
* published by the Free Software Foundation, either version 3 of the
|
|
14
|
+
* License, or (at your option) any later version.
|
|
15
|
+
*
|
|
16
|
+
* melinda-record-matching-js is distributed in the hope that it will be useful,
|
|
17
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19
|
+
* GNU Lesser General Public License for more details.
|
|
20
|
+
*
|
|
21
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
22
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
23
|
+
*
|
|
24
|
+
* @licend The above is the entire license notice
|
|
25
|
+
* for the JavaScript code in this file.
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import {testStringOrNumber} from '../../../matching-utils';
|
|
30
|
+
import createDebugLogger from 'debug';
|
|
31
|
+
|
|
32
|
+
// We should also get copyright time and copyright/publication times from 26x
|
|
33
|
+
|
|
34
|
+
export default () => ({
|
|
35
|
+
name: 'Publication time, allow consequent years',
|
|
36
|
+
extract: ({record}) => {
|
|
37
|
+
const value = record.get(/^008$/u)?.[0]?.value || undefined;
|
|
38
|
+
return testStringOrNumber(value) ? [String(value).slice(7, 11)] : [];
|
|
39
|
+
},
|
|
40
|
+
compare: (a, b) => {
|
|
41
|
+
const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib/publication-time-allow-cons-years');
|
|
42
|
+
debug(`Comparing ${a[0]} to ${b[0]}`);
|
|
43
|
+
|
|
44
|
+
const [firstA] = a;
|
|
45
|
+
const [firstB] = b;
|
|
46
|
+
|
|
47
|
+
if (firstA === firstB) {
|
|
48
|
+
return 0.1;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// If either of years is a non string/number, values are not comparable
|
|
52
|
+
if (!testStringOrNumber(firstA) || !testStringOrNumber(firstB)) {
|
|
53
|
+
return 0;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const firstANumber = parseInt(firstA, 10);
|
|
57
|
+
const firstBNumber = parseInt(firstB, 10);
|
|
58
|
+
|
|
59
|
+
if (isNaN(firstANumber) || isNaN(firstBNumber)) {
|
|
60
|
+
return -1;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Handle consequent years as a match
|
|
64
|
+
// see publication-time for a version that does not handle consequent years as a match
|
|
65
|
+
return firstANumber + 1 === firstBNumber || firstANumber - 1 === firstBNumber ? 0.1 : -1;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Melinda record matching modules for Javascript
|
|
6
6
|
*
|
|
7
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
7
|
+
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
8
8
|
*
|
|
9
9
|
* This file is part of melinda-record-matching-js
|
|
10
10
|
*
|
|
@@ -26,11 +26,16 @@
|
|
|
26
26
|
*
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
|
+
import {testStringOrNumber} from '../../../matching-utils';
|
|
30
|
+
|
|
31
|
+
// We should also get copyright time and copyright/publication times from 26x
|
|
32
|
+
// see publication-time-allow-cons-years for a version allowing consequent years to match
|
|
33
|
+
|
|
29
34
|
export default () => ({
|
|
30
35
|
name: 'Publication time',
|
|
31
|
-
extract: record => {
|
|
32
|
-
const value = record.get(/^008$/u)?.[0]?.value ||
|
|
33
|
-
return value ? [value.slice(7, 11)] : [];
|
|
36
|
+
extract: ({record}) => {
|
|
37
|
+
const value = record.get(/^008$/u)?.[0]?.value || undefined;
|
|
38
|
+
return testStringOrNumber(value) ? [String(value).slice(7, 11)] : [];
|
|
34
39
|
},
|
|
35
40
|
compare: (a, b) => a[0] === b[0] ? 0.1 : -1.0
|
|
36
41
|
});
|
|
@@ -26,8 +26,12 @@
|
|
|
26
26
|
*
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
|
+
// we could handle the case of books/notes
|
|
30
|
+
// Recordtype: LDR/06 - Type of Record
|
|
31
|
+
// Note: currently matchValidator fails all mismatching recordTypes, so this won't actually do much
|
|
32
|
+
|
|
29
33
|
export default () => ({
|
|
30
34
|
name: 'Record type',
|
|
31
|
-
extract:
|
|
35
|
+
extract: ({record}) => record.leader[6] ? [record.leader[6]] : [],
|
|
32
36
|
compare: (a, b) => a[0] === b[0] ? 0.1 : -0.5
|
|
33
37
|
});
|