Custom Modules
Custom modules can be defined either inside the KELE codebase or by importing and registering strategies from external modules. The external registration approach is recommended for most users because it avoids modifying the library itself.
I. Rule Selection Module
Option A: external module (recommended)
- Create a Python module in your own project (for example,
my_app/strategies.py). - Inherit from the
RuleSelectionStrategyprotocol. - Register your strategy class with the top-level registry:
python
from kele import register
from kele.control.grounding_selector.rule_strategies import RuleSelectionStrategy
@register.rule_selector("my_rule_strategy")
class MyRuleStrategy(RuleSelectionStrategy):
...- Reference
"my_rule_strategy"via thegrounding_rule_strategyconfiguration.
Option B: internal module
- Create a
.pyfile named_<name>_strategy.py, and place it under thekele/control/grounding_selector/_rule_stragetiesdirectory; - Inherit from the
RuleSelectionStrategyclass, and declare at least the functions required by this Protocol; - Register your strategy class with
@register_strategy('<name>'). Afterwards, you can use the strategy viagrounding_rule_strategy; - Remember to adjust the type annotation of
grounding_rule_strategy(add a candidate value to theLiteral).
II. Fact Selection Module
Since the engine performs reasoning at the item level, this is effectively term selection. Follow the same process as the rule selection module, but inherit from the TermSelectionStrategy protocol and register with register.term_selector(...) when defining external modules. Use the implementation via the grounding_term_strategy parameter. If you add internal strategies, remember to update the type annotation of grounding_term_strategy as well (add the new Literal candidate).