def __new__(cls, **kwargs): """ Create a Predicate. @param kwargs: exact (str): exact match iexact (str): Case-insensitive exact match startswith (str): istartswith (str): Case-insensitive startswith endswith (str): iendswith: Case-insensitive endswith contains (str): icontains: Case-insensitive contains regexp (str): regular expression begin_lt (float): begin_le (float): begin_gt (float): begin_ge (float): begin_eq (float): end_lt (float): end_le (float): end_gt (float): end_ge (float): end_eq (float): duration_lt (float): duration_le (float): duration_gt (float): duration_ge (float): duration_eq (float): @returns: (Predicate) >>> # extract pauses. >>> pred = Bool(exact="#") | Bool(exact="+") >>> annotations = [a for a in tier if pred(a)] >>> # extract long pauses. >>> pred = Bool(exact="#") & Bool(duration_gt=200) >>> annotations = [a for a in tier if pred(a)] """ functions = [] if not kwargs: functions.append(lambda a: True) for func_name, param in kwargs.items(): function = _bools.create(func_name, param) functions.append(function) return reduce(operator.and_, (Predicate(f) for f in functions))
def __new__(cls, **kwargs): """ Create a Predicate. @param kwargs: exact (str): label exact match iexact (str): label case-insensitive exact match startswith (str): istartswith (str): Case-insensitive startswith endswith (str): iendswith: Case-insensitive endswith contains (str): icontains: Case-insensitive contains regexp (str): regular expression begin_eq (float): begin time value equal to begin_lt (float): begin time value lower than begin_le (float): begin_gt (float): begin_ge (float): end_eq (float): end time value equal to end_lt (float): end time value lower than end_le (float): end_gt (float): end_ge (float): duration_eq (float): duration equal to duration_lt (float): duration_le (float): duration_gt (float): duration_ge (float): opt: option to be used while creating the function: "best": search on the best label only, and return true if it is matching the expected function "any": search in all labels, and return true if one of them is matching the expected function @returns: (Predicate) >>> # extract all pauses >>> pred = Sel(exact="#") | Sel(exact="+") >>> # extract long pauses >>> pred = (Sel(exact="#") | Sel(exact="+")) & Sel(duration_gt=200) """ functions = [] if not kwargs: functions.append(lambda a: True) opt="best" for func_name, param in kwargs.items(): if func_name == "opt": opt = param for func_name, param in kwargs.items(): if func_name != "opt": function = _bools.create(func_name, arg=param, opt=opt) functions.append(function) return reduce(operator.and_, (Predicate(f) for f in functions))