43 template <ComputeData DataType>
48 std::any_cast<IO<DataType>>(input);
50 }
catch (
const std::bad_any_cast&) {
63 return [required_context](
const std::any& ,
const ExecutionContext& ctx) ->
bool {
64 return ctx.execution_metadata.contains(
"computation_context") && std::any_cast<ComputationContext>(ctx.execution_metadata.at(
"computation_context")) == required_context;
76 return [param_name, expected_value](
const std::any& ,
const ExecutionContext& ctx) ->
bool {
77 return ctx.execution_metadata.contains(param_name) && ctx.execution_metadata.at(param_name).type() == expected_value.type();
88 return [matchers = std::move(matchers)](
const std::any& input,
const ExecutionContext& ctx) ->
bool {
89 return std::ranges::all_of(matchers, [&](
const auto& matcher) {
90 return matcher(input, ctx);
102 return [matchers = std::move(matchers)](
const std::any& input,
const ExecutionContext& ctx) ->
bool {
103 return std::ranges::any_of(matchers, [&](
const auto& matcher) {
104 return matcher(input, ctx);
120 const std::unordered_map<std::string, std::any>& parameters,
123 auto operation = std::make_shared<OperationType>(std::forward<Args>(args)...);
125 for (
const auto& [param_name, param_value] : parameters) {
127 operation->set_parameter(param_name, param_value);
142template <
typename OperationType>
147 operation->set_parameter(ctx_name, ctx_value);
static MatcherFunc combine_or(std::vector< MatcherFunc > matchers)
Combines multiple matchers with OR logic.
static MatcherFunc create_context_matcher(ComputationContext required_context)
Creates a matcher that checks for specific computation contexts.
static MatcherFunc create_type_matcher()
Creates a matcher that checks for specific data types.
std::function< bool(const std::any &, const ExecutionContext &)> MatcherFunc
static MatcherFunc combine_and(std::vector< MatcherFunc > matchers)
Combines multiple matchers with AND logic.
static MatcherFunc create_parameter_matcher(const std::string ¶m_name, const std::any &expected_value)
Creates a matcher that checks for specific parameter values.
Type-agnostic pattern matching for computation rules.
std::shared_ptr< OperationType > create_configured_operation(const std::unordered_map< std::string, std::any > ¶meters, Args &&... args)
Creates an operation instance with parameters using safe_any_cast system.
@ TEMPORAL
Time-based patterns, onset detection.
@ SPATIAL
Multi-dimensional geometric analysis.
@ SPECTRAL
Spectral energy (FFT-based)
@ RECURSIVE
Recursive/nested extraction.
void apply_context_parameters(std::shared_ptr< OperationType > operation, const ExecutionContext &ctx)
Applies context parameters to an operation.
ComputationContext
Defines the computational contexts in which rules can be applied.
@ SEMANTIC
Semantic operations.
@ STRUCTURAL
Graph/tree operations.
@ LOGICAL
Boolean/conditional operations.
@ CONCURRENT
Parallel/async operations.
@ PARAMETRIC
Parameter transformation.
@ REACTIVE
Event-driven operations.
@ CONVOLUTION
Convolution-based operations.
OperationType
Operation categories for organization and discovery.
std::unordered_map< std::string, std::any > execution_metadata
Context information for operation execution.