@natlibfi/melinda-record-matching 3.0.0-alpha.1 → 3.0.1-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/candidate-search/index.js +0 -4
  2. package/dist/candidate-search/index.js.map +1 -1
  3. package/dist/candidate-search/index.spec.js +1 -5
  4. package/dist/candidate-search/index.spec.js.map +1 -1
  5. package/dist/candidate-search/query-list/bib.js +0 -2
  6. package/dist/candidate-search/query-list/bib.js.map +1 -1
  7. package/dist/index.js +0 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/match-detection/features/bib/all-source-ids.js +0 -1
  10. package/dist/match-detection/features/bib/all-source-ids.js.map +1 -1
  11. package/dist/match-detection/features/bib/bibliographic-level.js +2 -1
  12. package/dist/match-detection/features/bib/bibliographic-level.js.map +1 -1
  13. package/dist/match-detection/features/bib/host-component.js +2 -1
  14. package/dist/match-detection/features/bib/host-component.js.map +1 -1
  15. package/dist/match-detection/features/bib/index.spec.js +0 -1
  16. package/dist/match-detection/features/bib/index.spec.js.map +1 -1
  17. package/dist/match-detection/features/bib/isbn.js +2 -1
  18. package/dist/match-detection/features/bib/isbn.js.map +1 -1
  19. package/dist/match-detection/features/bib/issn.js +2 -1
  20. package/dist/match-detection/features/bib/issn.js.map +1 -1
  21. package/dist/match-detection/features/bib/language.js +6 -6
  22. package/dist/match-detection/features/bib/language.js.map +1 -1
  23. package/dist/match-detection/features/bib/melinda-id.js +2 -1
  24. package/dist/match-detection/features/bib/melinda-id.js.map +1 -1
  25. package/dist/match-detection/features/bib/melinda-identifier-factory.js +0 -2
  26. package/dist/match-detection/features/bib/melinda-identifier-factory.js.map +1 -1
  27. package/dist/match-detection/features/bib/other-standard-identifier.js +2 -1
  28. package/dist/match-detection/features/bib/other-standard-identifier.js.map +1 -1
  29. package/dist/match-detection/features/bib/title.js +24 -6
  30. package/dist/match-detection/features/bib/title.js.map +1 -1
  31. package/dist/match-detection/index.js +11 -7
  32. package/dist/match-detection/index.js.map +1 -1
  33. package/dist/matching-utils.js +0 -2
  34. package/dist/matching-utils.js.map +1 -1
  35. package/package.json +8 -8
  36. package/src/candidate-search/index.js +1 -3
  37. package/src/candidate-search/index.spec.js +1 -3
  38. package/src/candidate-search/query-list/bib.js +0 -1
  39. package/src/index.js +0 -1
  40. package/src/match-detection/features/bib/all-source-ids.js +0 -1
  41. package/src/match-detection/features/bib/index.spec.js +1 -1
  42. package/src/match-detection/features/bib/language.js +6 -6
  43. package/src/match-detection/features/bib/melinda-identifier-factory.js +0 -1
  44. package/src/match-detection/features/bib/title.js +22 -4
  45. package/src/match-detection/index.js +7 -7
  46. package/src/matching-utils.js +0 -1
@@ -46,7 +46,6 @@ describe('candidate-search', () => {
46
46
  }
47
47
  });
48
48
 
