Skip to content

component_filters.py

ofrak.model.component_filters

AnalyzerOutputFilter (ComponentFilter)

Only allow analyzers whose outputs have some overlap with the requested outputs.

filter(self, components)

Filter out components according to the rules this component enforces.

Parameters:

Name Type Description Default
components Set[ofrak.component.interface.ComponentInterface]

Components to filter

required

Returns:

Type Description
Set[ofrak.component.interface.ComponentInterface]

All components which this filter allows

Source code in ofrak/model/component_filters.py
def filter(self, components: Set[ComponentInterface]) -> Set[ComponentInterface]:
    def component_is_analyzer_with_outputs(c: ComponentInterface):
        if _isinstance(c, Analyzer):
            analyzer_outputs = set(c.get_outputs_as_attribute_types())  # type: ignore
            return not analyzer_outputs.isdisjoint(self.outputs)
        return False

    return {c for c in components if component_is_analyzer_with_outputs(c)}

ComponentAndMetaFilter (ComponentMetaFilter)

Only allow components which match all of multiple filters. If there are no filters, all components will be filtered out.

filter(self, components)

Filter out components according to the rules this component enforces.

Parameters:

Name Type Description Default
components Set[ofrak.component.interface.ComponentInterface]

Components to filter

required

Returns:

Type Description
Set[ofrak.component.interface.ComponentInterface]

All components which this filter allows

Source code in ofrak/model/component_filters.py
def filter(self, components: Set[ComponentInterface]) -> Set[ComponentInterface]:
    if 0 == len(self.filters):
        return set()
    for component_filter in self.filters:
        components = component_filter.filter(components)
        if not components:
            break

    return components

ComponentMetaFilter (ComponentFilter, ABC)

Abstract class for filters containing sub-filters which must be evaluated for this filter to be resolved.

ComponentNotMetaFilter (ComponentMetaFilter)

Invert the result of a child filter, that is, filter out components that would pass it and pass components which the child filter would filter out.

filter(self, components)

Filter out components according to the rules this component enforces.

Parameters:

Name Type Description Default
components Set[ofrak.component.interface.ComponentInterface]

Components to filter

required

Returns:

Type Description
Set[ofrak.component.interface.ComponentInterface]

All components which this filter allows

Source code in ofrak/model/component_filters.py
def filter(self, components: Set[ComponentInterface]) -> Set[ComponentInterface]:
    return components.difference(self.filters[0].filter(components))

ComponentOrMetaFilter (ComponentMetaFilter)

Only allow components which match any one of multiple filters. If there are no filters, no components will be filtered out.

filter(self, components)

Filter out components according to the rules this component enforces.

Parameters:

Name Type Description Default
components Set[ofrak.component.interface.ComponentInterface]

Components to filter

required

Returns:

Type Description
Set[ofrak.component.interface.ComponentInterface]

All components which this filter allows

Source code in ofrak/model/component_filters.py
def filter(self, components: Set[ComponentInterface]) -> Set[ComponentInterface]:
    if 0 == len(self.filters):
        return components
    else:
        return set(itertools.chain(*(f.filter(components) for f in self.filters)))

ComponentPrioritySelectingMetaFilter (ComponentMetaFilter)

Selects exactly one filter to apply from a prioritized list of component filters. Only the first filter which allows more than zero components is applied. If no filters allow any components through, then this filter passes no components.

For example, if the filters are: - filter 1: tag matches A, B, or C - filter 2: tag matches C, D, or E - filter 3: tag matches E, F, or G

and the components under consideration are one targeting (E) and one targeting (F), then only the component targeting (E) passes this meta-filter. This is because: - filter 1 would filter out all components under consideration, so it's ignored; - filter 2 would allow one or more components (namely, the component targeting (E)), so this meta-filter then behaves like just filter 2 in this prioritized list.

filter(self, components)

Filter out components according to the rules this component enforces.

Parameters:

Name Type Description Default
components Set[ofrak.component.interface.ComponentInterface]

Components to filter

required

Returns:

Type Description
Set[ofrak.component.interface.ComponentInterface]

All components which this filter allows

Source code in ofrak/model/component_filters.py
def filter(self, components: Set[ComponentInterface]) -> Set[ComponentInterface]:
    for f in self.filters:
        components_passing_f = f.filter(components)
        if components_passing_f:
            return components_passing_f

    return set()

ComponentTargetFilter (ComponentFilter)

Only allow components which target at least one of the tags in a set. The tags must be strictly equal, that is, super/subclasses of the tags are not checked.

filter(self, components)

Filter out components according to the rules this component enforces.

Parameters:

Name Type Description Default
components Set[ofrak.component.interface.ComponentInterface]

Components to filter

required

Returns:

Type Description
Set[ofrak.component.interface.ComponentInterface]

All components which this filter allows

Source code in ofrak/model/component_filters.py
def filter(self, components: Set[ComponentInterface]) -> Set[ComponentInterface]:
    return {c for c in components if any(t in self.tags for t in c.targets)}

ComponentTypeFilter (ComponentFilter)

Only allow components of a specific type (e.g. Analyzer) to run.

filter(self, components)

Filter out components according to the rules this component enforces.

Parameters:

Name Type Description Default
components Set[ofrak.component.interface.ComponentInterface]

Components to filter

required

Returns:

Type Description
Set[ofrak.component.interface.ComponentInterface]

All components which this filter allows

Source code in ofrak/model/component_filters.py
def filter(self, components: Set[ComponentInterface]) -> Set[ComponentInterface]:
    return {c for c in components if _isinstance(c, self.component_type)}

ComponentWhitelistFilter (ComponentFilter)

Only allow components which belong to a specific set to be run.

filter(self, components)

Filter out components according to the rules this component enforces.

Parameters:

Name Type Description Default
components Set[ofrak.component.interface.ComponentInterface]

Components to filter

required

Returns:

Type Description
Set[ofrak.component.interface.ComponentInterface]

All components which this filter allows

Source code in ofrak/model/component_filters.py
def filter(self, components: Set[ComponentInterface]) -> Set[ComponentInterface]:
    return {c for c in components if c.get_id() in self.whitelisted_component_ids}