aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/store-query/src/main/java/tools/refinery/store/query/dnf/RelationalQuery.java
blob: 98f71e11c20f11a5c49395435535b9c061686298 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
 * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/>
 *
 * SPDX-License-Identifier: EPL-2.0
 */
package tools.refinery.store.query.dnf;

import tools.refinery.store.query.InvalidQueryException;
import tools.refinery.store.query.literal.CallLiteral;
import tools.refinery.store.query.literal.CallPolarity;
import tools.refinery.store.query.term.AssignedValue;
import tools.refinery.store.query.term.NodeVariable;

import java.util.Collections;
import java.util.List;

public final class RelationalQuery extends Query<Boolean> {
	RelationalQuery(Dnf dnf) {
		super(dnf);
		for (var parameter : dnf.getSymbolicParameters()) {
			var parameterType = parameter.tryGetType();
			if (parameterType.isPresent()) {
				throw new InvalidQueryException("Expected parameter %s of %s to be a node variable, got %s instead"
						.formatted(parameter, dnf, parameterType.get().getName()));
			}
		}
	}

	@Override
	public int arity() {
		return getDnf().arity();
	}

	@Override
	public Class<Boolean> valueType() {
		return Boolean.class;
	}

	@Override
	public Boolean defaultValue() {
		return false;
	}

	@Override
	protected RelationalQuery withDnfInternal(Dnf newDnf) {
		return newDnf.asRelation();
	}

	@Override
	public RelationalQuery withDnf(Dnf newDnf) {
		return (RelationalQuery) super.withDnf(newDnf);
	}

	public CallLiteral call(CallPolarity polarity, List<NodeVariable> arguments) {
		return getDnf().call(polarity, Collections.unmodifiableList(arguments));
	}

	public CallLiteral call(CallPolarity polarity, NodeVariable... arguments) {
		return getDnf().call(polarity, arguments);
	}

	public CallLiteral call(NodeVariable... arguments) {
		return getDnf().call(arguments);
	}

	public CallLiteral callTransitive(NodeVariable left, NodeVariable right) {
		return getDnf().callTransitive(left, right);
	}

	public AssignedValue<Integer> count(List<NodeVariable> arguments) {
		return getDnf().count(Collections.unmodifiableList(arguments));
	}

	public AssignedValue<Integer> count(NodeVariable... arguments) {
		return getDnf().count(arguments);
	}
}