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

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 +58 -0
  2. package/dist/candidate-search/candidate-search-utils.js.map +1 -0
  3. package/dist/candidate-search/index.js +273 -0
  4. package/dist/candidate-search/index.js.map +1 -0
  5. package/dist/candidate-search/index.spec.js +161 -0
  6. package/dist/candidate-search/index.spec.js.map +1 -0
  7. package/dist/candidate-search/query-list/bib.js +252 -0
  8. package/dist/candidate-search/query-list/bib.js.map +1 -0
  9. package/dist/candidate-search/query-list/bib.spec.js +72 -0
  10. package/dist/candidate-search/query-list/bib.spec.js.map +1 -0
  11. package/dist/candidate-search/query-list/index.js +67 -0
  12. package/dist/candidate-search/query-list/index.js.map +1 -0
  13. package/dist/index.js +578 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/index.spec.js +133 -0
  16. package/dist/index.spec.js.map +1 -0
  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 +120 -0
  20. package/dist/match-detection/features/bib/authors.js.map +1 -0
  21. package/dist/match-detection/features/bib/bibliographic-level.js +42 -0
  22. package/dist/match-detection/features/bib/bibliographic-level.js.map +1 -0
  23. package/dist/match-detection/features/bib/host-component.js +42 -0
  24. package/dist/match-detection/features/bib/host-component.js.map +1 -0
  25. package/dist/match-detection/features/bib/index.js +104 -0
  26. package/dist/match-detection/features/bib/index.js.map +1 -0
  27. package/dist/match-detection/features/bib/index.spec.js +97 -0
  28. package/dist/match-detection/features/bib/index.spec.js.map +1 -0
  29. package/dist/match-detection/features/bib/isbn.js +55 -0
  30. package/dist/match-detection/features/bib/isbn.js.map +1 -0
  31. package/dist/match-detection/features/bib/issn.js +55 -0
  32. package/dist/match-detection/features/bib/issn.js.map +1 -0
  33. package/dist/match-detection/features/bib/language.js +113 -0
  34. package/dist/match-detection/features/bib/language.js.map +1 -0
  35. package/dist/match-detection/features/bib/melinda-id.js +52 -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 +100 -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 +55 -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 +51 -0
  42. package/dist/match-detection/features/bib/publication-time.js.map +1 -0
  43. package/dist/match-detection/features/bib/record-type.js +43 -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 +127 -0
  46. package/dist/match-detection/features/bib/standard-identifier-factory.js.map +1 -0
  47. package/dist/match-detection/features/bib/title.js +95 -0
  48. package/dist/match-detection/features/bib/title.js.map +1 -0
  49. package/dist/match-detection/features/index.js +15 -0
  50. package/dist/match-detection/features/index.js.map +1 -0
  51. package/dist/match-detection/index.js +184 -0
  52. package/dist/match-detection/index.js.map +1 -0
  53. package/dist/match-detection/index.spec.js +99 -0
  54. package/dist/match-detection/index.spec.js.map +1 -0
  55. package/dist/matching-utils.js +104 -0
  56. package/dist/matching-utils.js.map +1 -0
  57. package/package.json +2 -1
  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
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _standardIdentifierFactory = _interopRequireDefault(require("./standard-identifier-factory"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ /**
13
+ *
14
+ * @licstart The following is the entire license notice for the JavaScript code in this file.
15
+ *
16
+ * Melinda record matching modules for Javascript
17
+ *
18
+ * Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
19
+ *
20
+ * This file is part of melinda-record-matching-js
21
+ *
22
+ * melinda-record-matching-js program is free software: you can redistribute it and/or modify
23
+ * it under the terms of the GNU Lesser General Public License as
24
+ * published by the Free Software Foundation, either version 3 of the
25
+ * License, or (at your option) any later version.
26
+ *
27
+ * melinda-record-matching-js is distributed in the hope that it will be useful,
28
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
29
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30
+ * GNU Lesser General Public License for more details.
31
+ *
32
+ * You should have received a copy of the GNU Affero General Public License
33
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
34
+ *
35
+ * @licend The above is the entire license notice
36
+ * for the JavaScript code in this file.
37
+ *
38
+ */
39
+ var _default = () => {
40
+ const {
41
+ extract,
42
+ compare
43
+ } = (0, _standardIdentifierFactory.default)({
44
+ pattern: /^024$/u,
45
+ subfieldCodes: ['a', 'z']
46
+ });
47
+ return {
48
+ extract,
49
+ compare,
50
+ name: 'Other standard identifier'
51
+ };
52
+ };
53
+
54
+ exports.default = _default;
55
+ //# sourceMappingURL=other-standard-identifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"other-standard-identifier.js","names":["extract","compare","createInterface","pattern","subfieldCodes","name"],"sources":["../../../../src/match-detection/features/bib/other-standard-identifier.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 createInterface from './standard-identifier-factory';\n\nexport default () => {\n const {extract, compare} = createInterface({pattern: /^024$/u, subfieldCodes: ['a', 'z']});\n return {extract, compare, name: 'Other standard identifier'};\n};\n"],"mappings":";;;;;;;AA4BA;;;;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;eAIe,MAAM;EACnB,MAAM;IAACA,OAAD;IAAUC;EAAV,IAAqB,IAAAC,kCAAA,EAAgB;IAACC,OAAO,EAAE,QAAV;IAAoBC,aAAa,EAAE,CAAC,GAAD,EAAM,GAAN;EAAnC,CAAhB,CAA3B;EACA,OAAO;IAACJ,OAAD;IAAUC,OAAV;IAAmBI,IAAI,EAAE;EAAzB,CAAP;AACD,C"}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _matchingUtils = require("../../../matching-utils");
9
+
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-2022 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
+ // We should also get copyright time and copyright/publication times from 26x
38
+ // We could also enable matching of records which have consequent publication years
39
+ var _default = () => ({
40
+ name: 'Publication time',
41
+ extract: record => {
42
+ var _record$get, _record$get$;
43
+
44
+ const value = ((_record$get = record.get(/^008$/u)) === null || _record$get === void 0 ? void 0 : (_record$get$ = _record$get[0]) === null || _record$get$ === void 0 ? void 0 : _record$get$.value) || undefined;
45
+ return (0, _matchingUtils.testStringOrNumber)(value) ? [String(value).slice(7, 11)] : [];
46
+ },
47
+ compare: (a, b) => a[0] === b[0] ? 0.1 : -1.0
48
+ });
49
+
50
+ exports.default = _default;
51
+ //# sourceMappingURL=publication-time.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publication-time.js","names":["name","extract","record","value","get","undefined","testStringOrNumber","String","slice","compare","a","b"],"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// We could also enable matching of records which have consequent publication years\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;;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;eAEe,OAAO;EACpBA,IAAI,EAAE,kBADc;EAEpBC,OAAO,EAAEC,MAAM,IAAI;IAAA;;IACjB,MAAMC,KAAK,GAAG,gBAAAD,MAAM,CAACE,GAAP,CAAW,QAAX,6EAAuB,CAAvB,+DAA2BD,KAA3B,KAAoCE,SAAlD;IACA,OAAO,IAAAC,iCAAA,EAAmBH,KAAnB,IAA4B,CAACI,MAAM,CAACJ,KAAD,CAAN,CAAcK,KAAd,CAAoB,CAApB,EAAuB,EAAvB,CAAD,CAA5B,GAA2D,EAAlE;EACD,CALmB;EAMpBC,OAAO,EAAE,CAACC,CAAD,EAAIC,CAAJ,KAAUD,CAAC,CAAC,CAAD,CAAD,KAASC,CAAC,CAAC,CAAD,CAAV,GAAgB,GAAhB,GAAsB,CAAC;AANtB,CAAP,C"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
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 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 could handle the case of books/notes
36
+ var _default = () => ({
37
+ name: 'Record type',
38
+ extract: r => r.leader[6] ? [r.leader[6]] : [],
39
+ compare: (a, b) => a[0] === b[0] ? 0.1 : -0.5
40
+ });
41
+
42
+ exports.default = _default;
43
+ //# sourceMappingURL=record-type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"record-type.js","names":["name","extract","r","leader","compare","a","b"],"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\nexport default () => ({\n name: 'Record type',\n extract: r => r.leader[6] ? [r.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;eAEe,OAAO;EACpBA,IAAI,EAAE,aADc;EAEpBC,OAAO,EAAEC,CAAC,IAAIA,CAAC,CAACC,MAAF,CAAS,CAAT,IAAc,CAACD,CAAC,CAACC,MAAF,CAAS,CAAT,CAAD,CAAd,GAA8B,EAFxB;EAGpBC,OAAO,EAAE,CAACC,CAAD,EAAIC,CAAJ,KAAUD,CAAC,CAAC,CAAD,CAAD,KAASC,CAAC,CAAC,CAAD,CAAV,GAAgB,GAAhB,GAAsB,CAAC;AAHtB,CAAP,C"}
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _debug = _interopRequireDefault(require("debug"));
9
+
10
+ var _matchingUtils = require("../../../matching-utils");
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ /**
15
+ *
16
+ * @licstart The following is the entire license notice for the JavaScript code in this file.
17
+ *
18
+ * Melinda record matching modules for Javascript
19
+ *
20
+ * Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
21
+ *
22
+ * This file is part of melinda-record-matching-js
23
+ *
24
+ * melinda-record-matching-js program is free software: you can redistribute it and/or modify
25
+ * it under the terms of the GNU Lesser General Public License as
26
+ * published by the Free Software Foundation, either version 3 of the
27
+ * License, or (at your option) any later version.
28
+ *
29
+ * melinda-record-matching-js is distributed in the hope that it will be useful,
30
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
31
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32
+ * GNU Lesser General Public License for more details.
33
+ *
34
+ * You should have received a copy of the GNU Affero General Public License
35
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
36
+ *
37
+ * @licend The above is the entire license notice
38
+ * for the JavaScript code in this file.
39
+ *
40
+ */
41
+ const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:match-detection:features:standard-identifiers');
42
+ const debugData = debug.extend('data');
43
+
44
+ var _default = ({
45
+ pattern,
46
+ subfieldCodes
47
+ }) => {
48
+ return {
49
+ extract,
50
+ compare
51
+ };
52
+
53
+ function extract(record) {
54
+ const [field] = record.get(pattern);
55
+
56
+ if (field) {
57
+ return field.subfields.filter(({
58
+ code
59
+ }) => subfieldCodes.includes(code)).map(({
60
+ code,
61
+ value
62
+ }) => ({
63
+ code,
64
+ value: (0, _matchingUtils.testStringOrNumber)(value) ? String(value).replace(/-/ug, '') : ''
65
+ })).filter(value => value);
66
+ }
67
+
68
+ return [];
69
+ }
70
+
71
+ function compare(a, b) {
72
+ if (a.length === 0 || b.length === 0) {
73
+ debugData(`No standardidentifiers to compare`);
74
+ return 0;
75
+ }
76
+
77
+ if (bothHaveValidIdentifiers()) {
78
+ const {
79
+ maxValues,
80
+ matchingValues
81
+ } = getValueCount(true);
82
+ return matchingValues / maxValues * 0.75;
83
+ }
84
+
85
+ const {
86
+ maxValues,
87
+ matchingValues
88
+ } = getValueCount();
89
+ return matchingValues / maxValues * 0.2;
90
+
91
+ function bothHaveValidIdentifiers() {
92
+ const aValues = a.filter(({
93
+ code
94
+ }) => code === 'a');
95
+ const bValues = a.filter(({
96
+ code
97
+ }) => code === 'a');
98
+ return aValues.length > 0 && bValues.length > 0;
99
+ }
100
+
101
+ function getValueCount(validOnly = false) {
102
+ const aValues = getIdentifiers(a);
103
+ const bValues = getIdentifiers(b);
104
+ return {
105
+ maxValues: aValues.length > bValues.length ? aValues.length : bValues.length,
106
+ matchingValues: aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length
107
+ };
108
+
109
+ function getIdentifiers(values) {
110
+ if (validOnly) {
111
+ return values.filter(({
112
+ code
113
+ }) => code === 'a').map(({
114
+ value
115
+ }) => value);
116
+ }
117
+
118
+ return values.map(({
119
+ value
120
+ }) => value);
121
+ }
122
+ }
123
+ }
124
+ };
125
+
126
+ exports.default = _default;
127
+ //# sourceMappingURL=standard-identifier-factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standard-identifier-factory.js","names":["debug","createDebugLogger","debugData","extend","pattern","subfieldCodes","extract","compare","record","field","get","subfields","filter","code","includes","map","value","testStringOrNumber","String","replace","a","b","length","bothHaveValidIdentifiers","maxValues","matchingValues","getValueCount","aValues","bValues","validOnly","getIdentifiers","aValue","some","bValue","values"],"sources":["../../../../src/match-detection/features/bib/standard-identifier-factory.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 createDebugLogger from 'debug';\nimport {testStringOrNumber} from '../../../matching-utils';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features:standard-identifiers');\nconst debugData = debug.extend('data');\n\nexport default ({pattern, subfieldCodes}) => {\n return {extract, compare};\n\n function extract(record) {\n const [field] = record.get(pattern);\n\n if (field) {\n return field.subfields\n .filter(({code}) => subfieldCodes.includes(code))\n .map(({code, value}) => ({code, value: testStringOrNumber(value) ? String(value).replace(/-/ug, '') : ''}))\n .filter(value => value);\n }\n\n return [];\n }\n\n function compare(a, b) {\n if (a.length === 0 || b.length === 0) {\n debugData(`No standardidentifiers to compare`);\n return 0;\n }\n\n if (bothHaveValidIdentifiers()) {\n const {maxValues, matchingValues} = getValueCount(true);\n return matchingValues / maxValues * 0.75;\n }\n\n const {maxValues, matchingValues} = getValueCount();\n return matchingValues / maxValues * 0.2;\n\n function bothHaveValidIdentifiers() {\n const aValues = a.filter(({code}) => code === 'a');\n const bValues = a.filter(({code}) => code === 'a');\n return aValues.length > 0 && bValues.length > 0;\n }\n\n function getValueCount(validOnly = false) {\n const aValues = getIdentifiers(a);\n const bValues = getIdentifiers(b);\n\n return {\n maxValues: aValues.length > bValues.length ? aValues.length : bValues.length,\n matchingValues: aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length\n };\n\n function getIdentifiers(values) {\n if (validOnly) {\n return values\n .filter(({code}) => code === 'a')\n .map(({value}) => value);\n }\n\n return values.map(({value}) => value);\n }\n }\n }\n};\n"],"mappings":";;;;;;;AA4BA;;AACA;;;;AA7BA;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;AAKA,MAAMA,KAAK,GAAG,IAAAC,cAAA,EAAkB,iFAAlB,CAAd;AACA,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAN,CAAa,MAAb,CAAlB;;eAEe,CAAC;EAACC,OAAD;EAAUC;AA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MAAMe,OAAO,GAAGR,CAAC,CAACR,MAAF,CAAS,CAAC;QAACC;MAAD,CAAD,KAAYA,IAAI,KAAK,GAA9B,CAAhB;MACA,OAAOc,OAAO,CAACL,MAAR,GAAiB,CAAjB,IAAsBM,OAAO,CAACN,MAAR,GAAiB,CAA9C;IACD;;IAED,SAASI,aAAT,CAAuBG,SAAS,GAAG,KAAnC,EAA0C;MACxC,MAAMF,OAAO,GAAGG,cAAc,CAACV,CAAD,CAA9B;MACA,MAAMQ,OAAO,GAAGE,cAAc,CAACT,CAAD,CAA9B;MAEA,OAAO;QACLG,SAAS,EAAEG,OAAO,CAACL,MAAR,GAAiBM,OAAO,CAACN,MAAzB,GAAkCK,OAAO,CAACL,MAA1C,GAAmDM,OAAO,CAACN,MADjE;QAELG,cAAc,EAAEE,OAAO,CAACf,MAAR,CAAemB,MAAM,IAAIH,OAAO,CAACI,IAAR,CAAaC,MAAM,IAAIF,MAAM,KAAKE,MAAlC,CAAzB,EAAoEX;MAF/E,CAAP;;MAKA,SAASQ,cAAT,CAAwBI,MAAxB,EAAgC;QAC9B,IAAIL,SAAJ,EAAe;UACb,OAAOK,MAAM,CACVtB,MADI,CACG,CAAC;YAACC;UAAD,CAAD,KAAYA,IAAI,KAAK,GADxB,EAEJE,GAFI,CAEA,CAAC;YAACC;UAAD,CAAD,KAAaA,KAFb,CAAP;QAGD;;QAED,OAAOkB,MAAM,CAACnB,GAAP,CAAW,CAAC;UAACC;QAAD,CAAD,KAAaA,KAAxB,CAAP;MACD;IACF;EACF;AACF,C"}
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _debug = _interopRequireDefault(require("debug"));
9
+
10
+ var _natural = require("natural");
11
+
12
+ var _matchingUtils = require("../../../matching-utils");
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ /**
17
+ *
18
+ * @licstart The following is the entire license notice for the JavaScript code in this file.
19
+ *
20
+ * Melinda record matching modules for Javascript
21
+ *
22
+ * Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
23
+ *
24
+ * This file is part of melinda-record-matching-js
25
+ *
26
+ * melinda-record-matching-js program is free software: you can redistribute it and/or modify
27
+ * it under the terms of the GNU Lesser General Public License as
28
+ * published by the Free Software Foundation, either version 3 of the
29
+ * License, or (at your option) any later version.
30
+ *
31
+ * melinda-record-matching-js is distributed in the hope that it will be useful,
32
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
33
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34
+ * GNU Lesser General Public License for more details.
35
+ *
36
+ * You should have received a copy of the GNU Affero General Public License
37
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
38
+ *
39
+ * @licend The above is the entire license notice
40
+ * for the JavaScript code in this file.
41
+ *
42
+ */
43
+ var _default = ({
44
+ treshold = 10
45
+ } = {}) => ({
46
+ name: 'Title',
47
+ extract: record => {
48
+ const title = getTitle();
49
+
50
+ if ((0, _matchingUtils.testStringOrNumber)(title)) {
51
+ return [String(title).replace(/[^\p{Letter}\p{Number}]/gu, '').toLowerCase()];
52
+ }
53
+
54
+ return [];
55
+
56
+ function getTitle() {
57
+ const [field] = record.get(/^245$/u);
58
+
59
+ if (field) {
60
+ return field.subfields.filter(({
61
+ code
62
+ }) => ['a', 'b'].includes(code)).map(({
63
+ value
64
+ }) => (0, _matchingUtils.testStringOrNumber)(value) ? String(value) : '').join('');
65
+ }
66
+
67
+ return false;
68
+ }
69
+ },
70
+ compare: (a, b) => {
71
+ const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:match-detection:features/bib/title');
72
+ const distance = (0, _natural.LevenshteinDistance)(a[0], b[0]);
73
+
74
+ if (distance === 0) {
75
+ return 0.5;
76
+ }
77
+
78
+ const maxLength = getMaxLength();
79
+ const percentage = distance / maxLength * 100;
80
+ debug(`'${a}' vs '${b}': Max length = ${maxLength}, distance = ${distance}, percentage = ${percentage}`);
81
+
82
+ if (percentage <= treshold) {
83
+ return 0.3;
84
+ }
85
+
86
+ return -0.5;
87
+
88
+ function getMaxLength() {
89
+ return a[0].length > b[0].length ? a[0].length : b[0].length;
90
+ }
91
+ }
92
+ });
93
+
94
+ exports.default = _default;
95
+ //# sourceMappingURL=title.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"title.js","names":["treshold","name","extract","record","title","getTitle","testStringOrNumber","String","replace","toLowerCase","field","get","subfields","filter","code","includes","map","value","join","compare","a","b","debug","createDebugLogger","distance","leven","maxLength","getMaxLength","percentage","length"],"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\nimport createDebugLogger from 'debug';\nimport {LevenshteinDistance as leven} from 'natural';\nimport {testStringOrNumber} from '../../../matching-utils';\n\nexport default ({treshold = 10} = {}) => ({\n name: 'Title',\n extract: record => {\n const title = getTitle();\n\n if (testStringOrNumber(title)) {\n return [String(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}) => 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":";;;;;;;AA4BA;;AACA;;AACA;;;;AA9BA;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;eAMe,CAAC;EAACA,QAAQ,GAAG;AAAZ,IAAkB,EAAnB,MAA2B;EACxCC,IAAI,EAAE,OADkC;EAExCC,OAAO,EAAEC,MAAM,IAAI;IACjB,MAAMC,KAAK,GAAGC,QAAQ,EAAtB;;IAEA,IAAI,IAAAC,iCAAA,EAAmBF,KAAnB,CAAJ,EAA+B;MAC7B,OAAO,CAACG,MAAM,CAACH,KAAD,CAAN,CAAcI,OAAd,CAAsB,2BAAtB,EAAmD,EAAnD,EAAuDC,WAAvD,EAAD,CAAP;IACD;;IAED,OAAO,EAAP;;IAEA,SAASJ,QAAT,GAAoB;MAClB,MAAM,CAACK,KAAD,IAAUP,MAAM,CAACQ,GAAP,CAAW,QAAX,CAAhB;;MAEA,IAAID,KAAJ,EAAW;QACT,OAAOA,KAAK,CAACE,SAAN,CACJC,MADI,CACG,CAAC;UAACC;QAAD,CAAD,KAAY,CAAC,GAAD,EAAM,GAAN,EAAWC,QAAX,CAAoBD,IAApB,CADf,EAEJE,GAFI,CAEA,CAAC;UAACC;QAAD,CAAD,KAAa,IAAAX,iCAAA,EAAmBW,KAAnB,IAA4BV,MAAM,CAACU,KAAD,CAAlC,GAA4C,EAFzD,EAGJC,IAHI,CAGC,EAHD,CAAP;MAID;;MACD,OAAO,KAAP;IACD;EACF,CAtBuC;EAuBxCC,OAAO,EAAE,CAACC,CAAD,EAAIC,CAAJ,KAAU;IACjB,MAAMC,KAAK,GAAG,IAAAC,cAAA,EAAkB,sEAAlB,CAAd;IACA,MAAMC,QAAQ,GAAG,IAAAC,4BAAA,EAAML,CAAC,CAAC,CAAD,CAAP,EAAYC,CAAC,CAAC,CAAD,CAAb,CAAjB;;IAEA,IAAIG,QAAQ,KAAK,CAAjB,EAAoB;MAClB,OAAO,GAAP;IACD;;IAED,MAAME,SAAS,GAAGC,YAAY,EAA9B;IACA,MAAMC,UAAU,GAAGJ,QAAQ,GAAGE,SAAX,GAAuB,GAA1C;IAEAJ,KAAK,CAAE,IAAGF,CAAE,SAAQC,CAAE,mBAAkBK,SAAU,gBAAeF,QAAS,kBAAiBI,UAAW,EAAjG,CAAL;;IAEA,IAAIA,UAAU,IAAI5B,QAAlB,EAA4B;MAC1B,OAAO,GAAP;IACD;;IAED,OAAO,CAAC,GAAR;;IAEA,SAAS2B,YAAT,GAAwB;MACtB,OAAOP,CAAC,CAAC,CAAD,CAAD,CAAKS,MAAL,GAAcR,CAAC,CAAC,CAAD,CAAD,CAAKQ,MAAnB,GAA4BT,CAAC,CAAC,CAAD,CAAD,CAAKS,MAAjC,GAA0CR,CAAC,CAAC,CAAD,CAAD,CAAKQ,MAAtD;IACD;EAEF;AA9CuC,CAA3B,C"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.bib = void 0;
7
+
8
+ var bib = _interopRequireWildcard(require("./bib"));
9
+
10
+ exports.bib = bib;
11
+
12
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
+
14
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"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"}
@@ -0,0 +1,184 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.features = exports.default = void 0;
7
+
8
+ var _debug = _interopRequireDefault(require("debug"));
9
+
10
+ var features = _interopRequireWildcard(require("./features"));
11
+
12
+ exports.features = features;
13
+
14
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
+
16
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
20
+ /* eslint-disable no-console */
21
+
22
+ /**
23
+ *
24
+ * @licstart The following is the entire license notice for the JavaScript code in this file.
25
+ *
26
+ * Melinda record matching modules for Javascript
27
+ *
28
+ * Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
29
+ *
30
+ * This file is part of melinda-record-matching-js
31
+ *
32
+ * melinda-record-matching-js program is free software: you can redistribute it and/or modify
33
+ * it under the terms of the GNU Lesser General Public License as
34
+ * published by the Free Software Foundation, either version 3 of the
35
+ * License, or (at your option) any later version.
36
+ *
37
+ * melinda-record-matching-js is distributed in the hope that it will be useful,
38
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
39
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40
+ * GNU Lesser General Public License for more details.
41
+ *
42
+ * You should have received a copy of the GNU Affero General Public License
43
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
44
+ *
45
+ * @licend The above is the entire license notice
46
+ * for the JavaScript code in this file.
47
+ *
48
+ */
49
+ var _default = ({
50
+ strategy,
51
+ treshold = 0.9
52
+ }, returnStrategy = false) => (recordA, recordB) => {
53
+ const minProbabilityQuantifier = 0.5;
54
+ const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:match-detection');
55
+ const debugData = debug.extend('data');
56
+ debugData(`Strategy: ${JSON.stringify(strategy)}`);
57
+ debugData(`Treshold: ${JSON.stringify(treshold)}`);
58
+ debugData(`ReturnStrategy: ${JSON.stringify(returnStrategy)}`);
59
+ const featuresA = extractFeatures(recordA);
60
+ debug(`We got an array of records: ${Array.isArray(recordB)}`);
61
+ const recordsB = Array.isArray(recordB) ? recordB : [recordB];
62
+ const detectionResults = recordsB.map(record => actualDetection(featuresA, record));
63
+ return Array.isArray(recordB) ? detectionResults : detectionResults[0];
64
+
65
+ function actualDetection(featuresA, record) {
66
+ const featuresB = extractFeatures(record);
67
+ debugData(`Features (a): ${JSON.stringify(featuresA)}`);
68
+ debugData(`Features (b): ${JSON.stringify(featuresB)}`);
69
+ const featurePairs = generateFeaturePairs(featuresA, featuresB);
70
+ const similarityVector = generateSimilarityVector(featurePairs);
71
+
72
+ if (similarityVector.some(v => v >= minProbabilityQuantifier)) {
73
+ const probability = calculateprobability(similarityVector);
74
+ debug(`probability: ${probability} (Treshold: ${treshold})`);
75
+ return returnResult({
76
+ match: probability >= treshold,
77
+ probability
78
+ });
79
+ }
80
+
81
+ debugData(`No feature yielded minimum probability amount of points (${minProbabilityQuantifier})`);
82
+ return returnResult({
83
+ match: false,
84
+ probability: 0.0
85
+ });
86
+ }
87
+
88
+ function extractFeatures(record) {
89
+ return strategy.reduce((acc, {
90
+ name,
91
+ extract
92
+ }) => acc.concat({
93
+ name,
94
+ value: extract(record)
95
+ }), []);
96
+ }
97
+
98
+ function returnResult(result) {
99
+ if (returnStrategy) {
100
+ debug(`Returning detection strategy with the result`);
101
+ const resultWithStrategy = {
102
+ match: result.match,
103
+ probability: result.probability,
104
+ strategy: formatStrategy(strategy),
105
+ treshold
106
+ };
107
+ debugData(`${JSON.stringify(resultWithStrategy)}`);
108
+ return resultWithStrategy;
109
+ }
110
+
111
+ return result;
112
+ }
113
+
114
+ function formatStrategy(strategy) {
115
+ const strategyNames = strategy.map(element => element.name);
116
+ return strategyNames || [];
117
+ }
118
+
119
+ function calculateprobability(similarityVector) {
120
+ const probability = similarityVector.reduce((acc, v) => acc + v, 0.0);
121
+ return probability > 1.0 ? 1.0 : probability;
122
+ }
123
+
124
+ function generateSimilarityVector(featurePairs) {
125
+ const compared = featurePairs.map(({
126
+ name,
127
+ a,
128
+ b
129
+ }) => {
130
+ const {
131
+ compare
132
+ } = strategy.find(({
133
+ name: featureName
134
+ }) => name === featureName);
135
+ const points = compare(a, b);
136
+ return {
137
+ name,
138
+ points
139
+ };
140
+ });
141
+ debugData(`Points: ${JSON.stringify(compared)}`);
142
+ return compared.map(({
143
+ points
144
+ }) => points);
145
+ }
146
+
147
+ function generateFeaturePairs(featuresA, featuresB) {
148
+ const pairs = generatePairs();
149
+ const missingFeatures = findMissing();
150
+ debug(`Not comparing the following features because one, or both records are missing features: ${JSON.stringify(missingFeatures)}`);
151
+ return pairs;
152
+
153
+ function generatePairs() {
154
+ return featuresA.reduce((acc, {
155
+ name,
156
+ value
157
+ }, index) => acc.concat({
158
+ name,
159
+ a: value,
160
+ b: featuresB[index].value
161
+ }), []).filter(({
162
+ a,
163
+ b
164
+ }) => {
165
+ if (a.length === 0 || b.length === 0) {
166
+ return false;
167
+ }
168
+
169
+ return true;
170
+ });
171
+ }
172
+
173
+ function findMissing() {
174
+ return featuresA.map(({
175
+ name
176
+ }) => name).filter(v => pairs.some(({
177
+ name
178
+ }) => name === v) === false);
179
+ }
180
+ }
181
+ };
182
+
183
+ exports.default = _default;
184
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["strategy","treshold","returnStrategy","recordA","recordB","minProbabilityQuantifier","debug","createDebugLogger","debugData","extend","JSON","stringify","featuresA","extractFeatures","Array","isArray","recordsB","detectionResults","map","record","actualDetection","featuresB","featurePairs","generateFeaturePairs","similarityVector","generateSimilarityVector","some","v","probability","calculateprobability","returnResult","match","reduce","acc","name","extract","concat","value","result","resultWithStrategy","formatStrategy","strategyNames","element","compared","a","b","compare","find","featureName","points","pairs","generatePairs","missingFeatures","findMissing","index","filter","length"],"sources":["../../src/match-detection/index.js"],"sourcesContent":["/* eslint-disable no-console */\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 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 * as features from './features';\n\nexport {features};\n\nexport default ({strategy, treshold = 0.9}, returnStrategy = false) => (recordA, recordB) => {\n const minProbabilityQuantifier = 0.5;\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection');\n const debugData = debug.extend('data');\n\n debugData(`Strategy: ${JSON.stringify(strategy)}`);\n debugData(`Treshold: ${JSON.stringify(treshold)}`);\n debugData(`ReturnStrategy: ${JSON.stringify(returnStrategy)}`);\n\n const featuresA = extractFeatures(recordA);\n\n debug(`We got an array of records: ${Array.isArray(recordB)}`);\n const recordsB = Array.isArray(recordB) ? recordB : [recordB];\n const detectionResults = recordsB.map(record => actualDetection(featuresA, record));\n\n return Array.isArray(recordB) ? detectionResults : detectionResults[0];\n\n function actualDetection(featuresA, record) {\n\n const featuresB = extractFeatures(record);\n\n debugData(`Features (a): ${JSON.stringify(featuresA)}`);\n debugData(`Features (b): ${JSON.stringify(featuresB)}`);\n\n const featurePairs = generateFeaturePairs(featuresA, featuresB);\n const similarityVector = generateSimilarityVector(featurePairs);\n\n if (similarityVector.some(v => v >= minProbabilityQuantifier)) {\n const probability = calculateprobability(similarityVector);\n debug(`probability: ${probability} (Treshold: ${treshold})`);\n return returnResult({match: probability >= treshold, probability});\n }\n\n debugData(`No feature yielded minimum probability amount of points (${minProbabilityQuantifier})`);\n return returnResult({match: false, probability: 0.0});\n }\n\n function extractFeatures(record) {\n return strategy.reduce((acc, {name, extract}) => acc.concat({name, value: extract(record)}), []);\n }\n\n function returnResult(result) {\n if (returnStrategy) {\n debug(`Returning detection strategy with the result`);\n const resultWithStrategy = {match: result.match, probability: result.probability, strategy: formatStrategy(strategy), treshold};\n debugData(`${JSON.stringify(resultWithStrategy)}`);\n return resultWithStrategy;\n }\n return result;\n }\n\n function formatStrategy(strategy) {\n const strategyNames = strategy.map(element => element.name);\n return strategyNames || [];\n }\n\n function calculateprobability(similarityVector) {\n const probability = similarityVector.reduce((acc, v) => acc + v, 0.0);\n return probability > 1.0 ? 1.0 : probability;\n }\n\n function generateSimilarityVector(featurePairs) {\n const compared = featurePairs.map(({name, a, b}) => {\n const {compare} = strategy.find(({name: featureName}) => name === featureName);\n const points = compare(a, b);\n return {name, points};\n });\n\n debugData(`Points: ${JSON.stringify(compared)}`);\n return compared.map(({points}) => points);\n }\n\n function generateFeaturePairs(featuresA, featuresB) {\n const pairs = generatePairs();\n const missingFeatures = findMissing();\n\n debug(`Not comparing the following features because one, or both records are missing features: ${JSON.stringify(missingFeatures)}`);\n return pairs;\n\n function generatePairs() {\n return featuresA\n .reduce((acc, {name, value}, index) => acc.concat({\n name,\n a: value,\n b: featuresB[index].value\n }), [])\n .filter(({a, b}) => {\n if (a.length === 0 || b.length === 0) {\n return false;\n }\n\n return true;\n });\n }\n\n function findMissing() {\n return featuresA\n .map(({name}) => name)\n .filter(v => pairs.some(({name}) => name === v) === false);\n }\n }\n\n};\n"],"mappings":";;;;;;;AA6BA;;AACA;;;;;;;;;;AA9BA;;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;AACA;eAOe,CAAC;EAACA,QAAD;EAAWC,QAAQ,GAAG;AAAtB,CAAD,EAA6BC,cAAc,GAAG,KAA9C,KAAwD,CAACC,OAAD,EAAUC,OAAV,KAAsB;EAC3F,MAAMC,wBAAwB,GAAG,GAAjC;EAEA,MAAMC,KAAK,GAAG,IAAAC,cAAA,EAAkB,mDAAlB,CAAd;EACA,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAN,CAAa,MAAb,CAAlB;EAEAD,SAAS,CAAE,aAAYE,IAAI,CAACC,SAAL,CAAeX,QAAf,CAAyB,EAAvC,CAAT;EACAQ,SAAS,CAAE,aAAYE,IAAI,CAACC,SAAL,CAAeV,QAAf,CAAyB,EAAvC,CAAT;EACAO,SAAS,CAAE,mBAAkBE,IAAI,CAACC,SAAL,CAAeT,cAAf,CAA+B,EAAnD,CAAT;EAEA,MAAMU,SAAS,GAAGC,eAAe,CAACV,OAAD,CAAjC;EAEAG,KAAK,CAAE,+BAA8BQ,KAAK,CAACC,OAAN,CAAcX,OAAd,CAAuB,EAAvD,CAAL;EACA,MAAMY,QAAQ,GAAGF,KAAK,CAACC,OAAN,CAAcX,OAAd,IAAyBA,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