use of edu.mit.csail.sdg.sim.SimTupleset in project org.alloytools.alloy by AlloyTools.
the class TableView method toTable.
// public static Table toTable(SimTupleset tupleset) {
// Table table = new Table(tupleset.size(), tupleset.arity(), 0);
// int row = 0;
// for ( SimTuple tuple : tupleset) {
// int column = 0;
// for ( SimAtom atom : tuple) {
// table.set(row, column++, atom);
// }
// row++;
// }
//
// return table;
// }
public static Table toTable(SimTupleset tupleset) {
if (tupleset.arity() == 0) {
return new Table(0, 0, 0);
}
if (tupleset.arity() == 1) {
Table t = new Table(tupleset.size(), 1, 0);
int row = 0;
for (SimTuple tuple : tupleset) {
t.set(row, 0, tuple.get(0));
row++;
}
return t;
}
SimTupleset head = tupleset.head(1);
Table table = new Table(head.size(), 2, 0);
int row = 0;
for (SimTuple tuple : head) {
SimAtom atom = tuple.head();
SimTuple target = SimTuple.make(atom);
SimTupleset singleton = SimTupleset.make(target);
SimTupleset joined = singleton.join(tupleset);
table.set(row, 0, atom.toString());
Table sub = toTable(joined);
table.set(row, 1, sub);
row++;
}
return table;
}
use of edu.mit.csail.sdg.sim.SimTupleset in project org.alloytools.alloy by AlloyTools.
the class TableView method toTable.
/**
* Format a solution to a string
*
* @param solution
* @param instance
* @param sigs
* @return
*/
public static Map<String, Table> toTable(A4Solution solution, Instance instance, SafeList<Sig> sigs) {
Map<String, Table> map = new HashMap<String, Table>();
for (Sig s : sigs) {
if (!s.label.startsWith("this/"))
continue;
TupleSet instanceTuples = instance.tuples(s.label);
if (instanceTuples != null) {
SimTupleset sigInstances = toSimTupleset(instanceTuples);
Table table = new Table(sigInstances.size() + 1, s.getFields().size() + 1, 1);
table.set(0, 0, s.label);
if (s.getFields().size() == 0 && sigInstances.size() <= 1)
continue;
int c = 1;
for (Field f : s.getFields()) {
table.set(0, c++, f.label);
}
map.put(s.label, table);
int r = 1;
for (SimTuple sigInstance : sigInstances) {
assert sigInstance.arity() == 1;
SimTupleset leftJoin = SimTupleset.make(sigInstance);
table.set(r, 0, sigInstance.get(0));
c = 1;
for (Field f : s.getFields()) {
SimTupleset relations = toSimTupleset(solution.eval(f));
SimTupleset joined = leftJoin.join(relations);
Table relationTable = toTable(joined);
table.set(r, c++, relationTable);
}
r++;
}
}
}
return map;
}
use of edu.mit.csail.sdg.sim.SimTupleset in project org.alloytools.alloy by AlloyTools.
the class TableView method toTable.
public static Table toTable(String s, boolean header) {
s = s.trim();
s = s.substring(1, s.length() - 1);
String[] clauses = s.split("\\s*,\\s*");
List<SimTuple> l = new ArrayList<>();
for (String tuple : clauses) {
String[] strings = tuple.split("\\s*->\\s*");
List<SimAtom> atoms = new ArrayList<>();
for (String string : strings) {
SimAtom atom = SimAtom.make(string);
atoms.add(atom);
}
l.add(SimTuple.make(atoms));
}
SimTupleset make = SimTupleset.make(l);
return toTable(make);
}
Aggregations