@natlibfi/marc-record-validators-melinda 10.15.6 → 10.16.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/field-008-18-34-character-groups.js +189 -0
  2. package/dist/field-008-18-34-character-groups.js.map +1 -0
  3. package/dist/field-008-18-34-character-groups.spec.js +51 -0
  4. package/dist/field-008-18-34-character-groups.spec.js.map +1 -0
  5. package/dist/fix-country-codes.js +95 -0
  6. package/dist/fix-country-codes.js.map +1 -0
  7. package/dist/fix-country-codes.spec.js +51 -0
  8. package/dist/fix-country-codes.spec.js.map +1 -0
  9. package/package.json +1 -1
  10. package/src/field-008-18-34-character-groups.js +142 -0
  11. package/src/field-008-18-34-character-groups.spec.js +52 -0
  12. package/src/fix-country-codes.js +93 -0
  13. package/src/fix-country-codes.spec.js +52 -0
  14. package/test-fixtures/field-008-18-34-character-groups/01/expectedResult.json +6 -0
  15. package/test-fixtures/field-008-18-34-character-groups/01/metadata.json +6 -0
  16. package/test-fixtures/field-008-18-34-character-groups/01/record.json +6 -0
  17. package/test-fixtures/field-008-18-34-character-groups/02/expectedResult.json +7 -0
  18. package/test-fixtures/field-008-18-34-character-groups/02/metadata.json +6 -0
  19. package/test-fixtures/field-008-18-34-character-groups/02/record.json +6 -0
  20. package/test-fixtures/field-008-18-34-character-groups/03/expectedResult.json +7 -0
  21. package/test-fixtures/field-008-18-34-character-groups/03/metadata.json +7 -0
  22. package/test-fixtures/field-008-18-34-character-groups/03/record.json +6 -0
  23. package/test-fixtures/field-008-18-34-character-groups/04/expectedResult.json +7 -0
  24. package/test-fixtures/field-008-18-34-character-groups/04/metadata.json +6 -0
  25. package/test-fixtures/field-008-18-34-character-groups/04/record.json +6 -0
  26. package/test-fixtures/field-008-18-34-character-groups/05/expectedResult.json +7 -0
  27. package/test-fixtures/field-008-18-34-character-groups/05/metadata.json +7 -0
  28. package/test-fixtures/field-008-18-34-character-groups/05/record.json +6 -0
  29. package/test-fixtures/fix-country-codes/01/expectedResult.json +5 -0
  30. package/test-fixtures/fix-country-codes/01/metadata.json +6 -0
  31. package/test-fixtures/fix-country-codes/01/record.json +6 -0
  32. package/test-fixtures/fix-country-codes/02/expectedResult.json +6 -0
  33. package/test-fixtures/fix-country-codes/02/metadata.json +6 -0
  34. package/test-fixtures/fix-country-codes/02/record.json +6 -0
  35. package/test-fixtures/fix-country-codes/03/expectedResult.json +9 -0
  36. package/test-fixtures/fix-country-codes/03/metadata.json +6 -0
  37. package/test-fixtures/fix-country-codes/03/record.json +6 -0
  38. package/test-fixtures/fix-country-codes/04/expectedResult.json +9 -0
  39. package/test-fixtures/fix-country-codes/04/metadata.json +6 -0
  40. package/test-fixtures/fix-country-codes/04/record.json +6 -0
  41. package/test-fixtures/fix-country-codes/05/expectedResult.json +8 -0
  42. package/test-fixtures/fix-country-codes/05/metadata.json +6 -0
  43. package/test-fixtures/fix-country-codes/05/record.json +5 -0
