Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

marc21-check(1)

NAME

marc21-check — Validate records against rule sets

SYNOPSIS

marc21 check [options] [path]…

DESCRIPTION

The check command can be used to verify whether records conform to a set of rules. The rules are defined by the user and are referenced by a unique identifier that can be chosen freely. When the command is executed, the input records are checked against each rule. If validation for a rule fails, the record is written to the output along with the control number (field 001), an error message, and the rule’s identifier. By default, the output is in DVRF format.

A set of rules is defined in TOML format and contains a list of rule definitions. The rule set can optionally be restricted using the (global) scope option. The rules contained in the file are then checked only for the records within the scope. In the following example, two rules with the identifiers RULE001 and RULE002 are defined. In accordance with the scope, these rules are applied only to authority records.

scope = 'ldr.type == "z"'

[rule.R001]
message = 'invalid field ABC'
...

[rule.R002]
message = 'invalid field DEF'
...

A rule consists, in addition to the identifier, of a error message (required), a (local) scope, the error level (warning, info, error), and the the validator specification (required). Depending on the selected validator, there might be additional required fields.

The output format is automatically determined based on the file extension. The following formats are supported: DVRF format (file extensions .json or .json.gz), CSV format (file extensions .csv or .csv.gz), text format (file extensions .txt or .txt.gz). If the format cannot be determined based on the file extension, the DVRF format is used by default. In text format, the control number is written to the output line by line without any additional information.

In the following example, the records in the file DUMP.mrc.gz are checked against the two rule sets gnd.toml and dnb.toml; the output is in DVRF format:

$ marc21 check -s -R gnd.toml -R dnb.toml DUMP.mrc.gz -o result.json

VALIDATORS

Duplicates

The duplicates validator can be used to verify whether a value — or a combination of multiple values — appears more than once. The default threshold is 2 and can be changed using the threshold option. The following rule checks whether there are values (rows of the query) in subfield a of data field 041 that appear more than twice:

[rule.DUPLICATE-LANGUAGE-CODES]
validator = 'duplicates'
query = '041.a'

The validator supports the following options/flags:

query = <query>
A query whose values are checked for duplicates.
threshold = <n>
The threshold value at which a row is considered a duplicate.
separator = <sep>
The separator used to join the individual columns of the query.This is only necessary if a duplicate was found; in that case, it is written to the output.
scope = <record-matcher>
Only records that meet the specified record matcher are checked.
invert-matcher = true | false
If this flag is set, the result is inverted: A record fails validation if the filter expression is false.

Filter

The filter validator checks whether a record matches a filter criterion (record matcher). Unless explicitly stated by the invert-match flag, the validation fails if the record match the filter expression. The filter expression must therefore be constructed in such a way that it identifies invalid records.

In the following example, the field 075 is checked to ensure that only valid entity codes appear in the subfield $b when the subfield $2 is set to the value gndgen. The validation of a record fails if a value is found in the field $b that is not b, f, g, p, s, or u.

[rule.GND-001-INVALID-ENTITY-CODE]
message = 'invalid entity code'
validator = 'filter'
filter = '075{ b not in ["b", "f", "g", "p", "s", "u"] && 2 == "gndgen" }'

The validator supports the following options/flags:

filter = <record-matcher>
A record matcher expression that is evaluated against the record.
invert-matcher = true | false
If this flag is set, the result is inverted: A record fails validation if the filter expression is false.

ISBN

The isbn validator checks whether the content of a field contains a valid ISBN. The format option can be used to specify whether to check only for valid ISBN-13s or for ISBN-10s.

[rule.ISBN]
validator = 'isbn'
path = '020.a'

The validator supports the following options/flags:

format = isbn13 | isbn10
Whether to check only for ISBN-13 or ISBN-10. If this option is not specified, both ISBN-13 and ISBN-10 are allowed.
scope = <record-matcher>
Only records that meet the specified record matcher are checked.
invert-matcher = true | false
If this flag is set, the result is inverted: A record fails validation if the filter expression is false.

OPTIONS

FILTER OPTIONS

-l, --limit <n>
Limit the result to first <n> records (a limit value 0 means no limit)
-s, --skip-invalid
Skip invalid records that can’t be decoded
--strsim-threshold <value>
The minimum score for string similarity comparisons. The value must be between 0 and 100.
--where
An filter expression for filtering records
--filter-normalization <form>
Transliterate the given filter or query expression into the specified Unicode normal form. Possible values: nfd, nfkd, nfc, nfkc. This option can also be specified by setting the environment variable MARC21_FILTER_NORMALIZATION.

COMMON OPTIONS

-p, --progress
If set, show a progress bar
--compression
Specify compression level (0..=9)

EXIT STATUS

  • 0 — Command succeeded.
  • 1 — Command failed.