49
- // eslint-disable-next-line max-statements
50
49
  async function callback({getFixture, factoryOptions, searchOptions, expectedFactoryError = false, expectedSearchError = false, enabled = true}) {
51
50
  const url = 'http://foo.bar';
52
51
 
@@ -77,7 +76,6 @@ describe('candidate-search', () => {
77
76
  };
78
77
  }
79
78
 
80
- // eslint-disable-next-line max-statements
81
79
  async function iterate({searchOptions, expectedSearchError, expectedErrorStatus, count = 1}) {
82
80
  const expectedResults = getFixture(`expectedResults${count}.json`);
83
81
 
@@ -108,7 +106,7 @@ describe('candidate-search', () => {
108
106
  }
109
107
 
110
108
  function formatResults(results) {
111
- debug(results); //eslint-disable-line
109
+ debug(results);
112
110
  return {
113
111
  ...results,
114
112
  records: results.records.map(({record, id}) => ({id, record: record.toObject()}))
@@ -217,7 +217,6 @@ export function bibTitle(record) {
217
217
  }
218
218
  }
219
219
 
220
- // eslint-disable-next-line max-statements
221
220
  export function bibStandardIdentifiers(record) {
222
221
 
223
222
  const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibStandardIdentifiers');
package/src/index.js CHANGED
@@ -235,7 +235,6 @@ export default ({detection: detectionOptions, search: searchOptions, maxMatches
235
235
  // - if creating the featureSet for the incoming record fails we have an unprocessable entity
236
236
  // - if creating the featureSet for a candidate record fails we could skip that candidate - but list the case as a detectionFailure, same as conversionFailures
237
237
 
238
- // eslint-disable-next-line max-statements
239
238
  function iterateRecords({records, recordSetSize, maxMatches, matches = [], nonMatches = [], recordMatches = [], recordNonMatches = [], recordCount = 0, recordDuplicateCount = 0, recordNonMatchCount = 0, recordMatchErrors = []}) {
240
239
 
241
240
  // recordSetSize : total amount of records in the current record set
@@ -1,4 +1,3 @@
1
- /* eslint-disable max-statements */
2
1
  /**
3
2
  *
4
3
  * @licstart The following is the entire license notice for the JavaScript code in this file.
@@ -40,7 +40,7 @@ describe('match-detection/features/bib/', () => {
40
40
  fixura: {
41
41
  reader: READERS.JSON
42
42
  },
43
- // eslint-disable-next-line max-statements
43
+
44
44
  callback: ({enabled = true, feature, options, type, ...expectations}) => {
45
45
 
46
46
  if (!enabled) {
@@ -1,4 +1,3 @@
1
- /* eslint-disable max-statements */
2
1
  /**
3
2
  *
4
3
  * @licstart The following is the entire license notice for the JavaScript code in this file.
@@ -42,14 +41,14 @@ export default () => ({
42
41
  debugData(`${label} 008: ${JSON.stringify(value008)}, 041: ${JSON.stringify(values041)}`);
43
42
 
44
43
  if (value008 && values041.length > 0) {
45
- debugData(`There's both 008 and 041, searching for value in both`);
44
+ debugData(`${label} There's both 008 and 041, searching for value in both`);
46
45
  const correspondingValue = values041.find(v => v === value008);
47
- debugData(`Corresponding value: ${correspondingValue}`);
46
+ debugData(`${label} Corresponding value: ${correspondingValue}`);
48
47
  return correspondingValue ? [correspondingValue] : [];
49
48
  }
50
49
 
51
50
  if (!value008 && values041.length < 1) {
52
- debugData(`No actual values found`);
51
+ debugData(`{$label} No actual values found`);
53
52
  return [];
54
53
  }
55
54
 
@@ -57,18 +56,19 @@ export default () => ({
57
56
 
58
57
  function get008Value() {
59
58
  const value = record.get(/^008$/u)?.[0]?.value || undefined;
60
- debugData(`008 value: ${value}`);
59
+ debugData(`${label} 008 value: ${value}`);
61
60
 
62
61
  if (!value) {
63
62
  return undefined;
64
63
  }
65
64
 
66
65
  const code = value.slice(35, 38);
67
- debugData(`008 code: ${code}`);
66
+ debugData(`${label} 008 code: ${code}`);
68
67
  return code === '|||' || code === ' ' || code === '^^^' ? undefined : code;
69
68
  }
70
69
 
71
70
  // Main language for the resource: in the first f041 $a or f041 $d
71
+ // Should we get all $a or $d languages instead of just the first?
72
72
  // Uses only f041s that have 2nd ind ' ', which means that the codes used are MARC 21 language codes
73
73
 
74
74
  function get041Values() {
@@ -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 &&
@@ -26,27 +26,45 @@
26
26
  *
27
27
  */
28
28
 
29
- import createDebugLogger from 'debug';
29
+
30
30
  import {LevenshteinDistance as leven} from 'natural';
31
31
  import {testStringOrNumber} from '../../../matching-utils';
32
+ import createDebugLogger from 'debug';
33
+
34
+ const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features:title');
35
+ const debugData = debug.extend('data');
36
+
32
37
 
33
38
  export default ({treshold = 10} = {}) => ({
34
39
  name: 'Title',
35
- extract: ({record}) => {
40
+ extract: ({record, recordExternal}) => {
41
+ const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';
36
42
  const title = getTitle();
43
+ debug(`${label} title: ${title}`);
37
44
 
38
45
  if (testStringOrNumber(title)) {
39
- return [String(title).replace(/[^\p{Letter}\p{Number}]/gu, '').toLowerCase()];
46
+ const titleAsNormalizedString = String(title)
47
+ // decompose unicode diacritics
48
+ .normalize('NFD')
49
+ // strip non-letters/numbers
50
+ // - note: combined with decomposing unicode diactics this normalizes both 'saa' and 'sää' as 'saa'
51
+ // - we could precompose the finnish letters back to avoid this
52
+ .replace(/[^\p{Letter}\p{Number}]/gu, '')
53
+ .toLowerCase();
54
+ debug(`${label} titleString: ${titleAsNormalizedString}`);
55
+ return [titleAsNormalizedString];
40
56
  }
41
57
 
42
58
  return [];
43
59
 
44
60
  function getTitle() {
45
61
  const [field] = record.get(/^245$/u);
62
+ debugData(`${label} titleField: ${JSON.stringify(field)}`);
46
63
 
47
64
  if (field) {
48
65
  return field.subfields
49
- .filter(({code}) => ['a', 'b'].includes(code))
66
+ // get also $n:s and $p:s here
67
+ .filter(({code}) => ['a', 'b', 'n', 'p'].includes(code))
50
68
  .map(({value}) => testStringOrNumber(value) ? String(value) : '')
51
69
  .join('');
52
70
  }
@@ -1,4 +1,3 @@
1
- /* eslint-disable no-console */
2
1
  /**
3
2
  *
4
3
  * @licstart The following is the entire license notice for the JavaScript code in this file.
@@ -32,7 +31,7 @@ import * as features from './features';
32
31
 
33
32
  export {features};
34
33
 
35
- export default ({strategy, treshold = 0.9}, returnStrategy = false) => ({recordA, recordB, recordAExternal = {}, recordBExternal = {}}) => {
34
+ export default ({strategy, treshold = 0.9}, returnStrategy = false, localSettings = {}) => ({recordA, recordB, recordAExternal = {}, recordBExternal = {}}) => {
36
35
  const minProbabilityQuantifier = 0.5;
37
36
 
38
37
  const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection');
@@ -41,8 +40,9 @@ export default ({strategy, treshold = 0.9}, returnStrategy = false) => ({recordA
41
40
  debugData(`Strategy: ${JSON.stringify(strategy)}, Treshold: ${JSON.stringify(treshold)}, ReturnStrategy: ${JSON.stringify(returnStrategy)}`);
42
41
  debugData(`Records: A: ${recordA}\nB: ${recordB}`);
43
42
  debug(`Externals: A: ${JSON.stringify(recordAExternal)}, B: ${JSON.stringify(recordBExternal)}`);
43
+ // We could add here labels for records if we didn't get external labels
44
44
 
45
- const featuresA = extractFeatures({record: recordA, recordExternal: recordAExternal});
45
+ const featuresA = extractFeatures({record: recordA, recordExternal: recordAExternal, localSettings});
46
46
 
47
47
  debug(`We got an array of records: ${Array.isArray(recordB)}`);
48
48
  const recordsB = Array.isArray(recordB) ? recordB : [recordB];
@@ -54,13 +54,13 @@ export default ({strategy, treshold = 0.9}, returnStrategy = false) => ({recordA
54
54
  // if we got a singular record, we return a singular result
55
55
  return Array.isArray(recordB) ? detectionResults : detectionResults[0];
56
56
 
57
- function actualDetection({featuresA, record, recordExternal, index}) {
57
+ function actualDetection({featuresA, record, recordExternal, index, localSettings}) {
58
58
  const labelA = recordAExternal && recordAExternal.label ? recordAExternal.label : 'a';
59
59
  const labelB = recordExternal && recordExternal.label ? recordExternal.label : 'b';
60
60
 
61
61
 
62
62
  debug(`Actual detection for record ${index + 1} ${labelB}`);
63
- const featuresB = extractFeatures({record, recordExternal});
63
+ const featuresB = extractFeatures({record, recordExternal, localSettings});
64
64
 
65
65
  debugData(`Features (a: ${labelA}): ${JSON.stringify(featuresA)}`);
66
66
  debugData(`Features (b: ${labelB}): ${JSON.stringify(featuresB)}`);
@@ -69,7 +69,7 @@ export default ({strategy, treshold = 0.9}, returnStrategy = false) => ({recordA
69
69
  const similarityVector = generateSimilarityVector(featurePairs);
70
70
 
71
71
  if (similarityVector.some(v => v >= minProbabilityQuantifier)) {
72
- const probability = calculateprobability(similarityVector);
72
+ const probability = calculateProbability(similarityVector);
73
73
  debug(`probability: ${probability} (Treshold: ${treshold})`);
74
74
  return returnResult({match: probability >= treshold, probability});
75
75
  }
@@ -97,7 +97,7 @@ export default ({strategy, treshold = 0.9}, returnStrategy = false) => ({recordA
97
97
  return strategyNames || [];
98
98
  }
99
99
 
100
- function calculateprobability(similarityVector) {
100
+ function calculateProbability(similarityVector) {
101
101
  const probability = similarityVector.reduce((acc, v) => acc + v, 0.0);
102
102
  return probability > 1.0 ? 1.0 : probability;
103
103
  }
@@ -31,7 +31,6 @@ import createDebugLogger from 'debug';
31
31
  const debug = createDebugLogger('@natlibfi/melinda-record-matching:utils');
32
32
  const debugData = debug.extend('data');
33
33
 
34
- // eslint-disable-next-line max-statements
35
34
  export function getMelindaIdsF035(record) {
36
35
 
37
36
  const debug = createDebugLogger('@natlibfi/melinda-record-matching:melinda-id');