fixed cartesian products in step 4

This commit is contained in:
Florian Steurer 2015-12-26 16:22:35 +01:00
parent 264910bfa4
commit 3ff45a01de
2 changed files with 27 additions and 35 deletions

View File

@ -47,14 +47,13 @@ public class Unify {
/*
* Step 4: Create possible typings
*
* "Manche Autoren identifizieren die Paare (a, (b,c)) und ((a,b),c)
* mit dem geordneten Tripel (a,b,c), wodurch das kartesische Produkt auch assoziativ wird." - Wikipedia
*/
// Sets that originate from pair pattern matching
// Sets of the "second level"
List<List<Set<MPair>>> pairSetsSet = calculatePairSets(eq2s, fc);
// The sets of the "first level"
Set<Set<?>> sets = new HashSet<Set<?>>();
// All Sets
List<Set<MPair>> sets = new ArrayList<Set<MPair>>();
if(eq1s.size() != 0)
sets.add(eq1s); // Add Eq1'
@ -67,26 +66,23 @@ public class Unify {
if(bufferSet.size() != 0)
sets.add(bufferSet);
// Sets that originate from pair pattern matching
// Sets of the "second level"
sets.addAll(calculatePairSets(eq2s, fc));
/* Up to here, no cartesian products are calculated.
* Around here, filters for pairs and sets can be applied */
ISetOperations setOps = new GuavaSetOperations();
// Calculate the inner cartesian products
// Cartesian products of the second level
// AddAll -> nur add
for(List<Set<MPair>> pairSets : pairSetsSet) // Prüfen ob addAll stimmt oder ob hier eigentlich nur 1 set sein sollte
sets.add(setOps.cartesianProduct(pairSets).stream().map(x -> new HashSet<>(x)).collect(Collectors.toSet()));
System.out.println(sets);
// Calculate the outer cartesian products
// Cartesian products of the first level
Set<List<Object>> eqsSet = setOps.cartesianProduct(new ArrayList<>(sets));
// Calculate the cartesian products
System.out.println(eqsSet);
Set<Set<MPair>> result = setOps.cartesianProduct(sets).stream().map(x -> new HashSet<MPair>(x)).collect(Collectors.toCollection(HashSet::new));
System.out.println(result);
/*
* Step 5: Substitution
*/
@ -196,11 +192,8 @@ public class Unify {
}
protected List<List<Set<MPair>>> calculatePairSets(Set<MPair> eq2s, IFiniteClosure fc) {
List<List<Set<MPair>>> result = new ArrayList<List<Set<MPair>>>();
for(int i = 0; i < 8; i++)
result.add(new ArrayList<Set<MPair>>());
protected List<Set<MPair>> calculatePairSets(Set<MPair> eq2s, IFiniteClosure fc) {
List<Set<MPair>> result = new ArrayList<Set<MPair>>();
for(MPair pair : eq2s) {
@ -223,15 +216,14 @@ public class Unify {
Set<MPair> set = new HashSet<>();
for(Type theta : fc.smArg(rhsType))
set.add(new MPair(lhsType, theta, PairOperator.EQUALSDOT));
result.get(2).add(set);
result.add(set);
}
// Case 4: (a <.? Theta')
else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType) {
Set<MPair> set = new HashSet<>();
set.add(new MPair(lhsType, ((ExtendsType) rhsType).getExtendedType(), PairOperator.EQUALSDOT));
result.get(3).add(set);
result.add(set);
}
// Case 5: (Theta <. a)
@ -239,7 +231,7 @@ public class Unify {
Set<MPair> set = new HashSet<>();
for(Type thetaS : fc.greater(lhsType))
set.add(new MPair(rhsType, thetaS, PairOperator.EQUALSDOT));
result.get(4).add(set);
result.add(set);
}
// Case 6: (? ext Theta <.? a)
@ -247,7 +239,7 @@ public class Unify {
Set<MPair> set = new HashSet<>();
for(Type thetaS : fc.grArg(lhsType))
set.add(new MPair(rhsType, thetaS, PairOperator.EQUALSDOT));
result.get(5).add(set);
result.add(set);
}
// Case 7: (? sup Theta <.? a)
@ -260,10 +252,10 @@ public class Unify {
Set<MPair> set = new HashSet<>();
for(Type thetaS : fc.grArg(lhsType))
set.add(new MPair(rhsType, thetaS, PairOperator.EQUALSDOT));
result.get(7).add(set);
result.add(set);
}
}
return result.stream().filter(x -> !x.isEmpty()).collect(Collectors.toList());
return result;
}
}

View File

@ -18,7 +18,7 @@ public class UnifyTest extends Unify {
FiniteClosureBuilder fcb = new FiniteClosureBuilder();
Set<MPair> eq = new HashSet<MPair>();
fcb.add(tf.getSimpleType("Number"), tf.getSimpleType("Object"));
//fcb.add(tf.getSimpleType("Number"), tf.getSimpleType("Object"));
fcb.add(tf.getSimpleType("Integer"), tf.getSimpleType("Number"));
fcb.add(tf.getSimpleType("Double"), tf.getSimpleType("Number"));
@ -26,15 +26,15 @@ public class UnifyTest extends Unify {
// Vector<Integer> <. Vector<A>
// Vector<Integer <. Vector<C>
// A <. Number
// A <. Integer
// Double <. B
// B <. Object
eq.add(new MPair(tf.getSimpleType("Vector", tf.getSimpleType("Integer")), tf.getSimpleType("Vector", "A"), PairOperator.SMALLERDOT));
eq.add(new MPair(tf.getSimpleType("Vector", tf.getSimpleType("Integer")), tf.getSimpleType("Vector", "C"), PairOperator.SMALLERDOT));
eq.add(new MPair(tf.getPlaceholderType("A"), tf.getSimpleType("Number"), PairOperator.SMALLERDOT));
eq.add(new MPair(tf.getPlaceholderType("A"), tf.getSimpleType("Integer"), PairOperator.SMALLERDOT));
//eq.add(new MPair(tf.getPlaceholderType("A"), tf.getPlaceholderType("C"), PairOperator.SMALLERDOT));
eq.add(new MPair(tf.getSimpleType("Double"), tf.getPlaceholderType("B"), PairOperator.SMALLERDOT));
eq.add(new MPair(tf.getPlaceholderType("B"), tf.getSimpleType("Object"), PairOperator.EQUALSDOT));
//eq.add(new MPair(tf.getPlaceholderType("B"), tf.getSimpleType("Object"), PairOperator.EQUALSDOT));
this.unify(eq, fc);