@natlibfi/melinda-record-matching 1.0.9 → 2.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 (60) hide show
  1. package/dist/candidate-search/candidate-search-utils.js +58 -0
  2. package/dist/candidate-search/candidate-search-utils.js.map +1 -0
  3. package/dist/candidate-search/index.js +16 -5
  4. package/dist/candidate-search/index.js.map +1 -1
  5. package/dist/candidate-search/index.spec.js +94 -86
  6. package/dist/candidate-search/index.spec.js.map +1 -1
  7. package/dist/candidate-search/query-list/bib.js +113 -23
  8. package/dist/candidate-search/query-list/bib.js.map +1 -1
  9. package/dist/candidate-search/query-list/bib.spec.js +25 -23
  10. package/dist/candidate-search/query-list/bib.spec.js.map +1 -1
  11. package/dist/candidate-search/query-list/index.js +6 -4
  12. package/dist/candidate-search/query-list/index.js.map +1 -1
  13. package/dist/index.js +3 -3
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.spec.js +53 -46
  16. package/dist/index.spec.js.map +1 -1
  17. package/dist/match-detection/features/bib/all-source-ids.js +122 -0
  18. package/dist/match-detection/features/bib/all-source-ids.js.map +1 -0
  19. package/dist/match-detection/features/bib/authors.js.map +1 -1
  20. package/dist/match-detection/features/bib/bibliographic-level.js.map +1 -1
  21. package/dist/match-detection/features/bib/host-component.js.map +1 -1
  22. package/dist/match-detection/features/bib/index.js +32 -16
  23. package/dist/match-detection/features/bib/index.js.map +1 -1
  24. package/dist/match-detection/features/bib/index.spec.js +50 -42
  25. package/dist/match-detection/features/bib/index.spec.js.map +1 -1
  26. package/dist/match-detection/features/bib/isbn.js.map +1 -1
  27. package/dist/match-detection/features/bib/issn.js.map +1 -1
  28. package/dist/match-detection/features/bib/language.js.map +1 -1
  29. package/dist/match-detection/features/bib/melinda-id.js +52 -0
  30. package/dist/match-detection/features/bib/melinda-id.js.map +1 -0
  31. package/dist/match-detection/features/bib/melinda-identifier-factory.js +100 -0
  32. package/dist/match-detection/features/bib/melinda-identifier-factory.js.map +1 -0
  33. package/dist/match-detection/features/bib/other-standard-identifier.js.map +1 -1
  34. package/dist/match-detection/features/bib/publication-time.js.map +1 -1
  35. package/dist/match-detection/features/bib/record-type.js.map +1 -1
  36. package/dist/match-detection/features/bib/standard-identifier-factory.js.map +1 -1
  37. package/dist/match-detection/features/bib/title.js.map +1 -1
  38. package/dist/match-detection/features/index.js +2 -2
  39. package/dist/match-detection/index.js +10 -6
  40. package/dist/match-detection/index.js.map +1 -1
  41. package/dist/match-detection/index.spec.js +32 -25
  42. package/dist/match-detection/index.spec.js.map +1 -1
  43. package/dist/matching-utils.js +95 -0
  44. package/dist/matching-utils.js.map +1 -0
  45. package/package.json +26 -29
  46. package/src/candidate-search/candidate-search-utils.js +53 -0
  47. package/src/candidate-search/index.js +11 -1
  48. package/src/candidate-search/index.spec.js +64 -58
  49. package/src/candidate-search/query-list/bib.js +130 -20
  50. package/src/candidate-search/query-list/bib.spec.js +16 -14
  51. package/src/candidate-search/query-list/index.js +3 -1
  52. package/src/index.spec.js +46 -39
  53. package/src/match-detection/features/bib/all-source-ids.js +122 -0
  54. package/src/match-detection/features/bib/index.js +2 -0
  55. package/src/match-detection/features/bib/index.spec.js +32 -23
  56. package/src/match-detection/features/bib/melinda-id.js +34 -0
  57. package/src/match-detection/features/bib/melinda-identifier-factory.js +94 -0
  58. package/src/match-detection/index.js +7 -4
  59. package/src/match-detection/index.spec.js +27 -20
  60. package/src/matching-utils.js +86 -0
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-console */
1
2
  /**
2
3
  *
3
4
  * @licstart The following is the entire license notice for the JavaScript code in this file.
@@ -31,15 +32,17 @@ import * as features from './features';
31
32
 
32
33
  export {features};
33
34
 
35
+ // eslint-disable-next-line max-statements
34
36
  export default ({strategy, treshold = 0.9}) => (recordA, recordB) => {
35
37
  const minProbabilityQuantifier = 0.5;
36
38
 
37
39
  const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection');
40
+ const debugData = debug.extend('data');
38
41
  const featuresA = extractFeatures(recordA);
39
42
  const featuresB = extractFeatures(recordB);
40
43
 
41
- debug(`Features (a): ${JSON.stringify(featuresA)}`);
42
- debug(`Features (b): ${JSON.stringify(featuresB)}`);
44
+ debugData(`Features (a): ${JSON.stringify(featuresA)}`);
45
+ debugData(`Features (b): ${JSON.stringify(featuresB)}`);
43
46
 
44
47
  const featurePairs = generateFeaturePairs();
45
48
  const similarityVector = generateSimilarityVector();
@@ -50,7 +53,7 @@ export default ({strategy, treshold = 0.9}) => (recordA, recordB) => {
50
53
  return {match: probability >= treshold, probability};
51
54
  }
52
55
 
53
- debug(`No feature yielded minimum probability amount of points (${minProbabilityQuantifier})`);
56
+ debugData(`No feature yielded minimum probability amount of points (${minProbabilityQuantifier})`);
54
57
  return {match: false, probability: 0.0};
55
58
 
56
59
  function calculateprobability() {
@@ -69,7 +72,7 @@ export default ({strategy, treshold = 0.9}) => (recordA, recordB) => {
69
72
  return {name, points};
70
73
  });
71
74
 
72
- debug(`Points: ${JSON.stringify(compared)}`);
75
+ debugData(`Points: ${JSON.stringify(compared)}`);
73
76
  return compared.map(({points}) => points);
74
77
  }
75
78
 
@@ -33,28 +33,35 @@ import {MarcRecord} from '@natlibfi/marc-record';
33
33
  import * as features from './features';
34
34
  import createDetectionInterface from '.';
35
35
 
36
- generateTests({
37
- path: [__dirname, '..', '..', 'test-fixtures', 'match-detection', 'index'],
38
- useMetadataFile: true,
39
- recurse: false,
40
- fixura: {
41
- reader: READERS.JSON
42
- },
43
- callback: ({getFixture, options, expectedResults}) => {
44
- const detect = createDetectionInterface(formatOptions());
45
- const recordA = new MarcRecord(getFixture('recordA.json'));
46
- const recordB = new MarcRecord(getFixture('recordB.json'));
47
- const results = detect(recordA, recordB);
36
+ describe('match-detection', () => {
37
+ generateTests({
38
+ path: [__dirname, '..', '..', 'test-fixtures', 'match-detection', 'index'],
39
+ useMetadataFile: true,
40
+ recurse: false,
41
+ fixura: {
42
+ reader: READERS.JSON
43
+ },
44
+ callback: ({getFixture, options, expectedResults, enabled = true}) => {
48
45
 
49
- expect(results).to.eql(expectedResults);
46
+ if (!enabled) {
47
+ return;
48
+ }
50
49
 
51
- function formatOptions() {
52
- const contextFeatures = features[options.strategy.type];
50
+ const detect = createDetectionInterface(formatOptions());
51
+ const recordA = new MarcRecord(getFixture('recordA.json'));
52
+ const recordB = new MarcRecord(getFixture('recordB.json'));
53
+ const results = detect(recordA, recordB);
53
54
 
54
- return {
55
- ...options,
56
- strategy: options.strategy.features.map(v => contextFeatures[v]())
57
- };
55
+ expect(results).to.eql(expectedResults);
56
+
57
+ function formatOptions() {
58
+ const contextFeatures = features[options.strategy.type];
59
+
60
+ return {
61
+ ...options,
62
+ strategy: options.strategy.features.map(v => contextFeatures[v]())
63
+ };
64
+ }
58
65
  }
59
- }
66
+ });
60
67
  });
@@ -0,0 +1,86 @@
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 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 createDebugLogger from 'debug';
30
+
31
+ const debug = createDebugLogger('@natlibfi/melinda-record-matching:utils');
32
+ const debugData = debug.extend('data');
33
+
34
+ // eslint-disable-next-line max-statements
35
+ export function getMelindaIdsF035(record) {
36
+
37
+ const debug = createDebugLogger('@natlibfi/melinda-record-matching:melinda-id');
38
+ const debugData = debug.extend('data');
39
+
40
+ const f035s = record.getFields('035');
41
+
42
+ if (f035s.length < 1) {
43
+ debug(`No f035s found.`);
44
+ return [];
45
+ }
46
+
47
+ const allF035MelindaIds = [].concat(...f035s.map(toMelindaIds));
48
+ const f035MelindaIds = [...new Set(allF035MelindaIds)];
49
+
50
+ debugData(`Fields (${f035s.length}): ${JSON.stringify(f035s)}`);
51
+ debugData(`Ids (${allF035MelindaIds.length}): ${JSON.stringify(allF035MelindaIds)}`);
52
+ debugData(`Unique ids (${f035MelindaIds.length}): ${JSON.stringify(f035MelindaIds)}`);
53
+
54
+ return f035MelindaIds;
55
+
56
+ function toMelindaIds({subfields}) {
57
+ const melindaIdRegExp = /^(?<prefix>\(FI-MELINDA\)|FCC)(?<id>\d{9})$/u;
58
+
59
+ return subfields
60
+ .filter(sub => ['a', 'z'].includes(sub.code))
61
+ .filter(sub => melindaIdRegExp.test(sub.value))
62
+ .map(({value}) => value.replace(melindaIdRegExp, '$<id>'));
63
+
64
+ }
65
+ }
66
+
67
+ export function validateSidFieldSubfieldCounts(field) {
68
+ // Valid SID-fields have just one $c and one $b
69
+ debugData(`Validating SID field ${JSON.stringify(field)}`);
70
+ const countC = countSubfields(field, 'c');
71
+ const countB = countSubfields(field, 'b');
72
+ debug(`Found ${countC} sf $cs and ${countB} sf $bs. IsValid: ${countC === 1 && countB === 1}`);
73
+
74
+ return countC === 1 && countB === 1;
75
+ }
76
+
77
+ function countSubfields(field, subfieldCode) {
78
+ // debug(`Counting subfields ${subfieldCode}`);
79
+ return field.subfields.filter(({code}) => code === subfieldCode).length;
80
+ }
81
+
82
+ export function getSubfieldValues(field, subfieldCode) {
83
+ debugData(`Get subfield(s) $${subfieldCode} from ${JSON.stringify(field)}`);
84
+ return field.subfields.filter(({code}) => code === subfieldCode).map(({value}) => value);
85
+ }
86
+