Search in sources :

Example 6 with Attribute

use of catdata.fql.decl.Attribute in project fql by CategoricalData.

the class PSMEval method exec.

@Override
public void exec(PSMInterp interp, Map<String, Set<Map<Object, Object>>> state) {
    try {
        Quad<Instance, Map<Pair<Node, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>, Triple<Instance, Map<Node, Map<Object, Pair<Arr<Node, Path>, Object>>>, Map<Node, Map<Pair<Arr<Node, Path>, Object>, Object>>>>, Map<Node, Map<Object, Pair<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Transform>>>, Map<Node, Map<Pair<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Transform>, Object>>> xxx = interp.exps2.get(AB);
        Instance Jw = xxx.first;
        Map<Pair<Node, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>, Triple<Instance, Map<Node, Map<Object, Pair<Arr<Node, Path>, Object>>>, Map<Node, Map<Pair<Arr<Node, Path>, Object>, Object>>>> map = xxx.second;
        Map<Node, Map<Object, Pair<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Transform>>> map2 = xxx.third;
        FinCat<Node, Path> cat = Jw.thesig.toCategory2().first;
        Instance abb = new Instance(sig, PSMGen.gather(ABB, sig, state));
        // Instance ab = new Instance(sig, PSMGen.gather(AB, sig, state));
        // //already have in interp
        Instance a = new Instance(sig, PSMGen.gather(A, sig, state));
        Instance b = new Instance(sig, PSMGen.gather(B, sig, state));
        Transform fst = new Transform(abb, Jw, PSMGen.gather(ABB + "_fst", sig, state));
        Transform snd = new Transform(abb, b, PSMGen.gather(ABB + "_snd", sig, state));
        List<Pair<String, List<Pair<Object, Object>>>> data = new LinkedList<>();
        for (Node n : sig.nodes) {
            List<Pair<Object, Object>> d = new LinkedList<>();
            Map<Object, Pair<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Transform>> m2 = map2.get(n);
            for (Pair<Object, Object> id : abb.data.get(n.string)) {
                Object id_ab = lookup(fst.data.get(n.string), id.first);
                Object x = lookup(snd.data.get(n.string), id.first);
                Transform t = m2.get(id_ab).second;
                LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> w = m2.get(id_ab).first;
                Triple<Instance, Map<Node, Map<Object, Pair<Arr<Node, Path>, Object>>>, Map<Node, Map<Pair<Arr<Node, Path>, Object>, Object>>> m = map.get(new Pair<>(n, w));
                Object y = m.third.get(n).get(new Pair<>(cat.id(n), x));
                Object f = lookup(t.data.get(n.string), y);
                d.add(new Pair<>(id.first, f));
            }
            data.add(new Pair<>(n.string, d));
        }
        Transform curry = new Transform(abb, a, data);
        PSMGen.shred(pre, curry, state);
    } catch (FQLException fe) {
        fe.printStackTrace();
        throw new RuntimeException(fe.getMessage());
    }
}
Also used : Arr(catdata.fql.cat.Arr) Instance(catdata.fql.decl.Instance) Attribute(catdata.fql.decl.Attribute) Node(catdata.fql.decl.Node) LinkedHashMap(java.util.LinkedHashMap) FQLException(catdata.fql.FQLException) Pair(catdata.Pair) Path(catdata.fql.decl.Path) LinkedList(java.util.LinkedList) Triple(catdata.Triple) Transform(catdata.fql.decl.Transform) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 7 with Attribute

use of catdata.fql.decl.Attribute in project fql by CategoricalData.

the class JDBCBridge method maybeExecInstance.

