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
|
/*
* SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/>
*
* SPDX-License-Identifier: EPL-2.0
*/
package tools.refinery.store.reasoning.refinement;
import tools.refinery.store.model.Interpretation;
import tools.refinery.store.reasoning.ReasoningAdapter;
import tools.refinery.store.reasoning.representation.PartialSymbol;
import tools.refinery.store.representation.Symbol;
import tools.refinery.store.tuple.Tuple;
import java.util.Objects;
public class ConcreteSymbolRefiner<A, C> implements PartialInterpretationRefiner<A, C> {
private final ReasoningAdapter adapter;
private final PartialSymbol<A, C> partialSymbol;
private final Interpretation<A> interpretation;
public ConcreteSymbolRefiner(ReasoningAdapter adapter, PartialSymbol<A, C> partialSymbol,
Symbol<A> concreteSymbol) {
this.adapter = adapter;
this.partialSymbol = partialSymbol;
interpretation = adapter.getModel().getInterpretation(concreteSymbol);
}
@Override
public ReasoningAdapter getAdapter() {
return adapter;
}
@Override
public PartialSymbol<A, C> getPartialSymbol() {
return partialSymbol;
}
@Override
public boolean merge(Tuple key, A value) {
var currentValue = interpretation.get(key);
var mergedValue = partialSymbol.abstractDomain().commonRefinement(currentValue, value);
if (!Objects.equals(currentValue, mergedValue)) {
interpretation.put(key, mergedValue);
}
return true;
}
public static <A1, C1> PartialInterpretationRefiner.Factory<A1, C1> of(Symbol<A1> concreteSymbol) {
return (adapter, partialSymbol) -> new ConcreteSymbolRefiner<>(adapter, partialSymbol, concreteSymbol);
}
}
|