@natlibfi/melinda-record-matching 2.2.1-alpha.1 → 2.2.1-alpha.3

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.
Files changed (66) hide show
  1. package/dist/candidate-search/candidate-search-utils.js +55 -0
  2. package/dist/candidate-search/candidate-search-utils.js.map +1 -0
  3. package/dist/candidate-search/index.js +258 -0
  4. package/dist/candidate-search/index.js.map +1 -0
  5. package/dist/candidate-search/index.spec.js +148 -0
  6. package/dist/candidate-search/index.spec.js.map +1 -0
  7. package/dist/candidate-search/query-list/bib.js +230 -0
  8. package/dist/candidate-search/query-list/bib.js.map +1 -0
  9. package/dist/candidate-search/query-list/bib.spec.js +63 -0
  10. package/dist/candidate-search/query-list/bib.spec.js.map +1 -0
  11. package/dist/candidate-search/query-list/index.js +61 -0
  12. package/dist/candidate-search/query-list/index.js.map +1 -0
  13. package/dist/index.js +559 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/index.spec.js +125 -0
  16. package/dist/index.spec.js.map +1 -0
  17. package/dist/match-detection/features/bib/all-source-ids.js +116 -0
  18. package/dist/match-detection/features/bib/all-source-ids.js.map +1 -0
  19. package/dist/match-detection/features/bib/authors.js +107 -0
  20. package/dist/match-detection/features/bib/authors.js.map +1 -0
  21. package/dist/match-detection/features/bib/bibliographic-level.js +39 -0
  22. package/dist/match-detection/features/bib/bibliographic-level.js.map +1 -0
  23. package/dist/match-detection/features/bib/host-component.js +39 -0
  24. package/dist/match-detection/features/bib/host-component.js.map +1 -0
  25. package/dist/match-detection/features/bib/index.js +91 -0
  26. package/dist/match-detection/features/bib/index.js.map +1 -0
  27. package/dist/match-detection/features/bib/index.spec.js +87 -0
  28. package/dist/match-detection/features/bib/index.spec.js.map +1 -0
  29. package/dist/match-detection/features/bib/isbn.js +50 -0
  30. package/dist/match-detection/features/bib/isbn.js.map +1 -0
  31. package/dist/match-detection/features/bib/issn.js +50 -0
  32. package/dist/match-detection/features/bib/issn.js.map +1 -0
  33. package/dist/match-detection/features/bib/language.js +98 -0
  34. package/dist/match-detection/features/bib/language.js.map +1 -0
  35. package/dist/match-detection/features/bib/melinda-id.js +47 -0
  36. package/dist/match-detection/features/bib/melinda-id.js.map +1 -0
  37. package/dist/match-detection/features/bib/melinda-identifier-factory.js +88 -0
  38. package/dist/match-detection/features/bib/melinda-identifier-factory.js.map +1 -0
  39. package/dist/match-detection/features/bib/other-standard-identifier.js +50 -0
  40. package/dist/match-detection/features/bib/other-standard-identifier.js.map +1 -0
  41. package/dist/match-detection/features/bib/publication-time.js +47 -0
  42. package/dist/match-detection/features/bib/publication-time.js.map +1 -0
  43. package/dist/match-detection/features/bib/record-type.js +41 -0
  44. package/dist/match-detection/features/bib/record-type.js.map +1 -0
  45. package/dist/match-detection/features/bib/standard-identifier-factory.js +112 -0
  46. package/dist/match-detection/features/bib/standard-identifier-factory.js.map +1 -0
  47. package/dist/match-detection/features/bib/title.js +78 -0
  48. package/dist/match-detection/features/bib/title.js.map +1 -0
  49. package/dist/match-detection/features/index.js +11 -0
  50. package/dist/match-detection/features/index.js.map +1 -0
  51. package/dist/match-detection/index.js +162 -0
  52. package/dist/match-detection/index.js.map +1 -0
  53. package/dist/match-detection/index.spec.js +88 -0
  54. package/dist/match-detection/index.spec.js.map +1 -0
  55. package/dist/matching-utils.js +95 -0
  56. package/dist/matching-utils.js.map +1 -0
  57. package/package.json +18 -17
  58. package/src/candidate-search/query-list/bib.js +19 -18
  59. package/src/candidate-search/query-list/index.js +1 -1
  60. package/src/match-detection/features/bib/authors.js +5 -2
  61. package/src/match-detection/features/bib/language.js +2 -2
  62. package/src/match-detection/features/bib/publication-time.js +8 -3
  63. package/src/match-detection/features/bib/record-type.js +2 -0
  64. package/src/match-detection/features/bib/standard-identifier-factory.js +4 -3
  65. package/src/match-detection/features/bib/title.js +6 -4
  66. package/src/matching-utils.js +13 -4
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "url": "git@github.com:natlibfi/melinda-record-matching-js.git"
15
15
  },
