blob: e8ed05a3c107f106354446a3bff0a122c6206d45 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
package tools.refinery.store.reasoning.rule;
import tools.refinery.store.reasoning.Reasoning;
import tools.refinery.store.reasoning.representation.PartialRelation;
import tools.refinery.store.model.Model;
import tools.refinery.store.query.term.Variable;
import tools.refinery.store.representation.TruthValue;
import tools.refinery.store.tuple.Tuple;
import java.util.List;
public record RelationRefinementAction(PartialRelation target, List<Variable> arguments, TruthValue value)
implements RuleAction {
public RelationRefinementAction {
if (arguments.size() != target.arity()) {
throw new IllegalArgumentException("%s needs %d parameters, but got %s".formatted(target.name(),
target.arity(), arguments.size()));
}
if (value == TruthValue.UNKNOWN) {
throw new IllegalArgumentException("Refining with UNKNOWN has no effect");
}
}
@Override
public RuleActionExecutor createExecutor(int[] argumentIndices, Model model) {
var targetInterpretation = model.getAdapter(Reasoning.ADAPTER).getPartialInterpretation(target);
return activationTuple -> {
int arity = argumentIndices.length;
var arguments = new int[arity];
for (int i = 0; i < arity; i++) {
arguments[i] = activationTuple.get(argumentIndices[i]);
}
return targetInterpretation.merge(Tuple.of(arguments), value);
};
}
}
|