diff options
author | Kristóf Marussy <kristof@marussy.com> | 2023-09-03 17:57:38 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2023-09-03 17:57:38 +0200 |
commit | cd96a9a4f54d45cda3ddf5df474946445d557090 (patch) | |
tree | 7a96a177236888ede9a51ffdd51940a672cfd070 /subprojects/language-web/src/main | |
parent | build: runtimeOnly Eclipse Collections if posible (diff) | |
download | refinery-cd96a9a4f54d45cda3ddf5df474946445d557090.tar.gz refinery-cd96a9a4f54d45cda3ddf5df474946445d557090.tar.zst refinery-cd96a9a4f54d45cda3ddf5df474946445d557090.zip |
feat: scope propagator in language
Diffstat (limited to 'subprojects/language-web/src/main')
-rw-r--r-- | subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsWorker.java | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsWorker.java b/subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsWorker.java index 108b87dc..8470bb99 100644 --- a/subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsWorker.java +++ b/subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsWorker.java | |||
@@ -22,15 +22,18 @@ import tools.refinery.language.semantics.metadata.MetadataCreator; | |||
22 | import tools.refinery.language.semantics.model.ModelInitializer; | 22 | import tools.refinery.language.semantics.model.ModelInitializer; |
23 | import tools.refinery.language.semantics.model.SemanticsUtils; | 23 | import tools.refinery.language.semantics.model.SemanticsUtils; |
24 | import tools.refinery.language.semantics.model.TracedException; | 24 | import tools.refinery.language.semantics.model.TracedException; |
25 | import tools.refinery.store.map.Cursor; | ||
25 | import tools.refinery.store.model.Model; | 26 | import tools.refinery.store.model.Model; |
26 | import tools.refinery.store.model.ModelStore; | 27 | import tools.refinery.store.model.ModelStore; |
27 | import tools.refinery.store.query.viatra.ViatraModelQueryAdapter; | 28 | import tools.refinery.store.query.viatra.ViatraModelQueryAdapter; |
28 | import tools.refinery.store.reasoning.ReasoningAdapter; | 29 | import tools.refinery.store.reasoning.ReasoningAdapter; |
29 | import tools.refinery.store.reasoning.ReasoningStoreAdapter; | 30 | import tools.refinery.store.reasoning.ReasoningStoreAdapter; |
30 | import tools.refinery.store.reasoning.literal.Concreteness; | 31 | import tools.refinery.store.reasoning.literal.Concreteness; |
32 | import tools.refinery.store.reasoning.refinement.RefinementResult; | ||
31 | import tools.refinery.store.reasoning.representation.PartialRelation; | 33 | import tools.refinery.store.reasoning.representation.PartialRelation; |
34 | import tools.refinery.store.reasoning.scope.ScopePropagatorAdapter; | ||
32 | import tools.refinery.store.reasoning.translator.TranslationException; | 35 | import tools.refinery.store.reasoning.translator.TranslationException; |
33 | import tools.refinery.store.representation.TruthValue; | 36 | import tools.refinery.store.reasoning.translator.multiobject.MultiObjectTranslator; |
34 | import tools.refinery.store.tuple.Tuple; | 37 | import tools.refinery.store.tuple.Tuple; |
35 | import tools.refinery.viatra.runtime.CancellationToken; | 38 | import tools.refinery.viatra.runtime.CancellationToken; |
36 | 39 | ||
@@ -75,7 +78,8 @@ class SemanticsWorker implements Callable<SemanticsResult> { | |||
75 | .with(ViatraModelQueryAdapter.builder() | 78 | .with(ViatraModelQueryAdapter.builder() |
76 | .cancellationToken(cancellationToken)) | 79 | .cancellationToken(cancellationToken)) |
77 | .with(ReasoningAdapter.builder() | 80 | .with(ReasoningAdapter.builder() |
78 | .requiredInterpretations(Concreteness.PARTIAL)); | 81 | .requiredInterpretations(Concreteness.PARTIAL)) |
82 | .with(ScopePropagatorAdapter.builder()); | ||
79 | cancellationToken.checkCancelled(); | 83 | cancellationToken.checkCancelled(); |
80 | try { | 84 | try { |
81 | var modelSeed = initializer.createModel(problem, builder); | 85 | var modelSeed = initializer.createModel(problem, builder); |
@@ -90,6 +94,9 @@ class SemanticsWorker implements Callable<SemanticsResult> { | |||
90 | cancellationToken.checkCancelled(); | 94 | cancellationToken.checkCancelled(); |
91 | var cancellableModelSeed = CancellableSeed.wrap(cancellationToken, modelSeed); | 95 | var cancellableModelSeed = CancellableSeed.wrap(cancellationToken, modelSeed); |
92 | var model = store.getAdapter(ReasoningStoreAdapter.class).createInitialModel(cancellableModelSeed); | 96 | var model = store.getAdapter(ReasoningStoreAdapter.class).createInitialModel(cancellableModelSeed); |
97 | if (model.getAdapter(ScopePropagatorAdapter.class).propagate() == RefinementResult.REJECTED) { | ||
98 | return new SemanticsInternalErrorResult("Scopes are unsatisfiable"); | ||
99 | } | ||
93 | cancellationToken.checkCancelled(); | 100 | cancellationToken.checkCancelled(); |
94 | var partialInterpretation = getPartialInterpretation(initializer, model); | 101 | var partialInterpretation = getPartialInterpretation(initializer, model); |
95 | 102 | ||
@@ -113,13 +120,18 @@ class SemanticsWorker implements Callable<SemanticsResult> { | |||
113 | json.add(name, tuples); | 120 | json.add(name, tuples); |
114 | cancellationToken.checkCancelled(); | 121 | cancellationToken.checkCancelled(); |
115 | } | 122 | } |
123 | json.add("builtin::count", getCountJson(model)); | ||
116 | return json; | 124 | return json; |
117 | } | 125 | } |
118 | 126 | ||
119 | private static JsonArray getTuplesJson(ReasoningAdapter adapter, PartialRelation partialSymbol) { | 127 | private static JsonArray getTuplesJson(ReasoningAdapter adapter, PartialRelation partialSymbol) { |
120 | var interpretation = adapter.getPartialInterpretation(Concreteness.PARTIAL, partialSymbol); | 128 | var interpretation = adapter.getPartialInterpretation(Concreteness.PARTIAL, partialSymbol); |
121 | var cursor = interpretation.getAll(); | 129 | var cursor = interpretation.getAll(); |
122 | var map = new TreeMap<Tuple, TruthValue>(); | 130 | return getTuplesJson(cursor); |
131 | } | ||
132 | |||
133 | private static JsonArray getTuplesJson(Cursor<Tuple, ?> cursor) { | ||
134 | var map = new TreeMap<Tuple, Object>(); | ||
123 | while (cursor.move()) { | 135 | while (cursor.move()) { |
124 | map.put(cursor.getKey(), cursor.getValue()); | 136 | map.put(cursor.getKey(), cursor.getValue()); |
125 | } | 137 | } |
@@ -130,7 +142,7 @@ class SemanticsWorker implements Callable<SemanticsResult> { | |||
130 | return tuples; | 142 | return tuples; |
131 | } | 143 | } |
132 | 144 | ||
133 | private static JsonArray toArray(Tuple tuple, TruthValue value) { | 145 | private static JsonArray toArray(Tuple tuple, Object value) { |
134 | int arity = tuple.getSize(); | 146 | int arity = tuple.getSize(); |
135 | var json = new JsonArray(arity + 1); | 147 | var json = new JsonArray(arity + 1); |
136 | for (int i = 0; i < arity; i++) { | 148 | for (int i = 0; i < arity; i++) { |
@@ -140,6 +152,12 @@ class SemanticsWorker implements Callable<SemanticsResult> { | |||
140 | return json; | 152 | return json; |
141 | } | 153 | } |
142 | 154 | ||
155 | private static JsonArray getCountJson(Model model) { | ||
156 | var interpretation = model.getInterpretation(MultiObjectTranslator.COUNT_STORAGE); | ||
157 | var cursor = interpretation.getAll(); | ||
158 | return getTuplesJson(cursor); | ||
159 | } | ||
160 | |||
143 | private SemanticsResult getTracedErrorResult(EObject sourceElement, String message) { | 161 | private SemanticsResult getTracedErrorResult(EObject sourceElement, String message) { |
144 | if (sourceElement == null || !problem.eResource().equals(sourceElement.eResource())) { | 162 | if (sourceElement == null || !problem.eResource().equals(sourceElement.eResource())) { |
145 | return new SemanticsInternalErrorResult(message); | 163 | return new SemanticsInternalErrorResult(message); |