16
16
  "license": "LGPL-3.0+",
17
- "version": "2.2.1-alpha.1",
17
+ "version": "2.2.1-alpha.3",
18
18
  "main": "./dist/index.js",
19
19
  "engines": {
20
20
  "node": ">=14"
@@ -23,6 +23,7 @@
23
23
  "access": "public"
24
24
  },
25
25
  "scripts": {
26
+ "prepare": "npm run build",
26
27
  "start": "node dist/index.js",
27
28
  "cli": "node dist/cli.js",
28
29
  "lint": "eslint src",
@@ -35,35 +36,35 @@
35
36
  "watch:test": "cross-env DEBUG=1 NODE_ENV=test nodemon -w src -w test-fixtures --exec 'npm run test:dev'"
36
37
  },
37
38
  "dependencies": {
38
- "@natlibfi/marc-record": "^7.0.0",
39
- "@natlibfi/marc-record-serializers": "^8.1.0",
40
- "@natlibfi/melinda-commons": "^12.0.3",
41
- "@natlibfi/sru-client": "^5.0.1",
39
+ "@natlibfi/marc-record": "^7.2.1",
40
+ "@natlibfi/marc-record-serializers": "^9.0.0",
41
+ "@natlibfi/melinda-commons": "^12.0.4",
42
+ "@natlibfi/sru-client": "^5.0.3",
42
43
  "debug": "^4.3.4",
43
44
  "moment": "^2.29.4",
44
45
  "natural": "^5.2.3",
45
- "uuid": "^8.3.2",
46
- "winston": "^3.8.1"
46
+ "uuid": "^9.0.0",
47
+ "winston": "^3.8.2"
47
48
  },
48
49
  "devDependencies": {
49
- "@babel/cli": "^7.18.10",
50
- "@babel/core": "^7.18.13",
51
- "@babel/eslint-parser": "^7.18.9",
52
- "@babel/node": "^7.18.10",
53
- "@babel/preset-env": "^7.18.10",
50
+ "@babel/cli": "^7.19.3",
51
+ "@babel/core": "^7.19.3",
52
+ "@babel/eslint-parser": "^7.19.1",
53
+ "@babel/node": "^7.19.1",
54
+ "@babel/preset-env": "^7.19.4",
54
55
  "@babel/register": "^7.18.9",
55
- "@natlibfi/eslint-config-melinda-backend": "^2.0.0",
56
+ "@natlibfi/eslint-config-melinda-backend": "^2.0.1",
56
57
  "@natlibfi/fixugen": "^1.1.0",
57
58
  "@natlibfi/fixugen-http-client": "^2.0.1",
58
- "@natlibfi/fixura": "^2.2.1",
59
+ "@natlibfi/fixura": "^2.2.5",
59
60
  "babel-plugin-istanbul": "^6.1.1",
60
61
  "babel-plugin-rewire": "^1.2.0",
61
62
  "chai": "^4.3.6",
62
63
  "chai-as-promised": "^7.1.1",
63
64
  "cross-env": "^7.0.3",
64
- "eslint": "^8.23.0",
65
- "mocha": "^9.2.2",
66
- "nodemon": "^2.0.19",
65
+ "eslint": "^8.25.0",
66
+ "mocha": "^10.0.0",
67
+ "nodemon": "^2.0.20",
67
68
  "nyc": "^15.1.0"
68
69
  },
