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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -69,6 +69,12 @@ Object.defineProperty(exports, "publicationTimeAllowConsYears", {
69
69
  return _publicationTimeAllowConsYears.default;
70
70
  }
71
71
  });
72
+ Object.defineProperty(exports, "publicationTimeAllowConsYearsMulti", {
73
+ enumerable: true,
74
+ get: function () {
75
+ return _publicationTimeAllowConsYearsMulti.default;
76
+ }
77
+ });
72
78
  Object.defineProperty(exports, "recordType", {
73
79
  enumerable: true,
74
80
  get: function () {
@@ -97,6 +103,7 @@ var _authors = _interopRequireDefault(require("./authors"));
97
103
  var _recordType = _interopRequireDefault(require("./record-type"));
98
104
  var _publicationTime = _interopRequireDefault(require("./publication-time"));
99
105
  var _publicationTimeAllowConsYears = _interopRequireDefault(require("./publication-time-allow-cons-years"));
106
+ var _publicationTimeAllowConsYearsMulti = _interopRequireDefault(require("./publication-time-allow-cons-years-multi"));
100
107
  var _language = _interopRequireDefault(require("./language"));
101
108
  var _bibliographicLevel = _interopRequireDefault(require("./bibliographic-level"));
102
109
  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 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"}
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 publicationTimeAllowConsYearsMulti} from './publication-time-allow-cons-years-multi';\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;AACA;AAAyD"}
@@ -47,16 +47,6 @@ var _default = () => ({
47
47
  const value008 = get008Value();
48
48
  const values041 = get041Values();
49
49
  debugData(`${label} 008: ${JSON.stringify(value008)}, 041: ${JSON.stringify(values041)}`);
50
-
51
- /*
52
- if (value008 && values041.length > 0) {
53
- debugData(`${label} There's both 008 and 041, searching for value in both`);
54
- const correspondingValue = values041.find(v => v === value008);
55
- debugData(`${label} Corresponding value: ${correspondingValue}`);
56
- return correspondingValue ? [correspondingValue] : [];
57
- }
58
- */
59
-
60
50
  if (!value008 && values041.length < 1) {
61
51
  debugData(`{$label} No actual values found`);
62
52
  return [];
@@ -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","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,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D,OAAO,CAAC,GAAG;IACb;IACAA,KAAK,CAAE,wBAAuBwC,cAAe,IAAGC,mBAAoB,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"}
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 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;A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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,257 @@
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
+ // We should also get publishing time type from f008
39
+ // We should get reprint times from f500 $a "Lisäpainos/Lisäpainokset:"
40
+ var _default = () => ({
41
+ name: 'Publication time, allow consequent years, years from multiple sources',
42
+ extract: ({
43
+ record,
44
+ recordExternal
45
+ }) => {
46
+ const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:match-detection:features/bib/publication-time-allow-cons-years-multi');
47
+ const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';
48
+ const f008Values = extractF008Values(record);
49
+ debug(`${label} f008: ${JSON.stringify(f008Values)}`);
50
+ const f26xValues = extractF26xValues(record);
51
+ debug(`${label} f26x: ${JSON.stringify(f26xValues)}`);
52
+ const f500Values = extractF500Years(record);
53
+ debug(`${label} f500: ${JSON.stringify(f500Values)}`);
54
+
55
+ // We should get copyrightYear from f008Date2 to copyrightYears when f008YearType = 'r'
56
+ // Is the original year (f008Date2) in f008YearType === 'r' comparable to copyrightYear?
57
+ // We should handle unknown years (here or comparison?)
58
+ // We should handle year ranges for continuing resources / collections
59
+
60
+ const normalYears = [...new Set(f26xValues.normalYears.concat(f008Values.f008Date1).filter(value => value && value !== ' ' && value !== '||||'))].sort();
61
+ const copyrightYears = [...new Set(f26xValues.copyrightYears)].sort();
62
+ const reprintYears = [...new Set(f500Values)].sort();
63
+ const combined = {
64
+ normalYears,
65
+ copyrightYears,
66
+ reprintYears
67
+ };
68
+ debug(`Combined: ${JSON.stringify(combined)}`);
69
+ return combined;
70
+ function extractF008Values(record) {
71
+ var _record$get, _record$get$;
72
+ // Record should have only one f008 - in case of several, we handle the first one
73
+ 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;
74
+ if (value && (0, _matchingUtils.testStringOrNumber)(value)) {
75
+ const f008Date1 = extractF008Date1(value);
76
+ const f008Date2 = extractF008Date2(value);
77
+ const f008YearType = extractF008YearType(value);
78
+ return {
79
+ f008Date1,
80
+ f008Date2,
81
+ f008YearType
82
+ };
83
+ }
84
+ return {
85
+ f008Date1: undefined,
86
+ f008Date2: undefined,
87
+ f008YearType: undefined
88
+ };
89
+ function extractF008Date1(value) {
90
+ return String(value).slice(7, 11);
91
+ }
92
+ function extractF008Date2(value) {
93
+ return String(value).slice(11, 15);
94
+ }
95
+ function extractF008YearType(value) {
96
+ return String(value).slice(6, 7);
97
+ }
98
+ }
99
+ function extractF26xValues(record) {
100
+ const copyrightRegex = /^(?<copyrightPrefix>cop|cop.|c|©|p|℗)/u;
101
+ const pubNormalSubFieldValues = extractPubNormalSubfieldValues(record, copyrightRegex);
102
+ debug(`Normal years: ${JSON.stringify(pubNormalSubFieldValues)}`);
103
+ const pubF264CopySubFieldValues = extractPubF264CopySubfieldValues(record);
104
+ debug(`F264 copyright years: ${JSON.stringify(pubF264CopySubFieldValues)}`);
105
+ const pubF260CopySubFieldValues = extractPubF260CopySubfieldValues(record, copyrightRegex);
106
+ debug(`F260 copyright years: ${JSON.stringify(pubF260CopySubFieldValues)}`);
107
+ return {
108
+ normalYears: pubNormalSubFieldValues,
109
+ copyrightYears: [...pubF260CopySubFieldValues, ...pubF264CopySubFieldValues]
110
+ };
111
+ function extractPubNormalSubfieldValues(record, copyrightRegex) {
112
+ return record.get(/^26[04]$/u).filter(field => !(field.tag === '264' && field.ind2 === '4')).map(({
113
+ subfields
114
+ }) => subfields).flat().filter(({
115
+ code
116
+ }) => code && code === 'c').filter(({
117
+ value
118
+ }) => value && !copyrightRegex.test(value)).map(({
119
+ value
120
+ }) => value).map(value => removeNonAlphaNumeric(value));
121
+ }
122
+ function extractPubF264CopySubfieldValues(record, copyrightRegex) {
123
+ return record.get(/^264$/u).filter(field => field.ind2 === '4').map(({
124
+ subfields
125
+ }) => subfields).flat().filter(({
126
+ code
127
+ }) => code && code === 'c').filter(({
128
+ value
129
+ }) => value).map(({
130
+ value
131
+ }) => value).map(value => value.replace(copyrightRegex, '')).map(value => removeNonAlphaNumeric(value));
132
+ }
133
+ function extractPubF260CopySubfieldValues(record, copyrightRegex) {
134
+ return record.get(/^260$/u).map(({
135
+ subfields
136
+ }) => subfields).flat().filter(({
137
+ code
138
+ }) => code && code === 'c').filter(({
139
+ value
140
+ }) => value && copyrightRegex.test(value)).map(({
141
+ value
142
+ }) => value).map(value => value.replace(copyrightRegex, '')).map(value => removeNonAlphaNumeric(value));
143
+ }
144
+ function removeNonAlphaNumeric(value) {
145
+ debug(`Cleaning: ${JSON.stringify(value)}`);
146
+ const nonAlphaNumericRegex = /[^A-Za-z0-9]/ug;
147
+ return value ? value.replace(nonAlphaNumericRegex, '') : value;
148
+ }
149
+ }
150
+ function extractF500Years(record) {
151
+ const reprintRegex = /(?<reprint>Lisäpainokset:|Lisäpainos:)/u;
152
+ const reprintFieldContents = record.get(/^500$/u).map(({
153
+ subfields
154
+ }) => subfields).flat().filter(({
155
+ code
156
+ }) => code === 'a').map(({
157
+ value
158
+ }) => value);
159
+ //.filter(value => value.test(reprintRegex));
160
+
161
+ debug(`f500 reprint field contents: ${JSON.stringify(reprintFieldContents)}`);
162
+ const filteredF500 = reprintFieldContents.filter(content => content && content.match(reprintRegex));
163
+ debug(`f500 reprint field contents (filtered): ${JSON.stringify(filteredF500)}`);
164
+ const reprintYears = extractReprintYears(filteredF500);
165
+ return reprintYears;
166
+ }
167
+ function extractReprintYears(contents) {
168
+ const yearRegex = /[0-9][0-9][0-9][0-9]/gu;
169
+ const years = contents.map(content => content.match(yearRegex)).flat();
170
+ debug(`${JSON.stringify(years)}`);
171
+ const uniqYears = [...new Set(years)].sort();
172
+ debug(`${JSON.stringify(uniqYears)}`);
173
+ return uniqYears;
174
+ }
175
+ },
176
+ // eslint-disable-next-line max-statements
177
+ compare: (a, b) => {
178
+ const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:match-detection:features/bib/publication-time-allow-cons-years-multi');
179
+ debug(`Comparing ${JSON.stringify(a)} to ${JSON.stringify(b)}`);
180
+ const [firstA] = a.normalYears ? a.normalYears : a;
181
+ const [firstB] = b.normalYears ? b.normalYears : b;
182
+ debug(`Comparing ${JSON.stringify(firstA)} to ${JSON.stringify(firstB)}`);
183
+ if (firstA === firstB) {
184
+ return 0.1;
185
+ }
186
+
187
+ // If either of years is a non string/number, values are not comparable
188
+ if (!(0, _matchingUtils.testStringOrNumber)(firstA) || !(0, _matchingUtils.testStringOrNumber)(firstB)) {
189
+ return 0;
190
+ }
191
+ const firstANumber = parseInt(firstA, 10);
192
+ const firstBNumber = parseInt(firstB, 10);
193
+
194
+ // Handle consequent years as a match
195
+ // see publication-time for a version that does not handle consequent years as a match
196
+ if (!(isNaN(firstANumber) || isNaN(firstBNumber)) && (firstANumber + 1 === firstBNumber || firstANumber - 1 === firstBNumber)) {
197
+ return 0.1;
198
+ }
199
+
200
+ // We should do something with copyrightYears, too
201
+
202
+ // Do not give minus points if a normal publishing year is found in normal years
203
+ const bNormalInANormal = a.normalYears.filter(aValue => b.normalYears.some(bValue => aValue === bValue));
204
+ const aNormalInBNormal = b.normalYears.filter(bValue => a.normalYears.some(aValue => bValue === aValue));
205
+ debug(`BNorm in ANorm: ${JSON.stringify(bNormalInANormal)}`);
206
+ debug(`ANorm in BNorm: ${JSON.stringify(aNormalInBNormal)}`);
207
+ if (bNormalInANormal > 0 || aNormalInBNormal > 0) {
208
+ return 0;
209
+ }
210
+
211
+ // Do not give minus points if a normal publishing year is found in reprint years
212
+ const bNormalInAReprint = a.reprintYears.filter(aValue => b.normalYears.some(bValue => aValue === bValue));
213
+ const aNormalInBReprint = b.reprintYears.filter(bValue => a.normalYears.some(aValue => bValue === aValue));
214
+ debug(`BNorm in AReprint: ${JSON.stringify(bNormalInAReprint)}`);
215
+ debug(`ANorm in BReprint: ${JSON.stringify(aNormalInBReprint)}`);
216
+ if (bNormalInAReprint > 0 || aNormalInBReprint > 0) {
217
+ return 0;
218
+ }
219
+ return -1;
220
+ }
221
+ }); // https://www.loc.gov/marc/bibliographic/bd008.html
222
+ // field 008
223
+ // 06 - Type of date/Publication status
224
+ // 07-10 - Date 1
225
+ // 11-14 - Date 2
226
+ //
227
+ // 06 - Type of date/Publication status
228
+ // b - No dates given; B.C. date involved
229
+ // c - Continuing resource currently published
230
+ // d - Continuing resource ceased publication
231
+ // e - Detailed date
232
+ // i - Inclusive dates of collection
233
+ // k - Range of years of bulk of collection
234
+ // m - Multiple dates
235
+ // n - Dates unknown
236
+ // p - Date of distribution/release/issue and production/recording session when different
237
+ // q - Questionable date
238
+ // r - Reprint/reissue date and original date
239
+ // s - Single known date/probable date
240
+ // t - Publication date and copyright date
241
+ // u - Continuing resource status unknown
242
+ // | - No attempt to code
243
+ //
244
+ // 07-10 - Date 1
245
+ // 1-9 - Date digit
246
+ // # - Date element is not applicable
247
+ // u - Date element is totally or partially unknown
248
+ // |||| - No attempt to code
249
+ //
250
+ // 11-14 - Date 2
251
+ // 1-9 - Date digit
252
+ // # - Date element is not applicable
253
+ // u - Date element is totally or partially unknown
254
+ // |||| - No attempt to code
255
+ //
256
+ exports.default = _default;
257
+ //# sourceMappingURL=publication-time-allow-cons-years-multi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publication-time-allow-cons-years-multi.js","names":["name","extract","record","recordExternal","debug","createDebugLogger","label","f008Values","extractF008Values","JSON","stringify","f26xValues","extractF26xValues","f500Values","extractF500Years","normalYears","Set","concat","f008Date1","filter","value","sort","copyrightYears","reprintYears","combined","get","undefined","testStringOrNumber","extractF008Date1","f008Date2","extractF008Date2","f008YearType","extractF008YearType","String","slice","copyrightRegex","pubNormalSubFieldValues","extractPubNormalSubfieldValues","pubF264CopySubFieldValues","extractPubF264CopySubfieldValues","pubF260CopySubFieldValues","extractPubF260CopySubfieldValues","field","tag","ind2","map","subfields","flat","code","test","removeNonAlphaNumeric","replace","nonAlphaNumericRegex","reprintRegex","reprintFieldContents","filteredF500","content","match","extractReprintYears","contents","yearRegex","years","uniqYears","compare","a","b","firstA","firstB","firstANumber","parseInt","firstBNumber","isNaN","bNormalInANormal","aValue","some","bValue","aNormalInBNormal","bNormalInAReprint","aNormalInBReprint"],"sources":["../../../../src/match-detection/features/bib/publication-time-allow-cons-years-multi.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// We should also get publishing time type from f008\n// We should get reprint times from f500 $a \"Lisäpainos/Lisäpainokset:\"\n\nexport default () => ({\n name: 'Publication time, allow consequent years, years from multiple sources',\n extract: ({record, recordExternal}) => {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib/publication-time-allow-cons-years-multi');\n const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';\n\n const f008Values = extractF008Values(record);\n debug(`${label} f008: ${JSON.stringify(f008Values)}`);\n\n const f26xValues = extractF26xValues(record);\n debug(`${label} f26x: ${JSON.stringify(f26xValues)}`);\n\n const f500Values = extractF500Years(record);\n debug(`${label} f500: ${JSON.stringify(f500Values)}`);\n\n // We should get copyrightYear from f008Date2 to copyrightYears when f008YearType = 'r'\n // Is the original year (f008Date2) in f008YearType === 'r' comparable to copyrightYear?\n // We should handle unknown years (here or comparison?)\n // We should handle year ranges for continuing resources / collections\n\n const normalYears = [...new Set(f26xValues.normalYears.concat(f008Values.f008Date1).filter(value => value && value !== ' ' && value !== '||||'))].sort();\n const copyrightYears = [...new Set(f26xValues.copyrightYears)].sort();\n const reprintYears = [...new Set(f500Values)].sort();\n\n const combined = {normalYears, copyrightYears, reprintYears};\n\n debug(`Combined: ${JSON.stringify(combined)}`);\n\n return combined;\n\n function extractF008Values(record) {\n // Record should have only one f008 - in case of several, we handle the first one\n const value = record.get(/^008$/u)?.[0]?.value || undefined;\n if (value && testStringOrNumber(value)) {\n const f008Date1 = extractF008Date1(value);\n const f008Date2 = extractF008Date2(value);\n const f008YearType = extractF008YearType(value);\n return {f008Date1, f008Date2, f008YearType};\n }\n return {f008Date1: undefined, f008Date2: undefined, f008YearType: undefined};\n\n function extractF008Date1(value) {\n return String(value).slice(7, 11);\n }\n\n function extractF008Date2(value) {\n return String(value).slice(11, 15);\n }\n\n function extractF008YearType(value) {\n return String(value).slice(6, 7);\n }\n }\n\n function extractF26xValues(record) {\n const copyrightRegex = /^(?<copyrightPrefix>cop|cop.|c|©|p|℗)/u;\n\n const pubNormalSubFieldValues = extractPubNormalSubfieldValues(record, copyrightRegex);\n debug(`Normal years: ${JSON.stringify(pubNormalSubFieldValues)}`);\n\n const pubF264CopySubFieldValues = extractPubF264CopySubfieldValues(record);\n debug(`F264 copyright years: ${JSON.stringify(pubF264CopySubFieldValues)}`);\n\n const pubF260CopySubFieldValues = extractPubF260CopySubfieldValues(record, copyrightRegex);\n debug(`F260 copyright years: ${JSON.stringify(pubF260CopySubFieldValues)}`);\n\n return {normalYears: pubNormalSubFieldValues, copyrightYears: [...pubF260CopySubFieldValues, ...pubF264CopySubFieldValues]};\n\n function extractPubNormalSubfieldValues(record, copyrightRegex) {\n return record.get(/^26[04]$/u)\n .filter((field) => !(field.tag === '264' && field.ind2 === '4'))\n .map(({subfields}) => subfields)\n .flat()\n .filter(({code}) => code && code === 'c')\n .filter(({value}) => value && !copyrightRegex.test(value))\n .map(({value}) => value)\n .map((value) => removeNonAlphaNumeric(value));\n }\n\n function extractPubF264CopySubfieldValues(record, copyrightRegex) {\n return record.get(/^264$/u)\n .filter((field) => field.ind2 === '4')\n .map(({subfields}) => subfields)\n .flat()\n .filter(({code}) => code && code === 'c')\n .filter(({value}) => value)\n .map(({value}) => value)\n .map((value) => value.replace(copyrightRegex, ''))\n .map((value) => removeNonAlphaNumeric(value));\n }\n\n function extractPubF260CopySubfieldValues(record, copyrightRegex) {\n return record.get(/^260$/u)\n .map(({subfields}) => subfields)\n .flat()\n .filter(({code}) => code && code === 'c')\n .filter(({value}) => value && copyrightRegex.test(value))\n .map(({value}) => value)\n .map((value) => value.replace(copyrightRegex, ''))\n .map((value) => removeNonAlphaNumeric(value));\n }\n\n function removeNonAlphaNumeric(value) {\n debug(`Cleaning: ${JSON.stringify(value)}`);\n const nonAlphaNumericRegex = /[^A-Za-z0-9]/ug;\n return value ? value.replace(nonAlphaNumericRegex, '') : value;\n }\n }\n\n function extractF500Years(record) {\n\n const reprintRegex = /(?<reprint>Lisäpainokset:|Lisäpainos:)/u;\n const reprintFieldContents = record.get(/^500$/u)\n .map(({subfields}) => subfields)\n .flat()\n .filter(({code}) => code === 'a')\n .map(({value}) => value);\n //.filter(value => value.test(reprintRegex));\n\n debug(`f500 reprint field contents: ${JSON.stringify(reprintFieldContents)}`);\n\n const filteredF500 = reprintFieldContents.filter((content) => content && content.match(reprintRegex));\n\n debug(`f500 reprint field contents (filtered): ${JSON.stringify(filteredF500)}`);\n\n const reprintYears = extractReprintYears(filteredF500);\n\n return reprintYears;\n }\n\n function extractReprintYears(contents) {\n const yearRegex = /[0-9][0-9][0-9][0-9]/gu;\n const years = contents.map(content => content.match(yearRegex))\n .flat();\n debug(`${JSON.stringify(years)}`);\n const uniqYears = [...new Set(years)].sort();\n debug(`${JSON.stringify(uniqYears)}`);\n return uniqYears;\n }\n\n },\n // eslint-disable-next-line max-statements\n compare: (a, b) => {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib/publication-time-allow-cons-years-multi');\n debug(`Comparing ${JSON.stringify(a)} to ${JSON.stringify(b)}`);\n\n const [firstA] = a.normalYears ? a.normalYears : a;\n const [firstB] = b.normalYears ? b.normalYears : b;\n\n debug(`Comparing ${JSON.stringify(firstA)} to ${JSON.stringify(firstB)}`);\n\n if (firstA === firstB) {\n return 0.1;\n }\n\n // If either of years is a non string/number, values are not comparable\n if (!testStringOrNumber(firstA) || !testStringOrNumber(firstB)) {\n return 0;\n }\n\n const firstANumber = parseInt(firstA, 10);\n const firstBNumber = parseInt(firstB, 10);\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 if (!(isNaN(firstANumber) || isNaN(firstBNumber)) &&\n (firstANumber + 1 === firstBNumber || firstANumber - 1 === firstBNumber)) {\n return 0.1;\n }\n\n // We should do something with copyrightYears, too\n\n // Do not give minus points if a normal publishing year is found in normal years\n const bNormalInANormal = a.normalYears.filter(aValue => b.normalYears.some(bValue => aValue === bValue));\n const aNormalInBNormal = b.normalYears.filter(bValue => a.normalYears.some(aValue => bValue === aValue));\n debug(`BNorm in ANorm: ${JSON.stringify(bNormalInANormal)}`);\n debug(`ANorm in BNorm: ${JSON.stringify(aNormalInBNormal)}`);\n\n if (bNormalInANormal > 0 || aNormalInBNormal > 0) {\n return 0;\n }\n\n // Do not give minus points if a normal publishing year is found in reprint years\n const bNormalInAReprint = a.reprintYears.filter(aValue => b.normalYears.some(bValue => aValue === bValue));\n const aNormalInBReprint = b.reprintYears.filter(bValue => a.normalYears.some(aValue => bValue === aValue));\n debug(`BNorm in AReprint: ${JSON.stringify(bNormalInAReprint)}`);\n debug(`ANorm in BReprint: ${JSON.stringify(aNormalInBReprint)}`);\n\n if (bNormalInAReprint > 0 || aNormalInBReprint > 0) {\n return 0;\n }\n\n return -1;\n\n }\n});\n\n// https://www.loc.gov/marc/bibliographic/bd008.html\n// field 008\n// 06 - Type of date/Publication status\n// 07-10 - Date 1\n// 11-14 - Date 2\n//\n// 06 - Type of date/Publication status\n// b - No dates given; B.C. date involved\n// c - Continuing resource currently published\n// d - Continuing resource ceased publication\n// e - Detailed date\n// i - Inclusive dates of collection\n// k - Range of years of bulk of collection\n// m - Multiple dates\n// n - Dates unknown\n// p - Date of distribution/release/issue and production/recording session when different\n// q - Questionable date\n// r - Reprint/reissue date and original date\n// s - Single known date/probable date\n// t - Publication date and copyright date\n// u - Continuing resource status unknown\n// | - No attempt to code\n//\n// 07-10 - Date 1\n// 1-9 - Date digit\n// # - Date element is not applicable\n// u - Date element is totally or partially unknown\n// |||| - No attempt to code\n//\n// 11-14 - Date 2\n// 1-9 - Date digit\n// # - Date element is not applicable\n// u - Date element is totally or partially unknown\n// |||| - No attempt to code\n//\n\n"],"mappings":";;;;;;AA4BA;AACA;AAAsC;AA7BtC;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;AACA;AACA;AAAA,eAEe,OAAO;EACpBA,IAAI,EAAE,uEAAuE;EAC7EC,OAAO,EAAE,CAAC;IAACC,MAAM;IAAEC;EAAc,CAAC,KAAK;IACrC,MAAMC,KAAK,GAAG,IAAAC,cAAiB,EAAC,wGAAwG,CAAC;IACzI,MAAMC,KAAK,GAAGH,cAAc,IAAIA,cAAc,CAACG,KAAK,GAAGH,cAAc,CAACG,KAAK,GAAG,QAAQ;IAEtF,MAAMC,UAAU,GAAGC,iBAAiB,CAACN,MAAM,CAAC;IAC5CE,KAAK,CAAE,GAAEE,KAAM,UAASG,IAAI,CAACC,SAAS,CAACH,UAAU,CAAE,EAAC,CAAC;IAErD,MAAMI,UAAU,GAAGC,iBAAiB,CAACV,MAAM,CAAC;IAC5CE,KAAK,CAAE,GAAEE,KAAM,UAASG,IAA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pE,KAAK,CAAE,mBAAkBK,IAAI,CAACC,SAAS,CAACkE,gBAAgB,CAAE,EAAC,CAAC;IAE5D,IAAIJ,gBAAgB,GAAG,CAAC,IAAII,gBAAgB,GAAG,CAAC,EAAE;MAChD,OAAO,CAAC;IACV;;IAEA;IACA,MAAMC,iBAAiB,GAAGb,CAAC,CAACzC,YAAY,CAACJ,MAAM,CAACsD,MAAM,IAAIR,CAAC,CAAClD,WAAW,CAAC2D,IAAI,CAACC,MAAM,IAAIF,MAAM,KAAKE,MAAM,CAAC,CAAC;IAC1G,MAAMG,iBAAiB,GAAGb,CAAC,CAAC1C,YAAY,CAACJ,MAAM,CAACwD,MAAM,IAAIX,CAAC,CAACjD,WAAW,CAAC2D,IAAI,CAACD,MAAM,IAAIE,MAAM,KAAKF,MAAM,CAAC,CAAC;IAC1GrE,KAAK,CAAE,sBAAqBK,IAAI,CAACC,SAAS,CAACmE,iBAAiB,CAAE,EAAC,CAAC;IAChEzE,KAAK,CAAE,sBAAqBK,IAAI,CAACC,SAAS,CAACoE,iBAAiB,CAAE,EAAC,CAAC;IAEhE,IAAID,iBAAiB,GAAG,CAAC,IAAIC,iBAAiB,GAAG,CAAC,EAAE;MAClD,OAAO,CAAC;IACV;IAEA,OAAO,CAAC,CAAC;EAEX;AACF,CAAC,CAAC,EAEF;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA"}
@@ -52,6 +52,11 @@ var _default = () => ({
52
52
  if (firstA === firstB) {
53
53
  return 0.1;
54
54
  }
55
+
56
+ // If either of years is a non string/number, values are not comparable
57
+ if (!(0, _matchingUtils.testStringOrNumber)(firstA) || !(0, _matchingUtils.testStringOrNumber)(firstB)) {
58
+ return 0;
59
+ }
55
60
  const firstANumber = parseInt(firstA, 10);
56
61
  const firstBNumber = parseInt(firstB, 10);
57
62
  if (isNaN(firstANumber) || isNaN(firstBNumber)) {
@@ -1 +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":";;;;;;AA4BA;AACA;AAAsC;AA7BtC;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;AAAA,eAEe,OAAO;EACpBA,IAAI,EAAE,0CAA0C;EAChDC,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,KAAK;IACjB,MAAMC,KAAK,GAAG,IAAAC,cAAiB,EAAC,kGAAkG,CAAC;IACnID,KAAK,CAAE,aAAYF,CAAC,CAAC,CAAC,CAAE,OAAMC,CAAC,CAAC,CAAC,CAAE,EAAC,CAAC;IAErC,MAAM,CAACG,MAAM,CAAC,GAAGJ,CAAC;IAClB,MAAM,CAACK,MAAM,CAAC,GAAGJ,CAAC;IAElB,IAAIG,MAAM,KAAKC,MAAM,EAAE;MACrB,OAAO,GAAG;IACZ;IAEA,MAAMC,YAAY,GAAGC,QAAQ,CAACH,MAAM,EAAE,EAAE,CAAC;IACzC,MAAMI,YAAY,GAAGD,QAAQ,CAACF,MAAM,EAAE,EAAE,CAAC;IAEzC,IAAII,KAAK,CAACH,YAAY,CAAC,IAAIG,KAAK,CAACD,YAAY,CAAC,EAAE;MAC9C,OAAO,CAAC,CAAC;IACX;;IAEA;IACA;IACA,OAAOF,YAAY,GAAG,CAAC,KAAKE,YAAY,IAAIF,YAAY,GAAG,CAAC,KAAKE,YAAY,GAAG,GAAG,GAAG,CAAC,CAAC;EAC1F;AACF,CAAC,CAAC;AAAA"}
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 // If either of years is a non string/number, values are not comparable\n if (!testStringOrNumber(firstA) || !testStringOrNumber(firstB)) {\n return 0;\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":";;;;;;AA4BA;AACA;AAAsC;AA7BtC;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;AAAA,eAEe,OAAO;EACpBA,IAAI,EAAE,0CAA0C;EAChDC,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,KAAK;IACjB,MAAMC,KAAK,GAAG,IAAAC,cAAiB,EAAC,kGAAkG,CAAC;IACnID,KAAK,CAAE,aAAYF,CAAC,CAAC,CAAC,CAAE,OAAMC,CAAC,CAAC,CAAC,CAAE,EAAC,CAAC;IAErC,MAAM,CAACG,MAAM,CAAC,GAAGJ,CAAC;IAClB,MAAM,CAACK,MAAM,CAAC,GAAGJ,CAAC;IAElB,IAAIG,MAAM,KAAKC,MAAM,EAAE;MACrB,OAAO,GAAG;IACZ;;IAEA;IACA,IAAI,CAAC,IAAAT,iCAAkB,EAACQ,MAAM,CAAC,IAAI,CAAC,IAAAR,iCAAkB,EAACS,MAAM,CAAC,EAAE;MAC9D,OAAO,CAAC;IACV;IAEA,MAAMC,YAAY,GAAGC,QAAQ,CAACH,MAAM,EAAE,EAAE,CAAC;IACzC,MAAMI,YAAY,GAAGD,QAAQ,CAACF,MAAM,EAAE,EAAE,CAAC;IAEzC,IAAII,KAAK,CAACH,YAAY,CAAC,IAAIG,KAAK,CAACD,YAAY,CAAC,EAAE;MAC9C,OAAO,CAAC,CAAC;IACX;;IAEA;IACA;IACA,OAAOF,YAAY,GAAG,CAAC,KAAKE,YAAY,IAAIF,YAAY,GAAG,CAAC,KAAKE,YAAY,GAAG,GAAG,GAAG,CAAC,CAAC;EAC1F;AACF,CAAC,CAAC;AAAA"}
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.1.0-alpha.1",
17
+ "version": "4.1.0-alpha.3",
18
18
  "main": "./dist/index.js",
19
19
  "engines": {
20
20
  "node": ">=18"
@@ -36,6 +36,7 @@ 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
38
  export {default as publicationTimeAllowConsYears} from './publication-time-allow-cons-years';
39
+ export {default as publicationTimeAllowConsYearsMulti} from './publication-time-allow-cons-years-multi';
39
40
  export {default as language} from './language';
40
41
  export {default as bibliographicLevel} from './bibliographic-level';
41
42
  export {default as melindaId} from './melinda-id';
@@ -41,15 +41,6 @@ export default () => ({
41
41
  const values041 = get041Values();
42
42
  debugData(`${label} 008: ${JSON.stringify(value008)}, 041: ${JSON.stringify(values041)}`);
43
43
 
44
- /*
45
- if (value008 && values041.length > 0) {
46
- debugData(`${label} There's both 008 and 041, searching for value in both`);
47
- const correspondingValue = values041.find(v => v === value008);
48
- debugData(`${label} Corresponding value: ${correspondingValue}`);
49
- return correspondingValue ? [correspondingValue] : [];
50
- }
51
- */
52
-
53
44
  if (!value008 && values041.length < 1) {
54
45
  debugData(`{$label} No actual values found`);
55
46
  return [];
@@ -0,0 +1,268 @@
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
+ // We should also get publishing time type from f008
34
+ // We should get reprint times from f500 $a "Lisäpainos/Lisäpainokset:"
35
+
36
+ export default () => ({
37
+ name: 'Publication time, allow consequent years, years from multiple sources',
38
+ extract: ({record, recordExternal}) => {
39
+ const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib/publication-time-allow-cons-years-multi');
40
+ const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';
41
+
42
+ const f008Values = extractF008Values(record);
43
+ debug(`${label} f008: ${JSON.stringify(f008Values)}`);
44
+
45
+ const f26xValues = extractF26xValues(record);
46
+ debug(`${label} f26x: ${JSON.stringify(f26xValues)}`);
47
+
48
+ const f500Values = extractF500Years(record);
49
+ debug(`${label} f500: ${JSON.stringify(f500Values)}`);
50
+
51
+ // We should get copyrightYear from f008Date2 to copyrightYears when f008YearType = 'r'
52
+ // Is the original year (f008Date2) in f008YearType === 'r' comparable to copyrightYear?
53
+ // We should handle unknown years (here or comparison?)
54
+ // We should handle year ranges for continuing resources / collections
55
+
56
+ const normalYears = [...new Set(f26xValues.normalYears.concat(f008Values.f008Date1).filter(value => value && value !== ' ' && value !== '||||'))].sort();
57
+ const copyrightYears = [...new Set(f26xValues.copyrightYears)].sort();
58
+ const reprintYears = [...new Set(f500Values)].sort();
59
+
60
+ const combined = {normalYears, copyrightYears, reprintYears};
61
+
62
+ debug(`Combined: ${JSON.stringify(combined)}`);
63
+
64
+ return combined;
65
+
66
+ function extractF008Values(record) {
67
+ // Record should have only one f008 - in case of several, we handle the first one
68
+ const value = record.get(/^008$/u)?.[0]?.value || undefined;
69
+ if (value && testStringOrNumber(value)) {
70
+ const f008Date1 = extractF008Date1(value);
71
+ const f008Date2 = extractF008Date2(value);
72
+ const f008YearType = extractF008YearType(value);
73
+ return {f008Date1, f008Date2, f008YearType};
74
+ }
75
+ return {f008Date1: undefined, f008Date2: undefined, f008YearType: undefined};
76
+
77
+ function extractF008Date1(value) {
78
+ return String(value).slice(7, 11);
79
+ }
80
+
81
+ function extractF008Date2(value) {
82
+ return String(value).slice(11, 15);
83
+ }
84
+
85
+ function extractF008YearType(value) {
86
+ return String(value).slice(6, 7);
87
+ }
88
+ }
89
+
90
+ function extractF26xValues(record) {
91
+ const copyrightRegex = /^(?<copyrightPrefix>cop|cop.|c|©|p|℗)/u;
92
+
93
+ const pubNormalSubFieldValues = extractPubNormalSubfieldValues(record, copyrightRegex);
94
+ debug(`Normal years: ${JSON.stringify(pubNormalSubFieldValues)}`);
95
+
96
+ const pubF264CopySubFieldValues = extractPubF264CopySubfieldValues(record);
97
+ debug(`F264 copyright years: ${JSON.stringify(pubF264CopySubFieldValues)}`);
98
+
99
+ const pubF260CopySubFieldValues = extractPubF260CopySubfieldValues(record, copyrightRegex);
100
+ debug(`F260 copyright years: ${JSON.stringify(pubF260CopySubFieldValues)}`);
101
+
102
+ return {normalYears: pubNormalSubFieldValues, copyrightYears: [...pubF260CopySubFieldValues, ...pubF264CopySubFieldValues]};
103
+
104
+ function extractPubNormalSubfieldValues(record, copyrightRegex) {
105
+ return record.get(/^26[04]$/u)
106
+ .filter((field) => !(field.tag === '264' && field.ind2 === '4'))
107
+ .map(({subfields}) => subfields)
108
+ .flat()
109
+ .filter(({code}) => code && code === 'c')
110
+ .filter(({value}) => value && !copyrightRegex.test(value))
111
+ .map(({value}) => value)
112
+ .map((value) => removeNonAlphaNumeric(value));
113
+ }
114
+
115
+ function extractPubF264CopySubfieldValues(record, copyrightRegex) {
116
+ return record.get(/^264$/u)
117
+ .filter((field) => field.ind2 === '4')
118
+ .map(({subfields}) => subfields)
119
+ .flat()
120
+ .filter(({code}) => code && code === 'c')
121
+ .filter(({value}) => value)
122
+ .map(({value}) => value)
123
+ .map((value) => value.replace(copyrightRegex, ''))
124
+ .map((value) => removeNonAlphaNumeric(value));
125
+ }
126
+
127
+ function extractPubF260CopySubfieldValues(record, copyrightRegex) {
128
+ return record.get(/^260$/u)
129
+ .map(({subfields}) => subfields)
130
+ .flat()
131
+ .filter(({code}) => code && code === 'c')
132
+ .filter(({value}) => value && copyrightRegex.test(value))
133
+ .map(({value}) => value)
134
+ .map((value) => value.replace(copyrightRegex, ''))
135
+ .map((value) => removeNonAlphaNumeric(value));
136
+ }
137
+
138
+ function removeNonAlphaNumeric(value) {
139
+ debug(`Cleaning: ${JSON.stringify(value)}`);
140
+ const nonAlphaNumericRegex = /[^A-Za-z0-9]/ug;
141
+ return value ? value.replace(nonAlphaNumericRegex, '') : value;
142
+ }
143
+ }
144
+
145
+ function extractF500Years(record) {
146
+
147
+ const reprintRegex = /(?<reprint>Lisäpainokset:|Lisäpainos:)/u;
148
+ const reprintFieldContents = record.get(/^500$/u)
149
+ .map(({subfields}) => subfields)
150
+ .flat()
151
+ .filter(({code}) => code === 'a')
152
+ .map(({value}) => value);
153
+ //.filter(value => value.test(reprintRegex));
154
+
155
+ debug(`f500 reprint field contents: ${JSON.stringify(reprintFieldContents)}`);
156
+
157
+ const filteredF500 = reprintFieldContents.filter((content) => content && content.match(reprintRegex));
158
+
159
+ debug(`f500 reprint field contents (filtered): ${JSON.stringify(filteredF500)}`);
160
+
161
+ const reprintYears = extractReprintYears(filteredF500);
162
+
163
+ return reprintYears;
164
+ }
165
+
166
+ function extractReprintYears(contents) {
167
+ const yearRegex = /[0-9][0-9][0-9][0-9]/gu;
168
+ const years = contents.map(content => content.match(yearRegex))
169
+ .flat();
170
+ debug(`${JSON.stringify(years)}`);
171
+ const uniqYears = [...new Set(years)].sort();
172
+ debug(`${JSON.stringify(uniqYears)}`);
173
+ return uniqYears;
174
+ }
175
+
176
+ },
177
+ // eslint-disable-next-line max-statements
178
+ compare: (a, b) => {
179
+ const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib/publication-time-allow-cons-years-multi');
180
+ debug(`Comparing ${JSON.stringify(a)} to ${JSON.stringify(b)}`);
181
+
182
+ const [firstA] = a.normalYears ? a.normalYears : a;
183
+ const [firstB] = b.normalYears ? b.normalYears : b;
184
+
185
+ debug(`Comparing ${JSON.stringify(firstA)} to ${JSON.stringify(firstB)}`);
186
+
187
+ if (firstA === firstB) {
188
+ return 0.1;
189
+ }
190
+
191
+ // If either of years is a non string/number, values are not comparable
192
+ if (!testStringOrNumber(firstA) || !testStringOrNumber(firstB)) {
193
+ return 0;
194
+ }
195
+
196
+ const firstANumber = parseInt(firstA, 10);
197
+ const firstBNumber = parseInt(firstB, 10);
198
+
199
+ // Handle consequent years as a match
200
+ // see publication-time for a version that does not handle consequent years as a match
201
+ if (!(isNaN(firstANumber) || isNaN(firstBNumber)) &&
202
+ (firstANumber + 1 === firstBNumber || firstANumber - 1 === firstBNumber)) {
203
+ return 0.1;
204
+ }
205
+
206
+ // We should do something with copyrightYears, too
207
+
208
+ // Do not give minus points if a normal publishing year is found in normal years
209
+ const bNormalInANormal = a.normalYears.filter(aValue => b.normalYears.some(bValue => aValue === bValue));
210
+ const aNormalInBNormal = b.normalYears.filter(bValue => a.normalYears.some(aValue => bValue === aValue));
211
+ debug(`BNorm in ANorm: ${JSON.stringify(bNormalInANormal)}`);
212
+ debug(`ANorm in BNorm: ${JSON.stringify(aNormalInBNormal)}`);
213
+
214
+ if (bNormalInANormal > 0 || aNormalInBNormal > 0) {
215
+ return 0;
216
+ }
217
+
218
+ // Do not give minus points if a normal publishing year is found in reprint years
219
+ const bNormalInAReprint = a.reprintYears.filter(aValue => b.normalYears.some(bValue => aValue === bValue));
220
+ const aNormalInBReprint = b.reprintYears.filter(bValue => a.normalYears.some(aValue => bValue === aValue));
221
+ debug(`BNorm in AReprint: ${JSON.stringify(bNormalInAReprint)}`);
222
+ debug(`ANorm in BReprint: ${JSON.stringify(aNormalInBReprint)}`);
223
+
224
+ if (bNormalInAReprint > 0 || aNormalInBReprint > 0) {
225
+ return 0;
226
+ }
227
+
228
+ return -1;
229
+
230
+ }
231
+ });
232
+
233
+ // https://www.loc.gov/marc/bibliographic/bd008.html
234
+ // field 008
235
+ // 06 - Type of date/Publication status
236
+ // 07-10 - Date 1
237
+ // 11-14 - Date 2
238
+ //
239
+ // 06 - Type of date/Publication status
240
+ // b - No dates given; B.C. date involved
241
+ // c - Continuing resource currently published
242
+ // d - Continuing resource ceased publication
243
+ // e - Detailed date
244
+ // i - Inclusive dates of collection
245
+ // k - Range of years of bulk of collection
246
+ // m - Multiple dates
247
+ // n - Dates unknown
248
+ // p - Date of distribution/release/issue and production/recording session when different
249
+ // q - Questionable date
250
+ // r - Reprint/reissue date and original date
251
+ // s - Single known date/probable date
252
+ // t - Publication date and copyright date
253
+ // u - Continuing resource status unknown
254
+ // | - No attempt to code
255
+ //
256
+ // 07-10 - Date 1
257
+ // 1-9 - Date digit
258
+ // # - Date element is not applicable
259
+ // u - Date element is totally or partially unknown
260
+ // |||| - No attempt to code
261
+ //
262
+ // 11-14 - Date 2
263
+ // 1-9 - Date digit
264
+ // # - Date element is not applicable
265
+ // u - Date element is totally or partially unknown
266
+ // |||| - No attempt to code
267
+ //
268
+
@@ -48,6 +48,11 @@ export default () => ({
48
48
  return 0.1;
49
49
  }
50
50
 
51
+ // If either of years is a non string/number, values are not comparable
52
+ if (!testStringOrNumber(firstA) || !testStringOrNumber(firstB)) {
53
+ return 0;
54
+ }
55
+
51
56
  const firstANumber = parseInt(firstA, 10);
52
57
  const firstBNumber = parseInt(firstB, 10);
53
58