diff options
Diffstat (limited to 'subprojects')
5 files changed, 77 insertions, 26 deletions
diff --git a/subprojects/frontend/src/index.tsx b/subprojects/frontend/src/index.tsx index a2746748..077bae79 100644 --- a/subprojects/frontend/src/index.tsx +++ b/subprojects/frontend/src/index.tsx | |||
@@ -12,11 +12,12 @@ import RootStore from './RootStore'; | |||
12 | 12 | ||
13 | const initialValue = `// Metamodel | 13 | const initialValue = `// Metamodel |
14 | class Person { | 14 | class Person { |
15 | contains Post[] posts opposite author | ||
15 | Person[] friend opposite friend | 16 | Person[] friend opposite friend |
16 | } | 17 | } |
17 | 18 | ||
18 | class Post { | 19 | class Post { |
19 | Person[1] author | 20 | container Person[1] author opposite posts |
20 | Post replyTo | 21 | Post replyTo |
21 | } | 22 | } |
22 | 23 | ||
@@ -30,15 +31,9 @@ error replyToNotFriend(Post x, Post y) <-> | |||
30 | error replyToCycle(Post x) <-> replyTo+(x, x). | 31 | error replyToCycle(Post x) <-> replyTo+(x, x). |
31 | 32 | ||
32 | // Instance model | 33 | // Instance model |
33 | Person(a). | ||
34 | Person(b). | ||
35 | friend(a, b). | 34 | friend(a, b). |
36 | friend(b, a). | ||
37 | Post(p1). | ||
38 | author(p1, a). | 35 | author(p1, a). |
39 | Post(p2). | ||
40 | author(p2, b). | 36 | author(p2, b). |
41 | replyTo(p2, p1). | ||
42 | 37 | ||
43 | !author(Post::new, a). | 38 | !author(Post::new, a). |
44 | 39 | ||
diff --git a/subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsService.java b/subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsService.java index eb7ab204..79ca32ff 100644 --- a/subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsService.java +++ b/subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsService.java | |||
@@ -84,7 +84,7 @@ public class SemanticsService extends AbstractCachedService<SemanticsResult> { | |||
84 | return new SemanticsSuccessResult(nodeTrace, partialInterpretation); | 84 | return new SemanticsSuccessResult(nodeTrace, partialInterpretation); |
85 | } catch (RuntimeException e) { | 85 | } catch (RuntimeException e) { |
86 | LOG.error("Error while computing semantics", e); | 86 | LOG.error("Error while computing semantics", e); |
87 | return new SemanticsErrorResult(e.toString()); | 87 | return new SemanticsErrorResult(e.getMessage()); |
88 | } | 88 | } |
89 | } | 89 | } |
90 | 90 | ||
diff --git a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/metamodel/MetamodelBuilder.java b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/metamodel/MetamodelBuilder.java index 92370e25..d0732edc 100644 --- a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/metamodel/MetamodelBuilder.java +++ b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/metamodel/MetamodelBuilder.java | |||
@@ -203,15 +203,15 @@ public class MetamodelBuilder { | |||
203 | throw new IllegalArgumentException("Opposite %s of %s is not defined" | 203 | throw new IllegalArgumentException("Opposite %s of %s is not defined" |
204 | .formatted(opposite, linkType)); | 204 | .formatted(opposite, linkType)); |
205 | } | 205 | } |
206 | if (!oppositeInfo.opposite().equals(linkType)) { | 206 | if (!linkType.equals(oppositeInfo.opposite())) { |
207 | throw new IllegalArgumentException("Expected %s to have opposite %s, got %s instead" | 207 | throw new IllegalArgumentException("Expected %s to have opposite %s, got %s instead" |
208 | .formatted(opposite, linkType, oppositeInfo.opposite())); | 208 | .formatted(opposite, linkType, oppositeInfo.opposite())); |
209 | } | 209 | } |
210 | if (!oppositeInfo.sourceType().equals(targetType)) { | 210 | if (!targetType.equals(oppositeInfo.sourceType())) { |
211 | throw new IllegalArgumentException("Expected %s to have source type %s, got %s instead" | 211 | throw new IllegalArgumentException("Expected %s to have source type %s, got %s instead" |
212 | .formatted(opposite, targetType, oppositeInfo.sourceType())); | 212 | .formatted(opposite, targetType, oppositeInfo.sourceType())); |
213 | } | 213 | } |
214 | if (!oppositeInfo.targetType().equals(sourceType)) { | 214 | if (!sourceType.equals(oppositeInfo.targetType())) { |
215 | throw new IllegalArgumentException("Expected %s to have target type %s, got %s instead" | 215 | throw new IllegalArgumentException("Expected %s to have target type %s, got %s instead" |
216 | .formatted(opposite, sourceType, oppositeInfo.targetType())); | 216 | .formatted(opposite, sourceType, oppositeInfo.targetType())); |
217 | } | 217 | } |
diff --git a/subprojects/store-reasoning/src/test/java/tools/refinery/store/reasoning/translator/metamodel/MetamodelBuilderTest.java b/subprojects/store-reasoning/src/test/java/tools/refinery/store/reasoning/translator/metamodel/MetamodelBuilderTest.java new file mode 100644 index 00000000..115ba8cd --- /dev/null +++ b/subprojects/store-reasoning/src/test/java/tools/refinery/store/reasoning/translator/metamodel/MetamodelBuilderTest.java | |||
@@ -0,0 +1,57 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.store.reasoning.translator.metamodel; | ||
7 | |||
8 | import org.junit.jupiter.api.Test; | ||
9 | import tools.refinery.store.reasoning.representation.PartialRelation; | ||
10 | import tools.refinery.store.reasoning.translator.multiplicity.ConstrainedMultiplicity; | ||
11 | import tools.refinery.store.representation.cardinality.CardinalityIntervals; | ||
12 | |||
13 | import static org.junit.jupiter.api.Assertions.assertThrows; | ||
14 | |||
15 | class MetamodelBuilderTest { | ||
16 | private final PartialRelation university = new PartialRelation("University", 1); | ||
17 | private final PartialRelation course = new PartialRelation("Course", 1); | ||
18 | private final PartialRelation courses = new PartialRelation("courses", 2); | ||
19 | private final PartialRelation location = new PartialRelation("location", 2); | ||
20 | |||
21 | @Test | ||
22 | void missingOppositeTest() { | ||
23 | var builder = Metamodel.builder() | ||
24 | .type(university) | ||
25 | .type(course) | ||
26 | .reference(courses, university, course, location) | ||
27 | .reference(location, course, university); | ||
28 | |||
29 | assertThrows(IllegalArgumentException.class, builder::build); | ||
30 | } | ||
31 | |||
32 | @Test | ||
33 | void invalidOppositeTypeTest() { | ||
34 | var builder = Metamodel.builder() | ||
35 | .type(university) | ||
36 | .type(course) | ||
37 | .reference(courses, university, course, location) | ||
38 | .reference(location, course, course, courses); | ||
39 | |||
40 | assertThrows(IllegalArgumentException.class, builder::build); | ||
41 | } | ||
42 | |||
43 | @Test | ||
44 | void invalidOppositeMultiplicityTest() { | ||
45 | var invalidMultiplicity = new PartialRelation("invalidMultiplicity", 1); | ||
46 | |||
47 | var builder = Metamodel.builder() | ||
48 | .type(university) | ||
49 | .type(course) | ||
50 | .reference(courses, university, true, course, location) | ||
51 | .reference(location, course, | ||
52 | ConstrainedMultiplicity.of(CardinalityIntervals.atLeast(2), invalidMultiplicity), | ||
53 | university, courses); | ||
54 | |||
55 | assertThrows(IllegalArgumentException.class, builder::build); | ||
56 | } | ||
57 | } | ||
diff --git a/subprojects/store-reasoning/src/test/java/tools/refinery/store/reasoning/translator/metamodel/MetamodelTest.java b/subprojects/store-reasoning/src/test/java/tools/refinery/store/reasoning/translator/metamodel/MetamodelTest.java index 87e28e80..eabbdffe 100644 --- a/subprojects/store-reasoning/src/test/java/tools/refinery/store/reasoning/translator/metamodel/MetamodelTest.java +++ b/subprojects/store-reasoning/src/test/java/tools/refinery/store/reasoning/translator/metamodel/MetamodelTest.java | |||
@@ -6,6 +6,7 @@ | |||
6 | package tools.refinery.store.reasoning.translator.metamodel; | 6 | package tools.refinery.store.reasoning.translator.metamodel; |
7 | 7 | ||
8 | import org.junit.jupiter.api.Test; | 8 | import org.junit.jupiter.api.Test; |
9 | import tools.refinery.store.model.Model; | ||
9 | import tools.refinery.store.model.ModelStore; | 10 | import tools.refinery.store.model.ModelStore; |
10 | import tools.refinery.store.query.viatra.ViatraModelQueryAdapter; | 11 | import tools.refinery.store.query.viatra.ViatraModelQueryAdapter; |
11 | import tools.refinery.store.reasoning.ReasoningAdapter; | 12 | import tools.refinery.store.reasoning.ReasoningAdapter; |
@@ -52,13 +53,6 @@ class MetamodelTest { | |||
52 | ConstrainedMultiplicity.of(CardinalityIntervals.SOME, invalidStudentCount), student) | 53 | ConstrainedMultiplicity.of(CardinalityIntervals.SOME, invalidStudentCount), student) |
53 | .build(); | 54 | .build(); |
54 | 55 | ||
55 | var store = ModelStore.builder() | ||
56 | .with(ViatraModelQueryAdapter.builder()) | ||
57 | .with(ReasoningAdapter.builder()) | ||
58 | .with(new MultiObjectTranslator()) | ||
59 | .with(new MetamodelTranslator(metamodel)) | ||
60 | .build(); | ||
61 | |||
62 | var seed = ModelSeed.builder(5) | 56 | var seed = ModelSeed.builder(5) |
63 | .seed(MultiObjectTranslator.COUNT_SYMBOL, builder -> builder | 57 | .seed(MultiObjectTranslator.COUNT_SYMBOL, builder -> builder |
64 | .reducedValue(CardinalityIntervals.ONE) | 58 | .reducedValue(CardinalityIntervals.ONE) |
@@ -87,7 +81,7 @@ class MetamodelTest { | |||
87 | .seed(enrolledStudents, builder -> builder.reducedValue(TruthValue.UNKNOWN)) | 81 | .seed(enrolledStudents, builder -> builder.reducedValue(TruthValue.UNKNOWN)) |
88 | .build(); | 82 | .build(); |
89 | 83 | ||
90 | var model = store.getAdapter(ReasoningStoreAdapter.class).createInitialModel(seed); | 84 | var model = createModel(metamodel, seed); |
91 | var reasoningAdapter = model.getAdapter(ReasoningAdapter.class); | 85 | var reasoningAdapter = model.getAdapter(ReasoningAdapter.class); |
92 | 86 | ||
93 | var coursesInterpretation = reasoningAdapter.getPartialInterpretation(Concreteness.PARTIAL, courses); | 87 | var coursesInterpretation = reasoningAdapter.getPartialInterpretation(Concreteness.PARTIAL, courses); |
@@ -114,12 +108,6 @@ class MetamodelTest { | |||
114 | .reference(courses, university, true, course) | 108 | .reference(courses, university, true, course) |
115 | .build(); | 109 | .build(); |
116 | 110 | ||
117 | var store = ModelStore.builder() | ||
118 | .with(ViatraModelQueryAdapter.builder()) | ||
119 | .with(ReasoningAdapter.builder()) | ||
120 | .with(new MultiObjectTranslator()) | ||
121 | .with(new MetamodelTranslator(metamodel)) | ||
122 | .build(); | ||
123 | 111 | ||
124 | var seed = ModelSeed.builder(4) | 112 | var seed = ModelSeed.builder(4) |
125 | .seed(MultiObjectTranslator.COUNT_SYMBOL, builder -> builder | 113 | .seed(MultiObjectTranslator.COUNT_SYMBOL, builder -> builder |
@@ -141,7 +129,7 @@ class MetamodelTest { | |||
141 | .put(Tuple.of(2, 3), TruthValue.TRUE)) | 129 | .put(Tuple.of(2, 3), TruthValue.TRUE)) |
142 | .build(); | 130 | .build(); |
143 | 131 | ||
144 | var model = store.getAdapter(ReasoningStoreAdapter.class).createInitialModel(seed); | 132 | var model = createModel(metamodel, seed); |
145 | var coursesInterpretation = model.getAdapter(ReasoningAdapter.class) | 133 | var coursesInterpretation = model.getAdapter(ReasoningAdapter.class) |
146 | .getPartialInterpretation(Concreteness.PARTIAL, courses); | 134 | .getPartialInterpretation(Concreteness.PARTIAL, courses); |
147 | 135 | ||
@@ -150,4 +138,15 @@ class MetamodelTest { | |||
150 | assertThat(coursesInterpretation.get(Tuple.of(2, 1)), is(TruthValue.UNKNOWN)); | 138 | assertThat(coursesInterpretation.get(Tuple.of(2, 1)), is(TruthValue.UNKNOWN)); |
151 | assertThat(coursesInterpretation.get(Tuple.of(2, 3)), is(TruthValue.TRUE)); | 139 | assertThat(coursesInterpretation.get(Tuple.of(2, 3)), is(TruthValue.TRUE)); |
152 | } | 140 | } |
141 | |||
142 | private static Model createModel(Metamodel metamodel, ModelSeed seed) { | ||
143 | var store = ModelStore.builder() | ||
144 | .with(ViatraModelQueryAdapter.builder()) | ||
145 | .with(ReasoningAdapter.builder()) | ||
146 | .with(new MultiObjectTranslator()) | ||
147 | .with(new MetamodelTranslator(metamodel)) | ||
148 | .build(); | ||
149 | |||
150 | return store.getAdapter(ReasoningStoreAdapter.class).createInitialModel(seed); | ||
151 | } | ||
153 | } | 152 | } |