diff options
author | 2023-09-14 19:29:36 +0200 | |
---|---|---|
committer | 2023-09-14 19:29:36 +0200 | |
commit | 98ed3b6db5f4e51961a161050cc31c66015116e8 (patch) | |
tree | 8bfd6d9bc8d6ed23b9eb0f889dd40b6c24fe8f92 /subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/psystem/queries/PQueries.java | |
parent | Merge pull request #38 from nagilooh/design-space-exploration (diff) | |
parent | Merge remote-tracking branch 'upstream/main' into partial-interpretation (diff) | |
download | refinery-98ed3b6db5f4e51961a161050cc31c66015116e8.tar.gz refinery-98ed3b6db5f4e51961a161050cc31c66015116e8.tar.zst refinery-98ed3b6db5f4e51961a161050cc31c66015116e8.zip |
Merge pull request #39 from kris7t/partial-interpretation
Implement partial interpretation based model generation
Diffstat (limited to 'subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/psystem/queries/PQueries.java')
-rw-r--r-- | subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/psystem/queries/PQueries.java | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/psystem/queries/PQueries.java b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/psystem/queries/PQueries.java new file mode 100644 index 00000000..56f8ca76 --- /dev/null +++ b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/psystem/queries/PQueries.java | |||
@@ -0,0 +1,110 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2014, Zoltan Ujhelyi, Istvan Rath and Daniel Varro | ||
3 | * This program and the accompanying materials are made available under the | ||
4 | * terms of the Eclipse Public License v. 2.0 which is available at | ||
5 | * http://www.eclipse.org/legal/epl-v20.html. | ||
6 | * | ||
7 | * SPDX-License-Identifier: EPL-2.0 | ||
8 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.matchers.psystem.queries; | ||
10 | |||
11 | import java.util.HashSet; | ||
12 | import java.util.Set; | ||
13 | import java.util.function.Function; | ||
14 | import java.util.function.Predicate; | ||
15 | import java.util.stream.Stream; | ||
16 | |||
17 | import tools.refinery.viatra.runtime.matchers.context.IInputKey; | ||
18 | import tools.refinery.viatra.runtime.matchers.psystem.IMultiQueryReference; | ||
19 | import tools.refinery.viatra.runtime.matchers.psystem.ITypeConstraint; | ||
20 | import tools.refinery.viatra.runtime.matchers.psystem.PBody; | ||
21 | import tools.refinery.viatra.runtime.matchers.psystem.PTraceable; | ||
22 | import tools.refinery.viatra.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
23 | import tools.refinery.viatra.runtime.matchers.psystem.queries.PQuery.PQueryStatus; | ||
24 | |||
25 | /** | ||
26 | * Utility class for using PQueries in functional/streaming collection operations effectively | ||
27 | * | ||
28 | * @author Zoltan Ujhelyi | ||
29 | * | ||
30 | */ | ||
31 | public final class PQueries { | ||
32 | |||
33 | /** | ||
34 | * Hidden constructor for utility class | ||
35 | */ | ||
36 | private PQueries() { | ||
37 | } | ||
38 | |||
39 | /** | ||
40 | * Predicate checking for the status of selected queries | ||
41 | * | ||
42 | */ | ||
43 | public static Predicate<PQuery> queryStatusPredicate(final PQueryStatus status) { | ||
44 | return query -> query.getStatus().equals(status); | ||
45 | } | ||
46 | |||
47 | /** | ||
48 | * Enumerates referred queries (without duplicates) for the given body | ||
49 | */ | ||
50 | public static Function<PBody, Stream<PQuery>> directlyReferencedQueriesFunction() { | ||
51 | return body -> (body.getConstraintsOfType(IMultiQueryReference.class).stream() | ||
52 | .flatMap(e -> e.getReferredQueries().stream()).distinct()); | ||
53 | } | ||
54 | |||
55 | /** | ||
56 | * Enumerates directly referred extensional relations (without duplicates) in the canonical form of the given query | ||
57 | * | ||
58 | * @param enumerablesOnly | ||
59 | * only enumerable type constraints are considered | ||
60 | * @since 2.0 | ||
61 | */ | ||
62 | public static Stream<IInputKey> directlyRequiredTypesOfQuery(PQuery query, boolean enumerablesOnly) { | ||
63 | return directlyRequiredTypesOfDisjunction(query.getDisjunctBodies(), enumerablesOnly); | ||
64 | } | ||
65 | |||
66 | /** | ||
67 | * Enumerates directly referred extensional relations (without duplicates) for the given formulation of a query. | ||
68 | * | ||
69 | * @param enumerablesOnly | ||
70 | * only enumerable type constraints are considered | ||
71 | * @since 2.0 | ||
72 | */ | ||
73 | public static Stream<IInputKey> directlyRequiredTypesOfDisjunction(PDisjunction disjunctBodies, | ||
74 | boolean enumerablesOnly) { | ||
75 | Class<? extends ITypeConstraint> filterClass = enumerablesOnly ? TypeConstraint.class : ITypeConstraint.class; | ||
76 | return disjunctBodies.getBodies().stream().flatMap(body -> body.getConstraintsOfType(filterClass).stream()) | ||
77 | .map(constraint -> constraint.getEquivalentJudgement().getInputKey()).distinct(); | ||
78 | } | ||
79 | |||
80 | /** | ||
81 | * @since 1.4 | ||
82 | */ | ||
83 | public static Predicate<PParameter> parameterDirectionPredicate(final PParameterDirection direction) { | ||
84 | return input -> input.getDirection() == direction; | ||
85 | } | ||
86 | |||
87 | /** | ||
88 | * Returns all {@link PTraceable}s contained in the given {@link PQuery}: itself, its bodies and their constraints. | ||
89 | * | ||
90 | * @since 1.6 | ||
91 | */ | ||
92 | public static Set<PTraceable> getTraceables(PQuery query) { | ||
93 | final Set<PTraceable> traceables = new HashSet<>(); | ||
94 | traceables.add(query); | ||
95 | query.getDisjunctBodies().getBodies().forEach(body -> { | ||
96 | traceables.add(body); | ||
97 | body.getConstraints().forEach(traceables::add); | ||
98 | }); | ||
99 | return traceables; | ||
100 | } | ||
101 | |||
102 | /** | ||
103 | * Calculates the simple name related from a given qualified name by finding the part after the last '.' character. | ||
104 | * | ||
105 | * @since 2.0 | ||
106 | */ | ||
107 | public static String calculateSimpleName(String qualifiedName) { | ||
108 | return qualifiedName.substring(qualifiedName.lastIndexOf('.') + 1); | ||
109 | } | ||
110 | } | ||