69
70
  "eslintConfig": {
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * Melinda record matching modules for Javascript
7
7
  *
8
- * Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
8
+ * Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
9
9
  *
10
10
  * This file is part of melinda-record-matching-js
11
11
  *
@@ -28,7 +28,7 @@
28
28
  */
29
29
  import createDebugLogger from 'debug';
30
30
  import {toQueries} from '../candidate-search-utils';
31
- import {getMelindaIdsF035, validateSidFieldSubfieldCounts, getSubfieldValues} from '../../matching-utils';
31
+ import {getMelindaIdsF035, validateSidFieldSubfieldCounts, getSubfieldValues, testStringOrNumber} from '../../matching-utils';
32
32
 
33
33
 
34
34
  export function bibSourceIds(record) {
@@ -108,7 +108,7 @@ export function bibSourceIds(record) {
108
108
 
109
109
  function removeSourcePrefix(subfieldValue) {
110
110
  const sourcePrefixRegex = (/^(?<sourcePrefix>\([A-Za-z0-9-]+\))(?<id>.+)$/u);
111
- const normalizedValue = subfieldValue ? subfieldValue.replace(sourcePrefixRegex, '$<id>') : '';
111
+ const normalizedValue = testStringOrNumber(subfieldValue) ? String(subfieldValue).replace(sourcePrefixRegex, '$<id>') : '';
112
112
  debugData(`Normalized ${subfieldValue} to ${normalizedValue}`);
113
113
  return normalizedValue;
114
114
  }
@@ -116,7 +116,7 @@ export function bibSourceIds(record) {
116
116
  function normalizeSidSubfieldValue(subfieldValue) {
117
117
  debugData(`Normalizing ${subfieldValue}`);
118
118
  const normalizeAwayRegex = (/[- ]/u);
119
- return subfieldValue ? subfieldValue.replace(normalizeAwayRegex, '') : '';
119
+ return testStringOrNumber(subfieldValue) ? String(subfieldValue).replace(normalizeAwayRegex, '') : '';
120
120
  }
121
121
 
122
122
  }
@@ -151,7 +151,7 @@ export function bibMelindaIds(record) {
151
151
  // bibHostComponents should search all 773 $ws for possible host id, but what should it do in case of multiple host ids?
152
152
  export function bibHostComponents(record) {
153
153
  const id = getHostId();
154
- return id ? [`melinda.partsofhost=${id}`] : [];
154
+ return testStringOrNumber(id) ? [`melinda.partsofhost=${id}`] : [];
155
155
 
156
156
  function getHostId() {
157
157
  const [field] = record.get(/^773$/u);
@@ -159,12 +159,12 @@ export function bibHostComponents(record) {
159
159
  if (field) {
160
160
  const {value} = field.subfields.find(({code}) => code === 'w') || {};
161
161
 
162
- if (value && (/^\(FI-MELINDA\)/u).test(value)) {
163
- return value.replace(/^\(FI-MELINDA\)/u, '');
162
+ if (testStringOrNumber(value) && (/^\(FI-MELINDA\)/u).test(String(value))) {
163
+ return String(value).replace(/^\(FI-MELINDA\)/u, '');
164
164
  }
165
165
 
166
- if (value && (/^\(FIN01\)/u).test(value)) {
167
- return value.replace(/^\(FIN01\)/u, '');
166
+ if (testStringOrNumber(value) && (/^\(FIN01\)/u).test(String(value))) {
167
+ return String(value).replace(/^\(FIN01\)/u, '');
168
168
  }
169
169
 
170
170
  return false;
@@ -185,8 +185,8 @@ export function bibTitle(record) {
185
185
  const title = getTitle();
186
186
  const booleanStartWords = ['and', 'or', 'nor', 'not'];
187
187
 
188
- if (title) {
189
- const formatted = title
188
+ if (testStringOrNumber(title)) {
189
+ const formatted = String(title)
190
190
  .replace(/[^\w\s\p{Alphabetic}]/gu, '')
191
191
  // Clean up concurrent spaces from fe. subfield changes
192
192
  .replace(/ +/gu, ' ')
@@ -208,7 +208,8 @@ export function bibTitle(record) {
208
208
  if (field) {
209
209
  return field.subfields
210
210
  .filter(({code}) => ['a', 'b'].includes(code))
211
- .map(({value}) => value)
211
+ .map(({value}) => testStringOrNumber(value) ? String(value) : '')
212
+ .filter(value => value)
212
213
  // In Melinda's index subfield separators are indexed as ' '
213
214
  .join(' ');
214
215
  }
@@ -244,18 +245,18 @@ export function bibStandardIdentifiers(record) {
244
245
 
245
246
  if (tag === '022') {
246
247
  return subfields
247
- .filter(sub => ['a', 'z', 'y'].includes(sub.code) && issnIsbnReqExp.test(sub.value) && sub.value !== undefined)
248
- .map(({value}) => value);
248
+ .filter(sub => ['a', 'z', 'y'].includes(sub.code) && testStringOrNumber(sub.value) && issnIsbnReqExp.test(String(sub.value)))
249
+ .map(({value}) => String(value));
249
250
  }
250
251
 
251
252
  if (tag === '020') {
252
253
  return subfields
253
- .filter(sub => ['a', 'z'].includes(sub.code) && issnIsbnReqExp.test(sub.value) && sub.value !== undefined)
254
- .map(({value}) => value);
254
+ .filter(sub => ['a', 'z'].includes(sub.code) && testStringOrNumber(sub.value) && issnIsbnReqExp.test(String(sub.value)))
255
+ .map(({value}) => String(value));
255
256
  }
256
257
 
257
258
  return subfields
258
- .filter(sub => ['a', 'z'].includes(sub.code) && otherIdReqExp.test(sub.value) && sub.value !== undefined)
259
- .map(({value}) => value);
259
+ .filter(sub => ['a', 'z'].includes(sub.code) && testStringOrNumber(sub.value) && otherIdReqExp.test(String(sub.value)))
260
+ .map(({value}) => String(value));
260
261
  }
261
262
  }
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * Melinda record matching modules for Javascript
6
6
  *
7
- * Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
7
+ * Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
8
8
  *
9
9
  * This file is part of melinda-record-matching-js
10
10
  *
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * Melinda record matching modules for Javascript
6
6
  *
7
- * Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
7
+ * Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
8
8
  *
9
9
  * This file is part of melinda-record-matching-js
10
10
  *
@@ -27,6 +27,9 @@
27
27
  */
28
28
 
29
29
  import {LevenshteinDistance as leven} from 'natural';
30
+ import {testStringOrNumber} from '../../../matching-utils';
31
+
32
+ // We should extract also organisational authors (110/710)
30
33
 
31
34
  export default ({nameTreshold = 10} = {}) => ({
32
35
  name: 'Authors',
@@ -40,7 +43,7 @@ export default ({nameTreshold = 10} = {}) => ({
40
43
 
41
44
  function toObj({code, value}) {
42
45
  if (code === 'a') {
43
- return {name: value ? value.replace(/[^\p{Letter}\p{Number}]/gu, '').toLowerCase() : ''};
46
+ return {name: testStringOrNumber(value) ? String(value).replace(/[^\p{Letter}\p{Number}]/gu, '').toLowerCase() : ''};
44
47
  }
45
48
 
46
49
  return {id: value};
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * Melinda record matching modules for Javascript
7
7
  *
8
- * Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
8
+ * Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
9
9
  *
10
10
  * This file is part of melinda-record-matching-js
11
11
  *
@@ -86,7 +86,7 @@ export default () => ({
86
86
  return 0;
87
87
  }
88
88
 
89
- debugData(`There area languages to compare`);
89
+ debugData(`There are languages to compare`);
90
90
 
91
91
  if (a[0] === b[0]) {
92
92
  return 0.1;
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * Melinda record matching modules for Javascript
6
6
  *
7
- * Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
7
+ * Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
8
8
  *
9
9
  * This file is part of melinda-record-matching-js
10
10
  *
@@ -26,11 +26,16 @@
26
26
  *
27
27
  */
28
28
 
29
+ import {testStringOrNumber} from '../../../matching-utils';
30
+
31
+ // We should also get copyright time and copyright/publication times from 26x
32
+ // We could also enable matching of records which have consequent publication years
33
+
29
34
  export default () => ({
30
35
  name: 'Publication time',
31
36
  extract: record => {
32
- const value = record.get(/^008$/u)?.[0]?.value || '';
33
- return value ? [value.slice(7, 11)] : [];
37
+ const value = record.get(/^008$/u)?.[0]?.value || undefined;
38
+ return testStringOrNumber(value) ? [String(value).slice(7, 11)] : [];
34
39
  },
35
40
  compare: (a, b) => a[0] === b[0] ? 0.1 : -1.0
36
41
  });
@@ -26,6 +26,8 @@
26
26
  *
27
27
  */
28
28
 
29
+ // we could handle the case of books/notes
30
+
29
31
  export default () => ({
30
32
  name: 'Record type',
31
33
  extract: r => r.leader[6] ? [r.leader[6]] : [],
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * Melinda record matching modules for Javascript
6
6
  *
7
- * Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
7
+ * Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
8
8
  *
9
9
  * This file is part of melinda-record-matching-js
10
10
  *
@@ -27,6 +27,7 @@
27
27
  */
28
28
 
29
29
  import createDebugLogger from 'debug';
30
+ import {testStringOrNumber} from '../../../matching-utils';
30
31
 
31
32
  const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features:standard-identifiers');
32
33
  const debugData = debug.extend('data');
@@ -40,8 +41,8 @@ export default ({pattern, subfieldCodes}) => {
40
41
  if (field) {
41
42
  return field.subfields
42
43
  .filter(({code}) => subfieldCodes.includes(code))
43
- // .map(({code, value}) => ({code, value: value.replace(/-/ug, '')}));
44
- .map(({code, value}) => ({code, value: value ? value.replace(/-/ug, '') : ''}));
44
+ .map(({code, value}) => ({code, value: testStringOrNumber(value) ? String(value).replace(/-/ug, '') : ''}))
45
+ .filter(value => value);
45
46
  }
46
47
 
47
48
  return [];
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * Melinda record matching modules for Javascript
6
6
  *
7
- * Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
7
+ * Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
8
8
  *
9
9
  * This file is part of melinda-record-matching-js
10
10
  *
@@ -28,14 +28,15 @@
28
28
 
29
29
  import createDebugLogger from 'debug';
30
30
  import {LevenshteinDistance as leven} from 'natural';
31
+ import {testStringOrNumber} from '../../../matching-utils';
31
32
 
32
33
  export default ({treshold = 10} = {}) => ({
33
34
  name: 'Title',
34
35
  extract: record => {
35
36
  const title = getTitle();
36
37
 
37
- if (title) {
38
- return [title.replace(/[^\p{Letter}\p{Number}]/gu, '').toLowerCase()];
38
+ if (testStringOrNumber(title)) {
39
+ return [String(title).replace(/[^\p{Letter}\p{Number}]/gu, '').toLowerCase()];
39
40
  }
40
41
 
41
42
  return [];
@@ -46,9 +47,10 @@ export default ({treshold = 10} = {}) => ({
46
47
  if (field) {
47
48
  return field.subfields
48
49
  .filter(({code}) => ['a', 'b'].includes(code))
49
- .map(({value}) => value)
50
+ .map(({value}) => testStringOrNumber(value) ? String(value) : '')
50
51
  .join('');
51
52
  }
53
+ return false;
52
54
  }
53
55
  },
54
56
  compare: (a, b) => {
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * Melinda record matching modules for Javascript
6
6
  *
7
- * Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
7
+ * Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
8
8
  *
9
9
  * This file is part of melinda-record-matching-js
10
10
  *
@@ -58,8 +58,8 @@ export function getMelindaIdsF035(record) {
58
58
 
59
59
  return subfields
60
60
  .filter(sub => ['a', 'z'].includes(sub.code))
61
- .filter(sub => melindaIdRegExp.test(sub.value))
62
- .map(({value}) => value ? value.replace(melindaIdRegExp, '$<id>') : '');
61
+ .filter(sub => testStringOrNumber(sub.value) && melindaIdRegExp.test(String(sub.value)))
62
+ .map(({value}) => testStringOrNumber(value) ? String(value).replace(melindaIdRegExp, '$<id>') : '');
63
63
 
64
64
  }
65
65
  }
@@ -81,6 +81,15 @@ function countSubfields(field, subfieldCode) {
81
81
 
82
82
  export function getSubfieldValues(field, subfieldCode) {
83
83
  debugData(`Get subfield(s) $${subfieldCode} from ${JSON.stringify(field)}`);
84
- return field.subfields.filter(({code}) => code === subfieldCode).map(({value}) => value);
84
+ return field.subfields
85
+ .filter(({code}) => code === subfieldCode)
86
+ .map(({value}) => testStringOrNumber(value) ? String(value) : '')
87
+ .filter(value => value);
85
88
  }
86
89
 
90
+ export function testStringOrNumber(value) {
91
+ if (typeof value === 'string' || typeof value === 'number') {
92
+ return true;
93
+ }
94
+ return false;
95
+ }