aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/base/BaseDecisionInterpretation.java
blob: 2a151aa2ffb5128f49f9d45b9e4b2543e949b5ed (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/>
 *
 * SPDX-License-Identifier: EPL-2.0
 */
package tools.refinery.store.reasoning.translator.base;

import tools.refinery.store.map.Cursor;
import tools.refinery.store.model.Interpretation;
import tools.refinery.store.query.resultset.ResultSet;
import tools.refinery.store.reasoning.MergeResult;
import tools.refinery.store.reasoning.PartialInterpretation;
import tools.refinery.store.reasoning.ReasoningAdapter;
import tools.refinery.store.reasoning.representation.PartialRelation;
import tools.refinery.store.representation.TruthValue;
import tools.refinery.store.tuple.Tuple;

public class BaseDecisionInterpretation implements PartialInterpretation<TruthValue, Boolean> {
	private final ReasoningAdapter reasoningAdapter;
	private PartialRelation partialRelation;
	private final ResultSet<Boolean> mustResultSet;
	private final ResultSet<Boolean> mayResultSet;
	private final ResultSet<Boolean> errorResultSet;
	private final ResultSet<Boolean> currentResultSet;
	private final Interpretation<TruthValue> interpretation;

	public BaseDecisionInterpretation(ReasoningAdapter reasoningAdapter, ResultSet<Boolean> mustResultSet,
									  ResultSet<Boolean> mayResultSet, ResultSet<Boolean> errorResultSet,
									  ResultSet<Boolean> currentResultSet, Interpretation<TruthValue> interpretation) {
		this.reasoningAdapter = reasoningAdapter;
		this.mustResultSet = mustResultSet;
		this.mayResultSet = mayResultSet;
		this.errorResultSet = errorResultSet;
		this.currentResultSet = currentResultSet;
		this.interpretation = interpretation;
	}

	@Override
	public ReasoningAdapter getAdapter() {
		return reasoningAdapter;
	}

	@Override
	public int countUnfinished() {
		return 0;
	}

	@Override
	public int countErrors() {
		return errorResultSet.size();
	}

	@Override
	public PartialRelation getPartialSymbol() {
		return partialRelation;
	}

	@Override
	public TruthValue get(Tuple key) {
		return null;
	}

	@Override
	public Cursor<Tuple, TruthValue> getAll() {
		return null;
	}

	@Override
	public MergeResult merge(Tuple key, TruthValue value) {
		TruthValue newValue;
		switch (value) {
		case UNKNOWN -> {
			return MergeResult.UNCHANGED;
		}
		case TRUE -> newValue = mayResultSet.get(key) ? TruthValue.TRUE : TruthValue.ERROR;
		case FALSE -> newValue = mustResultSet.get(key) ? TruthValue.ERROR : TruthValue.FALSE;
		case ERROR -> newValue = TruthValue.ERROR;
		default -> throw new IllegalArgumentException("Unknown truth value: " + value);
		}
		var oldValue = interpretation.put(key, newValue);
		return oldValue == TruthValue.ERROR ? MergeResult.UNCHANGED : MergeResult.REFINED;
	}

	@Override
	public Boolean getConcrete(Tuple key) {
		return currentResultSet.get(key);
	}

	@Override
	public Cursor<Tuple, Boolean> getAllConcrete() {
		return null;
	}
}