private static List<PSM> maybeExecInstance(InstOps ops, FQLProgram prog, Statement Stmt, String k, InstExp v, PSMInterp interp, Map<String, Set<Map<Object, Object>>> ret) throws SQLException {
    List<PSM> psm = new LinkedList<>();
    psm.addAll(PSMGen.makeTables(k, v.type(prog).toSig(prog), false));
    switch(DefunctGlobalOptions.debug.fql.sqlKind) {
        case NATIVE:
            psm.addAll(v.accept(k, ops).first);
            interp.interpX(psm, ret);
            break;
        case H2:
        case JDBC:
        default:
            if (v instanceof InstExp.FullSigma) {
                List<PSM> xxx = v.accept(k, ops).first;
                if (xxx.size() != 1) {
                    throw new RuntimeException();
                }
                FullSigma yyy = (FullSigma) xxx.get(0);
                int theguid = getGuid(Stmt);
                interp.guid = theguid;
                yyy.exec(interp, ret);
                Stmt.execute("SET @guid = " + interp.guid);
                psm.addAll(makeInserts(k, ret, v.type(prog).toSig(prog), ((InstExp.FullSigma) v).F.toMap(prog).source));
            } else if (v instanceof Exp) {
                List<PSM> xxx = v.accept(k, ops).first;
                if (xxx.size() != 1) {
                    throw new RuntimeException();
                }
                ExpPSM yyy = (ExpPSM) xxx.get(0);
                int theguid = getGuid(Stmt);
                interp.guid = theguid;
                yyy.exec(interp, ret);
                Stmt.execute("SET @guid = " + interp.guid);
                psm.addAll(makeInserts(k, ret, v.type(prog).toSig(prog), null));
            } else if (v instanceof Two) {
                List<PSM> xxx = v.accept(k, ops).first;
                if (xxx.size() != 1) {
                    throw new RuntimeException();
                }
                PropPSM yyy = (PropPSM) xxx.get(0);
                int theguid = getGuid(Stmt);
                interp.guid = theguid;
                yyy.exec(interp, ret);
                Stmt.execute("SET @guid = " + interp.guid);
                psm.addAll(makeInserts(k, ret, v.type(prog).toSig(prog), null));
            } else if (v instanceof Kernel) {
                List<PSM> xxx = v.accept(k, ops).first;
                if (xxx.size() != 1) {
                    throw new RuntimeException();
                }
                PSMUnChi yyy = (PSMUnChi) xxx.get(0);
                int theguid = getGuid(Stmt);
                interp.guid = theguid;
                yyy.exec(interp, ret);
                Stmt.execute("SET @guid = " + interp.guid);
                psm.addAll(makeInserts(k, ret, v.type(prog).toSig(prog), null));
                Signature ooo = v.type(prog).toSig(prog);
                for (Node n : ooo.nodes) {
                    psm.add(new SimpleCreateTable(k + "_trans_" + n.string, PSM.VARCHAR(), false));
                }
                for (Edge n : ooo.edges) {
                    psm.add(new SimpleCreateTable(k + "_trans_" + n.name, PSM.VARCHAR(), false));
                }
                for (Attribute<Node> n : ooo.attrs) {
                    psm.add(new SimpleCreateTable(k + "_trans_" + n.name, n.target.psm(), false));
                }
                psm.addAll(makeInserts(k + "_trans", ret, v.type(prog).toSig(prog), null));
            } else if (v instanceof External && DefunctGlobalOptions.debug.fql.sqlKind == SQLKIND.H2) {
            } else {
                psm.addAll(v.accept(k, ops).first);
            }
            for (PSM sql : psm) {
                Stmt.execute(sql.toPSM());
            }
            if (!(v instanceof InstExp.FullSigma) && !(v instanceof Exp) && !(v instanceof Two) && !(v instanceof Kernel)) {
                gatherInstance(prog, ret, Stmt, k, v);
            }
            if (v instanceof Delta) {
                gatherSubstInv(prog, ret, Stmt, k, v);
            } else if (v instanceof Times) {
                gatherTransform(prog, ret, Stmt, k + "_fst", v.type(prog).toConst(prog));
                gatherTransform(prog, ret, Stmt, k + "_snd", v.type(prog).toConst(prog));
            } else if (v instanceof One) {
                gatherSubstInv2(prog, ret, Stmt, k, v);
            }
            break;
    }
    return psm;
}
Also used : ExpPSM(catdata.fql.sql.ExpPSM) Attribute(catdata.fql.decl.Attribute) Node(catdata.fql.decl.Node) One(catdata.fql.decl.InstExp.One) PSMUnChi(catdata.fql.sql.PSMUnChi) PSM(catdata.fql.sql.PSM) PropPSM(catdata.fql.sql.PropPSM) ExpPSM(catdata.fql.sql.ExpPSM) PropPSM(catdata.fql.sql.PropPSM) Two(catdata.fql.decl.InstExp.Two) LinkedList(java.util.LinkedList) InstExp(catdata.fql.decl.InstExp) SimpleCreateTable(catdata.fql.sql.SimpleCreateTable) Delta(catdata.fql.decl.InstExp.Delta) Signature(catdata.fql.decl.Signature) Times(catdata.fql.decl.InstExp.Times) External(catdata.fql.decl.InstExp.External) FullSigma(catdata.fql.sql.FullSigma) LinkedList(java.util.LinkedList) List(java.util.List) Exp(catdata.fql.decl.InstExp.Exp) InstExp(catdata.fql.decl.InstExp) TransExp(catdata.fql.decl.TransExp) Kernel(catdata.fql.decl.InstExp.Kernel) Edge(catdata.fql.decl.Edge)

