@natlibfi/melinda-record-matching 4.0.1-alpha.1 → 4.1.0-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.
@@ -63,6 +63,12 @@ Object.defineProperty(exports, "publicationTime", {
63
63
  return _publicationTime.default;
64
64
  }
65
65
  });
66
+ Object.defineProperty(exports, "publicationTimeAllowConsYears", {
67
+ enumerable: true,
68
+ get: function () {
69
+ return _publicationTimeAllowConsYears.default;
70
+ }
71
+ });
66
72
  Object.defineProperty(exports, "recordType", {
67
73
  enumerable: true,
68
74
  get: function () {
@@ -90,6 +96,7 @@ var _titleVersionOriginal = _interopRequireDefault(require("./title-version-orig
90
96
  var _authors = _interopRequireDefault(require("./authors"));
91
97
  var _recordType = _interopRequireDefault(require("./record-type"));
92
98
  var _publicationTime = _interopRequireDefault(require("./publication-time"));
99
+ var _publicationTimeAllowConsYears = _interopRequireDefault(require("./publication-time-allow-cons-years"));
93
100
  var _language = _interopRequireDefault(require("./language"));
94
101
  var _bibliographicLevel = _interopRequireDefault(require("./bibliographic-level"));
95
102
  var _melindaId = _interopRequireDefault(require("./melinda-id"));
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../src/match-detection/features/bib/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\nexport {default as hostComponent} from './host-component';\nexport {default as isbn} from './isbn';\nexport {default as issn} from './issn';\nexport {default as otherStandardIdentifier} from './other-standard-identifier';\nexport {default as title} from './title';\nexport {default as titleVersionOriginal} from './title-version-original';\nexport {default as authors} from './authors';\nexport {default as recordType} from './record-type';\nexport {default as publicationTime} from './publication-time';\nexport {default as language} from './language';\nexport {default as bibliographicLevel} from './bibliographic-level';\nexport {default as melindaId} from './melinda-id';\nexport {default as allSourceIds} from './all-source-ids';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAyD"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../src/match-detection/features/bib/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\nexport {default as hostComponent} from './host-component';\nexport {default as isbn} from './isbn';\nexport {default as issn} from './issn';\nexport {default as otherStandardIdentifier} from './other-standard-identifier';\nexport {default as title} from './title';\nexport {default as titleVersionOriginal} from './title-version-original';\nexport {default as authors} from './authors';\nexport {default as recordType} from './record-type';\nexport {default as publicationTime} from './publication-time';\nexport {default as publicationTimeAllowConsYears} from './publication-time-allow-cons-years';\nexport {default as language} from './language';\nexport {default as bibliographicLevel} from './bibliographic-level';\nexport {default as melindaId} from './melinda-id';\nexport {default as allSourceIds} from './all-source-ids';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAyD"}
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _debug = _interopRequireDefault(require("debug"));
8
+ var _matchingUtils = require("../../../matching-utils");
8
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
10
  /**
10
11
  *
@@ -12,7 +13,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
12
13
  *
13
14
  * Melinda record matching modules for Javascript
14
15
  *
15
- * Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
16
+ * Copyright (C) 2020-2023 University Of Helsinki (The National Library Of Finland)
16
17
  *
17
18
  * This file is part of melinda-record-matching-js
18
19
  *
@@ -46,17 +47,23 @@ var _default = () => ({
46
47
  const value008 = get008Value();
47
48
  const values041 = get041Values();
48
49
  debugData(`${label} 008: ${JSON.stringify(value008)}, 041: ${JSON.stringify(values041)}`);
50
+
51
+ /*
49
52
  if (value008 && values041.length > 0) {
50
53
  debugData(`${label} There's both 008 and 041, searching for value in both`);
51
54
  const correspondingValue = values041.find(v => v === value008);
52
55
  debugData(`${label} Corresponding value: ${correspondingValue}`);
53
56
  return correspondingValue ? [correspondingValue] : [];
54
57
  }
58
+ */
59
+
55
60
  if (!value008 && values041.length < 1) {
56
61
  debugData(`{$label} No actual values found`);
57
62
  return [];
58
63
  }
59
- return value008 ? [value008] : [values041[0]];
64
+ const allValues = value008 === undefined ? values041 : values041.concat(value008);
65
+ const uniqueSortedValues = [...new Set(allValues)].sort();
66
+ return uniqueSortedValues;
60
67
  function get008Value() {
61
68
  var _record$get, _record$get$;
62
69
  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;
@@ -66,11 +73,9 @@ var _default = () => ({
66
73
  }
67
74
  const code = value.slice(35, 38);
68
75
  debugData(`${label} 008 code: ${code}`);
69
- return code === '|||' || code === ' ' || code === '^^^' ? undefined : code;
76
+ return isLangCodeForALanguage(code) ? code : undefined;
70
77
  }
71
78
 
72
- // Main language for the resource: in the first f041 $a or f041 $d
73
- // Should we get all $a or $d languages instead of just the first?
74
79
  // Uses only f041s that have 2nd ind ' ', which means that the codes used are MARC 21 language codes
75
80
 
76
81
  function get041Values() {
@@ -80,22 +85,67 @@ var _default = () => ({
80
85
  subfields
81
86
  }) => subfields).flat().filter(({
82
87
  code
83
- }) => code === 'a' || code === 'd').map(({
88
+ }) => code === 'a' || code === 'd').filter(({
89
+ value
90
+ }) => value && isLangCodeForALanguage(value)).map(({
84
91
  value
85
92
  }) => value);
86
93
  }
94
+
95
+ // Check if a string is a possible, validly formed language code for a single language
96
+ // Currently accept also codes in capitals
97
+ function isLangCodeForALanguage(code) {
98
+ if (code.length !== 3) {
99
+ debugData(`Code ${code} is not correct length (3) for a language code.`);
100
+ return false;
101
+ }
102
+ if (code === '|||' || code === ' ' || code === '^^^' || code === 'mul' || code === 'zxx') {
103
+ debugData(`Code ${code} is not code for a spesific language.`);
104
+ return false;
105
+ }
106
+ const langCodePattern = /^[a-z][a-z][a-z]$/ui;
107
+ if (!langCodePattern.test(code)) {
108
+ debugData(`Code ${code} is not valid as a language code`);
109
+ return false;
110
+ }
111
+ return true;
112
+ }
87
113
  },
114
+ // eslint-disable-next-line max-statements
88
115
  compare: (a, b) => {
89
- debugData(`Comparing ${JSON.stringify(a[0])} and ${JSON.stringify(b[0])}`);
116
+ debugData(`Comparing ${JSON.stringify(a)} and ${JSON.stringify(b)}`);
90
117
  if (a.length === 0 || b.length === 0) {
91
118
  debugData(`No language to compare`);
92
119
  return 0;
93
120
  }
94
- debugData(`There are languages to compare`);
95
- if (a[0] === b[0]) {
121
+ if (a.length === b.length && a.every((element, index) => element === b[index])) {
122
+ debugData(`All languages match`);
96
123
  return 0.1;
97
124
  }
98
- return a[0] === 'und' || b[0] === 'und' ? 0.0 : -1.0;
125
+ const {
126
+ matchingValues,
127
+ possibleMatchValues,
128
+ maxValues
129
+ } = (0, _matchingUtils.getMatchCounts)(a, b);
130
+ if (matchingValues < 1) {
131
+ debug(`Both have languages, but none of these match.`);
132
+ return -1.0;
133
+ }
134
+ debug(`Both have languages, ${matchingValues}/${possibleMatchValues} valid languages match.`);
135
+ // ignore non-matches if there is mismatching amount of values
136
+ debug(`Possible matches: ${possibleMatchValues}/${maxValues}`);
137
+ //we give some kind of penalty for mismatching amount of values instead of simple divide?
138
+ const missingCount = maxValues - possibleMatchValues;
139
+ const misMatchCount = possibleMatchValues - matchingValues;
140
+ debug(`\t missing: ${missingCount}`);
141
+ debug(`\t mismatches: ${misMatchCount}`);
142
+ const penaltyForMissing = 0.02 * (maxValues - possibleMatchValues);
143
+ const penaltyForMisMatch = 0.05 * (possibleMatchValues - matchingValues);
144
+ debug(`\t points: penaltyForMissing: ${penaltyForMissing}`);
145
+ debug(`\t points: penaltyForMisMatch: ${penaltyForMisMatch}`);
146
+ const points = Number(Number(0.1 - penaltyForMisMatch - penaltyForMissing).toFixed(2));
147
+ debug(`Total points: ${points}`);
148
+ return points;
99
149
  }
100
150
  });
101
151
  exports.default = _default;
@@ -1 +1 @@
1
- {"version":3,"file":"language.js","names":["debug","createDebugLogger","debugData","extend","name","extract","record","recordExternal","label","value008","get008Value","values041","get041Values","JSON","stringify","length","correspondingValue","find","v","value","get","undefined","code","slice","filter","ind2","map","subfields","flat","compare","a","b"],"sources":["../../../../src/match-detection/features/bib/language.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';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features:language');\nconst debugData = debug.extend('data');\n\nexport default () => ({\n name: 'Language',\n extract: ({record, recordExternal}) => {\n const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';\n\n const value008 = get008Value();\n const values041 = get041Values();\n debugData(`${label} 008: ${JSON.stringify(value008)}, 041: ${JSON.stringify(values041)}`);\n\n if (value008 && values041.length > 0) {\n debugData(`${label} There's both 008 and 041, searching for value in both`);\n const correspondingValue = values041.find(v => v === value008);\n debugData(`${label} Corresponding value: ${correspondingValue}`);\n return correspondingValue ? [correspondingValue] : [];\n }\n\n if (!value008 && values041.length < 1) {\n debugData(`{$label} No actual values found`);\n return [];\n }\n\n return value008 ? [value008] : [values041[0]];\n\n function get008Value() {\n const value = record.get(/^008$/u)?.[0]?.value || undefined;\n debugData(`${label} 008 value: ${value}`);\n\n if (!value) {\n return undefined;\n }\n\n const code = value.slice(35, 38);\n debugData(`${label} 008 code: ${code}`);\n return code === '|||' || code === ' ' || code === '^^^' ? undefined : code;\n }\n\n // Main language for the resource: in the first f041 $a or f041 $d\n // Should we get all $a or $d languages instead of just the first?\n // Uses only f041s that have 2nd ind ' ', which means that the codes used are MARC 21 language codes\n\n function get041Values() {\n return record.get(/^041$/u)\n .filter(({ind2}) => ind2 === ' ')\n .map(({subfields}) => subfields)\n .flat()\n .filter(({code}) => code === 'a' || code === 'd')\n .map(({value}) => value);\n }\n },\n compare: (a, b) => {\n debugData(`Comparing ${JSON.stringify(a[0])} and ${JSON.stringify(b[0])}`);\n\n if (a.length === 0 || b.length === 0) {\n debugData(`No language to compare`);\n return 0;\n }\n\n debugData(`There are languages to compare`);\n\n if (a[0] === b[0]) {\n return 0.1;\n }\n\n return a[0] === 'und' || b[0] === 'und' ? 0.0 : -1.0;\n }\n});\n"],"mappings":";;;;;;AA4BA;AAAsC;AA5BtC;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,MAAMA,KAAK,GAAG,IAAAC,cAAiB,EAAC,qEAAqE,CAAC;AACtG,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAM,CAAC,MAAM,CAAC;AAAC,eAExB,OAAO;EACpBC,IAAI,EAAE,UAAU;EAChBC,OAAO,EAAE,CAAC;IAACC,MAAM;IAAEC;EAAc,CAAC,KAAK;IACrC,MAAMC,KAAK,GAAGD,cAAc,IAAIA,cAAc,CAACC,KAAK,GAAGD,cAAc,CAACC,KAAK,GAAG,QAAQ;IAEtF,MAAMC,QAAQ,GAAGC,WAAW,EAAE;IAC9B,MAAMC,SAAS,GAAGC,YAAY,EAAE;IAChCV,SAAS,CAAE,GAAEM,KAAM,SAAQK,IAAI,CAACC,SAAS,CAACL,QAAQ,CAAE,UAASI,IAAI,CAACC,SAAS,CAACH,SAAS,CAAE,EAAC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AI,KAAK,GAAG,CAAC,CAChCC,GAAG,CAAC,CAAC;QAACC;MAAS,CAAC,KAAKA,SAAS,CAAC,CAC/BC,IAAI,EAAE,CACNJ,MAAM,CAAC,CAAC;QAACF;MAAI,CAAC,KAAKA,IAAI,KAAK,GAAG,IAAIA,IAAI,KAAK,GAAG,CAAC,CAChDI,GAAG,CAAC,CAAC;QAACP;MAAK,CAAC,KAAKA,KAAK,CAAC;IAC5B;EACF,CAAC;EACDU,OAAO,EAAE,CAACC,CAAC,EAAEC,CAAC,KAAK;IACjB7B,SAAS,CAAE,aAAYW,IAAI,CAACC,SAAS,CAACgB,CAAC,CAAC,CAAC,CAAC,CAAE,QAAOjB,IAAI,CAACC,SAAS,CAACiB,CAAC,CAAC,CAAC,CAAC,CAAE,EAAC,CAAC;IAE1E,IAAID,CAAC,CAACf,MAAM,KAAK,CAAC,IAAIgB,CAAC,CAAChB,MAAM,KAAK,CAAC,EAAE;MACpCb,SAAS,CAAE,wBAAuB,CAAC;MACnC,OAAO,CAAC;IACV;IAEAA,SAAS,CAAE,gCAA+B,CAAC;IAE3C,IAAI4B,CAAC,CAAC,CAAC,CAAC,KAAKC,CAAC,CAAC,CAAC,CAAC,EAAE;MACjB,OAAO,GAAG;IACZ;IAEA,OAAOD,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,IAAIC,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,GAAG,GAAG,GAAG,CAAC,GAAG;EACtD;AACF,CAAC,CAAC;AAAA"}
1
+ {"version":3,"file":"language.js","names":["debug","createDebugLogger","debugData","extend","name","extract","record","recordExternal","label","value008","get008Value","values041","get041Values","JSON","stringify","length","allValues","undefined","concat","uniqueSortedValues","Set","sort","value","get","code","slice","isLangCodeForALanguage","filter","ind2","map","subfields","flat","langCodePattern","test","compare","a","b","every","element","index","matchingValues","possibleMatchValues","maxValues","getMatchCounts","missingCount","misMatchCount","penaltyForMissing","penaltyForMisMatch","points","Number","toFixed"],"sources":["../../../../src/match-detection/features/bib/language.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-2023 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 {getMatchCounts} from '../../../matching-utils';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features:language');\nconst debugData = debug.extend('data');\n\nexport default () => ({\n name: 'Language',\n extract: ({record, recordExternal}) => {\n const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';\n\n const value008 = get008Value();\n const values041 = get041Values();\n debugData(`${label} 008: ${JSON.stringify(value008)}, 041: ${JSON.stringify(values041)}`);\n\n /*\n if (value008 && values041.length > 0) {\n debugData(`${label} There's both 008 and 041, searching for value in both`);\n const correspondingValue = values041.find(v => v === value008);\n debugData(`${label} Corresponding value: ${correspondingValue}`);\n return correspondingValue ? [correspondingValue] : [];\n }\n */\n\n if (!value008 && values041.length < 1) {\n debugData(`{$label} No actual values found`);\n return [];\n }\n\n const allValues = value008 === undefined ? values041 : values041.concat(value008);\n const uniqueSortedValues = [...new Set(allValues)].sort();\n\n return uniqueSortedValues;\n\n function get008Value() {\n const value = record.get(/^008$/u)?.[0]?.value || undefined;\n debugData(`${label} 008 value: ${value}`);\n\n if (!value) {\n return undefined;\n }\n\n const code = value.slice(35, 38);\n debugData(`${label} 008 code: ${code}`);\n return isLangCodeForALanguage(code) ? code : undefined;\n }\n\n // Uses only f041s that have 2nd ind ' ', which means that the codes used are MARC 21 language codes\n\n function get041Values() {\n return record.get(/^041$/u)\n .filter(({ind2}) => ind2 === ' ')\n .map(({subfields}) => subfields)\n .flat()\n .filter(({code}) => code === 'a' || code === 'd')\n .filter(({value}) => value && isLangCodeForALanguage(value))\n .map(({value}) => value);\n }\n\n // Check if a string is a possible, validly formed language code for a single language\n // Currently accept also codes in capitals\n function isLangCodeForALanguage(code) {\n if (code.length !== 3) {\n debugData(`Code ${code} is not correct length (3) for a language code.`);\n return false;\n }\n if (code === '|||' || code === ' ' || code === '^^^' || code === 'mul' || code === 'zxx') {\n debugData(`Code ${code} is not code for a spesific language.`);\n return false;\n }\n const langCodePattern = /^[a-z][a-z][a-z]$/ui;\n if (!langCodePattern.test(code)) {\n debugData(`Code ${code} is not valid as a language code`);\n return false;\n }\n return true;\n }\n\n },\n // eslint-disable-next-line max-statements\n compare: (a, b) => {\n debugData(`Comparing ${JSON.stringify(a)} and ${JSON.stringify(b)}`);\n\n if (a.length === 0 || b.length === 0) {\n debugData(`No language to compare`);\n return 0;\n }\n\n if (a.length === b.length && a.every((element, index) => element === b[index])) {\n debugData(`All languages match`);\n return 0.1;\n }\n\n const {matchingValues, possibleMatchValues, maxValues} = getMatchCounts(a, b);\n\n if (matchingValues < 1) {\n debug(`Both have languages, but none of these match.`);\n return -1.0;\n }\n debug(`Both have languages, ${matchingValues}/${possibleMatchValues} valid languages match.`);\n // ignore non-matches if there is mismatching amount of values\n debug(`Possible matches: ${possibleMatchValues}/${maxValues}`);\n //we give some kind of penalty for mismatching amount of values instead of simple divide?\n const missingCount = maxValues - possibleMatchValues;\n const misMatchCount = possibleMatchValues - matchingValues;\n debug(`\\t missing: ${missingCount}`);\n debug(`\\t mismatches: ${misMatchCount}`);\n\n const penaltyForMissing = 0.02 * (maxValues - possibleMatchValues);\n const penaltyForMisMatch = 0.05 * (possibleMatchValues - matchingValues);\n debug(`\\t points: penaltyForMissing: ${penaltyForMissing}`);\n debug(`\\t points: penaltyForMisMatch: ${penaltyForMisMatch}`);\n\n const points = Number(Number(0.1 - penaltyForMisMatch - penaltyForMissing).toFixed(2));\n debug(`Total points: ${points}`);\n\n return points;\n }\n});\n"],"mappings":";;;;;;AA4BA;AACA;AAAuD;AA7BvD;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,cAAiB,EAAC,qEAAqE,CAAC;AACtG,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAM,CAAC,MAAM,CAAC;AAAC,eAExB,OAAO;EACpBC,IAAI,EAAE,UAAU;EAChBC,OAAO,EAAE,CAAC;IAACC,MAAM;IAAEC;EAAc,CAAC,KAAK;IACrC,MAAMC,KAAK,GAAGD,cAAc,IAAIA,cAAc,CAACC,KAAK,GAAGD,cAAc,CAACC,KAAK,GAAG,QAAQ;IAEtF,MAAMC,QAAQ,GAAGC,WAAW,EAAE;IAC9B,MAAMC,SAAS,GAAGC,YAAY,EAAE;IAChCV,SAAS,CAAE,GAAEM,KAAM,SAAQK,IAAI,CAACC,SAAS,CAACL,QAAQ,CAAE,UAASI,IAAI,CAACC,SAAS,CAACH,SAAS,CAAE,EAAC,CAAC;;IAEzF;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;;IAEI,IAAI,CAACF,QAAQ,IAAIE,SAAS,CAACI,MAAM,GAAG,CAAC,EAAE;MACrCb,SAAS,CAAE,iCAAgC,CAAC;MAC5C,OAAO,EAAE;IACX;IAEA,MAAMc,SAAS,GAAGP,QAAQ,KAAKQ,SAAS,GAAGN,SAAS,GAAGA,SAAS,CAACO,MAAM,CAACT,QAAQ,CAAC;IACjF,MAAMU,kBAAkB,GAAG,CAAC,GAAG,IAAIC,GAAG,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oB,yBAAwB,CAAC;IAC7F;IACAzC,KAAK,CAAE,qBAAoByC,mBAAoB,IAAGC,SAAU,EAAC,CAAC;IAC9D;IACA,MAAME,YAAY,GAAGF,SAAS,GAAGD,mBAAmB;IACpD,MAAMI,aAAa,GAAGJ,mBAAmB,GAAGD,cAAc;IAC1DxC,KAAK,CAAE,eAAc4C,YAAa,EAAC,CAAC;IACpC5C,KAAK,CAAE,kBAAiB6C,aAAc,EAAC,CAAC;IAExC,MAAMC,iBAAiB,GAAG,IAAI,IAAIJ,SAAS,GAAGD,mBAAmB,CAAC;IAClE,MAAMM,kBAAkB,GAAG,IAAI,IAAIN,mBAAmB,GAAGD,cAAc,CAAC;IACxExC,KAAK,CAAE,iCAAgC8C,iBAAkB,EAAC,CAAC;IAC3D9C,KAAK,CAAE,kCAAiC+C,kBAAmB,EAAC,CAAC;IAE7D,MAAMC,MAAM,GAAGC,MAAM,CAACA,MAAM,CAAC,GAAG,GAAGF,kBAAkB,GAAGD,iBAAiB,CAAC,CAACI,OAAO,CAAC,CAAC,CAAC,CAAC;IACtFlD,KAAK,CAAE,iBAAgBgD,MAAO,EAAC,CAAC;IAEhC,OAAOA,MAAM;EACf;AACF,CAAC,CAAC;AAAA"}
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _matchingUtils = require("../../../matching-utils");
8
+ var _debug = _interopRequireDefault(require("debug"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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-2023 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
+ var _default = () => ({
39
+ name: 'Publication time, allow consequent years',
40
+ extract: ({
41
+ record
42
+ }) => {
43
+ var _record$get, _record$get$;
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) => {
48
+ const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:match-detection:features/bib/publication-time-allow-cons-years');
49
+ debug(`Comparing ${a[0]} to ${b[0]}`);
50
+ const [firstA] = a;
51
+ const [firstB] = b;
52
+ if (firstA === firstB) {
53
+ return 0.1;
54
+ }
55
+ const firstANumber = parseInt(firstA, 10);
56
+ const firstBNumber = parseInt(firstB, 10);
57
+ if (isNaN(firstANumber) || isNaN(firstBNumber)) {
58
+ return -1;
59
+ }
60
+
61
+ // Handle consequent years as a match
62
+ // see publication-time for a version that does not handle consequent years as a match
63
+ return firstANumber + 1 === firstBNumber || firstANumber - 1 === firstBNumber ? 0.1 : -1;
64
+ }
65
+ });
66
+ exports.default = _default;
67
+ //# sourceMappingURL=publication-time-allow-cons-years.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publication-time-allow-cons-years.js","names":["name","extract","record","value","get","undefined","testStringOrNumber","String","slice","compare","a","b","debug","createDebugLogger","firstA","firstB","firstANumber","parseInt","firstBNumber","isNaN"],"sources":["../../../../src/match-detection/features/bib/publication-time-allow-cons-years.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-2023 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';\nimport createDebugLogger from 'debug';\n\n// We should also get copyright time and copyright/publication times from 26x\n\nexport default () => ({\n name: 'Publication time, allow consequent years',\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) => {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib/publication-time-allow-cons-years');\n debug(`Comparing ${a[0]} to ${b[0]}`);\n\n const [firstA] = a;\n const [firstB] = b;\n\n if (firstA === firstB) {\n return 0.1;\n }\n\n const firstANumber = parseInt(firstA, 10);\n const firstBNumber = parseInt(firstB, 10);\n\n if (isNaN(firstANumber) || isNaN(firstBNumber)) {\n return -1;\n }\n\n // Handle consequent years as a match\n // see publication-time for a version that does not handle consequent years as a match\n return firstANumber + 1 === firstBNumber || firstANumber - 1 === firstBNumber ? 0.1 : -1;\n }\n});\n"],"mappings":";;;;;;AA4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GAAG,GAAG,CAAC,CAAC;EAC1F;AACF,CAAC,CAAC;AAAA"}
@@ -33,7 +33,7 @@ var _matchingUtils = require("../../../matching-utils");
33
33
  *
34
34
  */
35
35
  // We should also get copyright time and copyright/publication times from 26x
36
- // We could also enable matching of records which have consequent publication years
36
+ // see publication-time-allow-cons-years for a version allowing consequent years to match
37
37
  var _default = () => ({
38
38
  name: 'Publication time',
39
39
  extract: ({
@@ -1 +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;AAAA,eAEe,OAAO;EACpBA,IAAI,EAAE,kBAAkB;EACxBC,OAAO,EAAE,CAAC;IAACC;EAAM,CAAC,KAAK;IAAA;IACrB,MAAMC,KAAK,GAAG,gBAAAD,MAAM,CAACE,GAAG,CAAC,QAAQ,CAAC,gEAApB,YAAuB,CAAC,CAAC,iDAAzB,aAA2BD,KAAK,KAAIE,SAAS;IAC3D,OAAO,IAAAC,iCAAkB,EAACH,KAAK,CAAC,GAAG,CAACI,MAAM,CAACJ,KAAK,CAAC,CAACK,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE;EACtE,CAAC;EACDC,OAAO,EAAE,CAACC,CAAC,EAAEC,CAAC,KAAKD,CAAC,CAAC,CAAC,CAAC,KAAKC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC;AAC5C,CAAC,CAAC;AAAA"}
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// see publication-time-allow-cons-years for a version allowing consequent years to match\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;AAAA,eAEe,OAAO;EACpBA,IAAI,EAAE,kBAAkB;EACxBC,OAAO,EAAE,CAAC;IAACC;EAAM,CAAC,KAAK;IAAA;IACrB,MAAMC,KAAK,GAAG,gBAAAD,MAAM,CAACE,GAAG,CAAC,QAAQ,CAAC,gEAApB,YAAuB,CAAC,CAAC,iDAAzB,aAA2BD,KAAK,KAAIE,SAAS;IAC3D,OAAO,IAAAC,iCAAkB,EAACH,KAAK,CAAC,GAAG,CAACI,MAAM,CAACJ,KAAK,CAAC,CAACK,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE;EACtE,CAAC;EACDC,OAAO,EAAE,CAACC,CAAC,EAAEC,CAAC,KAAKD,CAAC,CAAC,CAAC,CAAC,KAAKC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC;AAC5C,CAAC,CAAC;AAAA"}
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.extractSubfieldsFromField = extractSubfieldsFromField;
7
+ exports.getMatchCounts = getMatchCounts;
7
8
  exports.getMelindaIdsF035 = getMelindaIdsF035;
8
9
  exports.getSubfieldValues = getSubfieldValues;
9
10
  exports.testStringOrNumber = testStringOrNumber;
@@ -116,4 +117,27 @@ function uniqueSubfields(subfields) {
116
117
  return arr;
117
118
  }, []);
118
119
  }
120
+ function getMatchCounts(aValues, bValues) {
121
+ const matchingValues = getMatchingValuesAmount(aValues, bValues);
122
+ return {
123
+ maxValues: aValues.length > bValues.length ? aValues.length : bValues.length,
124
+ // possibleMatchingValues: amount of identifiers in set of less identifiers (we cannot more values than these)
125
+ possibleMatchValues: aValues.length > bValues.length ? bValues.length : aValues.length,
126
+ matchingValues
127
+ };
128
+ function getMatchingValuesAmount(aValues, bValues) {
129
+ if (bValues.length > aValues.length) {
130
+ return aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length;
131
+ }
132
+ if (aValues.length > bValues.length) {
133
+ return bValues.filter(bValue => aValues.some(aValue => bValue === aValue)).length;
134
+ }
135
+
136
+ // If we have same amount of values, we'll check matches both ways, to avoid mixups in cases
137
+ // there would be duplicate values
138
+ const aToB = aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length;
139
+ const bToA = bValues.filter(bValue => aValues.some(aValue => bValue === aValue)).length;
140
+ return aToB < bToA ? aToB : bToA;
141
+ }
142
+ }
119
143
  //# sourceMappingURL=matching-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"matching-utils.js","names":["debug","createDebugLogger","debugData","extend","getMelindaIdsF035","record","f035s","getFields","length","allF035MelindaIds","concat","map","toMelindaIds","f035MelindaIds","Set","JSON","stringify","subfields","melindaIdRegExp","filter","sub","includes","code","testStringOrNumber","value","test","String","replace","validateSidFieldSubfieldCounts","field","countC","countSubfields","countB","subfieldCode","getSubfieldValues","extractSubfieldsFromField","subfieldCodes","undefined","resultSubfields","uniqueSubfields","reduce","arr","e","find","item","newArr"],"sources":["../src/matching-utils.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';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:utils');\nconst debugData = debug.extend('data');\n\nexport function getMelindaIdsF035(record) {\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:melinda-id');\n const debugData = debug.extend('data');\n\n const f035s = record.getFields('035');\n\n if (f035s.length < 1) {\n debug(`No f035s found.`);\n return [];\n }\n\n const allF035MelindaIds = [].concat(...f035s.map(toMelindaIds));\n const f035MelindaIds = [...new Set(allF035MelindaIds)];\n\n debugData(`Fields (${f035s.length}): ${JSON.stringify(f035s)}`);\n debugData(`Ids (${allF035MelindaIds.length}): ${JSON.stringify(allF035MelindaIds)}`);\n debugData(`Unique ids (${f035MelindaIds.length}): ${JSON.stringify(f035MelindaIds)}`);\n\n return f035MelindaIds;\n\n function toMelindaIds({subfields}) {\n const melindaIdRegExp = /^(?<prefix>\\(FI-MELINDA\\)|FCC)(?<id>\\d{9})$/u;\n\n return subfields\n .filter(sub => ['a', 'z'].includes(sub.code))\n .filter(sub => testStringOrNumber(sub.value) && melindaIdRegExp.test(String(sub.value)))\n .map(({value}) => testStringOrNumber(value) ? String(value).replace(melindaIdRegExp, '$<id>') : '');\n\n }\n}\n\nexport function validateSidFieldSubfieldCounts(field) {\n // Valid SID-fields have just one $c and one $b\n debugData(`Validating SID field ${JSON.stringify(field)}`);\n const countC = countSubfields(field, 'c');\n const countB = countSubfields(field, 'b');\n debug(`Found ${countC} sf $cs and ${countB} sf $bs. IsValid: ${countC === 1 && countB === 1}`);\n\n return countC === 1 && countB === 1;\n}\n\nfunction countSubfields(field, subfieldCode) {\n // debug(`Counting subfields ${subfieldCode}`);\n return field.subfields.filter(({code}) => code === subfieldCode).length;\n}\n\nexport function getSubfieldValues(field, subfieldCode) {\n debugData(`Get subfield(s) $${subfieldCode} from ${JSON.stringify(field)}`);\n return field.subfields\n .filter(({code}) => code === subfieldCode)\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .filter(value => value);\n}\n\nexport function testStringOrNumber(value) {\n if (typeof value === 'string' || typeof value === 'number') {\n return true;\n }\n return false;\n}\n\nexport function extractSubfieldsFromField(field, subfieldCodes) {\n if (field === undefined || field.subfields === undefined) {\n return [];\n }\n const resultSubfields = field.subfields\n .filter(({code}) => subfieldCodes.includes(code))\n .map(({code, value}) => ({code, value: testStringOrNumber(value) ? String(value) : ''}))\n .filter(value => value);\n return resultSubfields;\n}\n\nexport function uniqueSubfields(subfields) {\n return subfields.reduce((arr, e) => {\n if (!arr.find(item => item.code === e.code && item.value === e.value)) {\n const newArr = arr.concat(e);\n return newArr;\n }\n return arr;\n }, []);\n}\n"],"mappings":";;;;;;;;;;;AA4BA;AAAsC;AA5BtC;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,MAAMA,KAAK,GAAG,IAAAC,cAAiB,EAAC,yCAAyC,CAAC;AAC1E,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAM,CAAC,MAAM,CAAC;AAE/B,SAASC,iBAAiB,CAACC,MAAM,EAAE;EAExC,MAAML,KAAK,GAAG,IAAAC,cAAiB,EAAC,8CAA8C,CAAC;EAC/E,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAM,CAAC,MAAM,CAAC;EAEtC,MAAMG,KAAK,GAAGD,MAAM,CAACE,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Q,SAAS,IAAIR,KAAK,CAACZ,SAAS,KAAKoB,SAAS,EAAE;IACxD,OAAO,EAAE;EACX;EACA,MAAMC,eAAe,GAAGT,KAAK,CAACZ,SAAS,CACpCE,MAAM,CAAC,CAAC;IAACG;EAAI,CAAC,KAAKc,aAAa,CAACf,QAAQ,CAACC,IAAI,CAAC,CAAC,CAChDX,GAAG,CAAC,CAAC;IAACW,IAAI;IAAEE;EAAK,CAAC,MAAM;IAACF,IAAI;IAAEE,KAAK,EAAED,kBAAkB,CAACC,KAAK,CAAC,GAAGE,MAAM,CAACF,KAAK,CAAC,GAAG;EAAE,CAAC,CAAC,CAAC,CACvFL,MAAM,CAACK,KAAK,IAAIA,KAAK,CAAC;EACzB,OAAOc,eAAe;AACxB;AAEO,SAASC,eAAe,CAACtB,SAAS,EAAE;EACzC,OAAOA,SAAS,CAACuB,MAAM,CAAC,CAACC,GAAG,EAAEC,CAAC,KAAK;IAClC,IAAI,CAACD,GAAG,CAACE,IAAI,CAACC,IAAI,IAAIA,IAAI,CAACtB,IAAI,KAAKoB,CAAC,CAACpB,IAAI,IAAIsB,IAAI,CAACpB,KAAK,KAAKkB,CAAC,CAAClB,KAAK,CAAC,EAAE;MACrE,MAAMqB,MAAM,GAAGJ,GAAG,CAAC/B,MAAM,CAACgC,CAAC,CAAC;MAC5B,OAAOG,MAAM;IACf;IACA,OAAOJ,GAAG;EACZ,CAAC,EAAE,EAAE,CAAC;AACR"}
1
+ {"version":3,"file":"matching-utils.js","names":["debug","createDebugLogger","debugData","extend","getMelindaIdsF035","record","f035s","getFields","length","allF035MelindaIds","concat","map","toMelindaIds","f035MelindaIds","Set","JSON","stringify","subfields","melindaIdRegExp","filter","sub","includes","code","testStringOrNumber","value","test","String","replace","validateSidFieldSubfieldCounts","field","countC","countSubfields","countB","subfieldCode","getSubfieldValues","extractSubfieldsFromField","subfieldCodes","undefined","resultSubfields","uniqueSubfields","reduce","arr","e","find","item","newArr","getMatchCounts","aValues","bValues","matchingValues","getMatchingValuesAmount","maxValues","possibleMatchValues","aValue","some","bValue","aToB","bToA"],"sources":["../src/matching-utils.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';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:utils');\nconst debugData = debug.extend('data');\n\nexport function getMelindaIdsF035(record) {\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:melinda-id');\n const debugData = debug.extend('data');\n\n const f035s = record.getFields('035');\n\n if (f035s.length < 1) {\n debug(`No f035s found.`);\n return [];\n }\n\n const allF035MelindaIds = [].concat(...f035s.map(toMelindaIds));\n const f035MelindaIds = [...new Set(allF035MelindaIds)];\n\n debugData(`Fields (${f035s.length}): ${JSON.stringify(f035s)}`);\n debugData(`Ids (${allF035MelindaIds.length}): ${JSON.stringify(allF035MelindaIds)}`);\n debugData(`Unique ids (${f035MelindaIds.length}): ${JSON.stringify(f035MelindaIds)}`);\n\n return f035MelindaIds;\n\n function toMelindaIds({subfields}) {\n const melindaIdRegExp = /^(?<prefix>\\(FI-MELINDA\\)|FCC)(?<id>\\d{9})$/u;\n\n return subfields\n .filter(sub => ['a', 'z'].includes(sub.code))\n .filter(sub => testStringOrNumber(sub.value) && melindaIdRegExp.test(String(sub.value)))\n .map(({value}) => testStringOrNumber(value) ? String(value).replace(melindaIdRegExp, '$<id>') : '');\n\n }\n}\n\nexport function validateSidFieldSubfieldCounts(field) {\n // Valid SID-fields have just one $c and one $b\n debugData(`Validating SID field ${JSON.stringify(field)}`);\n const countC = countSubfields(field, 'c');\n const countB = countSubfields(field, 'b');\n debug(`Found ${countC} sf $cs and ${countB} sf $bs. IsValid: ${countC === 1 && countB === 1}`);\n\n return countC === 1 && countB === 1;\n}\n\nfunction countSubfields(field, subfieldCode) {\n // debug(`Counting subfields ${subfieldCode}`);\n return field.subfields.filter(({code}) => code === subfieldCode).length;\n}\n\nexport function getSubfieldValues(field, subfieldCode) {\n debugData(`Get subfield(s) $${subfieldCode} from ${JSON.stringify(field)}`);\n return field.subfields\n .filter(({code}) => code === subfieldCode)\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .filter(value => value);\n}\n\nexport function testStringOrNumber(value) {\n if (typeof value === 'string' || typeof value === 'number') {\n return true;\n }\n return false;\n}\n\nexport function extractSubfieldsFromField(field, subfieldCodes) {\n if (field === undefined || field.subfields === undefined) {\n return [];\n }\n const resultSubfields = field.subfields\n .filter(({code}) => subfieldCodes.includes(code))\n .map(({code, value}) => ({code, value: testStringOrNumber(value) ? String(value) : ''}))\n .filter(value => value);\n return resultSubfields;\n}\n\nexport function uniqueSubfields(subfields) {\n return subfields.reduce((arr, e) => {\n if (!arr.find(item => item.code === e.code && item.value === e.value)) {\n const newArr = arr.concat(e);\n return newArr;\n }\n return arr;\n }, []);\n}\n\nexport function getMatchCounts(aValues, bValues) {\n\n const matchingValues = getMatchingValuesAmount(aValues, bValues);\n\n return {\n maxValues: aValues.length > bValues.length ? aValues.length : bValues.length,\n // possibleMatchingValues: amount of identifiers in set of less identifiers (we cannot more values than these)\n possibleMatchValues: aValues.length > bValues.length ? bValues.length : aValues.length,\n matchingValues\n };\n\n function getMatchingValuesAmount(aValues, bValues) {\n if (bValues.length > aValues.length) {\n return aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length;\n }\n if (aValues.length > bValues.length) {\n return bValues.filter(bValue => aValues.some(aValue => bValue === aValue)).length;\n }\n\n // If we have same amount of values, we'll check matches both ways, to avoid mixups in cases\n // there would be duplicate values\n const aToB = aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length;\n const bToA = bValues.filter(bValue => aValues.some(aValue => bValue === aValue)).length;\n\n return aToB < bToA ? aToB : bToA;\n }\n}\n"],"mappings":";;;;;;;;;;;;AA4BA;AAAsC;AA5BtC;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,MAAMA,KAAK,GAAG,IAAAC,cAAiB,EAAC,yCAAyC,CAAC;AAC1E,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAM,CAAC,MAAM,CAAC;AAE/B,SAASC,iBAAiB,CAACC,MAAM,EAAE;EAExC,MAAML,KAAK,GAAG,IAAAC,cAAiB,EAAC,8CAA8C,CAAC;EAC/E,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAM,CAAC,MAAM,CAAC;EAEtC,MAAMG,KAAK,GAAGD,MAAM,CAACE,SAAS,CAAC,KAAK,CAAC;EAErC,IAAID,KAAK,CAACE,MAAM,GAAG,CAAC,EAAE;IACpBR,KAAK,CAAE,iBAAgB,CAAC;IACxB,OAAO,EAAE;EACX;EAEA,MAAMS,iBAAiB,GAAG,EAAE,CAACC,MAAM,CAAC,GAAGJ,KAAK,CAACK,GAAG,CAACC,YAAY,CAAC,CAAC;EAC/D,MAAMC,cAAc,GAAG,CAAC,GAAG,IAAIC,GAAG,CAACL,iBAAiB,CAAC,CAAC;EAEtDP,SAAS,CAAE,WAAUI,KAAK,CAACE,MAAO,MAAKO,IAAI,CAACC,SAAS,CAACV,KAAK,CAAE,EAAC,CAAC;EAC/DJ,SAAS,CAAE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ACoC,MAAM,IAAIR,OAAO,CAACO,IAAI,CAACD,MAAM,IAAIE,MAAM,KAAKF,MAAM,CAAC,CAAC,CAAC7C,MAAM;IACnF;;IAEA;IACA;IACA,MAAMgD,IAAI,GAAGT,OAAO,CAAC5B,MAAM,CAACkC,MAAM,IAAIL,OAAO,CAACM,IAAI,CAACC,MAAM,IAAIF,MAAM,KAAKE,MAAM,CAAC,CAAC,CAAC/C,MAAM;IACvF,MAAMiD,IAAI,GAAGT,OAAO,CAAC7B,MAAM,CAACoC,MAAM,IAAIR,OAAO,CAACO,IAAI,CAACD,MAAM,IAAIE,MAAM,KAAKF,MAAM,CAAC,CAAC,CAAC7C,MAAM;IAEvF,OAAOgD,IAAI,GAAGC,IAAI,GAAGD,IAAI,GAAGC,IAAI;EAClC;AACF"}
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": "4.0.1-alpha.1",
17
+ "version": "4.1.0-alpha.1",
18
18
  "main": "./dist/index.js",
19
19
  "engines": {
20
20
  "node": ">=18"
@@ -38,12 +38,12 @@
38
38
  "dependencies": {
39
39
  "@natlibfi/marc-record": "^7.2.2",
40
40
  "@natlibfi/marc-record-serializers": "^9.0.4",
41
- "@natlibfi/melinda-commons": "^12.0.9",
41
+ "@natlibfi/melinda-commons": "^13.0.2",
42
42
  "@natlibfi/sru-client": "^5.0.4",
43
43
  "debug": "^4.3.4",
44
- "isbn3": "^1.1.30",
44
+ "isbn3": "^1.1.33",
45
45
  "moment": "^2.29.4",
46
- "natural": "^6.1.4",
46
+ "natural": "^6.2.0",
47
47
  "uuid": "^9.0.0",
48
48
  "winston": "^3.8.2"
49
49
  },
@@ -51,7 +51,7 @@
51
51
  "@babel/cli": "^7.20.7",
52
52
  "@babel/core": "^7.20.12",
53
53
  "@babel/eslint-parser": "^7.19.1",
54
- "@babel/node": "^7.20.0",
54
+ "@babel/node": "^7.20.7",
55
55
  "@babel/preset-env": "^7.20.2",
56
56
  "@babel/register": "^7.18.9",
57
57
  "@natlibfi/eslint-config-melinda-backend": "^2.0.2",
@@ -63,7 +63,7 @@
63
63
  "chai": "^4.3.7",
64
64
  "chai-as-promised": "^7.1.1",
65
65
  "cross-env": "^7.0.3",
66
- "eslint": "^8.32.0",
66
+ "eslint": "^8.34.0",
67
67
  "mocha": "^10.2.0",
68
68
  "nodemon": "^2.0.20",
69
69
  "nyc": "^15.1.0"
@@ -35,6 +35,7 @@ export {default as titleVersionOriginal} from './title-version-original';
35
35
  export {default as authors} from './authors';
36
36
  export {default as recordType} from './record-type';
37
37
  export {default as publicationTime} from './publication-time';
38
+ export {default as publicationTimeAllowConsYears} from './publication-time-allow-cons-years';
38
39
  export {default as language} from './language';
39
40
  export {default as bibliographicLevel} from './bibliographic-level';
40
41
  export {default as melindaId} from './melinda-id';
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * Melinda record matching modules for Javascript
6
6
  *
7
- * Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
7
+ * Copyright (C) 2020-2023 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 {getMatchCounts} from '../../../matching-utils';
30
31
 
31
32
  const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features:language');
32
33
  const debugData = debug.extend('data');
@@ -40,19 +41,24 @@ export default () => ({
40
41
  const values041 = get041Values();
41
42
  debugData(`${label} 008: ${JSON.stringify(value008)}, 041: ${JSON.stringify(values041)}`);
42
43
 
44
+ /*
43
45
  if (value008 && values041.length > 0) {
44
46
  debugData(`${label} There's both 008 and 041, searching for value in both`);
45
47
  const correspondingValue = values041.find(v => v === value008);
46
48
  debugData(`${label} Corresponding value: ${correspondingValue}`);
47
49
  return correspondingValue ? [correspondingValue] : [];
48
50
  }
51
+ */
49
52
 
50
53
  if (!value008 && values041.length < 1) {
51
54
  debugData(`{$label} No actual values found`);
52
55
  return [];
53
56
  }
54
57
 
55
- return value008 ? [value008] : [values041[0]];
58
+ const allValues = value008 === undefined ? values041 : values041.concat(value008);
59
+ const uniqueSortedValues = [...new Set(allValues)].sort();
60
+
61
+ return uniqueSortedValues;
56
62
 
57
63
  function get008Value() {
58
64
  const value = record.get(/^008$/u)?.[0]?.value || undefined;
@@ -64,11 +70,9 @@ export default () => ({
64
70
 
65
71
  const code = value.slice(35, 38);
66
72
  debugData(`${label} 008 code: ${code}`);
67
- return code === '|||' || code === ' ' || code === '^^^' ? undefined : code;
73
+ return isLangCodeForALanguage(code) ? code : undefined;
68
74
  }
69
75
 
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
76
  // Uses only f041s that have 2nd ind ' ', which means that the codes used are MARC 21 language codes
73
77
 
74
78
  function get041Values() {
@@ -77,23 +81,67 @@ export default () => ({
77
81
  .map(({subfields}) => subfields)
78
82
  .flat()
79
83
  .filter(({code}) => code === 'a' || code === 'd')
84
+ .filter(({value}) => value && isLangCodeForALanguage(value))
80
85
  .map(({value}) => value);
81
86
  }
87
+
88
+ // Check if a string is a possible, validly formed language code for a single language
89
+ // Currently accept also codes in capitals
90
+ function isLangCodeForALanguage(code) {
91
+ if (code.length !== 3) {
92
+ debugData(`Code ${code} is not correct length (3) for a language code.`);
93
+ return false;
94
+ }
95
+ if (code === '|||' || code === ' ' || code === '^^^' || code === 'mul' || code === 'zxx') {
96
+ debugData(`Code ${code} is not code for a spesific language.`);
97
+ return false;
98
+ }
99
+ const langCodePattern = /^[a-z][a-z][a-z]$/ui;
100
+ if (!langCodePattern.test(code)) {
101
+ debugData(`Code ${code} is not valid as a language code`);
102
+ return false;
103
+ }
104
+ return true;
105
+ }
106
+
82
107
  },
108
+ // eslint-disable-next-line max-statements
83
109
  compare: (a, b) => {
84
- debugData(`Comparing ${JSON.stringify(a[0])} and ${JSON.stringify(b[0])}`);
110
+ debugData(`Comparing ${JSON.stringify(a)} and ${JSON.stringify(b)}`);
85
111
 
86
112
  if (a.length === 0 || b.length === 0) {
87
113
  debugData(`No language to compare`);
88
114
  return 0;
89
115
  }
90
116
 
91
- debugData(`There are languages to compare`);
92
-
93
- if (a[0] === b[0]) {
117
+ if (a.length === b.length && a.every((element, index) => element === b[index])) {
118
+ debugData(`All languages match`);
94
119
  return 0.1;
95
120
  }
96
121
 
97
- return a[0] === 'und' || b[0] === 'und' ? 0.0 : -1.0;
122
+ const {matchingValues, possibleMatchValues, maxValues} = getMatchCounts(a, b);
123
+
124
+ if (matchingValues < 1) {
125
+ debug(`Both have languages, but none of these match.`);
126
+ return -1.0;
127
+ }
128
+ debug(`Both have languages, ${matchingValues}/${possibleMatchValues} valid languages match.`);
129
+ // ignore non-matches if there is mismatching amount of values
130
+ debug(`Possible matches: ${possibleMatchValues}/${maxValues}`);
131
+ //we give some kind of penalty for mismatching amount of values instead of simple divide?
132
+ const missingCount = maxValues - possibleMatchValues;
133
+ const misMatchCount = possibleMatchValues - matchingValues;
134
+ debug(`\t missing: ${missingCount}`);
135
+ debug(`\t mismatches: ${misMatchCount}`);
136
+
137
+ const penaltyForMissing = 0.02 * (maxValues - possibleMatchValues);
138
+ const penaltyForMisMatch = 0.05 * (possibleMatchValues - matchingValues);
139
+ debug(`\t points: penaltyForMissing: ${penaltyForMissing}`);
140
+ debug(`\t points: penaltyForMisMatch: ${penaltyForMisMatch}`);
141
+
142
+ const points = Number(Number(0.1 - penaltyForMisMatch - penaltyForMissing).toFixed(2));
143
+ debug(`Total points: ${points}`);
144
+
145
+ return points;
98
146
  }
99
147
  });
@@ -0,0 +1,62 @@
1
+ /**
2
+ *
3
+ * @licstart The following is the entire license notice for the JavaScript code in this file.
4
+ *
5
+ * Melinda record matching modules for Javascript
6
+ *
7
+ * Copyright (C) 2020-2023 University Of Helsinki (The National Library Of Finland)
8
+ *
9
+ * This file is part of melinda-record-matching-js
10
+ *
11
+ * melinda-record-matching-js program is free software: you can redistribute it and/or modify
12
+ * it under the terms of the GNU Lesser General Public License as
13
+ * published by the Free Software Foundation, either version 3 of the
14
+ * License, or (at your option) any later version.
15
+ *
16
+ * melinda-record-matching-js is distributed in the hope that it will be useful,
17
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ * GNU Lesser General Public License for more details.
20
+ *
21
+ * You should have received a copy of the GNU Affero General Public License
22
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
+ *
24
+ * @licend The above is the entire license notice
25
+ * for the JavaScript code in this file.
26
+ *
27
+ */
28
+
29
+ import {testStringOrNumber} from '../../../matching-utils';
30
+ import createDebugLogger from 'debug';
31
+
32
+ // We should also get copyright time and copyright/publication times from 26x
33
+
34
+ export default () => ({
35
+ name: 'Publication time, allow consequent years',
36
+ extract: ({record}) => {
37
+ const value = record.get(/^008$/u)?.[0]?.value || undefined;
38
+ return testStringOrNumber(value) ? [String(value).slice(7, 11)] : [];
39
+ },
40
+ compare: (a, b) => {
41
+ const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib/publication-time-allow-cons-years');
42
+ debug(`Comparing ${a[0]} to ${b[0]}`);
43
+
44
+ const [firstA] = a;
45
+ const [firstB] = b;
46
+
47
+ if (firstA === firstB) {
48
+ return 0.1;
49
+ }
50
+
51
+ const firstANumber = parseInt(firstA, 10);
52
+ const firstBNumber = parseInt(firstB, 10);
53
+
54
+ if (isNaN(firstANumber) || isNaN(firstBNumber)) {
55
+ return -1;
56
+ }
57
+
58
+ // Handle consequent years as a match
59
+ // see publication-time for a version that does not handle consequent years as a match
60
+ return firstANumber + 1 === firstBNumber || firstANumber - 1 === firstBNumber ? 0.1 : -1;
61
+ }
62
+ });
@@ -29,7 +29,7 @@
29
29
  import {testStringOrNumber} from '../../../matching-utils';
30
30
 
31
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
32
+ // see publication-time-allow-cons-years for a version allowing consequent years to match
33
33
 
34
34
  export default () => ({
35
35
  name: 'Publication time',
@@ -113,3 +113,31 @@ export function uniqueSubfields(subfields) {
113
113
  return arr;
114
114
  }, []);
115
115
  }
116
+
117
+ export function getMatchCounts(aValues, bValues) {
118
+
119
+ const matchingValues = getMatchingValuesAmount(aValues, bValues);
120
+
121
+ return {
122
+ maxValues: aValues.length > bValues.length ? aValues.length : bValues.length,
123
+ // possibleMatchingValues: amount of identifiers in set of less identifiers (we cannot more values than these)
124
+ possibleMatchValues: aValues.length > bValues.length ? bValues.length : aValues.length,
125
+ matchingValues
126
+ };
127
+
128
+ function getMatchingValuesAmount(aValues, bValues) {
129
+ if (bValues.length > aValues.length) {
130
+ return aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length;
131
+ }
132
+ if (aValues.length > bValues.length) {
133
+ return bValues.filter(bValue => aValues.some(aValue => bValue === aValue)).length;
134
+ }
135
+
136
+ // If we have same amount of values, we'll check matches both ways, to avoid mixups in cases
137
+ // there would be duplicate values
138
+ const aToB = aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length;
139
+ const bToA = bValues.filter(bValue => aValues.some(aValue => bValue === aValue)).length;
140
+
141
+ return aToB < bToA ? aToB : bToA;
142
+ }
143
+ }