@natlibfi/marc-record-validators-melinda 3.2.0 → 3.3.14-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.
- package/.github/CODEOWNERS +2 -0
- package/.github/dependabot.yml +40 -0
- package/.github/workflows/melinda-node-tests.yml +61 -0
- package/LICENSE.txt +21 -661
- package/README.md +4 -5
- package/dist/access-rights.js +94 -0
- package/dist/access-rights.js.map +1 -0
- package/dist/access-rights.spec.js +150 -0
- package/dist/access-rights.spec.js.map +1 -0
- package/dist/double-commas.js +17 -27
- package/dist/double-commas.js.map +1 -1
- package/dist/double-commas.spec.js +72 -27
- package/dist/double-commas.spec.js.map +1 -1
- package/dist/duplicates-ind1.js +47 -27
- package/dist/duplicates-ind1.js.map +1 -1
- package/dist/duplicates-ind1.spec.js +44 -27
- package/dist/duplicates-ind1.spec.js.map +1 -1
- package/dist/empty-fields.js +79 -29
- package/dist/empty-fields.js.map +1 -1
- package/dist/empty-fields.spec.js +113 -27
- package/dist/empty-fields.spec.js.map +1 -1
- package/dist/ending-punctuation-conf.js +772 -129
- package/dist/ending-punctuation-conf.js.map +1 -1
- package/dist/ending-punctuation.js +291 -72
- package/dist/ending-punctuation.js.map +1 -1
- package/dist/ending-punctuation.spec.js +2638 -118
- package/dist/ending-punctuation.spec.js.map +1 -1
- package/dist/ending-whitespace.js +58 -0
- package/dist/ending-whitespace.js.map +1 -0
- package/dist/ending-whitespace.spec.js +42 -0
- package/dist/ending-whitespace.spec.js.map +1 -0
- package/dist/field-521-fix.js +96 -0
- package/dist/field-521-fix.js.map +1 -0
- package/dist/field-521-fix.spec.js +51 -0
- package/dist/field-521-fix.spec.js.map +1 -0
- package/dist/field-exclusion.js +214 -63
- package/dist/field-exclusion.js.map +1 -1
- package/dist/field-exclusion.spec.js +1057 -31
- package/dist/field-exclusion.spec.js.map +1 -1
- package/dist/field-structure.js +249 -78
- package/dist/field-structure.js.map +1 -1
- package/dist/field-structure.spec.js +534 -31
- package/dist/field-structure.spec.js.map +1 -1
- package/dist/fields-present.js +31 -27
- package/dist/fields-present.js.map +1 -1
- package/dist/fields-present.spec.js +120 -27
- package/dist/fields-present.spec.js.map +1 -1
- package/dist/fixed-fields.js +72 -27
- package/dist/fixed-fields.js.map +1 -1
- package/dist/fixed-fields.spec.js +139 -27
- package/dist/fixed-fields.spec.js.map +1 -1
- package/dist/identical-fields.js +42 -28
- package/dist/identical-fields.js.map +1 -1
- package/dist/identical-fields.spec.js +98 -27
- package/dist/identical-fields.spec.js.map +1 -1
- package/dist/index.js +202 -27
- package/dist/index.js.map +1 -1
- package/dist/indicator-fixes.js +191 -0
- package/dist/indicator-fixes.js.map +1 -0
- package/dist/indicator-fixes.spec.js +51 -0
- package/dist/indicator-fixes.spec.js.map +1 -0
- package/dist/isbn-issn.js +266 -27
- package/dist/isbn-issn.js.map +1 -1
- package/dist/isbn-issn.spec.js +594 -27
- package/dist/isbn-issn.spec.js.map +1 -1
- package/dist/item-language.js +171 -27
- package/dist/item-language.js.map +1 -1
- package/dist/item-language.spec.js +305 -27
- package/dist/item-language.spec.js.map +1 -1
- package/dist/mergeField500Lisapainokset.js +155 -0
- package/dist/mergeField500Lisapainokset.js.map +1 -0
- package/dist/mergeField500Lisapainokset.spec.js +51 -0
- package/dist/mergeField500Lisapainokset.spec.js.map +1 -0
- package/dist/mergeRelatorTermFields.js +140 -0
- package/dist/mergeRelatorTermFields.js.map +1 -0
- package/dist/mergeRelatorTermFields.spec.js +51 -0
- package/dist/mergeRelatorTermFields.spec.js.map +1 -0
- package/dist/multiple-subfield-0.js +120 -0
- package/dist/multiple-subfield-0.js.map +1 -0
- package/dist/multiple-subfield-0.spec.js +51 -0
- package/dist/multiple-subfield-0.spec.js.map +1 -0
- package/dist/non-breaking-space.js +61 -0
- package/dist/non-breaking-space.js.map +1 -0
- package/dist/non-breaking-space.spec.js +42 -0
- package/dist/non-breaking-space.spec.js.map +1 -0
- package/dist/normalize-identifiers.js +210 -0
- package/dist/normalize-identifiers.js.map +1 -0
- package/dist/normalize-identifiers.spec.js +51 -0
- package/dist/normalize-identifiers.spec.js.map +1 -0
- package/dist/normalize-utf8-diacritics.js +140 -0
- package/dist/normalize-utf8-diacritics.js.map +1 -0
- package/dist/normalize-utf8-diacritics.spec.js +51 -0
- package/dist/normalize-utf8-diacritics.spec.js.map +1 -0
- package/dist/punctuation/index.js +281 -0
- package/dist/punctuation/index.js.map +1 -0
- package/dist/punctuation/rules/aut.js +332 -0
- package/dist/punctuation/rules/aut.js.map +1 -0
- package/dist/punctuation/rules/bib.js +374 -0
- package/dist/punctuation/rules/bib.js.map +1 -0
- package/dist/punctuation/rules/index.js +21 -0
- package/dist/punctuation/rules/index.js.map +1 -0
- package/dist/punctuation.spec.js +51 -0
- package/dist/punctuation.spec.js.map +1 -0
- package/dist/punctuation2.js +726 -0
- package/dist/punctuation2.js.map +1 -0
- package/dist/punctuation2.spec.js +51 -0
- package/dist/punctuation2.spec.js.map +1 -0
- package/dist/reindexSubfield6OccurenceNumbers.js +199 -0
- package/dist/reindexSubfield6OccurenceNumbers.js.map +1 -0
- package/dist/reindexSubfield6OccurenceNumbers.spec.js +51 -0
- package/dist/reindexSubfield6OccurenceNumbers.spec.js.map +1 -0
- package/dist/removeDuplicateDataFields.js +405 -0
- package/dist/removeDuplicateDataFields.js.map +1 -0
- package/dist/removeDuplicateDataFields.spec.js +51 -0
- package/dist/removeDuplicateDataFields.spec.js.map +1 -0
- package/dist/removeInferiorDataFields.js +245 -0
- package/dist/removeInferiorDataFields.js.map +1 -0
- package/dist/removeInferiorDataFields.spec.js +51 -0
- package/dist/removeInferiorDataFields.spec.js.map +1 -0
- package/dist/resolvable-ext-references-melinda.js +112 -31
- package/dist/resolvable-ext-references-melinda.js.map +1 -1
- package/dist/resolvable-ext-references-melinda.spec.js +166 -27
- package/dist/resolvable-ext-references-melinda.spec.js.map +1 -1
- package/dist/resolveOrphanedSubfield6s.js +116 -0
- package/dist/resolveOrphanedSubfield6s.js.map +1 -0
- package/dist/resolveOrphanedSubfield6s.spec.js +51 -0
- package/dist/resolveOrphanedSubfield6s.spec.js.map +1 -0
- package/dist/sanitize-vocabulary-source-codes.js +93 -0
- package/dist/sanitize-vocabulary-source-codes.js.map +1 -0
- package/dist/sanitize-vocabulary-source-codes.spec.js +51 -0
- package/dist/sanitize-vocabulary-source-codes.spec.js.map +1 -0
- package/dist/sort-tags.js +53 -27
- package/dist/sort-tags.js.map +1 -1
- package/dist/sort-tags.spec.js +206 -27
- package/dist/sort-tags.spec.js.map +1 -1
- package/dist/sortRelatorTerms.js +135 -0
- package/dist/sortRelatorTerms.js.map +1 -0
- package/dist/sortRelatorTerms.spec.js +51 -0
- package/dist/sortRelatorTerms.spec.js.map +1 -0
- package/dist/sortSubfields.js +279 -0
- package/dist/sortSubfields.js.map +1 -0
- package/dist/sortSubfields.spec.js +51 -0
- package/dist/sortSubfields.spec.js.map +1 -0
- package/dist/stripPunctuation.js +49 -0
- package/dist/stripPunctuation.js.map +1 -0
- package/dist/stripPunctuation.spec.js +51 -0
- package/dist/stripPunctuation.spec.js.map +1 -0
- package/dist/subfield-exclusion.js +174 -57
- package/dist/subfield-exclusion.js.map +1 -1
- package/dist/subfield-exclusion.spec.js +521 -31
- package/dist/subfield-exclusion.spec.js.map +1 -1
- package/dist/subfield6Utils.js +457 -0
- package/dist/subfield6Utils.js.map +1 -0
- package/dist/subfield8Utils.js +99 -0
- package/dist/subfield8Utils.js.map +1 -0
- package/dist/typeOfDate-008.js +48 -0
- package/dist/typeOfDate-008.js.map +1 -0
- package/dist/typeOfDate-008.spec.js +47 -0
- package/dist/typeOfDate-008.spec.js.map +1 -0
- package/dist/unicode-decomposition.js +139 -30
- package/dist/unicode-decomposition.js.map +1 -1
- package/dist/unicode-decomposition.spec.js +90 -27
- package/dist/unicode-decomposition.spec.js.map +1 -1
- package/dist/update-field-540.js +119 -0
- package/dist/update-field-540.js.map +1 -0
- package/dist/update-field-540.spec.js +51 -0
- package/dist/update-field-540.spec.js.map +1 -0
- package/dist/urn.js +185 -0
- package/dist/urn.js.map +1 -0
- package/dist/urn.spec.js +238 -0
- package/dist/urn.spec.js.map +1 -0
- package/dist/utils.js +58 -0
- package/dist/utils.js.map +1 -0
- package/package.json +114 -124
- package/src/access-rights.js +84 -0
- package/src/access-rights.spec.js +126 -0
- package/src/double-commas.js +12 -49
- package/src/double-commas.spec.js +50 -82
- package/src/duplicates-ind1.js +34 -74
- package/src/duplicates-ind1.spec.js +39 -117
- package/src/empty-fields.js +62 -74
- package/src/empty-fields.spec.js +134 -207
- package/src/ending-punctuation-conf.js +679 -644
- package/src/ending-punctuation.js +260 -250
- package/src/ending-punctuation.spec.js +2545 -2322
- package/src/ending-whitespace.js +40 -0
- package/src/ending-whitespace.spec.js +44 -0
- package/src/field-521-fix.js +92 -0
- package/src/field-521-fix.spec.js +52 -0
- package/src/field-exclusion.js +197 -215
- package/src/field-exclusion.spec.js +883 -481
- package/src/field-structure.js +213 -271
- package/src/field-structure.spec.js +597 -474
- package/src/fields-present.js +19 -49
- package/src/fields-present.spec.js +90 -91
- package/src/fixed-fields.js +61 -94
- package/src/fixed-fields.spec.js +81 -125
- package/src/identical-fields.js +29 -48
- package/src/identical-fields.spec.js +114 -146
- package/src/index.js +41 -46
- package/src/indicator-fixes.js +211 -0
- package/src/indicator-fixes.spec.js +52 -0
- package/src/isbn-issn.js +254 -106
- package/src/isbn-issn.spec.js +399 -172
- package/src/item-language.js +158 -195
- package/src/item-language.spec.js +314 -306
- package/src/mergeField500Lisapainokset.js +153 -0
- package/src/mergeField500Lisapainokset.spec.js +52 -0
- package/src/mergeRelatorTermFields.js +143 -0
- package/src/mergeRelatorTermFields.spec.js +52 -0
- package/src/multiple-subfield-0.js +129 -0
- package/src/multiple-subfield-0.spec.js +52 -0
- package/src/non-breaking-space.js +49 -0
- package/src/non-breaking-space.spec.js +44 -0
- package/src/normalize-identifiers.js +197 -0
- package/src/normalize-identifiers.spec.js +52 -0
- package/src/normalize-utf8-diacritics.js +141 -0
- package/src/normalize-utf8-diacritics.spec.js +52 -0
- package/src/punctuation/index.js +292 -0
- package/src/punctuation/rules/aut.js +372 -0
- package/src/punctuation/rules/bib.js +420 -0
- package/src/punctuation/rules/index.js +7 -0
- package/src/punctuation.spec.js +52 -0
- package/src/punctuation2.js +441 -0
- package/src/punctuation2.spec.js +52 -0
- package/src/reindexSubfield6OccurenceNumbers.js +210 -0
- package/src/reindexSubfield6OccurenceNumbers.spec.js +52 -0
- package/src/removeDuplicateDataFields.js +447 -0
- package/src/removeDuplicateDataFields.spec.js +52 -0
- package/src/removeInferiorDataFields.js +259 -0
- package/src/removeInferiorDataFields.spec.js +52 -0
- package/src/resolvable-ext-references-melinda.js +89 -122
- package/src/resolvable-ext-references-melinda.spec.js +168 -198
- package/src/resolveOrphanedSubfield6s.js +115 -0
- package/src/resolveOrphanedSubfield6s.spec.js +52 -0
- package/src/sanitize-vocabulary-source-codes.js +99 -0
- package/src/sanitize-vocabulary-source-codes.spec.js +52 -0
- package/src/sort-tags.js +34 -60
- package/src/sort-tags.spec.js +256 -290
- package/src/sortRelatorTerms.js +142 -0
- package/src/sortRelatorTerms.spec.js +52 -0
- package/src/sortSubfields.js +176 -0
- package/src/sortSubfields.spec.js +52 -0
- package/src/stripPunctuation.js +42 -0
- package/src/stripPunctuation.spec.js +52 -0
- package/src/subfield-exclusion.js +157 -180
- package/src/subfield-exclusion.spec.js +507 -453
- package/src/subfield6Utils.js +485 -0
- package/src/subfield8Utils.js +102 -0
- package/src/typeOfDate-008.js +40 -0
- package/src/typeOfDate-008.spec.js +47 -0
- package/src/unicode-decomposition.js +130 -145
- package/src/unicode-decomposition.spec.js +89 -115
- package/src/update-field-540.js +99 -0
- package/src/update-field-540.spec.js +52 -0
- package/src/urn.js +164 -0
- package/src/urn.spec.js +231 -0
- package/src/utils.js +52 -0
- package/test-fixtures/duplicates-ind1/01/expectedResult.json +4 -0
- package/test-fixtures/duplicates-ind1/01/metadata.json +4 -0
- package/test-fixtures/duplicates-ind1/01/record.json +16 -0
- package/test-fixtures/duplicates-ind1/02/expectedResult.json +6 -0
- package/test-fixtures/duplicates-ind1/02/metadata.json +4 -0
- package/test-fixtures/duplicates-ind1/02/record.json +16 -0
- package/test-fixtures/duplicates-ind1/03/expectedResult.json +13 -0
- package/test-fixtures/duplicates-ind1/03/metadata.json +6 -0
- package/test-fixtures/duplicates-ind1/03/record.json +16 -0
- package/test-fixtures/ending-whitespace/01/expectedResult.json +4 -0
- package/test-fixtures/ending-whitespace/01/metadata.json +6 -0
- package/test-fixtures/ending-whitespace/01/record.json +15 -0
- package/test-fixtures/ending-whitespace/02/expectedResult.json +4 -0
- package/test-fixtures/ending-whitespace/02/metadata.json +6 -0
- package/test-fixtures/ending-whitespace/02/record.json +15 -0
- package/test-fixtures/ending-whitespace/03/expectedResult.json +17 -0
- package/test-fixtures/ending-whitespace/03/metadata.json +6 -0
- package/test-fixtures/ending-whitespace/03/record.json +15 -0
- package/test-fixtures/ending-whitespace/04/expectedResult.json +10 -0
- package/test-fixtures/ending-whitespace/04/metadata.json +6 -0
- package/test-fixtures/ending-whitespace/04/record.json +8 -0
- package/test-fixtures/fix521/01/expectedResult.json +6 -0
- package/test-fixtures/fix521/01/metadata.json +5 -0
- package/test-fixtures/fix521/01/record.json +13 -0
- package/test-fixtures/fix521/02/expectedResult.json +15 -0
- package/test-fixtures/fix521/02/metadata.json +5 -0
- package/test-fixtures/fix521/02/record.json +13 -0
- package/test-fixtures/fix521/03/expectedResult.json +5 -0
- package/test-fixtures/fix521/03/metadata.json +5 -0
- package/test-fixtures/fix521/03/record.json +13 -0
- package/test-fixtures/indicator-fixes/01/expectedResult.json +9 -0
- package/test-fixtures/indicator-fixes/01/metadata.json +5 -0
- package/test-fixtures/indicator-fixes/01/record.json +64 -0
- package/test-fixtures/indicator-fixes/02/expectedResult.json +66 -0
- package/test-fixtures/indicator-fixes/02/metadata.json +5 -0
- package/test-fixtures/indicator-fixes/02/record.json +64 -0
- package/test-fixtures/indicator-fixes/03/expectedResult.json +55 -0
- package/test-fixtures/indicator-fixes/03/metadata.json +5 -0
- package/test-fixtures/indicator-fixes/03/record.json +54 -0
- package/test-fixtures/indicator-fixes/04/expectedResult.json +66 -0
- package/test-fixtures/indicator-fixes/04/metadata.json +5 -0
- package/test-fixtures/indicator-fixes/04/record.json +65 -0
- package/test-fixtures/indicator-fixes/05/expectedResult.json +66 -0
- package/test-fixtures/indicator-fixes/05/metadata.json +5 -0
- package/test-fixtures/indicator-fixes/05/record.json +65 -0
- package/test-fixtures/indicator-fixes/06/expectedResult.json +75 -0
- package/test-fixtures/indicator-fixes/06/metadata.json +5 -0
- package/test-fixtures/indicator-fixes/06/record.json +74 -0
- package/test-fixtures/lisapainokset/fixer/01/expectedResult.json +37 -0
- package/test-fixtures/lisapainokset/fixer/01/metadata.json +6 -0
- package/test-fixtures/lisapainokset/fixer/01/record.json +61 -0
- package/test-fixtures/lisapainokset/fixer/02/expectedResult.json +44 -0
- package/test-fixtures/lisapainokset/fixer/02/metadata.json +6 -0
- package/test-fixtures/lisapainokset/fixer/02/record.json +45 -0
- package/test-fixtures/lisapainokset/fixer/03/expectedResult.json +21 -0
- package/test-fixtures/lisapainokset/fixer/03/metadata.json +6 -0
- package/test-fixtures/lisapainokset/fixer/03/record.json +45 -0
- package/test-fixtures/lisapainokset/validator/01/expectedResult.json +7 -0
- package/test-fixtures/lisapainokset/validator/01/metadata.json +6 -0
- package/test-fixtures/lisapainokset/validator/01/record.json +45 -0
- package/test-fixtures/lisapainokset/validator/02/expectedResult.json +6 -0
- package/test-fixtures/lisapainokset/validator/02/metadata.json +6 -0
- package/test-fixtures/lisapainokset/validator/02/record.json +61 -0
- package/test-fixtures/lisapainokset/validator/03/expectedResult.json +4 -0
- package/test-fixtures/lisapainokset/validator/03/metadata.json +6 -0
- package/test-fixtures/lisapainokset/validator/03/record.json +37 -0
- package/test-fixtures/mergeRelatorTermFields/fixer/01/expectedResult.json +14 -0
- package/test-fixtures/mergeRelatorTermFields/fixer/01/metadata.json +6 -0
- package/test-fixtures/mergeRelatorTermFields/fixer/01/record.json +16 -0
- package/test-fixtures/mergeRelatorTermFields/fixer/02/expectedResult.json +17 -0
- package/test-fixtures/mergeRelatorTermFields/fixer/02/metadata.json +6 -0
- package/test-fixtures/mergeRelatorTermFields/fixer/02/record.json +23 -0
- package/test-fixtures/mergeRelatorTermFields/validator/01/expectedResult.json +6 -0
- package/test-fixtures/mergeRelatorTermFields/validator/01/metadata.json +6 -0
- package/test-fixtures/mergeRelatorTermFields/validator/01/record.json +16 -0
- package/test-fixtures/mergeRelatorTermFields/validator/02/expectedResult.json +4 -0
- package/test-fixtures/mergeRelatorTermFields/validator/02/metadata.json +6 -0
- package/test-fixtures/mergeRelatorTermFields/validator/02/record.json +16 -0
- package/test-fixtures/non-breaking-space/01/expectedResult.json +4 -0
- package/test-fixtures/non-breaking-space/01/metadata.json +6 -0
- package/test-fixtures/non-breaking-space/01/record.json +15 -0
- package/test-fixtures/non-breaking-space/02/expectedResult.json +4 -0
- package/test-fixtures/non-breaking-space/02/metadata.json +6 -0
- package/test-fixtures/non-breaking-space/02/record.json +15 -0
- package/test-fixtures/non-breaking-space/03/expectedResult.json +17 -0
- package/test-fixtures/non-breaking-space/03/metadata.json +6 -0
- package/test-fixtures/non-breaking-space/03/record.json +15 -0
- package/test-fixtures/non-breaking-space/04/expectedResult.json +21 -0
- package/test-fixtures/non-breaking-space/04/metadata.json +6 -0
- package/test-fixtures/non-breaking-space/04/record.json +19 -0
- package/test-fixtures/normalize-identifiers/01/expectedResult.json +8 -0
- package/test-fixtures/normalize-identifiers/01/metadata.json +5 -0
- package/test-fixtures/normalize-identifiers/01/record.json +81 -0
- package/test-fixtures/normalize-identifiers/02/expectedResult.json +92 -0
- package/test-fixtures/normalize-identifiers/02/metadata.json +5 -0
- package/test-fixtures/normalize-identifiers/02/record.json +92 -0
- package/test-fixtures/normalize-identifiers/03/expectedResult.json +63 -0
- package/test-fixtures/normalize-identifiers/03/metadata.json +5 -0
- package/test-fixtures/normalize-identifiers/03/record.json +61 -0
- package/test-fixtures/normalize-identifiers/04/expectedResult.json +79 -0
- package/test-fixtures/normalize-identifiers/04/metadata.json +5 -0
- package/test-fixtures/normalize-identifiers/04/record.json +77 -0
- package/test-fixtures/normalize-utf8-diacritics/01/expectedResult.json +7 -0
- package/test-fixtures/normalize-utf8-diacritics/01/metadata.json +5 -0
- package/test-fixtures/normalize-utf8-diacritics/01/record.json +39 -0
- package/test-fixtures/normalize-utf8-diacritics/02/expectedResult.json +41 -0
- package/test-fixtures/normalize-utf8-diacritics/02/metadata.json +5 -0
- package/test-fixtures/normalize-utf8-diacritics/02/record.json +39 -0
- package/test-fixtures/normalize-utf8-diacritics/03/expectedResult.json +5 -0
- package/test-fixtures/normalize-utf8-diacritics/03/metadata.json +5 -0
- package/test-fixtures/normalize-utf8-diacritics/03/record.json +37 -0
- package/test-fixtures/normalize-utf8-diacritics/04/expectedResult.json +41 -0
- package/test-fixtures/normalize-utf8-diacritics/04/metadata.json +5 -0
- package/test-fixtures/normalize-utf8-diacritics/04/record.json +39 -0
- package/test-fixtures/normalize-utf8-diacritics/05/expectedResult.json +41 -0
- package/test-fixtures/normalize-utf8-diacritics/05/metadata.json +5 -0
- package/test-fixtures/normalize-utf8-diacritics/05/record.json +41 -0
- package/test-fixtures/punctuation/01/expectedResult.json +3 -0
- package/test-fixtures/punctuation/01/metadata.json +4 -0
- package/test-fixtures/punctuation/01/record.json +18 -0
- package/test-fixtures/punctuation/02/expectedResult.json +3 -0
- package/test-fixtures/punctuation/02/metadata.json +4 -0
- package/test-fixtures/punctuation/02/record.json +18 -0
- package/test-fixtures/punctuation/03/expectedResult.json +21 -0
- package/test-fixtures/punctuation/03/metadata.json +5 -0
- package/test-fixtures/punctuation/03/record.json +19 -0
- package/test-fixtures/punctuation/04/expectedResult.json +21 -0
- package/test-fixtures/punctuation/04/metadata.json +5 -0
- package/test-fixtures/punctuation/04/record.json +19 -0
- package/test-fixtures/punctuation/05/expectedResult.json +44 -0
- package/test-fixtures/punctuation/05/metadata.json +5 -0
- package/test-fixtures/punctuation/05/record.json +42 -0
- package/test-fixtures/punctuation2/01/expectedResult.json +12 -0
- package/test-fixtures/punctuation2/01/metadata.json +6 -0
- package/test-fixtures/punctuation2/01/record.json +37 -0
- package/test-fixtures/punctuation2/02/expectedResult.json +4 -0
- package/test-fixtures/punctuation2/02/metadata.json +6 -0
- package/test-fixtures/punctuation2/02/record.json +14 -0
- package/test-fixtures/punctuation2/04/expectedResult.json +7 -0
- package/test-fixtures/punctuation2/04/metadata.json +6 -0
- package/test-fixtures/punctuation2/04/record.json +22 -0
- package/test-fixtures/punctuation2/05/expectedResult.json +6 -0
- package/test-fixtures/punctuation2/05/metadata.json +6 -0
- package/test-fixtures/punctuation2/05/record.json +12 -0
- package/test-fixtures/punctuation2/98/expectedResult.json +45 -0
- package/test-fixtures/punctuation2/98/metadata.json +6 -0
- package/test-fixtures/punctuation2/98/record.json +43 -0
- package/test-fixtures/punctuation2/99/expectedResult.json +15 -0
- package/test-fixtures/punctuation2/99/metadata.json +6 -0
- package/test-fixtures/punctuation2/99/record.json +14 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/f01/expectedResult.json +35 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/f01/metadata.json +6 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/f01/record.json +34 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/f02/expectedResult.json +53 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/f02/metadata.json +6 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/f02/record.json +51 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/f03/expectedResult.json +46 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/f03/metadata.json +7 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/f03/record.json +44 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/v01/expectedResult.json +6 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/v01/metadata.json +5 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/v01/record.json +31 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/v02/expectedResult.json +6 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/v02/metadata.json +6 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/v02/record.json +38 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/v03/expectedResult.json +6 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/v03/metadata.json +6 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/v03/record.json +30 -0
- package/test-fixtures/remove-duplicate-datafields/f01/expectedResult.json +35 -0
- package/test-fixtures/remove-duplicate-datafields/f01/metadata.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/f01/record.json +34 -0
- package/test-fixtures/remove-duplicate-datafields/f03/expectedResult.json +20 -0
- package/test-fixtures/remove-duplicate-datafields/f03/metadata.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/f03/record.json +33 -0
- package/test-fixtures/remove-duplicate-datafields/f03b/expectedResult.json +20 -0
- package/test-fixtures/remove-duplicate-datafields/f03b/metadata.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/f03b/record.json +35 -0
- package/test-fixtures/remove-duplicate-datafields/f03c/expectedResult.json +25 -0
- package/test-fixtures/remove-duplicate-datafields/f03c/metadata.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/f03c/record.json +43 -0
- package/test-fixtures/remove-duplicate-datafields/f04/expectedResult.json +31 -0
- package/test-fixtures/remove-duplicate-datafields/f04/metadata.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/f04/record.json +41 -0
- package/test-fixtures/remove-duplicate-datafields/f05/expectedResult.json +23 -0
- package/test-fixtures/remove-duplicate-datafields/f05/metadata.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/f05/record.json +29 -0
- package/test-fixtures/remove-duplicate-datafields/f06/expectedResult.json +24 -0
- package/test-fixtures/remove-duplicate-datafields/f06/metadata.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/f06/record.json +41 -0
- package/test-fixtures/remove-duplicate-datafields/f07/expectedResult.json +15 -0
- package/test-fixtures/remove-duplicate-datafields/f07/metadata.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/f07/record.json +21 -0
- package/test-fixtures/remove-duplicate-datafields/f08/expectedResult.json +21 -0
- package/test-fixtures/remove-duplicate-datafields/f08/metadata.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/f08/record.json +33 -0
- package/test-fixtures/remove-duplicate-datafields/f09/expectedResult.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/f09/metadata.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/f09/record.json +9 -0
- package/test-fixtures/remove-duplicate-datafields/f10/expectedResult.json +15 -0
- package/test-fixtures/remove-duplicate-datafields/f10/metadata.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/f10/record.json +24 -0
- package/test-fixtures/remove-duplicate-datafields/f11/expectedResult.json +30 -0
- package/test-fixtures/remove-duplicate-datafields/f11/metadata.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/f11/record.json +53 -0
- package/test-fixtures/remove-duplicate-datafields/v01/expectedResult.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/v01/metadata.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/v01/record.json +31 -0
- package/test-fixtures/remove-duplicate-datafields/v02/expectedResult.json +10 -0
- package/test-fixtures/remove-duplicate-datafields/v02/metadata.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/v02/record.json +45 -0
- package/test-fixtures/remove-duplicate-datafields/v03/expectedResult.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/v03/metadata.json +7 -0
- package/test-fixtures/remove-duplicate-datafields/v03/record.json +37 -0
- package/test-fixtures/remove-duplicate-datafields/v04/expectedResult.json +8 -0
- package/test-fixtures/remove-duplicate-datafields/v04/metadata.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/v04/record.json +41 -0
- package/test-fixtures/remove-inferior-datafields/f01/expectedResult.json +21 -0
- package/test-fixtures/remove-inferior-datafields/f01/metadata.json +6 -0
- package/test-fixtures/remove-inferior-datafields/f01/record.json +31 -0
- package/test-fixtures/remove-inferior-datafields/f03/expectedResult.json +16 -0
- package/test-fixtures/remove-inferior-datafields/f03/metadata.json +6 -0
- package/test-fixtures/remove-inferior-datafields/f03/record.json +27 -0
- package/test-fixtures/remove-inferior-datafields/f04/expectedResult.json +31 -0
- package/test-fixtures/remove-inferior-datafields/f04/metadata.json +6 -0
- package/test-fixtures/remove-inferior-datafields/f04/record.json +38 -0
- package/test-fixtures/remove-inferior-datafields/f05/expectedResult.json +34 -0
- package/test-fixtures/remove-inferior-datafields/f05/metadata.json +6 -0
- package/test-fixtures/remove-inferior-datafields/f05/record.json +41 -0
- package/test-fixtures/remove-inferior-datafields/f06/expectedResult.json +16 -0
- package/test-fixtures/remove-inferior-datafields/f06/metadata.json +6 -0
- package/test-fixtures/remove-inferior-datafields/f06/record.json +20 -0
- package/test-fixtures/remove-inferior-datafields/v01/expectedResult.json +6 -0
- package/test-fixtures/remove-inferior-datafields/v01/metadata.json +6 -0
- package/test-fixtures/remove-inferior-datafields/v01/record.json +31 -0
- package/test-fixtures/remove-inferior-datafields/v02/expectedResult.json +6 -0
- package/test-fixtures/remove-inferior-datafields/v02/metadata.json +6 -0
- package/test-fixtures/remove-inferior-datafields/v02/record.json +21 -0
- package/test-fixtures/remove-orphanded-sf6s/f01/expectedResult.json +35 -0
- package/test-fixtures/remove-orphanded-sf6s/f01/metadata.json +6 -0
- package/test-fixtures/remove-orphanded-sf6s/f01/record.json +34 -0
- package/test-fixtures/remove-orphanded-sf6s/f02/expectedResult.json +40 -0
- package/test-fixtures/remove-orphanded-sf6s/f02/metadata.json +6 -0
- package/test-fixtures/remove-orphanded-sf6s/f02/record.json +43 -0
- package/test-fixtures/remove-orphanded-sf6s/v01/expectedResult.json +6 -0
- package/test-fixtures/remove-orphanded-sf6s/v01/metadata.json +6 -0
- package/test-fixtures/remove-orphanded-sf6s/v01/record.json +31 -0
- package/test-fixtures/remove-orphanded-sf6s/v02/expectedResult.json +6 -0
- package/test-fixtures/remove-orphanded-sf6s/v02/metadata.json +6 -0
- package/test-fixtures/remove-orphanded-sf6s/v02/record.json +31 -0
- package/test-fixtures/resolvable-ext-references-melinda.js +0 -27
- package/test-fixtures/sanitize-vocabulary-source-codes/f01/expectedResult.json +32 -0
- package/test-fixtures/sanitize-vocabulary-source-codes/f01/metadata.json +6 -0
- package/test-fixtures/sanitize-vocabulary-source-codes/f01/record.json +32 -0
- package/test-fixtures/sanitize-vocabulary-source-codes/f02/expectedResult.json +24 -0
- package/test-fixtures/sanitize-vocabulary-source-codes/f02/metadata.json +6 -0
- package/test-fixtures/sanitize-vocabulary-source-codes/f02/record.json +24 -0
- package/test-fixtures/sanitize-vocabulary-source-codes/v01/expectedResult.json +12 -0
- package/test-fixtures/sanitize-vocabulary-source-codes/v01/metadata.json +6 -0
- package/test-fixtures/sanitize-vocabulary-source-codes/v01/record.json +24 -0
- package/test-fixtures/sort-relator-terms/f01/expectedResult.json +23 -0
- package/test-fixtures/sort-relator-terms/f01/metadata.json +6 -0
- package/test-fixtures/sort-relator-terms/f01/record.json +22 -0
- package/test-fixtures/sort-relator-terms/f02/expectedResult.json +26 -0
- package/test-fixtures/sort-relator-terms/f02/metadata.json +6 -0
- package/test-fixtures/sort-relator-terms/f02/record.json +22 -0
- package/test-fixtures/sort-relator-terms/v01/expectedResult.json +5 -0
- package/test-fixtures/sort-relator-terms/v01/metadata.json +6 -0
- package/test-fixtures/sort-relator-terms/v01/record.json +22 -0
- package/test-fixtures/sort-relator-terms/v02/expectedResult.json +6 -0
- package/test-fixtures/sort-relator-terms/v02/metadata.json +6 -0
- package/test-fixtures/sort-relator-terms/v02/record.json +14 -0
- package/test-fixtures/sort-subfields/f01/expectedResult.json +24 -0
- package/test-fixtures/sort-subfields/f01/metadata.json +6 -0
- package/test-fixtures/sort-subfields/f01/record.json +20 -0
- package/test-fixtures/sort-subfields/v01/expectedResult.json +5 -0
- package/test-fixtures/sort-subfields/v01/metadata.json +6 -0
- package/test-fixtures/sort-subfields/v01/record.json +24 -0
- package/test-fixtures/sort-subfields/v02/expectedResult.json +6 -0
- package/test-fixtures/sort-subfields/v02/metadata.json +6 -0
- package/test-fixtures/sort-subfields/v02/record.json +8 -0
- package/test-fixtures/strip-punctuation/01/expectedResult.json +12 -0
- package/test-fixtures/strip-punctuation/01/metadata.json +6 -0
- package/test-fixtures/strip-punctuation/01/record.json +37 -0
- package/test-fixtures/strip-punctuation/02/expectedResult.json +4 -0
- package/test-fixtures/strip-punctuation/02/metadata.json +6 -0
- package/test-fixtures/strip-punctuation/02/record.json +14 -0
- package/test-fixtures/strip-punctuation/04/expectedResult.json +6 -0
- package/test-fixtures/strip-punctuation/04/metadata.json +6 -0
- package/test-fixtures/strip-punctuation/04/record.json +22 -0
- package/test-fixtures/strip-punctuation/05/expectedResult.json +6 -0
- package/test-fixtures/strip-punctuation/05/metadata.json +6 -0
- package/test-fixtures/strip-punctuation/05/record.json +12 -0
- package/test-fixtures/strip-punctuation/98/expectedResult.json +44 -0
- package/test-fixtures/strip-punctuation/98/metadata.json +6 -0
- package/test-fixtures/strip-punctuation/98/record.json +45 -0
- package/test-fixtures/strip-punctuation/99/expectedResult.json +16 -0
- package/test-fixtures/strip-punctuation/99/metadata.json +6 -0
- package/test-fixtures/strip-punctuation/99/record.json +16 -0
- package/test-fixtures/subfield0/f01/expectedResult.json +25 -0
- package/test-fixtures/subfield0/f01/metadata.json +6 -0
- package/test-fixtures/subfield0/f01/record.json +23 -0
- package/test-fixtures/subfield0/f02/expectedResult.json +35 -0
- package/test-fixtures/subfield0/f02/metadata.json +6 -0
- package/test-fixtures/subfield0/f02/record.json +41 -0
- package/test-fixtures/subfield0/f03/expectedResult.json +21 -0
- package/test-fixtures/subfield0/f03/metadata.json +7 -0
- package/test-fixtures/subfield0/f03/record.json +24 -0
- package/test-fixtures/subfield0/v01/expectedResult.json +4 -0
- package/test-fixtures/subfield0/v01/metadata.json +6 -0
- package/test-fixtures/subfield0/v01/record.json +23 -0
- package/test-fixtures/subfield0/v02/expectedResult.json +9 -0
- package/test-fixtures/subfield0/v02/metadata.json +6 -0
- package/test-fixtures/subfield0/v02/record.json +38 -0
- package/test-fixtures/typeOfDate-008/01/expectedResult.json +3 -0
- package/test-fixtures/typeOfDate-008/01/metadata.json +4 -0
- package/test-fixtures/typeOfDate-008/01/record.json +14 -0
- package/test-fixtures/typeOfDate-008/02/expectedResult.json +4 -0
- package/test-fixtures/typeOfDate-008/02/metadata.json +4 -0
- package/test-fixtures/typeOfDate-008/02/record.json +14 -0
- package/test-fixtures/typeOfDate-008/03/expectedResult.json +14 -0
- package/test-fixtures/typeOfDate-008/03/metadata.json +5 -0
- package/test-fixtures/typeOfDate-008/03/record.json +14 -0
- package/test-fixtures/typeOfDate-008/04/expectedResult.json +14 -0
- package/test-fixtures/typeOfDate-008/04/metadata.json +5 -0
- package/test-fixtures/typeOfDate-008/04/record.json +14 -0
- package/test-fixtures/typeOfDate-008/05/expectedResult.json +14 -0
- package/test-fixtures/typeOfDate-008/05/metadata.json +5 -0
- package/test-fixtures/typeOfDate-008/05/record.json +14 -0
- package/test-fixtures/update-field-540/f01/expectedResult.json +23 -0
- package/test-fixtures/update-field-540/f01/metadata.json +6 -0
- package/test-fixtures/update-field-540/f01/record.json +23 -0
- package/test-fixtures/update-field-540/v01/expectedResult.json +7 -0
- package/test-fixtures/update-field-540/v01/metadata.json +6 -0
- package/test-fixtures/update-field-540/v01/record.json +23 -0
- package/.travis.yml +0 -10
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* punctuation.js -- try and fix a marc field punctuation
|
|
3
|
+
*
|
|
4
|
+
* Author(s): Nicholas Volk <nicholas.volk@helsinki.fi>
|
|
5
|
+
*
|
|
6
|
+
* NOTE #1: https://www.kiwi.fi/display/kumea/Loppupisteohje is implemented via another validator/fixer (ending-punctuation).
|
|
7
|
+
* This file has some support but it's now yet thorough. (And mmight never be.)
|
|
8
|
+
* NOTE #2: Validator/fixer punctuation does similar stuff, but focuses on X00 fields.
|
|
9
|
+
* NOTE #3: As of 2023-06-05 control subfields ($0...$9) are obsolete. Don't use them in rules.
|
|
10
|
+
* (They are jumped over when looking for next (non-controlfield subfield)
|
|
11
|
+
*/
|
|
12
|
+
import {validateSingleField} from './ending-punctuation';
|
|
13
|
+
// import createDebugLogger from 'debug';
|
|
14
|
+
import {fieldToString, nvdebug} from './utils';
|
|
15
|
+
import clone from 'clone';
|
|
16
|
+
|
|
17
|
+
// const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/punctuation2');
|
|
18
|
+
|
|
19
|
+
export default function () {
|
|
20
|
+
return {
|
|
21
|
+
description: 'Add punctuation to data fields',
|
|
22
|
+
validate, fix
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
function fix(record) {
|
|
26
|
+
nvdebug('Add punctuation to data fields: fixer');
|
|
27
|
+
const res = {message: [], fix: [], valid: true};
|
|
28
|
+
record.fields.forEach(f => fieldFixPunctuation(f));
|
|
29
|
+
return res;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function validate(record) {
|
|
33
|
+
nvdebug('Add punctuation to data fields: validate');
|
|
34
|
+
|
|
35
|
+
const fieldsNeedingModification = record.fields.filter(f => fieldNeedsModification(f, true));
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
const values = fieldsNeedingModification.map(f => fieldToString(f));
|
|
39
|
+
const newValues = fieldsNeedingModification.map(f => fieldGetFixedString(f, true));
|
|
40
|
+
|
|
41
|
+
const messages = values.map((val, i) => `'${val}' => '${newValues[i]}'`);
|
|
42
|
+
|
|
43
|
+
const res = {message: messages};
|
|
44
|
+
|
|
45
|
+
res.valid = res.message.length < 1; // eslint-disable-line functional/immutable-data
|
|
46
|
+
return res;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function isControlSubfield(subfield) {
|
|
51
|
+
return ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'].includes(subfield.code);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function getNextRelevantSubfield(field, currSubfieldIndex) {
|
|
55
|
+
return field.subfields.find((subfield, index) => index > currSubfieldIndex && !isControlSubfield(subfield));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function fieldGetFixedString(field, add = true) {
|
|
59
|
+
const cloneField = clone(field);
|
|
60
|
+
const operation = add ? subfieldFixPunctuation : subfieldStripPunctuation;
|
|
61
|
+
cloneField.subfields.forEach((sf, i) => {
|
|
62
|
+
// NB! instead of next subfield, we should actually get next *non-control-subfield*!!!
|
|
63
|
+
// (In plain English: We should skip $0 - $9 at least, maybe $w as well...)
|
|
64
|
+
operation(cloneField, sf, getNextRelevantSubfield(cloneField, i));
|
|
65
|
+
});
|
|
66
|
+
return fieldToString(cloneField);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function fieldNeedsModification(field, add = true) {
|
|
70
|
+
if (!field.subfields) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const originalFieldAsString = fieldToString(field);
|
|
75
|
+
const modifiedFieldAsString = fieldGetFixedString(field, add);
|
|
76
|
+
|
|
77
|
+
return modifiedFieldAsString !== originalFieldAsString;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/////////////////////////////////////////////////////////////////////////////////////
|
|
81
|
+
// <= Above code is written for the validator logic <= //
|
|
82
|
+
// => Everything below was originally transferred from reducers' punctuation.js => //
|
|
83
|
+
/////////////////////////////////////////////////////////////////////////////////////
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
//const stripCrap = / *[-;:,+]+$/u;
|
|
87
|
+
const commaNeedsPuncAfter = /(?:[a-z0-9A-Z]|å|ä|ö|Å|Ä|Ö|\))$/u;
|
|
88
|
+
const defaultNeedsPuncAfter = /(?:[a-z0-9A-Z]|å|ä|ö|Å|Ä|Ö)$/u;
|
|
89
|
+
const defaultNeedsPuncAfter2 = /(?:[\]a-zA-Z0-9)]|ä|å|ö|Å|Ä|Ö)$/u;
|
|
90
|
+
const blocksPuncRHS = /^(?:\()/u;
|
|
91
|
+
const allowsPuncRHS = /^(?:[A-Za-z0-9]|å|ä|ö|Å|Ä|Ö)/u;
|
|
92
|
+
|
|
93
|
+
const dotIsProbablyPunc = /(?:[a-z0-9)]|å|ä|ö)\.$/u;
|
|
94
|
+
const puncIsProbablyPunc = /(?:[a-z0-9)]|å|ä|ö) ?[.,:;]$/u;
|
|
95
|
+
// NB! 65X: Finnish terms don't use punctuation, but international ones do. Neither one is currently (2021-11-08) coded here.
|
|
96
|
+
|
|
97
|
+
// Will unfortunately trigger "Sukunimi, Th." type:
|
|
98
|
+
const removeColons = {'code': 'abcdefghijklmnopqrstuvwxyz', 'remove': / *[;:]$/u};
|
|
99
|
+
const removeX00Comma = {'code': 'abcqde', 'followedBy': 'abcqde#', 'context': /.,$/u, 'remove': /,$/u};
|
|
100
|
+
const cleanRHS = {'code': 'abcd', 'followedBy': 'bcde', 'context': /(?:(?:[a-z0-9]|å|ä|ö)\.|,)$/u, 'contextRHS': blocksPuncRHS, 'remove': /[.,]$/u};
|
|
101
|
+
const cleanX00dCommaOrDot = {'code': 'd', 'followedBy': 'et#', 'context': /[0-9]-[,.]$/u, 'remove': /[,.]$/u};
|
|
102
|
+
const cleanX00aDot = {'code': 'abcde', 'followedBy': 'cdegj', 'context': dotIsProbablyPunc, 'remove': /\.$/u};
|
|
103
|
+
const cleanCorruption = {'code': 'abcdefghijklmnopqrstuvwxyz', 'remove': / \.$/u};
|
|
104
|
+
// These $e dot removals are tricky: before removing the comma, we should know that it ain't an abbreviation such as "esitt."...
|
|
105
|
+
const cleanX00eDot = {'code': 'e', 'followedBy': 'egj#', 'context': /(?:[ai]ja|jä)[.,]$/u, 'remove': /\.$/u};
|
|
106
|
+
|
|
107
|
+
const X00RemoveDotAfterBracket = {'code': 'cq', 'context': /\)\.$/u, 'remove': /\.$/u};
|
|
108
|
+
// 390, 800, 810, 830...
|
|
109
|
+
const cleanPuncBeforeLanguage = {'code': 'atvxyz', 'followedBy': 'l', 'context': puncIsProbablyPunc, 'remove': / *[.,:;]$/u};
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
const addX00aComma = {'add': ',', 'code': 'abcqdej', 'followedBy': 'cdeg', 'context': commaNeedsPuncAfter, 'contextRHS': allowsPuncRHS};
|
|
113
|
+
const addX00aComma2 = {'add': ',', 'code': 'abcdej', 'followedBy': 'cdeg', 'context': /(?:[A-Z]|Å|Ä|Ö)\.$/u, 'contextRHS': allowsPuncRHS};
|
|
114
|
+
const addX00aDot = {'add': '.', 'code': 'abcde', 'followedBy': '#tu', 'context': defaultNeedsPuncAfter};
|
|
115
|
+
|
|
116
|
+
const addX10bDot = {'name': 'Add X10 pre-$b dot', 'add': '.', 'code': 'ab', 'followedBy': 'b', 'context': defaultNeedsPuncAfter};
|
|
117
|
+
const addX10eComma = {'add': ',', 'code': 'abe', 'followedBy': 'e', 'context': defaultNeedsPuncAfter};
|
|
118
|
+
const addX10Dot = {'name': 'Add X10 final dot', 'add': '.', 'code': 'abe', 'followedBy': '#', 'context': defaultNeedsPuncAfter};
|
|
119
|
+
const addLanguageComma = {'name': 'Add comma before 810$l', 'add': ',', 'code': 'tv', 'followedBy': 'l', 'context': defaultNeedsPuncAfter2};
|
|
120
|
+
const addColonToRelationshipInformation = {'name': 'Add \':\' to 7X0 $i relationship info', 'add': ':', 'code': 'i', 'context': /[a-z)åäö]$/u};
|
|
121
|
+
|
|
122
|
+
// 490:
|
|
123
|
+
const addSemicolonBeforeVolumeDesignation = {'name': 'Add " ;" before $v', 'add': ' ;', 'code': 'atxy', 'followedBy': 'v', 'context': /[^;]$/u};
|
|
124
|
+
|
|
125
|
+
const NONE = 0;
|
|
126
|
+
const ADD = 2;
|
|
127
|
+
const REMOVE = 1;
|
|
128
|
+
const REMOVE_AND_ADD = 3;
|
|
129
|
+
|
|
130
|
+
// Crappy punctuation consists of various crap that is somewhat common.
|
|
131
|
+
// We strip crap for merge decisions. We are not trying to actively remove crap here.
|
|
132
|
+
|
|
133
|
+
const removeX00Whatever = [removeX00Comma, cleanX00aDot, cleanX00eDot, cleanCorruption, cleanX00dCommaOrDot, cleanRHS, X00RemoveDotAfterBracket, removeColons, cleanPuncBeforeLanguage];
|
|
134
|
+
const removeX10Whatever = [removeX00Comma, cleanX00aDot, cleanX00eDot, cleanCorruption, removeColons, cleanPuncBeforeLanguage];
|
|
135
|
+
|
|
136
|
+
const cleanCrappyPunctuationRules = {
|
|
137
|
+
'100': removeX00Whatever,
|
|
138
|
+
'110': removeX10Whatever,
|
|
139
|
+
'600': removeX00Whatever,
|
|
140
|
+
'610': removeX10Whatever,
|
|
141
|
+
'700': removeX00Whatever,
|
|
142
|
+
'710': removeX10Whatever,
|
|
143
|
+
'800': removeX00Whatever,
|
|
144
|
+
'810': removeX10Whatever,
|
|
145
|
+
'245': [
|
|
146
|
+
{'code': 'ab', 'followedBy': '!c', 'remove': / \/$/u},
|
|
147
|
+
{'code': 'abc', 'followedBy': '#', 'remove': /\.$/u, 'context': dotIsProbablyPunc}
|
|
148
|
+
],
|
|
149
|
+
'300': [
|
|
150
|
+
{'code': 'a', 'followedBy': '!b', 'remove': / *:$/u},
|
|
151
|
+
{'code': 'a', 'followedBy': 'b', 'remove': /:$/u, 'context': /[^ ]:$/u},
|
|
152
|
+
{'code': 'ab', 'followedBy': '!c', 'remove': / *;$/u},
|
|
153
|
+
{'code': 'ab', 'followedBy': 'c', 'remove': /;$/u, 'context': /[^ ];$/u},
|
|
154
|
+
{'code': 'abc', 'followedBy': '!e', 'remove': / *\+$/u} // Removes both valid (with one space) and invalid (spaceless et al) puncs
|
|
155
|
+
|
|
156
|
+
],
|
|
157
|
+
'490': [{'code': 'a', 'followedBy': 'xy', 'remove': / ;$/u}],
|
|
158
|
+
'773': [{'code': 'abdghiklmnopqrstuwxyz', 'followedBy': 'abdghiklmnopqrstuwxyz', 'remove': /\. -$/u}]
|
|
159
|
+
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const cleanLegalX00Comma = {'code': 'abcde', 'followedBy': 'cdegj', 'context': /.,$/u, 'remove': /,$/u};
|
|
163
|
+
// Accept upper case letters in X00$b, since they are probably Roman numerals.
|
|
164
|
+
const cleanLegalX00bDot = {'code': 'b', 'followedBy': 't#', context: /^[IVXLCDM]+\.$/u, 'remove': /\.$/u};
|
|
165
|
+
const cleanLegalX00Dot = {'code': 'abcdetvl', 'followedBy': 'tu#', 'context': /(?:[a-z0-9)]|å|ä|ö)\.$/u, 'remove': /\.$/u};
|
|
166
|
+
const cleanLanguageComma = {'name': 'language comma', 'code': 'tv', 'followedBy': 'l', 'context': /.,$/u, 'remove': /,$/u};
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
const legalX00punc = [cleanLegalX00Comma, cleanLegalX00bDot, cleanLegalX00Dot, cleanLanguageComma];
|
|
170
|
+
|
|
171
|
+
const cleanLegalX10Comma = {'name': 'X10comma', 'code': 'abe', 'followedBy': 'e', 'context': /.,$/u, 'remove': /,$/u};
|
|
172
|
+
const cleanLegalX10Dot = {'name': 'X10dot', 'code': 'ab', 'followedBy': 'b#', 'context': /.\.$/u, 'remove': /\.$/u};
|
|
173
|
+
|
|
174
|
+
const legalX10punc = [cleanLegalX10Comma, cleanLegalX10Dot, cleanX00eDot, cleanLanguageComma];
|
|
175
|
+
|
|
176
|
+
const cleanValidPunctuationRules = {
|
|
177
|
+
'100': legalX00punc,
|
|
178
|
+
'110': legalX10punc,
|
|
179
|
+
'600': legalX00punc,
|
|
180
|
+
'610': legalX10punc,
|
|
181
|
+
'700': legalX00punc,
|
|
182
|
+
'710': legalX10punc,
|
|
183
|
+
'800': legalX00punc,
|
|
184
|
+
'810': legalX10punc,
|
|
185
|
+
'245': [
|
|
186
|
+
{'name': 'A:B', 'code': 'a', 'followedBy': 'b', 'remove': / [:;=]$/u},
|
|
187
|
+
{'name': 'AB:K', 'code': 'ab', 'followedBy': 'k', 'remove': / :$/u},
|
|
188
|
+
{'name': 'ABK:F', 'code': 'abk', 'followedBy': 'f', 'remove': /,$/u},
|
|
189
|
+
{'name': 'ABFNP:C', 'code': 'abfnp', 'followedBy': 'c', 'remove': / \/$/u},
|
|
190
|
+
{'name': 'ABN:N', 'code': 'abn', 'followedBy': 'n', 'remove': /\.$/u},
|
|
191
|
+
{'name': 'ABNP:#', 'code': 'abnp', 'followedBy': '#', 'remove': /\.$/u},
|
|
192
|
+
{'name': 'N:P', 'code': 'n', 'followedBy': 'p', 'remove': /,$/u}
|
|
193
|
+
|
|
194
|
+
],
|
|
195
|
+
'260': [
|
|
196
|
+
{'code': 'a', 'followedBy': 'b', 'remove': / :$/u},
|
|
197
|
+
{'code': 'b', 'followedBy': 'c', 'remove': /,$/u},
|
|
198
|
+
{'code': 'c', 'followedBy': '#', 'remove': /\.$/u},
|
|
199
|
+
{'code': 'd', 'followedBy': 'e', 'remove': / :$/u},
|
|
200
|
+
{'code': 'e', 'followedBy': 'f', 'remove': /,$/u},
|
|
201
|
+
{'code': 'f', 'followedBy': '#', 'remove': /\.$/u} // Probably ')' but shouldit be removed?
|
|
202
|
+
],
|
|
203
|
+
'264': [
|
|
204
|
+
{'code': 'a', 'followedBy': 'b', 'remove': / :$/u},
|
|
205
|
+
{'code': 'b', 'followedBy': 'c', 'remove': /,$/u},
|
|
206
|
+
{'code': 'c', 'followedBy': '#', 'remove': /\.$/u}
|
|
207
|
+
],
|
|
208
|
+
'300': [
|
|
209
|
+
// NB! Remove crap as well, thus the '*' in / *:$/
|
|
210
|
+
{'code': 'a', 'followedBy': 'b', 'remove': / :$/u},
|
|
211
|
+
{'code': 'ab', 'followedBy': 'c', 'remove': / ;$/u},
|
|
212
|
+
{'code': 'abc', 'followedBy': 'e', 'remove': / \+$/u}
|
|
213
|
+
],
|
|
214
|
+
'490': [
|
|
215
|
+
{'code': 'axy', 'followedBy': 'xy', 'remove': /,$/u},
|
|
216
|
+
{'code': 'axy', 'followedBy': 'v', 'remove': / *;$/u}
|
|
217
|
+
],
|
|
218
|
+
'534': [{'code': 'p', 'followedBy': 'c', 'remove': /:$/u}],
|
|
219
|
+
// Experimental, MET366-ish (end punc in internationally valid, but we don't use it here in Finland):
|
|
220
|
+
'648': [{'code': 'a', 'content': /^[0-9]+\.$/u, 'ind2': ['4'], 'remove': /\.$/u}]
|
|
221
|
+
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
// addColonToRelationshipInformation only applies to 700/710 but as others don't have $i, it's fine
|
|
225
|
+
const addX00 = [addX00aComma, addX00aComma2, addX00aDot, addLanguageComma, addSemicolonBeforeVolumeDesignation, addColonToRelationshipInformation];
|
|
226
|
+
const addX10 = [addX10bDot, addX10eComma, addX10Dot, addLanguageComma, addSemicolonBeforeVolumeDesignation, addColonToRelationshipInformation];
|
|
227
|
+
const addPairedPunctuationRules = {
|
|
228
|
+
'100': addX00,
|
|
229
|
+
'110': addX10,
|
|
230
|
+
'245': [
|
|
231
|
+
// Blah! Also "$a = $b" and "$a ; $b" can be valid... But ' :' is better than nothing, I guess...
|
|
232
|
+
{'code': 'a', 'followedBy': 'b', 'add': ' :', 'context': defaultNeedsPuncAfter},
|
|
233
|
+
{'code': 'abk', 'followedBy': 'f', 'add': ',', 'context': defaultNeedsPuncAfter},
|
|
234
|
+
{'code': 'abfnp', 'followedBy': 'c', 'add': ' /', 'context': defaultNeedsPuncAfter},
|
|
235
|
+
{'code': 'abc', 'followedBy': '#', 'add': '.', 'context': defaultNeedsPuncAfter} // Stepping on punctuation/ toes
|
|
236
|
+
],
|
|
237
|
+
'260': [
|
|
238
|
+
{'code': 'a', 'followedBy': 'b', 'add': ' :', 'context': defaultNeedsPuncAfter2},
|
|
239
|
+
{'code': 'b', 'followedBy': 'c', 'add': ',', 'context': defaultNeedsPuncAfter2},
|
|
240
|
+
{'code': 'abc', 'followedBy': 'a', 'add': ' ;', 'context': defaultNeedsPuncAfter2},
|
|
241
|
+
{'code': 'e', 'followedBy': 'f', 'add': ' :', 'context': defaultNeedsPuncAfter2},
|
|
242
|
+
{'code': 'f', 'followedBy': 'g', 'add': ',', 'context': defaultNeedsPuncAfter2}
|
|
243
|
+
],
|
|
244
|
+
'264': [
|
|
245
|
+
{'code': 'a', 'followedBy': 'b', 'add': ' :', 'context': defaultNeedsPuncAfter2},
|
|
246
|
+
{'code': 'b', 'followedBy': 'c', 'add': ',', 'context': defaultNeedsPuncAfter2},
|
|
247
|
+
// NB! The $c rule messes dotless exception "264 #4 $c p1983" up
|
|
248
|
+
// We'll need to add a hacky postprocessor for this? Add 'hasInd1': '0123' etc?
|
|
249
|
+
{'code': 'c', 'followedBy': '#', 'add': '.', 'context': defaultNeedsPuncAfter2}
|
|
250
|
+
],
|
|
251
|
+
'300': [
|
|
252
|
+
{'code': 'a', 'followedBy': 'b', 'add': ' :', 'context': defaultNeedsPuncAfter2},
|
|
253
|
+
{'code': 'ab', 'followedBy': 'c', 'add': ' ;', 'context': defaultNeedsPuncAfter2},
|
|
254
|
+
{'code': 'abc', 'followedBy': 'e', 'add': ' +', 'context': defaultNeedsPuncAfter2}
|
|
255
|
+
],
|
|
256
|
+
'490': [
|
|
257
|
+
{'code': 'axy', 'followedBy': 'xy', 'add': ',', 'context': defaultNeedsPuncAfter},
|
|
258
|
+
addSemicolonBeforeVolumeDesignation
|
|
259
|
+
//{'code': 'axy', 'followedBy': 'v', 'add': ' ;', 'context': defaultNeedsPuncAfter}
|
|
260
|
+
],
|
|
261
|
+
'506': [{'code': 'a', 'followedBy': '#', 'add': '.', 'context': defaultNeedsPuncAfter2}],
|
|
262
|
+
'534': [{'code': 'p', 'followedBy': 'c', 'add': ':', 'context': defaultNeedsPuncAfter2}],
|
|
263
|
+
'600': addX00,
|
|
264
|
+
'610': addX10,
|
|
265
|
+
'700': addX00,
|
|
266
|
+
'710': addX10,
|
|
267
|
+
'800': addX00,
|
|
268
|
+
'810': addX10,
|
|
269
|
+
'830': [
|
|
270
|
+
{'code': 'axy', 'followedBy': 'xy', 'add': ',', 'context': defaultNeedsPuncAfter},
|
|
271
|
+
addSemicolonBeforeVolumeDesignation
|
|
272
|
+
//{'code': 'axy', 'followedBy': 'v', 'add': ' ;', 'context': defaultNeedsPuncAfter}
|
|
273
|
+
]
|
|
274
|
+
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
function ruleAppliesToSubfieldCode(targetSubfieldCodes, currSubfieldCode) {
|
|
279
|
+
const negation = targetSubfieldCodes.includes('!');
|
|
280
|
+
if (negation) {
|
|
281
|
+
return !targetSubfieldCodes.includes(currSubfieldCode);
|
|
282
|
+
}
|
|
283
|
+
return targetSubfieldCodes.includes(currSubfieldCode);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
function ruleAppliesToField(rule, field) {
|
|
288
|
+
if ('ind1' in rule && field.ind1.includes(rule.ind1)) {
|
|
289
|
+
return false;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if ('ind2' in rule && field.ind2.includes(rule.ind2)) {
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// If we want to check, say, $2, it should be implemented here!
|
|
297
|
+
|
|
298
|
+
return true;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
function ruleAppliesToCurrentSubfield(rule, subfield) {
|
|
303
|
+
if (!ruleAppliesToSubfieldCode(rule.code, subfield.code)) {
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
306
|
+
if ('context' in rule && !subfield.value.match(rule.context)) { // njsscan-ignore: regex_injection_dos
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
return true;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
function ruleAppliesToNextSubfield(rule, nextSubfield) {
|
|
313
|
+
if (!('followedBy' in rule)) { // Return true, if we are not interested in the next subfield
|
|
314
|
+
return true;
|
|
315
|
+
}
|
|
316
|
+
// The '#' existence check applies only to the RHS field. LHS always exists.
|
|
317
|
+
if (!nextSubfield) {
|
|
318
|
+
const negation = rule.followedBy.includes('!');
|
|
319
|
+
if (negation) {
|
|
320
|
+
return !rule.followedBy.includes('#');
|
|
321
|
+
}
|
|
322
|
+
return rule.followedBy.includes('#');
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
if (!ruleAppliesToSubfieldCode(rule.followedBy, nextSubfield.code)) {
|
|
326
|
+
return false;
|
|
327
|
+
}
|
|
328
|
+
if ('contextRHS' in rule && !nextSubfield.value.match(rule.contextRHS)) { // njsscan-ignore: regex_injection_dos
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
return true;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function checkRule(rule, field, subfield1, subfield2) {
|
|
335
|
+
if (!ruleAppliesToField(rule, field)) {
|
|
336
|
+
nvdebug(`FAIL ON WHOLE FIELD: '${fieldToString(field)}`);
|
|
337
|
+
return false;
|
|
338
|
+
}
|
|
339
|
+
//const name = rule.name || 'UNNAMED';
|
|
340
|
+
if (!ruleAppliesToCurrentSubfield(rule, subfield1)) {
|
|
341
|
+
//nvdebug(`${name}: FAIL ON LHS SUBFIELD: '$${subfield1.code} ${subfield1.value}', SF=${rule.code}`, debug);
|
|
342
|
+
return false;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// NB! This is not a perfect solution. We might have $e$0$e where $e$0 punctuation should actually be based on $e$e rules
|
|
346
|
+
if (!ruleAppliesToNextSubfield(rule, subfield2)) {
|
|
347
|
+
//const msg = subfield2 ? `${name}: FAIL ON RHS SUBFIELD '${subfield2.code}' not in [${rule.followedBy}]` : `${name}: FAIL ON RHS FIELD`;
|
|
348
|
+
//nvdebug(msg, debug);
|
|
349
|
+
return false;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
//nvdebug(`${name}: ACCEPT ${rule.code}/${subfield1.code}, SF2=${rule.followedBy}/${subfield2 ? subfield2.code : '#'}`, debug);
|
|
353
|
+
return true;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function applyPunctuationRules(field, subfield1, subfield2, ruleArray = null, operation = NONE) {
|
|
357
|
+
|
|
358
|
+
/*
|
|
359
|
+
if (ruleArray === null || operation === NONE) {
|
|
360
|
+
debug(`applyPunctuation(): No rules to apply!`);
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
*/
|
|
364
|
+
if (!(`${field.tag}` in ruleArray) || ruleArray === null || operation === NONE) {
|
|
365
|
+
|
|
366
|
+
/*
|
|
367
|
+
if (!['020', '650'].includes(tag) || !isControlSubfieldCode(subfield1.code)) { // eslint-disable-line functional/no-conditional-statements
|
|
368
|
+
nvdebug(`No punctuation rules found for ${tag} (looking for: ‡${subfield1.code})`, debug);
|
|
369
|
+
|
|
370
|
+
}
|
|
371
|
+
*/
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
//nvdebug(`OP=${operation} ${tag}: '${subfield1.code}: ${subfield1.value}' ??? '${subfield2 ? subfield2.code : '#'}'`, debug);
|
|
376
|
+
const activeRules = ruleArray[field.tag].filter(rule => checkRule(rule, field, subfield1, subfield2));
|
|
377
|
+
|
|
378
|
+
activeRules.forEach(rule => {
|
|
379
|
+
const originalValue = subfield1.value;
|
|
380
|
+
if (rule.remove && [REMOVE, REMOVE_AND_ADD].includes(operation) && subfield1.value.match(rule.remove)) { // eslint-disable-line functional/no-conditional-statements
|
|
381
|
+
//nvdebug(` PUNC REMOVAL TO BE PERFORMED FOR $${subfield1.code} '${subfield1.value}'`, debug);
|
|
382
|
+
subfield1.value = subfield1.value.replace(rule.remove, ''); // eslint-disable-line functional/immutable-data
|
|
383
|
+
//nvdebug(` PUNC REMOVAL PERFORMED FOR '${subfield1.value}'`, debug);
|
|
384
|
+
}
|
|
385
|
+
if (rule.add && [ADD, REMOVE_AND_ADD].includes(operation)) { // eslint-disable-line functional/no-conditional-statements
|
|
386
|
+
subfield1.value += rule.add; // eslint-disable-line functional/immutable-data
|
|
387
|
+
//nvdebug(` ADDED '${rule.add}' TO '${subfield1.value}'`, debug);
|
|
388
|
+
}
|
|
389
|
+
if (subfield1.value !== originalValue) { // eslint-disable-line functional/no-conditional-statements
|
|
390
|
+
//nvdebug(` PROCESS PUNC: '‡${subfield1.code} ${originalValue}' => '‡${subfield1.code} ${subfield1.value}'`, debug); // eslint-disable-line functional/immutable-data
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
function subfieldFixPunctuation(field, subfield1, subfield2) {
|
|
396
|
+
applyPunctuationRules(field, subfield1, subfield2, cleanCrappyPunctuationRules, REMOVE);
|
|
397
|
+
applyPunctuationRules(field, subfield1, subfield2, addPairedPunctuationRules, ADD);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
function subfieldStripPunctuation(field, subfield1, subfield2) {
|
|
401
|
+
nvdebug(`FSP1: '${subfield1.value}'`);
|
|
402
|
+
applyPunctuationRules(field, subfield1, subfield2, cleanValidPunctuationRules, REMOVE);
|
|
403
|
+
nvdebug(`FSP2: '${subfield1.value}'`);
|
|
404
|
+
applyPunctuationRules(field, subfield1, subfield2, cleanCrappyPunctuationRules, REMOVE);
|
|
405
|
+
nvdebug(`FSP3: '${subfield1.value}'`);
|
|
406
|
+
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
export function fieldStripPunctuation(field) {
|
|
410
|
+
if (!field.subfields) {
|
|
411
|
+
return field;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
field.subfields.forEach((sf, i) => {
|
|
415
|
+
// NB! instead of next subfield, we should actually get next *non-control-subfield*!!!
|
|
416
|
+
// (In plain English: We should skip $0 - $9 at least, maybe $w as well...)
|
|
417
|
+
subfieldStripPunctuation(field, sf, getNextRelevantSubfield(field, i));
|
|
418
|
+
|
|
419
|
+
});
|
|
420
|
+
return field;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
export function fieldFixPunctuation(field) {
|
|
424
|
+
if (!field.subfields) {
|
|
425
|
+
return field;
|
|
426
|
+
}
|
|
427
|
+
nvdebug(`################### fieldFixPunctuation() TEST ${fieldToString(field)}`);
|
|
428
|
+
|
|
429
|
+
field.subfields.forEach((sf, i) => {
|
|
430
|
+
// NB! instead of next subfield, we should actually get next *non-control-subfield*!!!
|
|
431
|
+
// (In plain English: We should skip $0 - $9 at least, maybe $w as well...)
|
|
432
|
+
subfieldFixPunctuation(field, sf, getNextRelevantSubfield(field, i));
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
// Use shared code for final punctuation (sadly this does not fix intermediate punc):
|
|
436
|
+
if (field.useExternalEndPunctuation) { // eslint-disable-line functional/no-conditional-statements
|
|
437
|
+
// addFinalPunctuation(field); // local version. use shared code instead.
|
|
438
|
+
validateSingleField(field, false, true); // NB! Don't use field.tag as second argument! It's a string, not an int. 3rd arg must be true (=fix)
|
|
439
|
+
}
|
|
440
|
+
return field;
|
|
441
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {expect} from 'chai';
|
|
2
|
+
import {MarcRecord} from '@natlibfi/marc-record';
|
|
3
|
+
import validatorFactory from './punctuation2';
|
|
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', 'punctuation2'],
|
|
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/punctuation2: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
|
+
}
|