Example 8 with Attribute

use of catdata.fql.decl.Attribute in project fql by CategoricalData.

the class FinFunctor method toMapping.

/**
 * Converts a functor to a mapping by converting the source and target
 * categories
 *
 * @return the mapping, and a bunch of isomorphisms
 * @throws FQLException
 */
public Triple<Mapping, Quad<Signature, Pair<Map<ObjA, String>, Map<String, ObjA>>, Pair<Map<Arr<ObjA, ArrowA>, String>, Map<String, Arr<ObjA, ArrowA>>>, Pair<Map<Attribute<ObjA>, String>, Map<String, Attribute<ObjA>>>>, Quad<Signature, Pair<Map<ObjB, String>, Map<String, ObjB>>, Pair<Map<Arr<ObjB, ArrowB>, String>, Map<String, Arr<ObjB, ArrowB>>>, Pair<Map<Attribute<ObjB>, String>, Map<String, Attribute<ObjB>>>>> toMapping(Map<String, Type> types) throws FQLException {
    Quad<Signature, Pair<Map<ObjA, String>, Map<String, ObjA>>, Pair<Map<Arr<ObjA, ArrowA>, String>, Map<String, Arr<ObjA, ArrowA>>>, Pair<Map<Attribute<ObjA>, String>, Map<String, Attribute<ObjA>>>> src = srcCat.toSig(types);
    Quad<Signature, Pair<Map<ObjB, String>, Map<String, ObjB>>, Pair<Map<Arr<ObjB, ArrowB>, String>, Map<String, Arr<ObjB, ArrowB>>>, Pair<Map<Attribute<ObjB>, String>, Map<String, Attribute<ObjB>>>> dst = dstCat.toSig(types);
    Signature srcSig = src.first;
    Signature dstSig = dst.first;
    Map<Arr<ObjA, ArrowA>, String> srcM = src.third.first;
    Map<ObjA, String> srcM2 = src.second.first;
    Map<Attribute<ObjA>, String> srcMA = src.fourth.first;
    Map<Arr<ObjB, ArrowB>, String> dstM = dst.third.first;
    Map<ObjB, String> dstM2 = dst.second.first;
    Map<Attribute<ObjB>, String> dstMA = dst.fourth.first;
    List<Pair<String, String>> nm = new LinkedList<>();
    List<Pair<String, List<String>>> em = new LinkedList<>();
    for (Arr<ObjA, ArrowA> a : srcCat.arrows) {
        if (srcCat.isId(a)) {
            ObjA o = a.src;
            ObjB u = objMapping.get(o);
            nm.add(new Pair<>(srcM2.get(o), dstM2.get(u)));
        } else {
            Arr<ObjB, ArrowB> u = arrowMapping.get(a);
            List<String> t = new LinkedList<>();
            t.add(dstM2.get(u.src));
            if (!dstCat.isId(u)) {
                t.add(dstM.get(u));
            }
            em.add(new Pair<>(srcM.get(a), t));
        }
    }
    List<Pair<String, String>> am0 = new LinkedList<>();
    for (Attribute<ObjA> k : am.keySet()) {
        am0.add(new Pair<>(srcMA.get(k), dstMA.get(am.get(k))));
    }
    Mapping m = new Mapping(/*n,*/
    srcSig, dstSig, nm, am0, em);
    return new Triple<>(m, src, dst);
}
Also used : Attribute(catdata.fql.decl.Attribute) Mapping(catdata.fql.decl.Mapping) Pair(catdata.Pair) LinkedList(java.util.LinkedList) Triple(catdata.Triple) Signature(catdata.fql.decl.Signature)

Example 9 with Attribute

use of catdata.fql.decl.Attribute in project fql by CategoricalData.

the class CategoryOfElements method makePanel.

