blob: a1e4b816f3aef9372cfbbe0c0bc0ebc0de450cce (
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
37
38
39
40
41
42
43
44
45
46
47
48
49
|
/*
* SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/>
*
* SPDX-License-Identifier: EPL-2.0
*/
package tools.refinery.store.reasoning.translator.base;
import tools.refinery.store.model.Model;
import tools.refinery.store.reasoning.representation.PartialRelation;
import tools.refinery.store.reasoning.seed.Seed;
import tools.refinery.store.reasoning.seed.UniformSeed;
import tools.refinery.store.reasoning.translator.TranslatedRelation;
import tools.refinery.store.reasoning.translator.TranslationUnit;
import tools.refinery.store.representation.Symbol;
import tools.refinery.store.representation.TruthValue;
import java.util.Collection;
import java.util.List;
public class BaseDecisionTranslationUnit extends TranslationUnit {
private final PartialRelation partialRelation;
private final Seed<TruthValue> seed;
private final Symbol<TruthValue> symbol;
public BaseDecisionTranslationUnit(PartialRelation partialRelation, Seed<TruthValue> seed) {
if (seed.arity() != partialRelation.arity()) {
throw new IllegalArgumentException("Expected seed with arity %d for %s, got arity %s"
.formatted(partialRelation.arity(), partialRelation, seed.arity()));
}
this.partialRelation = partialRelation;
this.seed = seed;
symbol = Symbol.of(partialRelation.name(), partialRelation.arity(), TruthValue.class, TruthValue.UNKNOWN);
}
public BaseDecisionTranslationUnit(PartialRelation partialRelation) {
this(partialRelation, new UniformSeed<>(partialRelation.arity(), TruthValue.UNKNOWN));
}
@Override
public Collection<TranslatedRelation> getTranslatedRelations() {
return List.of(new TranslatedBaseDecision(getReasoningBuilder(), partialRelation, symbol));
}
@Override
public void initializeModel(Model model, int nodeCount) {
var interpretation = model.getInterpretation(symbol);
interpretation.putAll(seed.getCursor(TruthValue.UNKNOWN, nodeCount));
}
}
|