@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,726 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = _default;
|
|
7
|
+
exports.fieldFixPunctuation = fieldFixPunctuation;
|
|
8
|
+
exports.fieldGetFixedString = fieldGetFixedString;
|
|
9
|
+
exports.fieldNeedsModification = fieldNeedsModification;
|
|
10
|
+
exports.fieldStripPunctuation = fieldStripPunctuation;
|
|
11
|
+
var _endingPunctuation = require("./ending-punctuation");
|
|
12
|
+
var _utils = require("./utils");
|
|
13
|
+
var _clone = _interopRequireDefault(require("clone"));
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
/*
|
|
16
|
+
* punctuation.js -- try and fix a marc field punctuation
|
|
17
|
+
*
|
|
18
|
+
* Author(s): Nicholas Volk <nicholas.volk@helsinki.fi>
|
|
19
|
+
*
|
|
20
|
+
* NOTE #1: https://www.kiwi.fi/display/kumea/Loppupisteohje is implemented via another validator/fixer (ending-punctuation).
|
|
21
|
+
* This file has some support but it's now yet thorough. (And mmight never be.)
|
|
22
|
+
* NOTE #2: Validator/fixer punctuation does similar stuff, but focuses on X00 fields.
|
|
23
|
+
* NOTE #3: As of 2023-06-05 control subfields ($0...$9) are obsolete. Don't use them in rules.
|
|
24
|
+
* (They are jumped over when looking for next (non-controlfield subfield)
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
// import createDebugLogger from 'debug';
|
|
28
|
+
|
|
29
|
+
// const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/punctuation2');
|
|
30
|
+
|
|
31
|
+
function _default() {
|
|
32
|
+
return {
|
|
33
|
+
description: 'Add punctuation to data fields',
|
|
34
|
+
validate,
|
|
35
|
+
fix
|
|
36
|
+
};
|
|
37
|
+
function fix(record) {
|
|
38
|
+
(0, _utils.nvdebug)('Add punctuation to data fields: fixer');
|
|
39
|
+
const res = {
|
|
40
|
+
message: [],
|
|
41
|
+
fix: [],
|
|
42
|
+
valid: true
|
|
43
|
+
};
|
|
44
|
+
record.fields.forEach(f => fieldFixPunctuation(f));
|
|
45
|
+
return res;
|
|
46
|
+
}
|
|
47
|
+
function validate(record) {
|
|
48
|
+
(0, _utils.nvdebug)('Add punctuation to data fields: validate');
|
|
49
|
+
const fieldsNeedingModification = record.fields.filter(f => fieldNeedsModification(f, true));
|
|
50
|
+
const values = fieldsNeedingModification.map(f => (0, _utils.fieldToString)(f));
|
|
51
|
+
const newValues = fieldsNeedingModification.map(f => fieldGetFixedString(f, true));
|
|
52
|
+
const messages = values.map((val, i) => `'${val}' => '${newValues[i]}'`);
|
|
53
|
+
const res = {
|
|
54
|
+
message: messages
|
|
55
|
+
};
|
|
56
|
+
res.valid = res.message.length < 1; // eslint-disable-line functional/immutable-data
|
|
57
|
+
return res;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function isControlSubfield(subfield) {
|
|
61
|
+
return ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'].includes(subfield.code);
|
|
62
|
+
}
|
|
63
|
+
function getNextRelevantSubfield(field, currSubfieldIndex) {
|
|
64
|
+
return field.subfields.find((subfield, index) => index > currSubfieldIndex && !isControlSubfield(subfield));
|
|
65
|
+
}
|
|
66
|
+
function fieldGetFixedString(field, add = true) {
|
|
67
|
+
const cloneField = (0, _clone.default)(field);
|
|
68
|
+
const operation = add ? subfieldFixPunctuation : subfieldStripPunctuation;
|
|
69
|
+
cloneField.subfields.forEach((sf, i) => {
|
|
70
|
+
// NB! instead of next subfield, we should actually get next *non-control-subfield*!!!
|
|
71
|
+
// (In plain English: We should skip $0 - $9 at least, maybe $w as well...)
|
|
72
|
+
operation(cloneField, sf, getNextRelevantSubfield(cloneField, i));
|
|
73
|
+
});
|
|
74
|
+
return (0, _utils.fieldToString)(cloneField);
|
|
75
|
+
}
|
|
76
|
+
function fieldNeedsModification(field, add = true) {
|
|
77
|
+
if (!field.subfields) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
const originalFieldAsString = (0, _utils.fieldToString)(field);
|
|
81
|
+
const modifiedFieldAsString = fieldGetFixedString(field, add);
|
|
82
|
+
return modifiedFieldAsString !== originalFieldAsString;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/////////////////////////////////////////////////////////////////////////////////////
|
|
86
|
+
// <= Above code is written for the validator logic <= //
|
|
87
|
+
// => Everything below was originally transferred from reducers' punctuation.js => //
|
|
88
|
+
/////////////////////////////////////////////////////////////////////////////////////
|
|
89
|
+
|
|
90
|
+
//const stripCrap = / *[-;:,+]+$/u;
|
|
91
|
+
const commaNeedsPuncAfter = /(?:[a-z0-9A-Z]|å|ä|ö|Å|Ä|Ö|\))$/u;
|
|
92
|
+
const defaultNeedsPuncAfter = /(?:[a-z0-9A-Z]|å|ä|ö|Å|Ä|Ö)$/u;
|
|
93
|
+
const defaultNeedsPuncAfter2 = /(?:[\]a-zA-Z0-9)]|ä|å|ö|Å|Ä|Ö)$/u;
|
|
94
|
+
const blocksPuncRHS = /^(?:\()/u;
|
|
95
|
+
const allowsPuncRHS = /^(?:[A-Za-z0-9]|å|ä|ö|Å|Ä|Ö)/u;
|
|
96
|
+
const dotIsProbablyPunc = /(?:[a-z0-9)]|å|ä|ö)\.$/u;
|
|
97
|
+
const puncIsProbablyPunc = /(?:[a-z0-9)]|å|ä|ö) ?[.,:;]$/u;
|
|
98
|
+
// NB! 65X: Finnish terms don't use punctuation, but international ones do. Neither one is currently (2021-11-08) coded here.
|
|
99
|
+
|
|
100
|
+
// Will unfortunately trigger "Sukunimi, Th." type:
|
|
101
|
+
const removeColons = {
|
|
102
|
+
'code': 'abcdefghijklmnopqrstuvwxyz',
|
|
103
|
+
'remove': / *[;:]$/u
|
|
104
|
+
};
|
|
105
|
+
const removeX00Comma = {
|
|
106
|
+
'code': 'abcqde',
|
|
107
|
+
'followedBy': 'abcqde#',
|
|
108
|
+
'context': /.,$/u,
|
|
109
|
+
'remove': /,$/u
|
|
110
|
+
};
|
|
111
|
+
const cleanRHS = {
|
|
112
|
+
'code': 'abcd',
|
|
113
|
+
'followedBy': 'bcde',
|
|
114
|
+
'context': /(?:(?:[a-z0-9]|å|ä|ö)\.|,)$/u,
|
|
115
|
+
'contextRHS': blocksPuncRHS,
|
|
116
|
+
'remove': /[.,]$/u
|
|
117
|
+
};
|
|
118
|
+
const cleanX00dCommaOrDot = {
|
|
119
|
+
'code': 'd',
|
|
120
|
+
'followedBy': 'et#',
|
|
121
|
+
'context': /[0-9]-[,.]$/u,
|
|
122
|
+
'remove': /[,.]$/u
|
|
123
|
+
};
|
|
124
|
+
const cleanX00aDot = {
|
|
125
|
+
'code': 'abcde',
|
|
126
|
+
'followedBy': 'cdegj',
|
|
127
|
+
'context': dotIsProbablyPunc,
|
|
128
|
+
'remove': /\.$/u
|
|
129
|
+
};
|
|
130
|
+
const cleanCorruption = {
|
|
131
|
+
'code': 'abcdefghijklmnopqrstuvwxyz',
|
|
132
|
+
'remove': / \.$/u
|
|
133
|
+
};
|
|
134
|
+
// These $e dot removals are tricky: before removing the comma, we should know that it ain't an abbreviation such as "esitt."...
|
|
135
|
+
const cleanX00eDot = {
|
|
136
|
+
'code': 'e',
|
|
137
|
+
'followedBy': 'egj#',
|
|
138
|
+
'context': /(?:[ai]ja|jä)[.,]$/u,
|
|
139
|
+
'remove': /\.$/u
|
|
140
|
+
};
|
|
141
|
+
const X00RemoveDotAfterBracket = {
|
|
142
|
+
'code': 'cq',
|
|
143
|
+
'context': /\)\.$/u,
|
|
144
|
+
'remove': /\.$/u
|
|
145
|
+
};
|
|
146
|
+
// 390, 800, 810, 830...
|
|
147
|
+
const cleanPuncBeforeLanguage = {
|
|
148
|
+
'code': 'atvxyz',
|
|
149
|
+
'followedBy': 'l',
|
|
150
|
+
'context': puncIsProbablyPunc,
|
|
151
|
+
'remove': / *[.,:;]$/u
|
|
152
|
+
};
|
|
153
|
+
const addX00aComma = {
|
|
154
|
+
'add': ',',
|
|
155
|
+
'code': 'abcqdej',
|
|
156
|
+
'followedBy': 'cdeg',
|
|
157
|
+
'context': commaNeedsPuncAfter,
|
|
158
|
+
'contextRHS': allowsPuncRHS
|
|
159
|
+
};
|
|
160
|
+
const addX00aComma2 = {
|
|
161
|
+
'add': ',',
|
|
162
|
+
'code': 'abcdej',
|
|
163
|
+
'followedBy': 'cdeg',
|
|
164
|
+
'context': /(?:[A-Z]|Å|Ä|Ö)\.$/u,
|
|
165
|
+
'contextRHS': allowsPuncRHS
|
|
166
|
+
};
|
|
167
|
+
const addX00aDot = {
|
|
168
|
+
'add': '.',
|
|
169
|
+
'code': 'abcde',
|
|
170
|
+
'followedBy': '#tu',
|
|
171
|
+
'context': defaultNeedsPuncAfter
|
|
172
|
+
};
|
|
173
|
+
const addX10bDot = {
|
|
174
|
+
'name': 'Add X10 pre-$b dot',
|
|
175
|
+
'add': '.',
|
|
176
|
+
'code': 'ab',
|
|
177
|
+
'followedBy': 'b',
|
|
178
|
+
'context': defaultNeedsPuncAfter
|
|
179
|
+
};
|
|
180
|
+
const addX10eComma = {
|
|
181
|
+
'add': ',',
|
|
182
|
+
'code': 'abe',
|
|
183
|
+
'followedBy': 'e',
|
|
184
|
+
'context': defaultNeedsPuncAfter
|
|
185
|
+
};
|
|
186
|
+
const addX10Dot = {
|
|
187
|
+
'name': 'Add X10 final dot',
|
|
188
|
+
'add': '.',
|
|
189
|
+
'code': 'abe',
|
|
190
|
+
'followedBy': '#',
|
|
191
|
+
'context': defaultNeedsPuncAfter
|
|
192
|
+
};
|
|
193
|
+
const addLanguageComma = {
|
|
194
|
+
'name': 'Add comma before 810$l',
|
|
195
|
+
'add': ',',
|
|
196
|
+
'code': 'tv',
|
|
197
|
+
'followedBy': 'l',
|
|
198
|
+
'context': defaultNeedsPuncAfter2
|
|
199
|
+
};
|
|
200
|
+
const addColonToRelationshipInformation = {
|
|
201
|
+
'name': 'Add \':\' to 7X0 $i relationship info',
|
|
202
|
+
'add': ':',
|
|
203
|
+
'code': 'i',
|
|
204
|
+
'context': /[a-z)åäö]$/u
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
// 490:
|
|
208
|
+
const addSemicolonBeforeVolumeDesignation = {
|
|
209
|
+
'name': 'Add " ;" before $v',
|
|
210
|
+
'add': ' ;',
|
|
211
|
+
'code': 'atxy',
|
|
212
|
+
'followedBy': 'v',
|
|
213
|
+
'context': /[^;]$/u
|
|
214
|
+
};
|
|
215
|
+
const NONE = 0;
|
|
216
|
+
const ADD = 2;
|
|
217
|
+
const REMOVE = 1;
|
|
218
|
+
const REMOVE_AND_ADD = 3;
|
|
219
|
+
|
|
220
|
+
// Crappy punctuation consists of various crap that is somewhat common.
|
|
221
|
+
// We strip crap for merge decisions. We are not trying to actively remove crap here.
|
|
222
|
+
|
|
223
|
+
const removeX00Whatever = [removeX00Comma, cleanX00aDot, cleanX00eDot, cleanCorruption, cleanX00dCommaOrDot, cleanRHS, X00RemoveDotAfterBracket, removeColons, cleanPuncBeforeLanguage];
|
|
224
|
+
const removeX10Whatever = [removeX00Comma, cleanX00aDot, cleanX00eDot, cleanCorruption, removeColons, cleanPuncBeforeLanguage];
|
|
225
|
+
const cleanCrappyPunctuationRules = {
|
|
226
|
+
'100': removeX00Whatever,
|
|
227
|
+
'110': removeX10Whatever,
|
|
228
|
+
'600': removeX00Whatever,
|
|
229
|
+
'610': removeX10Whatever,
|
|
230
|
+
'700': removeX00Whatever,
|
|
231
|
+
'710': removeX10Whatever,
|
|
232
|
+
'800': removeX00Whatever,
|
|
233
|
+
'810': removeX10Whatever,
|
|
234
|
+
'245': [{
|
|
235
|
+
'code': 'ab',
|
|
236
|
+
'followedBy': '!c',
|
|
237
|
+
'remove': / \/$/u
|
|
238
|
+
}, {
|
|
239
|
+
'code': 'abc',
|
|
240
|
+
'followedBy': '#',
|
|
241
|
+
'remove': /\.$/u,
|
|
242
|
+
'context': dotIsProbablyPunc
|
|
243
|
+
}],
|
|
244
|
+
'300': [{
|
|
245
|
+
'code': 'a',
|
|
246
|
+
'followedBy': '!b',
|
|
247
|
+
'remove': / *:$/u
|
|
248
|
+
}, {
|
|
249
|
+
'code': 'a',
|
|
250
|
+
'followedBy': 'b',
|
|
251
|
+
'remove': /:$/u,
|
|
252
|
+
'context': /[^ ]:$/u
|
|
253
|
+
}, {
|
|
254
|
+
'code': 'ab',
|
|
255
|
+
'followedBy': '!c',
|
|
256
|
+
'remove': / *;$/u
|
|
257
|
+
}, {
|
|
258
|
+
'code': 'ab',
|
|
259
|
+
'followedBy': 'c',
|
|
260
|
+
'remove': /;$/u,
|
|
261
|
+
'context': /[^ ];$/u
|
|
262
|
+
}, {
|
|
263
|
+
'code': 'abc',
|
|
264
|
+
'followedBy': '!e',
|
|
265
|
+
'remove': / *\+$/u
|
|
266
|
+
} // Removes both valid (with one space) and invalid (spaceless et al) puncs
|
|
267
|
+
],
|
|
268
|
+
|
|
269
|
+
'490': [{
|
|
270
|
+
'code': 'a',
|
|
271
|
+
'followedBy': 'xy',
|
|
272
|
+
'remove': / ;$/u
|
|
273
|
+
}],
|
|
274
|
+
'773': [{
|
|
275
|
+
'code': 'abdghiklmnopqrstuwxyz',
|
|
276
|
+
'followedBy': 'abdghiklmnopqrstuwxyz',
|
|
277
|
+
'remove': /\. -$/u
|
|
278
|
+
}]
|
|
279
|
+
};
|
|
280
|
+
const cleanLegalX00Comma = {
|
|
281
|
+
'code': 'abcde',
|
|
282
|
+
'followedBy': 'cdegj',
|
|
283
|
+
'context': /.,$/u,
|
|
284
|
+
'remove': /,$/u
|
|
285
|
+
};
|
|
286
|
+
// Accept upper case letters in X00$b, since they are probably Roman numerals.
|
|
287
|
+
const cleanLegalX00bDot = {
|
|
288
|
+
'code': 'b',
|
|
289
|
+
'followedBy': 't#',
|
|
290
|
+
context: /^[IVXLCDM]+\.$/u,
|
|
291
|
+
'remove': /\.$/u
|
|
292
|
+
};
|
|
293
|
+
const cleanLegalX00Dot = {
|
|
294
|
+
'code': 'abcdetvl',
|
|
295
|
+
'followedBy': 'tu#',
|
|
296
|
+
'context': /(?:[a-z0-9)]|å|ä|ö)\.$/u,
|
|
297
|
+
'remove': /\.$/u
|
|
298
|
+
};
|
|
299
|
+
const cleanLanguageComma = {
|
|
300
|
+
'name': 'language comma',
|
|
301
|
+
'code': 'tv',
|
|
302
|
+
'followedBy': 'l',
|
|
303
|
+
'context': /.,$/u,
|
|
304
|
+
'remove': /,$/u
|
|
305
|
+
};
|
|
306
|
+
const legalX00punc = [cleanLegalX00Comma, cleanLegalX00bDot, cleanLegalX00Dot, cleanLanguageComma];
|
|
307
|
+
const cleanLegalX10Comma = {
|
|
308
|
+
'name': 'X10comma',
|
|
309
|
+
'code': 'abe',
|
|
310
|
+
'followedBy': 'e',
|
|
311
|
+
'context': /.,$/u,
|
|
312
|
+
'remove': /,$/u
|
|
313
|
+
};
|
|
314
|
+
const cleanLegalX10Dot = {
|
|
315
|
+
'name': 'X10dot',
|
|
316
|
+
'code': 'ab',
|
|
317
|
+
'followedBy': 'b#',
|
|
318
|
+
'context': /.\.$/u,
|
|
319
|
+
'remove': /\.$/u
|
|
320
|
+
};
|
|
321
|
+
const legalX10punc = [cleanLegalX10Comma, cleanLegalX10Dot, cleanX00eDot, cleanLanguageComma];
|
|
322
|
+
const cleanValidPunctuationRules = {
|
|
323
|
+
'100': legalX00punc,
|
|
324
|
+
'110': legalX10punc,
|
|
325
|
+
'600': legalX00punc,
|
|
326
|
+
'610': legalX10punc,
|
|
327
|
+
'700': legalX00punc,
|
|
328
|
+
'710': legalX10punc,
|
|
329
|
+
'800': legalX00punc,
|
|
330
|
+
'810': legalX10punc,
|
|
331
|
+
'245': [{
|
|
332
|
+
'name': 'A:B',
|
|
333
|
+
'code': 'a',
|
|
334
|
+
'followedBy': 'b',
|
|
335
|
+
'remove': / [:;=]$/u
|
|
336
|
+
}, {
|
|
337
|
+
'name': 'AB:K',
|
|
338
|
+
'code': 'ab',
|
|
339
|
+
'followedBy': 'k',
|
|
340
|
+
'remove': / :$/u
|
|
341
|
+
}, {
|
|
342
|
+
'name': 'ABK:F',
|
|
343
|
+
'code': 'abk',
|
|
344
|
+
'followedBy': 'f',
|
|
345
|
+
'remove': /,$/u
|
|
346
|
+
}, {
|
|
347
|
+
'name': 'ABFNP:C',
|
|
348
|
+
'code': 'abfnp',
|
|
349
|
+
'followedBy': 'c',
|
|
350
|
+
'remove': / \/$/u
|
|
351
|
+
}, {
|
|
352
|
+
'name': 'ABN:N',
|
|
353
|
+
'code': 'abn',
|
|
354
|
+
'followedBy': 'n',
|
|
355
|
+
'remove': /\.$/u
|
|
356
|
+
}, {
|
|
357
|
+
'name': 'ABNP:#',
|
|
358
|
+
'code': 'abnp',
|
|
359
|
+
'followedBy': '#',
|
|
360
|
+
'remove': /\.$/u
|
|
361
|
+
}, {
|
|
362
|
+
'name': 'N:P',
|
|
363
|
+
'code': 'n',
|
|
364
|
+
'followedBy': 'p',
|
|
365
|
+
'remove': /,$/u
|
|
366
|
+
}],
|
|
367
|
+
'260': [{
|
|
368
|
+
'code': 'a',
|
|
369
|
+
'followedBy': 'b',
|
|
370
|
+
'remove': / :$/u
|
|
371
|
+
}, {
|
|
372
|
+
'code': 'b',
|
|
373
|
+
'followedBy': 'c',
|
|
374
|
+
'remove': /,$/u
|
|
375
|
+
}, {
|
|
376
|
+
'code': 'c',
|
|
377
|
+
'followedBy': '#',
|
|
378
|
+
'remove': /\.$/u
|
|
379
|
+
}, {
|
|
380
|
+
'code': 'd',
|
|
381
|
+
'followedBy': 'e',
|
|
382
|
+
'remove': / :$/u
|
|
383
|
+
}, {
|
|
384
|
+
'code': 'e',
|
|
385
|
+
'followedBy': 'f',
|
|
386
|
+
'remove': /,$/u
|
|
387
|
+
}, {
|
|
388
|
+
'code': 'f',
|
|
389
|
+
'followedBy': '#',
|
|
390
|
+
'remove': /\.$/u
|
|
391
|
+
} // Probably ')' but shouldit be removed?
|
|
392
|
+
],
|
|
393
|
+
|
|
394
|
+
'264': [{
|
|
395
|
+
'code': 'a',
|
|
396
|
+
'followedBy': 'b',
|
|
397
|
+
'remove': / :$/u
|
|
398
|
+
}, {
|
|
399
|
+
'code': 'b',
|
|
400
|
+
'followedBy': 'c',
|
|
401
|
+
'remove': /,$/u
|
|
402
|
+
}, {
|
|
403
|
+
'code': 'c',
|
|
404
|
+
'followedBy': '#',
|
|
405
|
+
'remove': /\.$/u
|
|
406
|
+
}],
|
|
407
|
+
'300': [
|
|
408
|
+
// NB! Remove crap as well, thus the '*' in / *:$/
|
|
409
|
+
{
|
|
410
|
+
'code': 'a',
|
|
411
|
+
'followedBy': 'b',
|
|
412
|
+
'remove': / :$/u
|
|
413
|
+
}, {
|
|
414
|
+
'code': 'ab',
|
|
415
|
+
'followedBy': 'c',
|
|
416
|
+
'remove': / ;$/u
|
|
417
|
+
}, {
|
|
418
|
+
'code': 'abc',
|
|
419
|
+
'followedBy': 'e',
|
|
420
|
+
'remove': / \+$/u
|
|
421
|
+
}],
|
|
422
|
+
'490': [{
|
|
423
|
+
'code': 'axy',
|
|
424
|
+
'followedBy': 'xy',
|
|
425
|
+
'remove': /,$/u
|
|
426
|
+
}, {
|
|
427
|
+
'code': 'axy',
|
|
428
|
+
'followedBy': 'v',
|
|
429
|
+
'remove': / *;$/u
|
|
430
|
+
}],
|
|
431
|
+
'534': [{
|
|
432
|
+
'code': 'p',
|
|
433
|
+
'followedBy': 'c',
|
|
434
|
+
'remove': /:$/u
|
|
435
|
+
}],
|
|
436
|
+
// Experimental, MET366-ish (end punc in internationally valid, but we don't use it here in Finland):
|
|
437
|
+
'648': [{
|
|
438
|
+
'code': 'a',
|
|
439
|
+
'content': /^[0-9]+\.$/u,
|
|
440
|
+
'ind2': ['4'],
|
|
441
|
+
'remove': /\.$/u
|
|
442
|
+
}]
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
// addColonToRelationshipInformation only applies to 700/710 but as others don't have $i, it's fine
|
|
446
|
+
const addX00 = [addX00aComma, addX00aComma2, addX00aDot, addLanguageComma, addSemicolonBeforeVolumeDesignation, addColonToRelationshipInformation];
|
|
447
|
+
const addX10 = [addX10bDot, addX10eComma, addX10Dot, addLanguageComma, addSemicolonBeforeVolumeDesignation, addColonToRelationshipInformation];
|
|
448
|
+
const addPairedPunctuationRules = {
|
|
449
|
+
'100': addX00,
|
|
450
|
+
'110': addX10,
|
|
451
|
+
'245': [
|
|
452
|
+
// Blah! Also "$a = $b" and "$a ; $b" can be valid... But ' :' is better than nothing, I guess...
|
|
453
|
+
{
|
|
454
|
+
'code': 'a',
|
|
455
|
+
'followedBy': 'b',
|
|
456
|
+
'add': ' :',
|
|
457
|
+
'context': defaultNeedsPuncAfter
|
|
458
|
+
}, {
|
|
459
|
+
'code': 'abk',
|
|
460
|
+
'followedBy': 'f',
|
|
461
|
+
'add': ',',
|
|
462
|
+
'context': defaultNeedsPuncAfter
|
|
463
|
+
}, {
|
|
464
|
+
'code': 'abfnp',
|
|
465
|
+
'followedBy': 'c',
|
|
466
|
+
'add': ' /',
|
|
467
|
+
'context': defaultNeedsPuncAfter
|
|
468
|
+
}, {
|
|
469
|
+
'code': 'abc',
|
|
470
|
+
'followedBy': '#',
|
|
471
|
+
'add': '.',
|
|
472
|
+
'context': defaultNeedsPuncAfter
|
|
473
|
+
} // Stepping on punctuation/ toes
|
|
474
|
+
],
|
|
475
|
+
|
|
476
|
+
'260': [{
|
|
477
|
+
'code': 'a',
|
|
478
|
+
'followedBy': 'b',
|
|
479
|
+
'add': ' :',
|
|
480
|
+
'context': defaultNeedsPuncAfter2
|
|
481
|
+
}, {
|
|
482
|
+
'code': 'b',
|
|
483
|
+
'followedBy': 'c',
|
|
484
|
+
'add': ',',
|
|
485
|
+
'context': defaultNeedsPuncAfter2
|
|
486
|
+
}, {
|
|
487
|
+
'code': 'abc',
|
|
488
|
+
'followedBy': 'a',
|
|
489
|
+
'add': ' ;',
|
|
490
|
+
'context': defaultNeedsPuncAfter2
|
|
491
|
+
}, {
|
|
492
|
+
'code': 'e',
|
|
493
|
+
'followedBy': 'f',
|
|
494
|
+
'add': ' :',
|
|
495
|
+
'context': defaultNeedsPuncAfter2
|
|
496
|
+
}, {
|
|
497
|
+
'code': 'f',
|
|
498
|
+
'followedBy': 'g',
|
|
499
|
+
'add': ',',
|
|
500
|
+
'context': defaultNeedsPuncAfter2
|
|
501
|
+
}],
|
|
502
|
+
'264': [{
|
|
503
|
+
'code': 'a',
|
|
504
|
+
'followedBy': 'b',
|
|
505
|
+
'add': ' :',
|
|
506
|
+
'context': defaultNeedsPuncAfter2
|
|
507
|
+
}, {
|
|
508
|
+
'code': 'b',
|
|
509
|
+
'followedBy': 'c',
|
|
510
|
+
'add': ',',
|
|
511
|
+
'context': defaultNeedsPuncAfter2
|
|
512
|
+
},
|
|
513
|
+
// NB! The $c rule messes dotless exception "264 #4 $c p1983" up
|
|
514
|
+
// We'll need to add a hacky postprocessor for this? Add 'hasInd1': '0123' etc?
|
|
515
|
+
{
|
|
516
|
+
'code': 'c',
|
|
517
|
+
'followedBy': '#',
|
|
518
|
+
'add': '.',
|
|
519
|
+
'context': defaultNeedsPuncAfter2
|
|
520
|
+
}],
|
|
521
|
+
'300': [{
|
|
522
|
+
'code': 'a',
|
|
523
|
+
'followedBy': 'b',
|
|
524
|
+
'add': ' :',
|
|
525
|
+
'context': defaultNeedsPuncAfter2
|
|
526
|
+
}, {
|
|
527
|
+
'code': 'ab',
|
|
528
|
+
'followedBy': 'c',
|
|
529
|
+
'add': ' ;',
|
|
530
|
+
'context': defaultNeedsPuncAfter2
|
|
531
|
+
}, {
|
|
532
|
+
'code': 'abc',
|
|
533
|
+
'followedBy': 'e',
|
|
534
|
+
'add': ' +',
|
|
535
|
+
'context': defaultNeedsPuncAfter2
|
|
536
|
+
}],
|
|
537
|
+
'490': [{
|
|
538
|
+
'code': 'axy',
|
|
539
|
+
'followedBy': 'xy',
|
|
540
|
+
'add': ',',
|
|
541
|
+
'context': defaultNeedsPuncAfter
|
|
542
|
+
}, addSemicolonBeforeVolumeDesignation
|
|
543
|
+
//{'code': 'axy', 'followedBy': 'v', 'add': ' ;', 'context': defaultNeedsPuncAfter}
|
|
544
|
+
],
|
|
545
|
+
|
|
546
|
+
'506': [{
|
|
547
|
+
'code': 'a',
|
|
548
|
+
'followedBy': '#',
|
|
549
|
+
'add': '.',
|
|
550
|
+
'context': defaultNeedsPuncAfter2
|
|
551
|
+
}],
|
|
552
|
+
'534': [{
|
|
553
|
+
'code': 'p',
|
|
554
|
+
'followedBy': 'c',
|
|
555
|
+
'add': ':',
|
|
556
|
+
'context': defaultNeedsPuncAfter2
|
|
557
|
+
}],
|
|
558
|
+
'600': addX00,
|
|
559
|
+
'610': addX10,
|
|
560
|
+
'700': addX00,
|
|
561
|
+
'710': addX10,
|
|
562
|
+
'800': addX00,
|
|
563
|
+
'810': addX10,
|
|
564
|
+
'830': [{
|
|
565
|
+
'code': 'axy',
|
|
566
|
+
'followedBy': 'xy',
|
|
567
|
+
'add': ',',
|
|
568
|
+
'context': defaultNeedsPuncAfter
|
|
569
|
+
}, addSemicolonBeforeVolumeDesignation
|
|
570
|
+
//{'code': 'axy', 'followedBy': 'v', 'add': ' ;', 'context': defaultNeedsPuncAfter}
|
|
571
|
+
]
|
|
572
|
+
};
|
|
573
|
+
|
|
574
|
+
function ruleAppliesToSubfieldCode(targetSubfieldCodes, currSubfieldCode) {
|
|
575
|
+
const negation = targetSubfieldCodes.includes('!');
|
|
576
|
+
if (negation) {
|
|
577
|
+
return !targetSubfieldCodes.includes(currSubfieldCode);
|
|
578
|
+
}
|
|
579
|
+
return targetSubfieldCodes.includes(currSubfieldCode);
|
|
580
|
+
}
|
|
581
|
+
function ruleAppliesToField(rule, field) {
|
|
582
|
+
if ('ind1' in rule && field.ind1.includes(rule.ind1)) {
|
|
583
|
+
return false;
|
|
584
|
+
}
|
|
585
|
+
if ('ind2' in rule && field.ind2.includes(rule.ind2)) {
|
|
586
|
+
return false;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
// If we want to check, say, $2, it should be implemented here!
|
|
590
|
+
|
|
591
|
+
return true;
|
|
592
|
+
}
|
|
593
|
+
function ruleAppliesToCurrentSubfield(rule, subfield) {
|
|
594
|
+
if (!ruleAppliesToSubfieldCode(rule.code, subfield.code)) {
|
|
595
|
+
return false;
|
|
596
|
+
}
|
|
597
|
+
if ('context' in rule && !subfield.value.match(rule.context)) {
|
|
598
|
+
// njsscan-ignore: regex_injection_dos
|
|
599
|
+
return false;
|
|
600
|
+
}
|
|
601
|
+
return true;
|
|
602
|
+
}
|
|
603
|
+
function ruleAppliesToNextSubfield(rule, nextSubfield) {
|
|
604
|
+
if (!('followedBy' in rule)) {
|
|
605
|
+
// Return true, if we are not interested in the next subfield
|
|
606
|
+
return true;
|
|
607
|
+
}
|
|
608
|
+
// The '#' existence check applies only to the RHS field. LHS always exists.
|
|
609
|
+
if (!nextSubfield) {
|
|
610
|
+
const negation = rule.followedBy.includes('!');
|
|
611
|
+
if (negation) {
|
|
612
|
+
return !rule.followedBy.includes('#');
|
|
613
|
+
}
|
|
614
|
+
return rule.followedBy.includes('#');
|
|
615
|
+
}
|
|
616
|
+
if (!ruleAppliesToSubfieldCode(rule.followedBy, nextSubfield.code)) {
|
|
617
|
+
return false;
|
|
618
|
+
}
|
|
619
|
+
if ('contextRHS' in rule && !nextSubfield.value.match(rule.contextRHS)) {
|
|
620
|
+
// njsscan-ignore: regex_injection_dos
|
|
621
|
+
return false;
|
|
622
|
+
}
|
|
623
|
+
return true;
|
|
624
|
+
}
|
|
625
|
+
function checkRule(rule, field, subfield1, subfield2) {
|
|
626
|
+
if (!ruleAppliesToField(rule, field)) {
|
|
627
|
+
(0, _utils.nvdebug)(`FAIL ON WHOLE FIELD: '${(0, _utils.fieldToString)(field)}`);
|
|
628
|
+
return false;
|
|
629
|
+
}
|
|
630
|
+
//const name = rule.name || 'UNNAMED';
|
|
631
|
+
if (!ruleAppliesToCurrentSubfield(rule, subfield1)) {
|
|
632
|
+
//nvdebug(`${name}: FAIL ON LHS SUBFIELD: '$${subfield1.code} ${subfield1.value}', SF=${rule.code}`, debug);
|
|
633
|
+
return false;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
// 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
|
|
637
|
+
if (!ruleAppliesToNextSubfield(rule, subfield2)) {
|
|
638
|
+
//const msg = subfield2 ? `${name}: FAIL ON RHS SUBFIELD '${subfield2.code}' not in [${rule.followedBy}]` : `${name}: FAIL ON RHS FIELD`;
|
|
639
|
+
//nvdebug(msg, debug);
|
|
640
|
+
return false;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
//nvdebug(`${name}: ACCEPT ${rule.code}/${subfield1.code}, SF2=${rule.followedBy}/${subfield2 ? subfield2.code : '#'}`, debug);
|
|
644
|
+
return true;
|
|
645
|
+
}
|
|
646
|
+
function applyPunctuationRules(field, subfield1, subfield2, ruleArray = null, operation = NONE) {
|
|
647
|
+
/*
|
|
648
|
+
if (ruleArray === null || operation === NONE) {
|
|
649
|
+
debug(`applyPunctuation(): No rules to apply!`);
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
652
|
+
*/
|
|
653
|
+
if (!(`${field.tag}` in ruleArray) || ruleArray === null || operation === NONE) {
|
|
654
|
+
/*
|
|
655
|
+
if (!['020', '650'].includes(tag) || !isControlSubfieldCode(subfield1.code)) { // eslint-disable-line functional/no-conditional-statements
|
|
656
|
+
nvdebug(`No punctuation rules found for ${tag} (looking for: ‡${subfield1.code})`, debug);
|
|
657
|
+
}
|
|
658
|
+
*/
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
//nvdebug(`OP=${operation} ${tag}: '${subfield1.code}: ${subfield1.value}' ??? '${subfield2 ? subfield2.code : '#'}'`, debug);
|
|
663
|
+
const activeRules = ruleArray[field.tag].filter(rule => checkRule(rule, field, subfield1, subfield2));
|
|
664
|
+
activeRules.forEach(rule => {
|
|
665
|
+
const originalValue = subfield1.value;
|
|
666
|
+
if (rule.remove && [REMOVE, REMOVE_AND_ADD].includes(operation) && subfield1.value.match(rule.remove)) {
|
|
667
|
+
// eslint-disable-line functional/no-conditional-statements
|
|
668
|
+
//nvdebug(` PUNC REMOVAL TO BE PERFORMED FOR $${subfield1.code} '${subfield1.value}'`, debug);
|
|
669
|
+
subfield1.value = subfield1.value.replace(rule.remove, ''); // eslint-disable-line functional/immutable-data
|
|
670
|
+
//nvdebug(` PUNC REMOVAL PERFORMED FOR '${subfield1.value}'`, debug);
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
if (rule.add && [ADD, REMOVE_AND_ADD].includes(operation)) {
|
|
674
|
+
// eslint-disable-line functional/no-conditional-statements
|
|
675
|
+
subfield1.value += rule.add; // eslint-disable-line functional/immutable-data
|
|
676
|
+
//nvdebug(` ADDED '${rule.add}' TO '${subfield1.value}'`, debug);
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
if (subfield1.value !== originalValue) {// eslint-disable-line functional/no-conditional-statements
|
|
680
|
+
//nvdebug(` PROCESS PUNC: '‡${subfield1.code} ${originalValue}' => '‡${subfield1.code} ${subfield1.value}'`, debug); // eslint-disable-line functional/immutable-data
|
|
681
|
+
}
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
function subfieldFixPunctuation(field, subfield1, subfield2) {
|
|
685
|
+
applyPunctuationRules(field, subfield1, subfield2, cleanCrappyPunctuationRules, REMOVE);
|
|
686
|
+
applyPunctuationRules(field, subfield1, subfield2, addPairedPunctuationRules, ADD);
|
|
687
|
+
}
|
|
688
|
+
function subfieldStripPunctuation(field, subfield1, subfield2) {
|
|
689
|
+
(0, _utils.nvdebug)(`FSP1: '${subfield1.value}'`);
|
|
690
|
+
applyPunctuationRules(field, subfield1, subfield2, cleanValidPunctuationRules, REMOVE);
|
|
691
|
+
(0, _utils.nvdebug)(`FSP2: '${subfield1.value}'`);
|
|
692
|
+
applyPunctuationRules(field, subfield1, subfield2, cleanCrappyPunctuationRules, REMOVE);
|
|
693
|
+
(0, _utils.nvdebug)(`FSP3: '${subfield1.value}'`);
|
|
694
|
+
}
|
|
695
|
+
function fieldStripPunctuation(field) {
|
|
696
|
+
if (!field.subfields) {
|
|
697
|
+
return field;
|
|
698
|
+
}
|
|
699
|
+
field.subfields.forEach((sf, i) => {
|
|
700
|
+
// NB! instead of next subfield, we should actually get next *non-control-subfield*!!!
|
|
701
|
+
// (In plain English: We should skip $0 - $9 at least, maybe $w as well...)
|
|
702
|
+
subfieldStripPunctuation(field, sf, getNextRelevantSubfield(field, i));
|
|
703
|
+
});
|
|
704
|
+
return field;
|
|
705
|
+
}
|
|
706
|
+
function fieldFixPunctuation(field) {
|
|
707
|
+
if (!field.subfields) {
|
|
708
|
+
return field;
|
|
709
|
+
}
|
|
710
|
+
(0, _utils.nvdebug)(`################### fieldFixPunctuation() TEST ${(0, _utils.fieldToString)(field)}`);
|
|
711
|
+
field.subfields.forEach((sf, i) => {
|
|
712
|
+
// NB! instead of next subfield, we should actually get next *non-control-subfield*!!!
|
|
713
|
+
// (In plain English: We should skip $0 - $9 at least, maybe $w as well...)
|
|
714
|
+
subfieldFixPunctuation(field, sf, getNextRelevantSubfield(field, i));
|
|
715
|
+
});
|
|
716
|
+
|
|
717
|
+
// Use shared code for final punctuation (sadly this does not fix intermediate punc):
|
|
718
|
+
if (field.useExternalEndPunctuation) {
|
|
719
|
+
// eslint-disable-line functional/no-conditional-statements
|
|
720
|
+
// addFinalPunctuation(field); // local version. use shared code instead.
|
|
721
|
+
(0, _endingPunctuation.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)
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
return field;
|
|
725
|
+
}
|
|
726
|
+
//# sourceMappingURL=punctuation2.js.map
|