fixed RuleSetStrucType refl().

This commit is contained in:
Aldaron7 2018-05-07 19:03:47 +02:00
parent a17342458e
commit 6f85c2b376

View File

@ -51,25 +51,38 @@ public class RuleSetStrucType extends RuleSet {
// Filter SMALLERDOT Pairs // Filter SMALLERDOT Pairs
final Set<UnifyPair> pairsSmallerDot = pairs.stream().filter(p -> PairOperator.SMALLERDOT.equals(p.getPairOp())) final Set<UnifyPair> pairsSmallerDot = pairs.stream().filter(p -> PairOperator.SMALLERDOT.equals(p.getPairOp()))
.collect(Collectors.toSet()); .collect(Collectors.toSet());
// System.out.println("Pairs to test: " + pairsSmallerDot);
// Filter Tuples of Pairs for a potential Linking (t<T1,T1<T2,...,Tn<t) // Filter Tuples of Pairs for a potential Linking (t<T1,T1<T2,...,Tn<t)
List<Pair<UnifyPair, UnifyPair>> tupleOfPotentialLinkings = new ArrayList<>(); List<Pair<UnifyPair, UnifyPair>> tupleOfPotentialLinkings = new ArrayList<>();
for (UnifyPair pair : pairsSmallerDot) { for (UnifyPair pair : pairsSmallerDot) {
if (!(pair.getRhsType() instanceof PlaceholderType)) { if (!(pair.getRhsType() instanceof PlaceholderType)) {
// System.out.println("Pair not suitable for outerLeftPair: " + pair);
continue; continue;
} }
tupleOfPotentialLinkings = pairsSmallerDot.stream() // System.out.println("Try to find tuple of potential linkings for pair " + pair);
.filter(p -> p.getLhsType() instanceof PlaceholderType && p.getRhsType().equals(pair.getLhsType())) tupleOfPotentialLinkings.addAll(pairsSmallerDot.stream().filter(p -> {
.map(p -> new Pair<>(pair, p)).collect(Collectors.toList()); // System.out.println(" Pair pair: " + pair);
// System.out.println("Pair p: " + p);
// System.out.println("p.lhs instnceof PH: " + (p.getLhsType() instanceof PlaceholderType));
// System.out.println("p.rhs equals pair.lhs: " + (p.getRhsType().equals(pair.getLhsType())));
return (p.getLhsType() instanceof PlaceholderType) && (p.getRhsType().equals(pair.getLhsType()));
}).map(p -> {
// System.out.println("Pair to map: " + p);
return new Pair<>(pair, p);
}).collect(Collectors.toList()));
// System.out.println("tuple of potential linkings: " + tupleOfPotentialLinkings);
} }
// Build Linking between the Pairs. Empty if no Linking is possible. // Build Linking between the Pairs. Empty if no Linking is possible.
for (Pair<UnifyPair, UnifyPair> tuple : tupleOfPotentialLinkings) { for (Pair<UnifyPair, UnifyPair> tuple : tupleOfPotentialLinkings) {
UnifyPair outerLeftPair = tuple.getKey(); UnifyPair outerLeftPair = tuple.getKey();
UnifyPair outerRightPair = tuple.getValue(); UnifyPair outerRightPair = tuple.getValue();
// System.out.println("Try linking pair: " + outerLeftPair + ", " + outerRightPair);
Optional<Set<UnifyPair>> opt = StrucTypeUnifyUtils.linkPairs(outerLeftPair, outerRightPair, Optional<Set<UnifyPair>> opt = StrucTypeUnifyUtils.linkPairs(outerLeftPair, outerRightPair,
pairsSmallerDot); pairsSmallerDot);
// Remove Pairs of the Linking incl. outerLeft and outerRight, add // Remove Pairs of the Linking incl. outerLeft and outerRight, add
// EQUALSDOT Pairs instead. // EQUALSDOT Pairs instead.
if (opt.isPresent()) { if (opt.isPresent()) {
// System.out.println("Linking found: " + opt.get());
pairs.remove(outerLeftPair); pairs.remove(outerLeftPair);
pairs.remove(outerRightPair); pairs.remove(outerRightPair);
pairs.removeAll(opt.get()); pairs.removeAll(opt.get());
@ -86,6 +99,7 @@ public class RuleSetStrucType extends RuleSet {
.add(UnifyTypeFactory.generateEqualDotPair(placeholder, outermostUnifyType))); .add(UnifyTypeFactory.generateEqualDotPair(placeholder, outermostUnifyType)));
return Optional.of(pairs); return Optional.of(pairs);
} }
// System.out.println("No Linking found");
} }
// No Linking was found. // No Linking was found.
return Optional.empty(); return Optional.empty();