@natlibfi/marc-record-validators-melinda 12.0.0-alpha.6 → 12.0.0-alpha.8

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.
@@ -171,6 +171,18 @@ function normalize245Indicator1(field, record) {
171
171
  field.ind1 = field1XX.length === 0 ? '0' : '1';
172
172
  }
173
173
 
174
+ function noDisplayConstantGenerated520Indicator1(field) {
175
+ if (field.tag !== '520') {
176
+ return;
177
+ }
178
+ const as = field.subfields.filter(sf => sf.code === 'a');
179
+ // Set ind1=8 "no display constant generated" fro certain values (part of MELKEHITYS-2579):
180
+ if (as.length === 1 && ['Abstract.', 'Abstrakt.', 'Abstrakti.', 'Abstract.', 'English Summary.', 'Sammandrag.', 'Tiivistelmä.'].includes(field.subfields[0].value)) {
181
+ field.ind1 = '8';
182
+ }
183
+
184
+ }
185
+
174
186
  function normalize776Indicator2(field) {
175
187
  if (field.tag !== '776') {
176
188
  return;
@@ -242,6 +254,7 @@ function recordNormalizeIndicators(record) {
242
254
  function fieldNormalizeIndicators(field, record, languages) {
243
255
  normalize084Indicator1(field);
244
256
  normalize245Indicator1(field, record);
257
+ noDisplayConstantGenerated520Indicator1(field);
245
258
  normalizeNonFilingIndicator1(field, languages);
246
259
  normalizeNonFilingIndicator2(field, languages);
247
260
  normalize776Indicator2(field);
@@ -2,7 +2,7 @@
2
2
 
3
3
  import {subfieldArraysContainSameData} from "../utils.js";
4
4
 
5
- function tagToDataProvenanceSubfieldCode(tag) {
5
+ export function tagToDataProvenanceSubfieldCode(tag) {
6
6
  if ( ['533', '800', '810', '811', '830'].includes(tag)) {
7
7
  return 'y';
8
8
  }
@@ -10,9 +10,10 @@
10
10
  * (They are jumped over when looking for next (non-controlfield subfield)
11
11
  */
12
12
  import {validateSingleField} from './ending-punctuation.js';
13
+ import {tagToDataProvenanceSubfieldCode} from './merge-fields/dataProvenance.js';
13
14
  import {fieldGetUnambiguousTag} from './subfield6Utils.js';
14
15
  //import createDebugLogger from 'debug';
15
- import {fieldToString, nvdebug} from './utils.js';
16
+ import {fieldToString, isControlSubfieldCode, nvdebug} from './utils.js';
16
17
  import clone from 'clone';
17
18
 
18
19
  //const debug = createDebugLogger('debug/punctuation2');
@@ -49,12 +50,19 @@ export default function () {
49
50
  }
50
51
  }
51
52
 
52
- function isControlSubfield(subfield) {
53
- return ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'].includes(subfield.code);
53
+
54
+
55
+ function isIrrelevantSubfield(subfield, tag) {
56
+ const dataProvenanceSubfieldCode = tagToDataProvenanceSubfieldCode(tag);
57
+ if (subfield.code === dataProvenanceSubfieldCode) {
58
+ return true;
59
+ }
60
+ return isControlSubfieldCode(subfield.code); // Currently this contains other stuff as well ($3, $4, $7, $9...)
54
61
  }
55
62
 
63
+
56
64
  function getNextRelevantSubfield(field, currSubfieldIndex) {
57
- return field.subfields.find((subfield, index) => index > currSubfieldIndex && !isControlSubfield(subfield));
65
+ return field.subfields.find((subfield, index) => index > currSubfieldIndex && !isIrrelevantSubfield(subfield, field.tag));
58
66
  }
59
67
 
60
68
  export function fieldGetFixedString(field, add = true) {
@@ -155,7 +163,8 @@ const remove490And830Whatever = [{'code': 'axyzv', 'followedBy': 'axyzv', 'remov
155
163
  const linkingEntryRemoveWhatever = [
156
164
  {'code': 'i', 'followedBy': 'at', 'remove': / ?:$/u}, // ':'
157
165
  {'code': 'at', 'remove': /\.$/u},
158
- {'code': 'abdghiklmnopqrstuwxyz', 'followedBy': 'abdghiklmnopqrstuwxyz', 'remove': /\. -$/u}
166
+ // Only ". -" separator is still used in music. We can strip it, but can only create the non-music punctuation!
167
+ {'code': 'abdghiklmnopqrstuwxyz', 'followedBy': 'abdghiklmnopqrstuwxyz#', 'remove': /\. -$/u}
159
168
  ];
160
169
 
161
170
 
@@ -1,9 +1,23 @@
1
1
  import assert from 'node:assert';
2
- import {MarcRecord} from '@natlibfi/marc-record';
2
+ import createDebugLogger from 'debug';
3
+ import fetchMock from 'fetch-mock';
4
+
3
5
  import validatorFactory from './translate-terms.js';
6
+
7
+ import {MarcRecord} from '@natlibfi/marc-record';
4
8
  import {READERS} from '@natlibfi/fixura';
5
9
  import generateTests from '@natlibfi/fixugen';
6
- import createDebugLogger from 'debug';
10
+ import {fakeData} from '../test-fixtures/translate-terms-data.js';
11
+
12
+ const uris = [
13
+ 'http://www.yso.fi/onto/yso/p13299',
14
+ 'http://www.yso.fi/onto/yso/p111739',
15
+ 'http://www.yso.fi/onto/yso/p6197061979',
16
+ 'http://www.yso.fi/onto/yso/p6196061969',
17
+ 'http://urn.fi/URN:NBN:fi:au:slm:s161'
18
+ ];
19
+
20
+
7
21
 
8
22
  generateTests({
9
23
  callback,
@@ -15,6 +29,15 @@ generateTests({
15
29
  },
16
30
  hooks: {
17
31
  before: async () => {
32
+
33
+ fetchMock.mockGlobal()
34
+ .get(`https://api.finto.fi/rest/v1/data?uri=${uris[0]}&format=application%2Fjson`, {status: 200, headers: {}, body: fakeData})
35
+ .get(`https://api.finto.fi/rest/v1/data?uri=${uris[1]}&format=application%2Fjson`, {status: 200, headers: {}, body: fakeData})
36
+ .get(`https://api.finto.fi/rest/v1/data?uri=${uris[2]}&format=application%2Fjson`, {status: 200, headers: {}, body: fakeData})
37
+ .get(`https://api.finto.fi/rest/v1/data?uri=${uris[3]}&format=application%2Fjson`, {status: 200, headers: {}, body: fakeData})
38
+ .get(`https://api.finto.fi/rest/v1/data?uri=${uris[4]}&format=application%2Fjson`, {status: 200, headers: {}, body: fakeData});
39
+
40
+
18
41
  testValidatorFactory();
19
42
  }
20
43
  }
package/src/utils.js CHANGED
@@ -103,6 +103,12 @@ export function nvdebugFieldArray(fields, prefix = ' ', func = undefined) {
103
103
  }
104
104
 
105
105
  export function isControlSubfieldCode(subfieldCode) {
106
+ // NB! Only $w, $0, $1, $5, $6 and $8 are really control subfields. In Finland $9 is oft a control subfield
107
+ // $3 material (part of the whole thing)
108
+ // $4 means 'relationship' (similar to relator terms at least in X00 and similar)
109
+ // $7 is usually provinance subfield. However, it can be stored in other subfields as well. See merge-fields/dataProvenance.js for details
110
+ // However, change this only if needed. Maybe all provinance subfields should return true?
111
+ // This may become relevant when AI starts to create stuff...
106
112
  if (['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'w'].includes(subfieldCode)) {
107
113
  return true;
108
114
  }
@@ -0,0 +1,11 @@
1
+ {
2
+ "_validationOptions": {},
3
+ "fields": [
4
+ { "tag": "005", "value": "20220202020202.0" },
5
+ { "tag": "520", "ind1": "8", "ind2": " ", "subfields": [ {"code": "a", "value": "Abstrakti."}, {"code": "9", "value": "TESTI<KEEP>"} ]},
6
+ { "tag": "520", "ind1": " ", "ind2": " ", "subfields": [ {"code": "a", "value": "Whatever."}]},
7
+ { "tag": "520", "ind1": "8", "ind2": " ", "subfields": [ {"code": "a", "value": "Tiivistelmä."}]}
8
+
9
+ ],
10
+ "leader": ""
11
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "description": "10: certain value have ind1=8 as per MELKEHITYS-2579",
3
+ "fix": true
4
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "_validationOptions": {},
3
+ "fields": [
4
+ { "tag": "005", "value": "20220202020202.0" },
5
+ { "tag": "520", "ind1": " ", "ind2": " ", "subfields": [ {"code": "a", "value": "Abstrakti."}, {"code": "9", "value": "TESTI<KEEP>"} ]},
6
+ { "tag": "520", "ind1": " ", "ind2": " ", "subfields": [ {"code": "a", "value": "Whatever."}]},
7
+ { "tag": "520", "ind1": "3", "ind2": " ", "subfields": [ {"code": "a", "value": "Tiivistelmä."}]}
8
+
9
+ ],
10
+ "leader": ""
11
+ }
@@ -0,0 +1,42 @@
1
+ const fakeTerms = {
2
+ graph: [
3
+ {
4
+ uri: 'http://www.yso.fi/onto/yso/p13299',
5
+ prefLabel: [
6
+ { lang: 'fi', value: 'laiturit' },
7
+ { lang: 'sv', value: 'bryggor'}
8
+ ]
9
+ },
10
+ {
11
+ uri: 'http://www.yso.fi/onto/yso/p111739',
12
+ prefLabel: [
13
+ { lang: 'fi', value: 'Ivalo (Inari)' },
14
+ { lang: 'sv', value: 'Ivalo (Enare)'}
15
+ ]
16
+ },
17
+ {
18
+ uri: 'http://www.yso.fi/onto/yso/p6197061979',
19
+ prefLabel: [
20
+ { lang: 'fi', value: '1970-luku' },
21
+ { lang: 'sv', value: '1970-talet' }
22
+ ]
23
+ },
24
+ {
25
+ uri: 'http://www.yso.fi/onto/yso/p6196061969',
26
+ prefLabel: [
27
+ { lang: 'fi', value: '1960-luku' },
28
+ { lang: 'sv', value: '1960-talet' }
29
+ ]
30
+ },
31
+ {
32
+ uri: 'http://urn.fi/URN:NBN:fi:au:slm:s161',
33
+ prefLabel: [
34
+ { lang: 'fi', value: 'naistenlehdet' },
35
+ { lang: 'sv', value: 'damtidningar' }
36
+ ]
37
+ }
38
+ ]
39
+
40
+ };
41
+
42
+ export const fakeData = JSON.stringify(fakeTerms);