Search in sources :

Example 1 with SimAtom

use of edu.mit.csail.sdg.sim.SimAtom 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;
}
Also used : Table(org.alloytools.util.table.Table) SimTupleset(edu.mit.csail.sdg.sim.SimTupleset) SimTuple(edu.mit.csail.sdg.sim.SimTuple) SimAtom(edu.mit.csail.sdg.sim.SimAtom)

Example 2 with SimAtom

use of edu.mit.csail.sdg.sim.SimAtom 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);
}
Also used : SimTupleset(edu.mit.csail.sdg.sim.SimTupleset) SimTuple(edu.mit.csail.sdg.sim.SimTuple) ArrayList(java.util.ArrayList) SimAtom(edu.mit.csail.sdg.sim.SimAtom)

Example 3 with SimAtom

use of edu.mit.csail.sdg.sim.SimAtom in project org.alloytools.alloy by AlloyTools.

the class TableView method toSimTuple.

private static SimTuple toSimTuple(A4Tuple a4t) {
    List<SimAtom> atoms = new ArrayList<>();
    for (int i = 0; i < a4t.arity(); i++) {
        SimAtom atom = SimAtom.make(a4t.atom(i));
        atoms.add(atom);
    }
    return SimTuple.make(atoms);
}
Also used : ArrayList(java.util.ArrayList) SimAtom(edu.mit.csail.sdg.sim.SimAtom)

Example 4 with SimAtom

use of edu.mit.csail.sdg.sim.SimAtom in project org.alloytools.alloy by AlloyTools.

the class TableView method toSimTuple.

private static SimTuple toSimTuple(Tuple tuple) {
    List<SimAtom> atoms = new ArrayList<>();
    for (int i = 0; i < tuple.arity(); i++) {
        SimAtom atom = SimAtom.make(tuple.atom(i).toString());
        atoms.add(atom);
    }
    return SimTuple.make(atoms);
}
Also used : ArrayList(java.util.ArrayList) SimAtom(edu.mit.csail.sdg.sim.SimAtom)

Aggregations

SimAtom (edu.mit.csail.sdg.sim.SimAtom)4 ArrayList (java.util.ArrayList)3 SimTuple (edu.mit.csail.sdg.sim.SimTuple)2 SimTupleset (edu.mit.csail.sdg.sim.SimTupleset)2 Table (org.alloytools.util.table.Table)1