Skip to content

Commit cf75695

Browse files
committed
Add Khiops dictionary rule API support
- add a `Rule` class - add `{Variable,VariableBlock}.{get,set}_rule` methods - add an `upper_scope` function which applies the upper-scope operand `.` to `Variable` and `Rule` instances and to upper-scoped instances of these.
1 parent 676cd4c commit cf75695

File tree

5 files changed

+683
-7
lines changed

5 files changed

+683
-7
lines changed

doc/samples/samples.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,17 +655,23 @@ Samples
655655
fold_index_variable.name = "FoldIndex"
656656
fold_index_variable.type = "Numerical"
657657
fold_index_variable.used = False
658-
fold_index_variable.rule = "Ceil(Product(" + str(fold_number) + ", Random()))"
659658
dictionary.add_variable(fold_index_variable)
660659
660+
# Create fold indexing rule and set it on `fold_index_variable`
661+
dictionary.get_variable(fold_index_variable.name).set_rule(
662+
kh.Rule("Ceil", kh.Rule("Product", fold_number, kh.Rule("Random()"))),
663+
)
664+
661665
# Add variables that indicate if the instance is in the train dataset:
662666
for fold_index in range(1, fold_number + 1):
663667
is_in_train_dataset_variable = kh.Variable()
664668
is_in_train_dataset_variable.name = "IsInTrainDataset" + str(fold_index)
665669
is_in_train_dataset_variable.type = "Numerical"
666670
is_in_train_dataset_variable.used = False
667-
is_in_train_dataset_variable.rule = "NEQ(FoldIndex, " + str(fold_index) + ")"
668671
dictionary.add_variable(is_in_train_dataset_variable)
672+
dictionary.get_variable(is_in_train_dataset_variable.name).set_rule(
673+
kh.Rule("NEQ", fold_index_variable, fold_index),
674+
)
669675
670676
# Print dictionary with fold variables
671677
print("Dictionary file with fold variables")

0 commit comments

Comments
 (0)