Filter Matcher

Inheritance diagram of musify.processors.filter_matcher

Processors that filter down objects and data types based on some given configuration.

Classes:

MatchResult([included, excluded, compared, ...])

Results from FilterMatcher separated by individual filter results.

FilterMatcher([include, exclude, comparers, ...])

Get matches for items based on given filters.

class musify.processors.filter_matcher.MatchResult(included=(), excluded=(), compared=(), grouped=())

Bases: Result, Generic

Results from FilterMatcher separated by individual filter results.

Attributes:

included

Objects that matched include settings.

excluded

Objects that matched exclude settings.

compared

Objects that matched Comparer settings

grouped

Objects that matched on any group_by settings

combined

Combine the individual results to one combined list

included: Collection[TypeVar(T, bound= Any)] = ()

Objects that matched include settings.

excluded: Collection[TypeVar(T, bound= Any)] = ()

Objects that matched exclude settings.

compared: Collection[TypeVar(T, bound= Any)] = ()

Objects that matched Comparer settings

grouped: Collection[TypeVar(T, bound= Any)] = ()

Objects that matched on any group_by settings

property combined: list[T]

Combine the individual results to one combined list

class musify.processors.filter_matcher.FilterMatcher(include=FilterDefinedList({'values': ()}), exclude=FilterDefinedList({'values': ()}), comparers=FilterComparers({'comparers': {}, 'match_all': True}), group_by=None, *_, **__)

Bases: FilterComposite, Generic

Get matches for items based on given filters.

Parameters:
  • include (U (default: FilterDefinedList({'values': ()}))) – A Filter for simple include comparisons to use when matching.

  • exclude (V (default: FilterDefinedList({'values': ()}))) – A Filter for simple exclude comparisons to use when matching.

  • comparers (X (default: FilterComparers({'comparers': {}, 'match_all': True}))) – A Filter for fine-grained comparisons to use when matching. When not given or the given Filter is not ready, returns all given values on match unless include or exclude are defined and ready.

  • group_by (TagField | None (default: None)) – Once all other filters are applied, also include all other items that match this tag type from the matched items for any remaining unmatched items.

Attributes:

logger

The MusifyLogger for this object

include

The filter that, when processed, returns items to include

exclude

The filter that, when processed, returns items to exclude

comparers

The comparers to use when processing for this filter

group_by

Once all other filters are applied, also include all other items that match this tag type from the matched items for the remaining items given

Methods:

process(values[, reference])

Return a new, filtered list of items from input values that match the stored filters.

process_to_result(values[, reference])

Same as process() but returns the results of each filter to a :py:class`MatchResult` object

as_dict()

Return a dictionary representation of the key attributes of this object.

logger: MusifyLogger

The MusifyLogger for this object

include

The filter that, when processed, returns items to include

exclude

The filter that, when processed, returns items to exclude

comparers

The comparers to use when processing for this filter

group_by

Once all other filters are applied, also include all other items that match this tag type from the matched items for the remaining items given

process(values, reference=None, *_, **__)

Return a new, filtered list of items from input values that match the stored filters.

Parameters:
  • values (Collection[T]) – List of items to filter.

  • reference (T | None (default: None)) – Optional reference track to use when filtering on comparers and the comparer has no expected value.

Returns:

list[T] – List of items that match the conditions.

process_to_result(values, reference=None, *_, **__)

Same as process() but returns the results of each filter to a :py:class`MatchResult` object

Return type:

MatchResult

as_dict()

Return a dictionary representation of the key attributes of this object.

The results of this function are used to produce the following:
  • A JSON representation of the object when calling json()

  • The string representation of the object when calling str() on the object

  • The representation of the object when calling repr() on the object