@@ -0,0 +1,189 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = _default;
7
+ exports.justifyAndSortField008CharacterGroups = justifyAndSortField008CharacterGroups;
8
+ var _clone = _interopRequireDefault(require("clone"));
9
+ var _utils = require("./utils");
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ //import createDebugLogger from 'debug';
12
+
13
+ // Author(s): Nicholas Volk
14
+ // NB! CR 008/24 vs 008/25-27 is not supported yet!
15
+
16
+ function _default() {
17
+ return {
18
+ description: 'Justify left and sort character groups within 008/18-24',
19
+ validate,
20
+ fix
21
+ };
22
+ function fix(record) {
23
+ const typeOfMaterial = record.getTypeOfMaterial();
24
+ record.fields.forEach(field => {
25
+ justifyAndSortField008CharacterGroups(field, typeOfMaterial);
26
+ });
27
+ // Fix always succeeds (even when it really does not):
28
+ const res = {
29
+ message: [],
30
+ fix: [],
31
+ valid: true
32
+ };
33
+ return res;
34
+ }
35
+ function validate(record) {
36
+ const res = {
37
+ message: []
38
+ };
39
+ const typeOfMaterial = record.getTypeOfMaterial();
40
+ record.fields?.forEach(field => {
41
+ validateField(field, res, typeOfMaterial);
42
+ });
43
+ res.valid = !(res.message.length >= 1); // eslint-disable-line functional/immutable-data
44
+ return res;
45
+ }
46
+ function validateField(field, res, typeOfMaterial) {
47
+ if (field.tag !== '008') {
48
+ // Optimize code a bit...
49
+ return;
50
+ }
51
+ const orig = (0, _utils.fieldToString)(field);
52
+ const normalizedField = justifyAndSortField008CharacterGroups((0, _clone.default)(field), typeOfMaterial);
53
+ const mod = (0, _utils.fieldToString)(normalizedField);
54
+ if (orig !== mod) {
55
+ // Fail as the input is "broken"/"crap"/sumthing
56
+ res.message.push(`TODO: '${orig}' => '${mod}'`); // eslint-disable-line functional/immutable-data
57
+ return;
58
+ }
59
+ return;
60
+ }
61
+ }
62
+
63
+ // Should we add legal values?
64
+ const characterGroups = [{
65
+ type: 'BK',
66
+ start: 18,
67
+ end: 21,
68
+ sort: true,
69
+ name: 'illustrations'
70
+ }, {
71
+ type: 'BK',
72
+ start: 24,
73
+ end: 27,
74
+ sort: true,
75
+ name: 'nature of contents'
76
+ },
77
+ // English doc does not explicitly mention alphabetical sorting... Finnish does.
78
+ {
79
+ type: 'CR',
80
+ start: 25,
81
+ end: 27,
82
+ sort: true,
83
+ name: 'nature of contents'
84
+ },
85
+ // NB! 24 vs 25-27 logic needs to be implemented separately
86
+ {
87
+ type: 'MP',
88
+ start: 18,
89
+ end: 21,
90
+ sort: false,
91
+ name: 'relief'
92
+ },
93
+ // Order of importance!
94
+ {
95
+ type: 'MP',
96
+ start: 33,
97
+ end: 34,
98
+ sort: false,
99
+ name: 'special format of characteristics'
100
+ },
101
+ // Order of importance!
102
+ {
103
+ type: 'MU',
104
+ start: 24,
105
+ end: 29,
106
+ sort: true,
107
+ name: 'accompanying material'
108
+ }, {
109
+ type: 'MU',
110
+ start: 30,
111
+ end: 31,
112
+ sort: true,
113
+ name: 'literary text for sound recordings'
114
+ }];
115
+ const BIG_BAD_VALUE = 999999999;
116
+ function processCharacterGroup(field, group) {
117
+ const originalContent = field.value.substring(group.start, group.end + 1);
118
+ const content = removeDuplicateValues(fixBlanks(originalContent));
119
+ //console.info(`008/${group.start}-${group.end}: '${originalContent}'`); // eslint-disable-line no-console
120
+ const charArray = content.split('');
121
+ charArray.sort(function (a, b) {
122
+ // eslint-disable-line functional/immutable-data, prefer-arrow-callback
123
+ return scoreChar(a) - scoreChar(b);
124
+ });
125
+ const newContent = charArray.join('');
126
+ if (originalContent === newContent) {
127
+ return;
128
+ }
129
+
130
+ //console.info(`'${fieldToString(field)}' =>`); // eslint-disable-line no-console
131
+
132
+ field.value = `${field.value.substring(0, group.start)}${newContent}${field.value.substring(group.end + 1)}`; // eslint-disable-line functional/immutable-data
133
+ //console.info(`'${fieldToString(field)}'`); // eslint-disable-line no-console
134
+
135
+ function fixBlanks(str) {
136
+ if (str.includes('|') && str.match(/[^ |]/u)) {
137
+ return str.replaceAll('|', ' ');
138
+ }
139
+ return str;
140
+ }
141
+ function scoreChar(c) {
142
+ if (c === '|' || c === ' ') {
143
+ return BIG_BAD_VALUE; // Max value, these should code last
144
+ }
145
+ if (!group.sort) {
146
+ // more meaningful comes first: keep the original order
147
+ return 1;
148
+ }
149
+ const asciiCode = c.charCodeAt(0);
150
+ // a-z get values 1-26:
151
+ if (asciiCode >= 97 && asciiCode <= 122) {
152
+ return asciiCode - 96;
153
+ }
154
+ // 0-9 get values 100-109
155
+ if (asciiCode >= 48 && asciiCode <= 57) {
156
+ return asciiCode + 52;
157
+ }
158
+ // Others (=crap) return something between '9' and BIG BAD VALUE
159
+ return asciiCode + 200;
160
+ }
161
+ }
162
+ function justifyAndSortField008CharacterGroups(field, typeOfMaterial) {
163
+ if (field.tag !== '008' || field.subfields) {
164
+ return field;
165
+ }
166
+
167
+ //console.info(typeOfMaterial); // eslint-disable-line no-console
168
+
169
+ const relevantCharacterGroups = characterGroups.filter(gr => gr.type === typeOfMaterial);
170
+ relevantCharacterGroups.forEach(group => processCharacterGroup(field, group));
171
+
172
+ //justifyField008CharacterGroups(field, typeOfMaterial); // Oops: also sorts...
173
+
174
+ // NB! add value # and | normalizations
175
+ //fixBlanks(field, typeOfMaterial);
176
+
177
+ return field;
178
+ }
179
+ function removeDuplicateValues(str) {
180
+ const arr = str.split('');
181
+ // Take only the first instance of a proper value-carrying character
182
+ const reducedStr = arr.filter((c, i) => c === ' ' || c === '|' || arr.indexOf(c) === i).join('');
183
+ //console.info(`I: '${str}'`); // eslint-disable-line no-console
184
+ //console.info(`M: '${reducedStr}'`); // eslint-disable-line no-console
185
+ const output = `${reducedStr}${' '.repeat(str.length - reducedStr.length)}`; // Had some weird trouble with str.padEnd(n)
186
+ //console.info(`M: '${output}'`); // eslint-disable-line no-console
187
+ return output;
188
+ }
189
+ //# sourceMappingURL=field-008-18-34-character-groups.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field-008-18-34-character-groups.js","names":["_clone","_interopRequireDefault","require","_utils","obj","__esModule","default","_default","description","validate","fix","record","typeOfMaterial","getTypeOfMaterial","fields","forEach","field","justifyAndSortField008CharacterGroups","res","message","valid","validateField","length","tag","orig","fieldToString","normalizedField","clone","mod","push","characterGroups","type","start","end","sort","name","BIG_BAD_VALUE","processCharacterGroup","group","originalContent","value","substring","content","removeDuplicateValues","fixBlanks","charArray","split","a","b","scoreChar","newContent","join","str","includes","match","replaceAll","c","asciiCode","charCodeAt","subfields","relevantCharacterGroups","filter","gr","arr","reducedStr","i","indexOf","output","repeat"],"sources":["../src/field-008-18-34-character-groups.js"],"sourcesContent":["//import createDebugLogger from 'debug';\nimport clone from 'clone';\nimport {fieldToString} from './utils';\n// Author(s): Nicholas Volk\n// NB! CR 008/24 vs 008/25-27 is not supported yet!\n\nexport default function () {\n\n return {\n description: 'Justify left and sort character groups within 008/18-24',\n validate, fix\n };\n\n function fix(record) {\n const typeOfMaterial = record.getTypeOfMaterial();\n record.fields.forEach(field => {\n justifyAndSortField008CharacterGroups(field, typeOfMaterial);\n });\n // Fix always succeeds (even when it really does not):\n const res = {message: [], fix: [], valid: true};\n return res;\n }\n\n function validate(record) {\n const res = {message: []};\n\n const typeOfMaterial = record.getTypeOfMaterial();\n\n record.fields?.forEach(field => {\n validateField(field, res, typeOfMaterial);\n });\n\n res.valid = !(res.message.length >= 1); // eslint-disable-line functional/immutable-data\n return res;\n }\n\n function validateField(field, res, typeOfMaterial) {\n if (field.tag !== '008') { // Optimize code a bit...\n return;\n }\n const orig = fieldToString(field);\n\n const normalizedField = justifyAndSortField008CharacterGroups(clone(field), typeOfMaterial);\n const mod = fieldToString(normalizedField);\n if (orig !== mod) { // Fail as the input is \"broken\"/\"crap\"/sumthing\n res.message.push(`TODO: '${orig}' => '${mod}'`); // eslint-disable-line functional/immutable-data\n return;\n }\n return;\n }\n}\n\n// Should we add legal values?\nconst characterGroups = [\n {type: 'BK', start: 18, end: 21, sort: true, name: 'illustrations'},\n {type: 'BK', start: 24, end: 27, sort: true, name: 'nature of contents'}, // English doc does not explicitly mention alphabetical sorting... Finnish does.\n {type: 'CR', start: 25, end: 27, sort: true, name: 'nature of contents'}, // NB! 24 vs 25-27 logic needs to be implemented separately\n {type: 'MP', start: 18, end: 21, sort: false, name: 'relief'}, // Order of importance!\n {type: 'MP', start: 33, end: 34, sort: false, name: 'special format of characteristics'}, // Order of importance!\n {type: 'MU', start: 24, end: 29, sort: true, name: 'accompanying material'},\n {type: 'MU', start: 30, end: 31, sort: true, name: 'literary text for sound recordings'}\n];\n\nconst BIG_BAD_VALUE = 999999999;\n\nfunction processCharacterGroup(field, group) {\n const originalContent = field.value.substring(group.start, group.end + 1);\n const content = removeDuplicateValues(fixBlanks(originalContent));\n //console.info(`008/${group.start}-${group.end}: '${originalContent}'`); // eslint-disable-line no-console\n const charArray = content.split('');\n\n charArray.sort(function(a, b) { // eslint-disable-line functional/immutable-data, prefer-arrow-callback\n return scoreChar(a) - scoreChar(b);\n });\n\n const newContent = charArray.join('');\n if (originalContent === newContent) {\n return;\n }\n\n //console.info(`'${fieldToString(field)}' =>`); // eslint-disable-line no-console\n\n field.value = `${field.value.substring(0, group.start)}${newContent}${field.value.substring(group.end + 1)}`; // eslint-disable-line functional/immutable-data\n //console.info(`'${fieldToString(field)}'`); // eslint-disable-line no-console\n\n function fixBlanks(str) {\n if (str.includes('|') && str.match(/[^ |]/u)) {\n return str.replaceAll('|', ' ');\n }\n return str;\n }\n\n function scoreChar(c) {\n if (c === '|' || c === ' ') {\n return BIG_BAD_VALUE; // Max value, these should code last\n }\n if (!group.sort) { // more meaningful comes first: keep the original order\n return 1;\n }\n const asciiCode = c.charCodeAt(0);\n // a-z get values 1-26:\n if (asciiCode >= 97 && asciiCode <= 122) {\n return asciiCode - 96;\n }\n // 0-9 get values 100-109\n if (asciiCode >= 48 && asciiCode <= 57) {\n return asciiCode + 52;\n }\n // Others (=crap) return something between '9' and BIG BAD VALUE\n return asciiCode + 200;\n }\n}\n\nexport function justifyAndSortField008CharacterGroups(field, typeOfMaterial) {\n if (field.tag !== '008' || field.subfields) {\n return field;\n }\n\n //console.info(typeOfMaterial); // eslint-disable-line no-console\n\n const relevantCharacterGroups = characterGroups.filter(gr => gr.type === typeOfMaterial);\n\n relevantCharacterGroups.forEach(group => processCharacterGroup(field, group));\n\n //justifyField008CharacterGroups(field, typeOfMaterial); // Oops: also sorts...\n\n // NB! add value # and | normalizations\n //fixBlanks(field, typeOfMaterial);\n\n return field;\n}\n\nfunction removeDuplicateValues(str) {\n const arr = str.split('');\n // Take only the first instance of a proper value-carrying character\n const reducedStr = arr.filter((c, i) => c === ' ' || c === '|' || arr.indexOf(c) === i).join('');\n //console.info(`I: '${str}'`); // eslint-disable-line no-console\n //console.info(`M: '${reducedStr}'`); // eslint-disable-line no-console\n const output = `${reducedStr}${' '.repeat(str.length - reducedStr.length)}`; // Had some weird trouble with str.padEnd(n)\n //console.info(`M: '${output}'`); // eslint-disable-line no-console\n return output;\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AAG,CAACG,OAAO,CAACV,CAAC,CAAC,KAAKS,CAAC,CAAC,CAACd,IAAI,CAAC,EAAE,CAAC;EAChG;EACA;EACA,MAAMgB,MAAM,GAAI,GAAEH,UAAW,GAAE,GAAG,CAACI,MAAM,CAAChB,GAAG,CAAC9B,MAAM,GAAG0C,UAAU,CAAC1C,MAAM,CAAE,EAAC,CAAC,CAAC;EAC7E;EACA,OAAO6C,MAAM;AACf"}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ var _chai = require("chai");
4
+ var _marcRecord = require("@natlibfi/marc-record");
5
+ var _field0081834CharacterGroups = _interopRequireDefault(require("./field-008-18-34-character-groups"));
6
+ var _fixura = require("@natlibfi/fixura");
7
+ var _fixugen = _interopRequireDefault(require("@natlibfi/fixugen"));
8
+ var _debug = _interopRequireDefault(require("debug"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ (0, _fixugen.default)({
11
+ callback,
12
+ path: [__dirname, '..', 'test-fixtures', 'field-008-18-34-character-groups'],
13
+ useMetadataFile: true,
14
+ recurse: false,
15
+ fixura: {
16
+ reader: _fixura.READERS.JSON
17
+ },
18
+ mocha: {
19
+ before: () => testValidatorFactory()
20
+ }
21
+ });
22
+ const debug = (0, _debug.default)('@natlibfi/marc-record-validators-melinda/field-008-18-34-character-groups:test');
23
+ async function testValidatorFactory() {
24
+ const validator = await (0, _field0081834CharacterGroups.default)();
25
+ (0, _chai.expect)(validator).to.be.an('object').that.has.any.keys('description', 'validate');
26
+ (0, _chai.expect)(validator.description).to.be.a('string');
27
+ (0, _chai.expect)(validator.validate).to.be.a('function');
28
+ }
29
+ async function callback({
30
+ getFixture,
31
+ enabled = true,
32
+ fix = false
33
+ }) {
34
+ if (enabled === false) {
35
+ debug('TEST SKIPPED!');
36
+ return;
37
+ }
38
+ const validator = await (0, _field0081834CharacterGroups.default)();
39
+ const record = new _marcRecord.MarcRecord(getFixture('record.json'));
40
+ const expectedResult = getFixture('expectedResult.json');
41
+ // console.log(expectedResult); // eslint-disable-line
42
+
43
+ if (!fix) {
44
+ const result = await validator.validate(record);
45
+ (0, _chai.expect)(result).to.eql(expectedResult);
46
+ return;
47
+ }
48
+ await validator.fix(record);
49
+ (0, _chai.expect)(record).to.eql(expectedResult);
50
+ }
51
+ //# sourceMappingURL=field-008-18-34-character-groups.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field-008-18-34-character-groups.spec.js","names":["_chai","require","_marcRecord","_field0081834CharacterGroups","_interopRequireDefault","_fixura","_fixugen","_debug","obj","__esModule","default","generateTests","callback","path","__dirname","useMetadataFile","recurse","fixura","reader","READERS","JSON","mocha","before","testValidatorFactory","debug","createDebugLogger","validator","validatorFactory","expect","to","be","an","that","has","any","keys","description","a","validate","getFixture","enabled","fix","record","MarcRecord","expectedResult","result","eql"],"sources":["../src/field-008-18-34-character-groups.spec.js"],"sourcesContent":["import {expect} from 'chai';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport validatorFactory from './field-008-18-34-character-groups';\nimport {READERS} from '@natlibfi/fixura';\nimport generateTests from '@natlibfi/fixugen';\nimport createDebugLogger from 'debug';\n\ngenerateTests({\n callback,\n path: [__dirname, '..', 'test-fixtures', 'field-008-18-34-character-groups'],\n useMetadataFile: true,\n recurse: false,\n fixura: {\n reader: READERS.JSON\n },\n mocha: {\n before: () => testValidatorFactory()\n }\n});\nconst debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/field-008-18-34-character-groups:test');\n\nasync function testValidatorFactory() {\n const validator = await validatorFactory();\n\n expect(validator)\n .to.be.an('object')\n .that.has.any.keys('description', 'validate');\n\n expect(validator.description).to.be.a('string');\n expect(validator.validate).to.be.a('function');\n}\n\nasync function callback({getFixture, enabled = true, fix = false}) {\n if (enabled === false) {\n debug('TEST SKIPPED!');\n return;\n }\n\n const validator = await validatorFactory();\n const record = new MarcRecord(getFixture('record.json'));\n const expectedResult = getFixture('expectedResult.json');\n // console.log(expectedResult); // eslint-disable-line\n\n if (!fix) {\n const result = await validator.validate(record);\n expect(result).to.eql(expectedResult);\n return;\n }\n\n await validator.fix(record);\n expect(record).to.eql(expectedResult);\n}\n"],"mappings":";;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,4BAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAF,sBAAA,CAAAH,OAAA;AACA,IAAAM,MAAA,GAAAH,sBAAA,CAAAH,OAAA;AAAsC,SAAAG,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAEtC,IAAAG,gBAAa,EAAC;EACZC,QAAQ;EACRC,IAAI,EAAE,CAACC,SAAS,EAAE,IAAI,EAAE,eAAe,EAAE,kCAAkC,CAAC;EAC5EC,eAAe,EAAE,IAAI;EACrBC,OAAO,EAAE,KAAK;EACdC,MAAM,EAAE;IACNC,MAAM,EAAEC,eAAO,CAACC;EAClB,CAAC;EACDC,KAAK,EAAE;IACLC,MAAM,EAAEA,CAAA,KAAMC,oBAAoB,CAAC;EACrC;AACF,CAAC,CAAC;AACF,MAAMC,KAAK,GAAG,IAAAC,cAAiB,EAAC,gFAAgF,CAAC;AAEjH,eAAeF,oBAAoBA,CAAA,EAAG;EACpC,MAAMG,SAAS,GAAG,MAAM,IAAAC,oCAAgB,EAAC,CAAC;EAE1C,IAAAC,YAAM,EAACF,SAAS,CAAC,CACdG,EAAE,CAACC,EAAE,CAACC,EAAE,CAAC,QAAQ,CAAC,CAClBC,IAAI,CAACC,GAAG,CAACC,GAAG,CAACC,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC;EAE/C,IAAAP,YAAM,EAACF,SAAS,CAACU,WAAW,CAAC,CAACP,EAAE,CAACC,EAAE,CAACO,CAAC,CAAC,QAAQ,CAAC;EAC/C,IAAAT,YAAM,EAACF,SAAS,CAACY,QAAQ,CAAC,CAACT,EAAE,CAACC,EAAE,CAACO,CAAC,CAAC,UAAU,CAAC;AAChD;AAEA,eAAezB,QAAQA,CAAC;EAAC2B,UAAU;EAAEC,OAAO,GAAG,IAAI;EAAEC,GAAG,GAAG;AAAK,CAAC,EAAE;EACjE,IAAID,OAAO,KAAK,KAAK,EAAE;IACrBhB,KAAK,CAAC,eAAe,CAAC;IACtB;EACF;EAEA,MAAME,SAAS,GAAG,MAAM,IAAAC,oCAAgB,EAAC,CAAC;EAC1C,MAAMe,MAAM,GAAG,IAAIC,sBAAU,CAACJ,UAAU,CAAC,aAAa,CAAC,CAAC;EACxD,MAAMK,cAAc,GAAGL,UAAU,CAAC,qBAAqB,CAAC;EACxD;;EAEA,IAAI,CAACE,GAAG,EAAE;IACR,MAAMI,MAAM,GAAG,MAAMnB,SAAS,CAACY,QAAQ,CAACI,MAAM,CAAC;IAC/C,IAAAd,YAAM,EAACiB,MAAM,CAAC,CAAChB,EAAE,CAACiB,GAAG,CAACF,cAAc,CAAC;IACrC;EACF;EAEA,MAAMlB,SAAS,CAACe,GAAG,CAACC,MAAM,CAAC;EAC3B,IAAAd,YAAM,EAACc,MAAM,CAAC,CAACb,EAAE,CAACiB,GAAG,CAACF,cAAc,CAAC;AACvC"}
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = _default;
7
+ // Fix country codes in 008/15-17
8
+ //
9
+ // This is proto. Extend later...
10
+ //
11
+ // Author(s): Nicholas Volk
12
+
13
+ //import createDebugLogger from 'debug';
14
+ //import {fieldToString, nvdebug} from './utils';
15
+
16
+ function _default() {
17
+ return {
18
+ description: 'Fix deprecated country codes',
19
+ validate,
20
+ fix
21
+ };
22
+ function fix(record) {
23
+ //nvdebug(`FIX ME`);
24
+ const res = {
25
+ message: [],
26
+ fix: [],
27
+ valid: true
28
+ };
29
+ const [field008] = record.get('008');
30
+ if (!field008) {
31
+ return res;
32
+ }
33
+ fixCountryCode(field008);
34
+ return res;
35
+ }
36
+ function validate(record) {
37
+ const res = {
38
+ message: [],
39
+ valid: true
40
+ };
41
+ const [field008] = record.get('008');
42
+ if (!field008) {
43
+ return res;
44
+ }
45
+ const originalCountryCode = getCountryCodeFromField008(field008);
46
+ const modifiedCountryCode = deprecatedCountryCodeToCurrentCountryCode(originalCountryCode);
47
+ if (originalCountryCode === modifiedCountryCode) {
48
+ return res;
49
+ }
50
+ res.message.push(`Modify 008/15-17: '${originalCountryCode}' => '${modifiedCountryCode}'`); // eslint-disable-line functional/immutable-data
51
+
52
+ res.valid = false; // eslint-disable-line functional/immutable-data
53
+ return res;
54
+ }
55
+ function fixCountryCode(field008) {
56
+ const originalCountryCode = getCountryCodeFromField008(field008);
57
+ const modifiedCountryCode = deprecatedCountryCodeToCurrentCountryCode(originalCountryCode);
58
+ if (originalCountryCode !== modifiedCountryCode && modifiedCountryCode.length === 3) {
59
+ field008.value = `${field008.value.substring(0, 15)}${modifiedCountryCode}${field008.value.substring(18)}`; // eslint-disable-line functional/immutable-data
60
+ return;
61
+ }
62
+ }
63
+ function getCountryCodeFromField008(field) {
64
+ return field.value.substring(15, 18); // return 008/15-17
65
+ }
66
+ function deprecatedCountryCodeToCurrentCountryCode(countryCode) {
67
+ if (countryCode === 'air') {
68
+ // Armenia
69
+ return 'ai ';
70
+ }
71
+ if (countryCode === 'ajr') {
72
+ // Azerbaidzan
73
+ return 'aj ';
74
+ }
75
+ // Australia
76
+ if (['aca', 'qua', 'tma', 'vra', 'wea', 'xga', 'xna', 'xoa', 'xra'].includes(countryCode)) {
77
+ return 'at ';
78
+ }
79
+
80
+ // Canada
81
+ if (['abc', 'bcc', 'cn ', 'mbc', 'nfc', 'nkc', 'nsc', 'ntc', 'nuc', 'onc', 'pic', 'quc', 'snc', 'ykc'].includes(countryCode)) {
82
+ return 'xxc';
83
+ }
84
+ // Great Britain:
85
+ if (['enk', 'nik', 'stk', 'uik', 'uk ', 'wlk'].includes(countryCode)) {
86
+ return 'xxk';
87
+ }
88
+ // United States:
89
+ if (['aku', 'alu', 'aru', 'azu', 'cau', 'cou', 'ctu', 'dcu', 'deu', 'flu', 'gau', 'hiu', 'iau', 'idu', 'ilu', 'inu', 'kgr', 'ksu', 'kyu', 'lau', 'mau', 'mdu', 'meu', 'miu', 'mnu', 'mou', 'msu', 'mtu', 'nbu', 'ncu', 'nhu', 'nju', 'nmu', 'nvu', 'nyu', 'ohu', 'oku', 'oru', 'pau', 'riu', 'scu', 'sdu', 'tnu', 'txu', 'us ', 'utu', 'vau', 'vtu', 'wau', 'wiu', 'wvu', 'wyu'].includes(countryCode)) {
90
+ return 'xxu';
91
+ }
92
+ return countryCode;
93
+ }
94
+ }
95
+ //# sourceMappingURL=fix-country-codes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fix-country-codes.js","names":["_default","description","validate","fix","record","res","message","valid","field008","get","fixCountryCode","originalCountryCode","getCountryCodeFromField008","modifiedCountryCode","deprecatedCountryCodeToCurrentCountryCode","push","length","value","substring","field","countryCode","includes"],"sources":["../src/fix-country-codes.js"],"sourcesContent":["// Fix country codes in 008/15-17\n//\n// This is proto. Extend later...\n//\n// Author(s): Nicholas Volk\n\n//import createDebugLogger from 'debug';\n//import {fieldToString, nvdebug} from './utils';\n\n\nexport default function () {\n\n return {\n description: 'Fix deprecated country codes',\n validate, fix\n };\n\n function fix(record) {\n //nvdebug(`FIX ME`);\n const res = {message: [], fix: [], valid: true};\n\n const [field008] = record.get('008');\n if (!field008) {\n return res;\n }\n\n fixCountryCode(field008);\n\n return res;\n }\n\n function validate(record) {\n const res = {message: [], valid: true};\n\n const [field008] = record.get('008');\n\n if (!field008) {\n return res;\n }\n\n const originalCountryCode = getCountryCodeFromField008(field008);\n const modifiedCountryCode = deprecatedCountryCodeToCurrentCountryCode(originalCountryCode);\n if (originalCountryCode === modifiedCountryCode) {\n return res;\n }\n\n res.message.push(`Modify 008/15-17: '${originalCountryCode}' => '${modifiedCountryCode}'`); // eslint-disable-line functional/immutable-data\n\n res.valid = false; // eslint-disable-line functional/immutable-data\n return res;\n }\n\n function fixCountryCode(field008) {\n const originalCountryCode = getCountryCodeFromField008(field008);\n const modifiedCountryCode = deprecatedCountryCodeToCurrentCountryCode(originalCountryCode);\n if (originalCountryCode !== modifiedCountryCode && modifiedCountryCode.length === 3) {\n field008.value = `${field008.value.substring(0, 15)}${modifiedCountryCode}${field008.value.substring(18)}`; // eslint-disable-line functional/immutable-data\n return;\n }\n }\n\n function getCountryCodeFromField008(field) {\n return field.value.substring(15, 18); // return 008/15-17\n }\n\n function deprecatedCountryCodeToCurrentCountryCode(countryCode) {\n if (countryCode === 'air') { // Armenia\n return 'ai ';\n }\n if (countryCode === 'ajr') { // Azerbaidzan\n return 'aj ';\n }\n // Australia\n if (['aca', 'qua', 'tma', 'vra', 'wea', 'xga', 'xna', 'xoa', 'xra'].includes(countryCode)) {\n return 'at ';\n }\n\n // Canada\n if (['abc', 'bcc', 'cn ', 'mbc', 'nfc', 'nkc', 'nsc', 'ntc', 'nuc', 'onc', 'pic', 'quc', 'snc', 'ykc'].includes(countryCode)) {\n return 'xxc';\n }\n // Great Britain:\n if (['enk', 'nik', 'stk', 'uik', 'uk ', 'wlk'].includes(countryCode)) {\n return 'xxk';\n }\n // United States:\n if (['aku', 'alu', 'aru', 'azu', 'cau', 'cou', 'ctu', 'dcu', 'deu', 'flu', 'gau', 'hiu', 'iau', 'idu', 'ilu', 'inu', 'kgr', 'ksu', 'kyu', 'lau', 'mau', 'mdu', 'meu', 'miu', 'mnu', 'mou', 'msu', 'mtu', 'nbu', 'ncu', 'nhu', 'nju', 'nmu', 'nvu', 'nyu', 'ohu', 'oku', 'oru', 'pau', 'riu', 'scu', 'sdu', 'tnu', 'txu', 'us ', 'utu', 'vau', 'vtu', 'wau', 'wiu', 'wvu', 'wyu'].includes(countryCode)) {\n return 'xxu';\n }\n return countryCode;\n }\n\n}\n"],"mappings":";;;;;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,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAACC,QAAQ,CAACD,WAAW,CAAC,EAAE;MACtY,OAAO,KAAK;IACd;IACA,OAAOA,WAAW;EACpB;AAEF"}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ var _chai = require("chai");
4
+ var _marcRecord = require("@natlibfi/marc-record");
5
+ var _fixCountryCodes = _interopRequireDefault(require("./fix-country-codes"));
6
+ var _fixura = require("@natlibfi/fixura");
7
+ var _fixugen = _interopRequireDefault(require("@natlibfi/fixugen"));
8
+ var _debug = _interopRequireDefault(require("debug"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ (0, _fixugen.default)({
11
+ callback,
12
+ path: [__dirname, '..', 'test-fixtures', 'fix-country-codes'],
13
+ useMetadataFile: true,
14
+ recurse: false,
15
+ fixura: {
16
+ reader: _fixura.READERS.JSON
17
+ },
18
+ mocha: {
19
+ before: () => testValidatorFactory()
20
+ }
21
+ });
22
+ const debug = (0, _debug.default)('@natlibfi/marc-record-validators-melinda/fix-country-codestest');
23
+ async function testValidatorFactory() {
24
+ const validator = await (0, _fixCountryCodes.default)();
25
+ (0, _chai.expect)(validator).to.be.an('object').that.has.any.keys('description', 'validate');
26
+ (0, _chai.expect)(validator.description).to.be.a('string');
27
+ (0, _chai.expect)(validator.validate).to.be.a('function');
28
+ }
29
+ async function callback({
30
+ getFixture,
31
+ enabled = true,
32
+ fix = false
33
+ }) {
34
+ if (enabled === false) {
35
+ debug('TEST SKIPPED!');
36
+ return;
37
+ }
38
+ const validator = await (0, _fixCountryCodes.default)();
39
+ const record = new _marcRecord.MarcRecord(getFixture('record.json'));
40
+ const expectedResult = getFixture('expectedResult.json');
41
+ // console.log(expectedResult); // eslint-disable-line
42
+
43
+ if (!fix) {
44
+ const result = await validator.validate(record);
45
+ (0, _chai.expect)(result).to.eql(expectedResult);
46
+ return;
47
+ }
48
+ await validator.fix(record);
49
+ (0, _chai.expect)(record).to.eql(expectedResult);
50
+ }
51
+ //# sourceMappingURL=fix-country-codes.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fix-country-codes.spec.js","names":["_chai","require","_marcRecord","_fixCountryCodes","_interopRequireDefault","_fixura","_fixugen","_debug","obj","__esModule","default","generateTests","callback","path","__dirname","useMetadataFile","recurse","fixura","reader","READERS","JSON","mocha","before","testValidatorFactory","debug","createDebugLogger","validator","validatorFactory","expect","to","be","an","that","has","any","keys","description","a","validate","getFixture","enabled","fix","record","MarcRecord","expectedResult","result","eql"],"sources":["../src/fix-country-codes.spec.js"],"sourcesContent":["import {expect} from 'chai';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport validatorFactory from './fix-country-codes';\nimport {READERS} from '@natlibfi/fixura';\nimport generateTests from '@natlibfi/fixugen';\nimport createDebugLogger from 'debug';\n\ngenerateTests({\n callback,\n path: [__dirname, '..', 'test-fixtures', 'fix-country-codes'],\n useMetadataFile: true,\n recurse: false,\n fixura: {\n reader: READERS.JSON\n },\n mocha: {\n before: () => testValidatorFactory()\n }\n});\nconst debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/fix-country-codestest');\n\nasync function testValidatorFactory() {\n const validator = await validatorFactory();\n\n expect(validator)\n .to.be.an('object')\n .that.has.any.keys('description', 'validate');\n\n expect(validator.description).to.be.a('string');\n expect(validator.validate).to.be.a('function');\n}\n\nasync function callback({getFixture, enabled = true, fix = false}) {\n if (enabled === false) {\n debug('TEST SKIPPED!');\n return;\n }\n\n const validator = await validatorFactory();\n const record = new MarcRecord(getFixture('record.json'));\n const expectedResult = getFixture('expectedResult.json');\n // console.log(expectedResult); // eslint-disable-line\n\n if (!fix) {\n const result = await validator.validate(record);\n expect(result).to.eql(expectedResult);\n return;\n }\n\n await validator.fix(record);\n expect(record).to.eql(expectedResult);\n}\n"],"mappings":";;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAF,sBAAA,CAAAH,OAAA;AACA,IAAAM,MAAA,GAAAH,sBAAA,CAAAH,OAAA;AAAsC,SAAAG,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAEtC,IAAAG,gBAAa,EAAC;EACZC,QAAQ;EACRC,IAAI,EAAE,CAACC,SAAS,EAAE,IAAI,EAAE,eAAe,EAAE,mBAAmB,CAAC;EAC7DC,eAAe,EAAE,IAAI;EACrBC,OAAO,EAAE,KAAK;EACdC,MAAM,EAAE;IACNC,MAAM,EAAEC,eAAO,CAACC;EAClB,CAAC;EACDC,KAAK,EAAE;IACLC,MAAM,EAAEA,CAAA,KAAMC,oBAAoB,CAAC;EACrC;AACF,CAAC,CAAC;AACF,MAAMC,KAAK,GAAG,IAAAC,cAAiB,EAAC,gEAAgE,CAAC;AAEjG,eAAeF,oBAA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natlibfi/marc-record-validators-melinda.git"
15
15
  },
16
16
  "license": "MIT",
17
- "version": "10.15.6",
17
+ "version": "10.16.0-alpha.2",
18
18
  "main": "./dist/index.js",
19
19
  "publishConfig": {
20
20
  "access": "public"
@@ -0,0 +1,142 @@
1
+ //import createDebugLogger from 'debug';
2
+ import clone from 'clone';
3
+ import {fieldToString} from './utils';
4
+ // Author(s): Nicholas Volk
5
+ // NB! CR 008/24 vs 008/25-27 is not supported yet!
6
+
7
+ export default function () {
8
+
9
+ return {
10
+ description: 'Justify left and sort character groups within 008/18-24',
11
+ validate, fix
12
+ };
13
+
14
+ function fix(record) {
15
+ const typeOfMaterial = record.getTypeOfMaterial();
16
+ record.fields.forEach(field => {
17
+ justifyAndSortField008CharacterGroups(field, typeOfMaterial);
18
+ });
19
+ // Fix always succeeds (even when it really does not):
20
+ const res = {message: [], fix: [], valid: true};
21
+ return res;
22
+ }
23
+
24
+ function validate(record) {
25
+ const res = {message: []};
26
+
27
+ const typeOfMaterial = record.getTypeOfMaterial();
28
+
29
+ record.fields?.forEach(field => {
30
+ validateField(field, res, typeOfMaterial);
31
+ });
32
+
33
+ res.valid = !(res.message.length >= 1); // eslint-disable-line functional/immutable-data
34
+ return res;
35
+ }
36
+
37
+ function validateField(field, res, typeOfMaterial) {
38
+ if (field.tag !== '008') { // Optimize code a bit...
39
+ return;
40
+ }
41
+ const orig = fieldToString(field);
42
+
43
+ const normalizedField = justifyAndSortField008CharacterGroups(clone(field), typeOfMaterial);
44
+ const mod = fieldToString(normalizedField);
45
+ if (orig !== mod) { // Fail as the input is "broken"/"crap"/sumthing
46
+ res.message.push(`TODO: '${orig}' => '${mod}'`); // eslint-disable-line functional/immutable-data
47
+ return;
48
+ }
49
+ return;
50
+ }
51
+ }
52
+
53
+ // Should we add legal values?
54
+ const characterGroups = [
55
+ {type: 'BK', start: 18, end: 21, sort: true, name: 'illustrations'},
56
+ {type: 'BK', start: 24, end: 27, sort: true, name: 'nature of contents'}, // English doc does not explicitly mention alphabetical sorting... Finnish does.
57
+ {type: 'CR', start: 25, end: 27, sort: true, name: 'nature of contents'}, // NB! 24 vs 25-27 logic needs to be implemented separately
58
+ {type: 'MP', start: 18, end: 21, sort: false, name: 'relief'}, // Order of importance!
59
+ {type: 'MP', start: 33, end: 34, sort: false, name: 'special format of characteristics'}, // Order of importance!
60
+ {type: 'MU', start: 24, end: 29, sort: true, name: 'accompanying material'},
61
+ {type: 'MU', start: 30, end: 31, sort: true, name: 'literary text for sound recordings'}
62
+ ];
63
+
64
+ const BIG_BAD_VALUE = 999999999;
65
+
66
+ function processCharacterGroup(field, group) {
67
+ const originalContent = field.value.substring(group.start, group.end + 1);
68
+ const content = removeDuplicateValues(fixBlanks(originalContent));
69
+ //console.info(`008/${group.start}-${group.end}: '${originalContent}'`); // eslint-disable-line no-console
70
+ const charArray = content.split('');
71
+
72
+ charArray.sort(function(a, b) { // eslint-disable-line functional/immutable-data, prefer-arrow-callback
73
+ return scoreChar(a) - scoreChar(b);
74
+ });
75
+
76
+ const newContent = charArray.join('');
77
+ if (originalContent === newContent) {
78
+ return;
79
+ }
80
+
81
+ //console.info(`'${fieldToString(field)}' =>`); // eslint-disable-line no-console
82
+
83
+ field.value = `${field.value.substring(0, group.start)}${newContent}${field.value.substring(group.end + 1)}`; // eslint-disable-line functional/immutable-data
84
+ //console.info(`'${fieldToString(field)}'`); // eslint-disable-line no-console
85
+
86
+ function fixBlanks(str) {
87
+ if (str.includes('|') && str.match(/[^ |]/u)) {
88
+ return str.replaceAll('|', ' ');
89
+ }
90
+ return str;
91
+ }
92
+
93
+ function scoreChar(c) {
94
+ if (c === '|' || c === ' ') {
95
+ return BIG_BAD_VALUE; // Max value, these should code last
96
+ }
97
+ if (!group.sort) { // more meaningful comes first: keep the original order
98
+ return 1;
99
+ }
100
+ const asciiCode = c.charCodeAt(0);
101
+ // a-z get values 1-26:
102
+ if (asciiCode >= 97 && asciiCode <= 122) {
103
+ return asciiCode - 96;
104
+ }
105
+ // 0-9 get values 100-109
106
+ if (asciiCode >= 48 && asciiCode <= 57) {
107
+ return asciiCode + 52;
108
+ }
109
+ // Others (=crap) return something between '9' and BIG BAD VALUE
110
+ return asciiCode + 200;
111
+ }
112
+ }
113
+
114
+ export function justifyAndSortField008CharacterGroups(field, typeOfMaterial) {
115
+ if (field.tag !== '008' || field.subfields) {
116
+ return field;
117
+ }
118
+
119
+ //console.info(typeOfMaterial); // eslint-disable-line no-console
120
+
121
+ const relevantCharacterGroups = characterGroups.filter(gr => gr.type === typeOfMaterial);
122
+
123
+ relevantCharacterGroups.forEach(group => processCharacterGroup(field, group));
124
+
125
+ //justifyField008CharacterGroups(field, typeOfMaterial); // Oops: also sorts...
126
+
127
+ // NB! add value # and | normalizations
128
+ //fixBlanks(field, typeOfMaterial);
129
+
130
+ return field;
131
+ }
132
+
133
+ function removeDuplicateValues(str) {
134
+ const arr = str.split('');
135
+ // Take only the first instance of a proper value-carrying character
136
+ const reducedStr = arr.filter((c, i) => c === ' ' || c === '|' || arr.indexOf(c) === i).join('');
137
+ //console.info(`I: '${str}'`); // eslint-disable-line no-console
138
+ //console.info(`M: '${reducedStr}'`); // eslint-disable-line no-console
139
+ const output = `${reducedStr}${' '.repeat(str.length - reducedStr.length)}`; // Had some weird trouble with str.padEnd(n)
140
+ //console.info(`M: '${output}'`); // eslint-disable-line no-console
141
+ return output;
142
+ }
@@ -0,0 +1,52 @@
1
+ import {expect} from 'chai';
2
+ import {MarcRecord} from '@natlibfi/marc-record';
3
+ import validatorFactory from './field-008-18-34-character-groups';
4
+ import {READERS} from '@natlibfi/fixura';
5
+ import generateTests from '@natlibfi/fixugen';
6
+ import createDebugLogger from 'debug';
7
+
8
+ generateTests({
9
+ callback,
10
+ path: [__dirname, '..', 'test-fixtures', 'field-008-18-34-character-groups'],
11
+ useMetadataFile: true,
12
+ recurse: false,
13
+ fixura: {
14
+ reader: READERS.JSON
15
+ },
16
+ mocha: {
17
+ before: () => testValidatorFactory()
18
+ }
19
+ });
20
+ const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/field-008-18-34-character-groups:test');
21
+
22
+ async function testValidatorFactory() {
23
+ const validator = await validatorFactory();
24
+
25
+ expect(validator)
26
+ .to.be.an('object')
27
+ .that.has.any.keys('description', 'validate');
28
+
29
+ expect(validator.description).to.be.a('string');
30
+ expect(validator.validate).to.be.a('function');
31
+ }
32
+
33
+ async function callback({getFixture, enabled = true, fix = false}) {
34
+ if (enabled === false) {
35
+ debug('TEST SKIPPED!');
36
+ return;
37
+ }
38
+
39
+ const validator = await validatorFactory();
40
+ const record = new MarcRecord(getFixture('record.json'));
41
+ const expectedResult = getFixture('expectedResult.json');
42
+ // console.log(expectedResult); // eslint-disable-line
43
+
44
+ if (!fix) {
45
+ const result = await validator.validate(record);
46
+ expect(result).to.eql(expectedResult);
47
+ return;
48
+ }
49
+
50
+ await validator.fix(record);
51
+ expect(record).to.eql(expectedResult);
52
+ }
@@ -0,0 +1,93 @@
1
+ // Fix country codes in 008/15-17
2
+ //
3
+ // This is proto. Extend later...
4
+ //
5
+ // Author(s): Nicholas Volk
6
+
7
+ //import createDebugLogger from 'debug';
8
+ //import {fieldToString, nvdebug} from './utils';
9
+
10
+
11
+ export default function () {
12
+
13
+ return {
14
+ description: 'Fix deprecated country codes',
15
+ validate, fix
16
+ };
17
+
18
+ function fix(record) {
19
+ //nvdebug(`FIX ME`);
20
+ const res = {message: [], fix: [], valid: true};
21
+
22
+ const [field008] = record.get('008');
23
+ if (!field008) {
24
+ return res;
25
+ }
26
+
27
+ fixCountryCode(field008);
28
+
29
+ return res;
30
+ }
31
+
32
+ function validate(record) {
33
+ const res = {message: [], valid: true};
34
+
35
+ const [field008] = record.get('008');
36
+
37
+ if (!field008) {
38
+ return res;
39
+ }
40
+
41
+ const originalCountryCode = getCountryCodeFromField008(field008);
42
+ const modifiedCountryCode = deprecatedCountryCodeToCurrentCountryCode(originalCountryCode);
43
+ if (originalCountryCode === modifiedCountryCode) {
44
+ return res;
45
+ }
46
+
47
+ res.message.push(`Modify 008/15-17: '${originalCountryCode}' => '${modifiedCountryCode}'`); // eslint-disable-line functional/immutable-data
48
+
49
+ res.valid = false; // eslint-disable-line functional/immutable-data
50
+ return res;
51
+ }
52
+
53
+ function fixCountryCode(field008) {
54
+ const originalCountryCode = getCountryCodeFromField008(field008);
55
+ const modifiedCountryCode = deprecatedCountryCodeToCurrentCountryCode(originalCountryCode);
56
+ if (originalCountryCode !== modifiedCountryCode && modifiedCountryCode.length === 3) {
57
+ field008.value = `${field008.value.substring(0, 15)}${modifiedCountryCode}${field008.value.substring(18)}`; // eslint-disable-line functional/immutable-data
58
+ return;
59
+ }
60
+ }
61
+
62
+ function getCountryCodeFromField008(field) {
63
+ return field.value.substring(15, 18); // return 008/15-17
64
+ }
65
+
66
+ function deprecatedCountryCodeToCurrentCountryCode(countryCode) {
67
+ if (countryCode === 'air') { // Armenia
68
+ return 'ai ';
69
+ }
70
+ if (countryCode === 'ajr') { // Azerbaidzan
71
+ return 'aj ';
72
+ }
73
+ // Australia
74
+ if (['aca', 'qua', 'tma', 'vra', 'wea', 'xga', 'xna', 'xoa', 'xra'].includes(countryCode)) {
75
+ return 'at ';
76
+ }
77
+
78
+ // Canada
79
+ if (['abc', 'bcc', 'cn ', 'mbc', 'nfc', 'nkc', 'nsc', 'ntc', 'nuc', 'onc', 'pic', 'quc', 'snc', 'ykc'].includes(countryCode)) {
80
+ return 'xxc';
81
+ }
82
+ // Great Britain:
83
+ if (['enk', 'nik', 'stk', 'uik', 'uk ', 'wlk'].includes(countryCode)) {
84
+ return 'xxk';
85
+ }
86
+ // United States:
87
+ if (['aku', 'alu', 'aru', 'azu', 'cau', 'cou', 'ctu', 'dcu', 'deu', 'flu', 'gau', 'hiu', 'iau', 'idu', 'ilu', 'inu', 'kgr', 'ksu', 'kyu', 'lau', 'mau', 'mdu', 'meu', 'miu', 'mnu', 'mou', 'msu', 'mtu', 'nbu', 'ncu', 'nhu', 'nju', 'nmu', 'nvu', 'nyu', 'ohu', 'oku', 'oru', 'pau', 'riu', 'scu', 'sdu', 'tnu', 'txu', 'us ', 'utu', 'vau', 'vtu', 'wau', 'wiu', 'wvu', 'wyu'].includes(countryCode)) {
88
+ return 'xxu';
89
+ }
90
+ return countryCode;
91
+ }
92
+
93
+ }
@@ -0,0 +1,52 @@
1
+ import {expect} from 'chai';
2
+ import {MarcRecord} from '@natlibfi/marc-record';
3
+ import validatorFactory from './fix-country-codes';
4
+ import {READERS} from '@natlibfi/fixura';
5
+ import generateTests from '@natlibfi/fixugen';
6
+ import createDebugLogger from 'debug';
7
+
8
+ generateTests({
9
+ callback,
10
+ path: [__dirname, '..', 'test-fixtures', 'fix-country-codes'],
11
+ useMetadataFile: true,
12
+ recurse: false,
13
+ fixura: {
14
+ reader: READERS.JSON
15
+ },
16
+ mocha: {
17
+ before: () => testValidatorFactory()
18
+ }
19
+ });
20
+ const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/fix-country-codestest');
21
+
22
+ async function testValidatorFactory() {
23
+ const validator = await validatorFactory();
24
+
25
+ expect(validator)
26
+ .to.be.an('object')
27
+ .that.has.any.keys('description', 'validate');
28
+
29
+ expect(validator.description).to.be.a('string');
30
+ expect(validator.validate).to.be.a('function');
31
+ }
32
+
33
+ async function callback({getFixture, enabled = true, fix = false}) {
34
+ if (enabled === false) {
35
+ debug('TEST SKIPPED!');
36
+ return;
37
+ }
38
+
39
+ const validator = await validatorFactory();
40
+ const record = new MarcRecord(getFixture('record.json'));
41
+ const expectedResult = getFixture('expectedResult.json');
42
+ // console.log(expectedResult); // eslint-disable-line
43
+
44
+ if (!fix) {
45
+ const result = await validator.validate(record);
46
+ expect(result).to.eql(expectedResult);
47
+ return;
48
+ }
49
+
50
+ await validator.fix(record);
51
+ expect(record).to.eql(expectedResult);
52
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "message": [
3
+ "TODO: '008 121110s2002 fi cb| | mk |fin |' => '008 121110s2002 fi bc |km |fin |'"
4
+ ],
5
+ "valid": false
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "description": "Validate BK 008/19-22 and 008/24-27",
3
+ "enabled": true,
4
+ "fix": false,
5
+ "only": false
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "leader": "01234cam8a22234564i 4500",
3
+ "fields": [
4
+ { "tag": "008", "value": "121110s2002 fi cb| | mk |fin |" }
5
+ ]
6
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "_validationOptions": {},
3
+ "leader": "01234cam8a22234564i 4500",
4
+ "fields": [
5
+ { "tag": "008", "value": "121110s2002 fi bc |km |fin |" }
6
+ ]
7
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "description": "Fix BK 008/19-22 and 008/24-27",
3
+ "enabled": true,
4
+ "fix": true,
5
+ "only": false
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "leader": "01234cam8a22234564i 4500",
3
+ "fields": [
4
+ { "tag": "008", "value": "121110s2002 fi cb| | mk |fin |" }
5
+ ]
6
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "_validationOptions": {},
3
+ "leader": "01234cas8a22234564i 4500",
4
+ "fields": [
5
+ { "tag": "008", "value": "121110s2002 fi cb| | km |fin |" }
6
+ ]
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "description": "Fix CR 008/19-22 and 008/25-27",
3
+ "comment": "TODO: handle 008/24 vs 008/25-27 later on",
4
+ "enabled": true,
5
+ "fix": true,
6
+ "only": false
7
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "leader": "01234cas8a22234564i 4500",
3
+ "fields": [
4
+ { "tag": "008", "value": "121110s2002 fi cb| | mk |fin |" }
5
+ ]
6
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "_validationOptions": {},
3
+ "leader": "01234cjm8a22234564i 4500",
4
+ "fields": [
5
+ { "tag": "008", "value": "121110s2002 fi ana fik z ||fin |" }
6
+ ]
7
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "description": "Fix MU 008/24-29 and 008/30-31",
3
+ "enabled": true,
4
+ "fix": true,
5
+ "only": false
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "leader": "01234cjm8a22234564i 4500",
3
+ "fields": [
4
+ { "tag": "008", "value": "121110s2002 fi ana |i f k z||fin |" }
5
+ ]
6
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "_validationOptions": {},
3
+ "leader": "01234cem8a22234564i 4500",
4
+ "fields": [
5
+ { "tag": "008", "value": "121110s2002 fi mc aa|a aa ||n fin |" }
6
+ ]
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "description": "Fix MP 008/18-21 and 008/33-34",
3
+ "comment": "Note that alphanumerical stuff comes in priority order and is not sorted",
4
+ "enabled": true,
5
+ "fix": true,
6
+ "only": false
7
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "leader": "01234cem8a22234564i 4500",
3
+ "fields": [
4
+ { "tag": "008", "value": "121110s2002 fi |m caa|a aa |||nfin |" }
5
+ ]
6
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "message" : [
3
+ ],
4
+ "valid": true
5
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "description": "Validate 008/15-17: nothing to do",
3
+ "enabled": true,
4
+ "fix": false,
5
+ "only": false
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "fields" : [
3
+ { "tag": "005", "value": "20220202020202.0" },
4
+ { "tag": "008", "value": "860616s1985 fi |||||||||||||||||swe||"}
5
+ ]
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "message": [
3
+ "Modify 008/15-17: 'azu' => 'xxu'"
4
+ ],
5
+ "valid": false
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "description": "Validate 008/15-17: azu -> xxu",
3
+ "enabled": true,
4
+ "fix": false,
5
+ "only": false
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "fields" : [
3
+ { "tag": "005", "value": "20220202020202.0" },
4
+ { "tag": "008", "value": "860616s1985 azu|||||||||||||||||swe||"}
5
+ ]
6
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "_validationOptions": {},
3
+ "leader": "",
4
+ "fields" : [
5
+ { "tag": "005", "value": "20220202020202.0" },
6
+ { "tag": "008", "value": "860616s1985 fi |||||||||||||||||swe||"}
7
+ ]
8
+
9
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "description": "Fix 008/15-17: nothing to do",
3
+ "enabled": true,
4
+ "fix": true,
5
+ "only": false
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "fields" : [
3
+ { "tag": "005", "value": "20220202020202.0" },
4
+ { "tag": "008", "value": "860616s1985 fi |||||||||||||||||swe||"}
5
+ ]
6
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "_validationOptions": {},
3
+ "leader": "",
4
+ "fields" : [
5
+ { "tag": "005", "value": "20220202020202.0" },
6
+ { "tag": "008", "value": "860616s1985 at |||||||||||||||||swe||"}
7
+ ]
8
+
9
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "description": "Fix 008/15-17: 'tma' => 'at#'",
3
+ "enabled": true,
4
+ "fix": true,
5
+ "only": false
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "fields" : [
3
+ { "tag": "005", "value": "20220202020202.0" },
4
+ { "tag": "008", "value": "860616s1985 tma|||||||||||||||||swe||"}
5
+ ]
6
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "_validationOptions": {},
3
+ "leader": "",
4
+ "fields" : [
5
+ { "tag": "005", "value": "20220202020202.0" }
6
+ ]
7
+
8
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "description": "Fix 008/15-17: sanity check against missing 008 field",
3
+ "enabled": true,
4
+ "fix": true,
5
+ "only": false
6
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "fields" : [
3
+ { "tag": "005", "value": "20220202020202.0" }
4
+ ]
5
+ }