1. Predicates#
Predicates are used within marc21-learn to filter records and fields
according to specific criteria. Filtering out records that are not needed
early on prevents unnecessary computations; in particular, it avoids
unnecessary memory allocations. In the context of the Polars integration, the
filter expressions are used for predicate pushdown to filter out records as
early as possible.
When filtering records, a distinction is made between the two basic
expressions: leader matcher and field
matcher. These elementary expressions can be
combined into more complex expressions using the Boolean connectives conjunction (&&) and disjunction (||),
as well as grouping ((...)). While the leader matcher makes statements about the leader of a record,
the field matcher is used to make statements about
the variable fields.
The following sections demonstrate the various ways to filter records using
the read_marc21() function and the Ada Lovelace test record. After
the predicate has been applied to the record, the height of the DataFrame
is checked. If the height is 1, the test record meets the criterion;
otherwise, it does not.