Base class for any filter system.
Module sppas.src.structs
Class sppasBaseFilters
Description
Constructor
Create a sppasBaseFilters instance.
Parameters
- obj: (object) The object to be filtered.
View Source
def __init__(self, obj):
"""Create a sppasBaseFilters instance.
:param obj: (object) The object to be filtered.
"""
self.obj = obj
Public functions
test_args
Raise an exception if any of the args is not correct.
Parameters
- comparator: (sppasBaseComparator)
View Source
@staticmethod
def test_args(comparator, **kwargs):
"""Raise an exception if any of the args is not correct.
:param comparator: (sppasBaseComparator)
"""
names = ['logic_bool', 'logic_bool_label'] + comparator.get_function_names()
for func_name, value in kwargs.items():
if func_name.startswith('not_'):
func_name = func_name[4:]
if func_name not in names:
raise sppasKeyError('kwargs function name', func_name)
fix_logic_bool
Return the value of a logic boolean predicate.
Expect the "logic_bool" argument.
Returns
- (str) "and" or "or". By default, the logical "and" is returned.
Raises
sppasValueError
View Source
@staticmethod
def fix_logic_bool(**kwargs):
"""Return the value of a logic boolean predicate.
Expect the "logic_bool" argument.
:return: (str) "and" or "or". By default, the logical "and" is returned.
:raise: sppasValueError
"""
for func_name, value in kwargs.items():
if func_name == 'logic_bool':
if value not in ['and', 'or']:
raise sppasValueError(value, 'logic bool')
return value
return 'and'
fix_logic_bool_label
Return the value of a logic boolean predicate.
Expect the "logicboollabel" args.
Returns
- (str) "all" or "any". By default, "any" is returned.
Raises
sppasValueError
View Source
@staticmethod
def fix_logic_bool_label(**kwargs):
"""Return the value of a logic boolean predicate.
Expect the "logic_bool_label" args.
:return: (str) "all" or "any". By default, "any" is returned.
:raise: sppasValueError
"""
for func_name, value in kwargs.items():
if func_name == 'logic_bool_label':
if value not in ['all', 'any']:
raise sppasValueError(value, 'logic bool label')
return value
return 'any'
fix_function_values
Return the list of function names and the expected value.
Parameters
- comparator: (sppasBaseComparator)
View Source
@staticmethod
def fix_function_values(comparator, **kwargs):
"""Return the list of function names and the expected value.
:param comparator: (sppasBaseComparator)
"""
fct_values = list()
for func_name, value in kwargs.items():
if func_name in comparator.get_function_names():
fct_values.append('{:s} = {!s:s}'.format(func_name, value))
return fct_values
fix_functions
Parse the args to get the list of function/value/complement.
Parameters
- comparator: (sppasBaseComparator)
View Source
@staticmethod
def fix_functions(comparator, **kwargs):
"""Parse the args to get the list of function/value/complement.
:param comparator: (sppasBaseComparator)
"""
f_functions = list()
for func_name, value in kwargs.items():
logical_not = False
if func_name.startswith('not_'):
logical_not = True
func_name = func_name[4:]
if func_name in comparator.get_function_names():
f_functions.append((comparator.get(func_name), value, logical_not))
return f_functions