public static Pair<JPanel, JPanel> makePanel(String name, Instance i, Color c) {
    try {
        JPanel ret;
        JPanel ret2;
        Pair<Graph<Pair<Node, Object>, Pair<Path, Integer>>, HashMap<Pair<Node, Object>, Map<Attribute<Node>, Object>>> g = build(i);
        ret = g.first.getVertexCount() == 0 ? new JPanel() : doView(c, i, g.first, g.second);
        ret2 = dot(name, i, g.first, g.second);
        return new Pair<>(ret, ret2);
    } catch (FQLException e) {
        JPanel p = new JPanel(new GridLayout(1, 1));
        JTextArea a = new JTextArea(e.getMessage());
        p.add(new JScrollPane(a));
        return new Pair<>(p, p);
    }
}
Also used : Path(catdata.fql.decl.Path) JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) HashMap(java.util.HashMap) Attribute(catdata.fql.decl.Attribute) Node(catdata.fql.decl.Node) FQLException(catdata.fql.FQLException) GridLayout(java.awt.GridLayout) Graph(edu.uci.ics.jung.graph.Graph) Pair(catdata.Pair)

Example 10 with Attribute

use of catdata.fql.decl.Attribute in project fql by CategoricalData.

the class CategoryOfElements method doView.

private static JPanel doView(Color clr, @SuppressWarnings("unused") Instance inst, Graph<Pair<Node, Object>, Pair<Path, Integer>> sgv, Map<Pair<Node, Object>, Map<Attribute<Node>, Object>> map0) {
    JPanel cards = new JPanel(new CardLayout());
    Layout<Pair<Node, Object>, Pair<Path, Integer>> layout = new FRLayout<>(sgv);
    layout.setSize(new Dimension(600, 400));
    VisualizationViewer<Pair<Node, Object>, Pair<Path, Integer>> vv = new VisualizationViewer<>(layout);
    Function<Pair<Node, Object>, Paint> vertexPaint = (Pair<Node, Object> i) -> clr;
    DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
    gm.setMode(Mode.TRANSFORMING);
    vv.setGraphMouse(gm);
    gm.setMode(Mode.PICKING);
    vv.getRenderContext().setVertexLabelRenderer(new MyVertexT(cards));
    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    vv.getRenderContext().setEdgeLabelTransformer((Pair<Path, Integer> t) -> t.first.toString());
    vv.getRenderContext().setVertexLabelTransformer((Pair<Node, Object> t) -> t.second.toString());
    JPanel ret = new JPanel(new GridLayout(1, 1));
    JSplitPane pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    for (Pair<Node, Object> n : sgv.getVertices()) {
        Map<Attribute<Node>, Object> s = map0.get(n);
        Object[] columnNames = new Object[s.keySet().size()];
        Object[][] rowData = new Object[1][s.keySet().size()];
        int i = 0;
        for (Attribute<Node> a : s.keySet()) {
            columnNames[i] = a.name;
            rowData[0][i] = s.get(a);
            i++;
        }
        JPanel p = new JPanel(new GridLayout(1, 1));
        JTable table = new JTable(rowData, columnNames);
        JScrollPane jsp = new JScrollPane(table);
        p.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Attributes for " + n.second));
        p.add(jsp);
        cards.add(p, n.second.toString());
    }
    cards.add(new JPanel(), "blank");
    CardLayout cl = (CardLayout) (cards.getLayout());
    cl.show(cards, "blank");
    pane.add(new GraphZoomScrollPane(vv));
    pane.add(cards);
    pane.setResizeWeight(.8d);
    ret.add(pane);
    return ret;
}
Also used : JPanel(javax.swing.JPanel) Attribute(catdata.fql.decl.Attribute) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) Node(catdata.fql.decl.Node) GridLayout(java.awt.GridLayout) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) Pair(catdata.Pair) JScrollPane(javax.swing.JScrollPane) CardLayout(java.awt.CardLayout) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) Paint(java.awt.Paint) Paint(java.awt.Paint) JTable(javax.swing.JTable) JSplitPane(javax.swing.JSplitPane)

Aggregations

Attribute (catdata.fql.decl.Attribute)21 Pair (catdata.Pair)20 Node (catdata.fql.decl.Node)19 HashMap (java.util.HashMap)15 LinkedList (java.util.LinkedList)15 Map (java.util.Map)12 FQLException (catdata.fql.FQLException)11 Instance (catdata.fql.decl.Instance)11 LinkedHashMap (java.util.LinkedHashMap)11 Arr (catdata.fql.cat.Arr)10 Edge (catdata.fql.decl.Edge)10 Path (catdata.fql.decl.Path)10 Signature (catdata.fql.decl.Signature)10 List (java.util.List)8 Triple (catdata.Triple)6 Transform (catdata.fql.decl.Transform)6 HashSet (java.util.HashSet)6 Set (java.util.Set)6 Fn (catdata.fql.Fn)4 FinCat (catdata.fql.cat.FinCat)3