diff options
author | Kristóf Marussy <kristof@marussy.com> | 2024-06-28 00:29:07 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2024-06-28 00:29:07 +0200 |
commit | 8f64ac2df4c6a31ad95ea04fb23717c76557e9cd (patch) | |
tree | 3209d71646072e3918d1fed25ef47a3b244d862d /subprojects/language-semantics/src/main/java | |
parent | refactor(store): NeighborhoodCalculator API (diff) | |
download | refinery-8f64ac2df4c6a31ad95ea04fb23717c76557e9cd.tar.gz refinery-8f64ac2df4c6a31ad95ea04fb23717c76557e9cd.tar.zst refinery-8f64ac2df4c6a31ad95ea04fb23717c76557e9cd.zip |
fix(semantics): configure StateCoderAdapter
Diffstat (limited to 'subprojects/language-semantics/src/main/java')
2 files changed, 20 insertions, 8 deletions
diff --git a/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/ModelInitializer.java b/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/ModelInitializer.java index 486eb89b..c2243f08 100644 --- a/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/ModelInitializer.java +++ b/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/ModelInitializer.java | |||
@@ -52,7 +52,9 @@ import tools.refinery.store.reasoning.translator.multiplicity.ConstrainedMultipl | |||
52 | import tools.refinery.store.reasoning.translator.multiplicity.Multiplicity; | 52 | import tools.refinery.store.reasoning.translator.multiplicity.Multiplicity; |
53 | import tools.refinery.store.reasoning.translator.multiplicity.UnconstrainedMultiplicity; | 53 | import tools.refinery.store.reasoning.translator.multiplicity.UnconstrainedMultiplicity; |
54 | import tools.refinery.store.reasoning.translator.predicate.PredicateTranslator; | 54 | import tools.refinery.store.reasoning.translator.predicate.PredicateTranslator; |
55 | import tools.refinery.store.statecoding.StateCoderBuilder; | ||
55 | import tools.refinery.store.tuple.Tuple; | 56 | import tools.refinery.store.tuple.Tuple; |
57 | import tools.refinery.store.tuple.Tuple1; | ||
56 | 58 | ||
57 | import java.util.*; | 59 | import java.util.*; |
58 | 60 | ||
@@ -78,6 +80,8 @@ public class ModelInitializer { | |||
78 | 80 | ||
79 | private BuiltinSymbols builtinSymbols; | 81 | private BuiltinSymbols builtinSymbols; |
80 | 82 | ||
83 | private final List<Tuple1> individuals = new ArrayList<>(); | ||
84 | |||
81 | private PartialRelation nodeRelation; | 85 | private PartialRelation nodeRelation; |
82 | 86 | ||
83 | private final Map<Relation, RelationInfo> relationInfoMap = new LinkedHashMap<>(); | 87 | private final Map<Relation, RelationInfo> relationInfoMap = new LinkedHashMap<>(); |
@@ -190,6 +194,8 @@ public class ModelInitializer { | |||
190 | } | 194 | } |
191 | collectPredicates(storeBuilder); | 195 | collectPredicates(storeBuilder); |
192 | collectRules(storeBuilder); | 196 | collectRules(storeBuilder); |
197 | storeBuilder.tryGetAdapter(StateCoderBuilder.class) | ||
198 | .ifPresent(stateCoderBuilder -> stateCoderBuilder.individuals(individuals)); | ||
193 | } catch (TranslationException e) { | 199 | } catch (TranslationException e) { |
194 | throw problemTrace.wrapException(e); | 200 | throw problemTrace.wrapException(e); |
195 | } | 201 | } |
@@ -224,29 +230,33 @@ public class ModelInitializer { | |||
224 | } | 230 | } |
225 | } | 231 | } |
226 | for (var node : problem.getNodes()) { | 232 | for (var node : problem.getNodes()) { |
227 | collectNode(node); | 233 | collectNode(node, false); |
228 | } | 234 | } |
229 | } | 235 | } |
230 | 236 | ||
231 | private void collectNodes(Statement statement) { | 237 | private void collectNodes(Statement statement) { |
232 | if (statement instanceof NodeDeclaration nodeDeclaration) { | 238 | if (statement instanceof NodeDeclaration nodeDeclaration) { |
239 | boolean individual = nodeDeclaration.getKind() == NodeKind.ATOM; | ||
233 | for (var node : nodeDeclaration.getNodes()) { | 240 | for (var node : nodeDeclaration.getNodes()) { |
234 | collectNode(node); | 241 | collectNode(node, individual); |
235 | } | 242 | } |
236 | } else if (statement instanceof ClassDeclaration classDeclaration) { | 243 | } else if (statement instanceof ClassDeclaration classDeclaration) { |
237 | var newNode = classDeclaration.getNewNode(); | 244 | var newNode = classDeclaration.getNewNode(); |
238 | if (newNode != null) { | 245 | if (newNode != null) { |
239 | collectNode(newNode); | 246 | collectNode(newNode, false); |
240 | } | 247 | } |
241 | } else if (statement instanceof EnumDeclaration enumDeclaration) { | 248 | } else if (statement instanceof EnumDeclaration enumDeclaration) { |
242 | for (var literal : enumDeclaration.getLiterals()) { | 249 | for (var literal : enumDeclaration.getLiterals()) { |
243 | collectNode(literal); | 250 | collectNode(literal, true); |
244 | } | 251 | } |
245 | } | 252 | } |
246 | } | 253 | } |
247 | 254 | ||
248 | private void collectNode(Node node) { | 255 | private void collectNode(Node node, boolean individual) { |
249 | problemTrace.collectNode(node); | 256 | int nodeId = problemTrace.collectNode(node); |
257 | if (individual) { | ||
258 | individuals.add(Tuple.of(nodeId)); | ||
259 | } | ||
250 | } | 260 | } |
251 | 261 | ||
252 | private void collectPartialSymbols() { | 262 | private void collectPartialSymbols() { |
diff --git a/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/ProblemTraceImpl.java b/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/ProblemTraceImpl.java index 3a979bf0..4b44339c 100644 --- a/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/ProblemTraceImpl.java +++ b/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/ProblemTraceImpl.java | |||
@@ -70,8 +70,10 @@ class ProblemTraceImpl implements ProblemTrace { | |||
70 | return nodeTrace; | 70 | return nodeTrace; |
71 | } | 71 | } |
72 | 72 | ||
73 | void collectNode(Node node) { | 73 | int collectNode(Node node) { |
74 | mutableNodeTrace.getIfAbsentPut(node, mutableNodeTrace.size()); | 74 | var nextId = mutableNodeTrace.size(); |
75 | mutableNodeTrace.getIfAbsentPut(node, nextId); | ||
76 | return nextId; | ||
75 | } | 77 | } |
76 | 78 | ||
77 | @Override | 79 | @Override |