From 0bd7854ae802ad04c1c9e3da4e87dde542152b46 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Thu, 27 Jun 2024 19:47:46 +0200 Subject: refactor(store): NeighborhoodCalculator API * Use US English spelling consistently * Avoid Eclipse Collections types on API --- .../PartialNeighborhoodCalculator.java | 68 ++++++++++++++++++++++ .../PartialNeighbourhoodCalculator.java | 67 --------------------- 2 files changed, 68 insertions(+), 67 deletions(-) create mode 100644 subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/interpretation/PartialNeighborhoodCalculator.java delete mode 100644 subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/interpretation/PartialNeighbourhoodCalculator.java (limited to 'subprojects/store-reasoning/src') diff --git a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/interpretation/PartialNeighborhoodCalculator.java b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/interpretation/PartialNeighborhoodCalculator.java new file mode 100644 index 00000000..31295e64 --- /dev/null +++ b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/interpretation/PartialNeighborhoodCalculator.java @@ -0,0 +1,68 @@ +/* + * SPDX-FileCopyrightText: 2024 The Refinery Authors + * + * SPDX-License-Identifier: EPL-2.0 + */ +package tools.refinery.store.reasoning.interpretation; + +import tools.refinery.store.map.Cursor; +import tools.refinery.store.model.Model; +import tools.refinery.store.query.ModelQueryAdapter; +import tools.refinery.store.reasoning.ReasoningAdapter; +import tools.refinery.store.reasoning.literal.Concreteness; +import tools.refinery.store.reasoning.representation.PartialSymbol; +import tools.refinery.store.statecoding.StateCodeCalculatorFactory; +import tools.refinery.store.statecoding.StateCoderResult; +import tools.refinery.store.statecoding.neighborhood.AbstractNeighborhoodCalculator; +import tools.refinery.store.statecoding.neighborhood.IndividualsSet; +import tools.refinery.store.tuple.Tuple; + +import java.util.List; + +public class PartialNeighborhoodCalculator extends AbstractNeighborhoodCalculator> { + private final ModelQueryAdapter queryAdapter; + private final Concreteness concreteness; + + protected PartialNeighborhoodCalculator(Model model, IndividualsSet individuals, Concreteness concreteness, + int depth) { + super(model, individuals, depth); + queryAdapter = model.getAdapter(ModelQueryAdapter.class); + this.concreteness = concreteness; + } + + @Override + public StateCoderResult calculateCodes() { + queryAdapter.flushChanges(); + return super.calculateCodes(); + } + + @Override + protected List> getInterpretations() { + var adapter = getModel().getAdapter(ReasoningAdapter.class); + var partialSymbols = adapter.getStoreAdapter().getPartialSymbols(); + return partialSymbols.stream() + .>map(partialSymbol -> + adapter.getPartialInterpretation(concreteness, (PartialSymbol) partialSymbol)) + .toList(); + } + + @Override + protected int getArity(PartialInterpretation interpretation) { + return interpretation.getPartialSymbol().arity(); + } + + @Override + protected Object getNullValue(PartialInterpretation interpretation) { + return interpretation.get(Tuple.of()); + } + + @Override + protected Cursor getCursor(PartialInterpretation interpretation) { + return interpretation.getAll(); + } + + public static StateCodeCalculatorFactory factory(Concreteness concreteness, int depth) { + return (model, interpretations, individuals) -> new PartialNeighborhoodCalculator(model, individuals, + concreteness, depth); + } +} diff --git a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/interpretation/PartialNeighbourhoodCalculator.java b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/interpretation/PartialNeighbourhoodCalculator.java deleted file mode 100644 index 67e20dbc..00000000 --- a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/interpretation/PartialNeighbourhoodCalculator.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2024 The Refinery Authors - * - * SPDX-License-Identifier: EPL-2.0 - */ -package tools.refinery.store.reasoning.interpretation; - -import org.eclipse.collections.api.set.primitive.IntSet; -import tools.refinery.store.map.Cursor; -import tools.refinery.store.model.Model; -import tools.refinery.store.query.ModelQueryAdapter; -import tools.refinery.store.reasoning.ReasoningAdapter; -import tools.refinery.store.reasoning.literal.Concreteness; -import tools.refinery.store.reasoning.representation.PartialSymbol; -import tools.refinery.store.statecoding.StateCodeCalculatorFactory; -import tools.refinery.store.statecoding.StateCoderResult; -import tools.refinery.store.statecoding.neighbourhood.AbstractNeighbourhoodCalculator; -import tools.refinery.store.tuple.Tuple; - -import java.util.List; - -public class PartialNeighbourhoodCalculator extends AbstractNeighbourhoodCalculator> { - private final ModelQueryAdapter queryAdapter; - private final Concreteness concreteness; - - protected PartialNeighbourhoodCalculator(Model model, IntSet individuals, Concreteness concreteness, int depth) { - super(model, individuals, depth); - queryAdapter = model.getAdapter(ModelQueryAdapter.class); - this.concreteness = concreteness; - } - - @Override - public StateCoderResult calculateCodes() { - queryAdapter.flushChanges(); - return super.calculateCodes(); - } - - @Override - protected List> getInterpretations() { - var adapter = getModel().getAdapter(ReasoningAdapter.class); - var partialSymbols = adapter.getStoreAdapter().getPartialSymbols(); - return partialSymbols.stream() - .>map(partialSymbol -> - adapter.getPartialInterpretation(concreteness, (PartialSymbol) partialSymbol)) - .toList(); - } - - @Override - protected int getArity(PartialInterpretation interpretation) { - return interpretation.getPartialSymbol().arity(); - } - - @Override - protected Object getNullValue(PartialInterpretation interpretation) { - return interpretation.get(Tuple.of()); - } - - @Override - protected Cursor getCursor(PartialInterpretation interpretation) { - return interpretation.getAll(); - } - - public static StateCodeCalculatorFactory factory(Concreteness concreteness, int depth) { - return (model, interpretations, individuals) -> new PartialNeighbourhoodCalculator(model, individuals, - concreteness, depth); - } -} -- cgit v1.2.3-54-g00ecf