Search in sources :

Example 21 with Arr

use of catdata.fql.cat.Arr in project fql by CategoricalData.

the class Instance method toFunctor2.

public Inst<Node, Path, Object, Object> toFunctor2() throws FQLException {
    FinCat<Node, Path> cat = thesig.toCategory2().first;
    Map<Node, Set<Value<Object, Object>>> objM = new HashMap<>();
    for (Node obj : cat.objects) {
        if (data.get(obj.string) == null) {
            throw new RuntimeException("No data for " + obj + " in " + data);
        }
        objM.put(obj, conv(data.get(obj.string)));
    }
    Map<Arr<Node, Path>, Map<Value<Object, Object>, Value<Object, Object>>> arrM = new HashMap<>();
    for (Arr<Node, Path> arr : cat.arrows) {
        List<String> es = arr.arr.asList();
        String h = es.get(0);
        Set<Pair<Object, Object>> h0 = data.get(h);
        for (int i = 1; i < es.size(); i++) {
            h0 = compose2(h0, data.get(es.get(i)));
        }
        Map<Value<Object, Object>, Value<Object, Object>> xxx = FDM.degraph(h0);
        arrM.put(arr, xxx);
    }
    return new Inst<>(objM, arrM, cat);
}
Also used : Arr(catdata.fql.cat.Arr) Set(java.util.Set) HashSet(java.util.HashSet) Inst(catdata.fql.cat.Inst) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Paint(java.awt.Paint) Value(catdata.fql.cat.Value) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Pair(catdata.Pair)

Example 22 with Arr

use of catdata.fql.cat.Arr in project fql by CategoricalData.

the class Mapping method view.

/**
 * The viewer for mappings.
 */
@SuppressWarnings("serial")
public JPanel view() {
    Object[][] arr = new Object[nm.size()][2];
    int i = 0;
    for (Entry<Node, Node> eq : nm.entrySet()) {
        arr[i][0] = eq.getKey();
        arr[i][1] = eq.getValue();
        i++;
    }
    Arrays.sort(arr, Comparator.comparing(f3 -> f3[0].toString()));
    JTable nmC = new JTable(arr, new Object[] { "Source node", "Target node" }) {

        @Override
        public Dimension getPreferredScrollableViewportSize() {
            Dimension d = getPreferredSize();
            return new Dimension(d.width, d.height);
        }
    };
    Object[][] arr2 = new Object[em.size()][2];
    int i2 = 0;
    for (Entry<Edge, Path> eq : em.entrySet()) {
        arr2[i2][0] = eq.getKey();
        arr2[i2][1] = eq.getValue().toLong();
        i2++;
    }
    Arrays.sort(arr2, Comparator.comparing(f2 -> f2[0].toString()));
    JTable emC = new JTable(arr2, new Object[] { "Source edge", "Target path" }) {

        @Override
        public Dimension getPreferredScrollableViewportSize() {
            Dimension d = getPreferredSize();
            return new Dimension(d.width, d.height);
        }
    };
    Object[][] arr3 = new Object[am.size()][2];
    int i3 = 0;
    for (Entry<Attribute<Node>, Attribute<Node>> eq : am.entrySet()) {
        arr3[i3][0] = eq.getKey();
        arr3[i3][1] = eq.getValue();
        i3++;
    }
    Arrays.sort(arr3, Comparator.comparing(f -> f[0].toString()));
    JTable amC = new JTable(arr3, new Object[] { "Source attribute", "Target attribute" }) {

        @Override
        public Dimension getPreferredScrollableViewportSize() {
            Dimension d = getPreferredSize();
            return new Dimension(d.width, d.height);
        }
    };
    List<JComponent> p = new LinkedList<>();
    // JPanel p = new JPanel(new GridLayout(2, 2));
    JScrollPane q1 = new JScrollPane(nmC);
    JScrollPane q2 = new JScrollPane(emC);
    JScrollPane q3 = new JScrollPane(amC);
    JPanel j1 = new JPanel(new GridLayout(1, 1));
    j1.add(q1);
    j1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Node mapping"));
    p.add(j1);
    JPanel j2 = new JPanel(new GridLayout(1, 1));
    j2.add(q2);
    j2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Arrow mapping"));
    p.add(j2);
    JPanel j3 = new JPanel(new GridLayout(1, 1));
    j3.add(q3);
    j3.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Attribute mapping"));
    p.add(j3);
    // p.setBorder(BorderFactory.createEtchedBorder());
    return FqlUtil.makeGrid(p);
}
Also used : Color(java.awt.Color) UIManager(javax.swing.UIManager) java.util(java.util) Const(catdata.fql.decl.MapExp.Const) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) EmbeddedDependency(catdata.fql.sql.EmbeddedDependency) Constructor(java.lang.reflect.Constructor) FQLException(catdata.fql.FQLException) GridLayout(java.awt.GridLayout) FinFunctor(catdata.fql.cat.FinFunctor) FinCat(catdata.fql.cat.FinCat) JTabbedPane(javax.swing.JTabbedPane) PSM(catdata.fql.sql.PSM) Graph(edu.uci.ics.jung.graph.Graph) PrettyPrinter(catdata.fql.parse.PrettyPrinter) DirectedSparseMultigraph(edu.uci.ics.jung.graph.DirectedSparseMultigraph) Fn(catdata.fql.Fn) Pair(catdata.Pair) Stroke(java.awt.Stroke) JComponent(javax.swing.JComponent) Layout(edu.uci.ics.jung.algorithms.layout.Layout) Function(com.google.common.base.Function) PSMGen(catdata.fql.sql.PSMGen) BorderFactory(javax.swing.BorderFactory) JScrollPane(javax.swing.JScrollPane) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) Paint(java.awt.Paint) Arr(catdata.fql.cat.Arr) Entry(java.util.Map.Entry) Triple(catdata.Triple) JTable(javax.swing.JTable) BasicStroke(java.awt.BasicStroke) FqlUtil(catdata.fql.FqlUtil) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) JTextArea(javax.swing.JTextArea) JPanel(javax.swing.JPanel) FqlOptions(catdata.fql.FqlOptions) DefunctGlobalOptions(catdata.ide.DefunctGlobalOptions) Mode(edu.uci.ics.jung.visualization.control.ModalGraphMouse.Mode) JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) JComponent(javax.swing.JComponent) Dimension(java.awt.Dimension) Paint(java.awt.Paint) GridLayout(java.awt.GridLayout) JTable(javax.swing.JTable)

Example 23 with Arr

use of catdata.fql.cat.Arr in project fql by CategoricalData.

the class Signature method view.

@SuppressWarnings("serial")
public JPanel view() {
    Object[][] arr = new Object[eqs.size()][2];
    int i = 0;
    for (Eq eq : eqs) {
        arr[i][0] = eq.lhs;
        arr[i][1] = eq.rhs;
        i++;
    }
    Arrays.sort(arr, Comparator.comparing(f4 -> f4[0].toString()));
    JTable eqsComponent = new JTable(arr, new Object[] { "lhs", "rhs" }) {

        @Override
        public Dimension getPreferredScrollableViewportSize() {
            Dimension d = getPreferredSize();
            return new Dimension(d.width, d.height);
        }
    };
    List<JComponent> p = new LinkedList<>();
    JPanel eqsTemp = new JPanel(new GridLayout(1, 1));
    eqsTemp.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2), "Equations (" + eqs.size() + ")"));
    eqsTemp.add(new JScrollPane(eqsComponent));
    Object[][] sn = new String[nodes.size()][1];
    int ii = 0;
    for (Node n : nodes) {
        sn[ii++][0] = n.string;
    }
    Arrays.sort(sn, Comparator.comparing(f3 -> f3[0].toString()));
    JTable nodesComponent = new JTable(sn, new String[] { "Name" }) {

        @Override
        public Dimension getPreferredScrollableViewportSize() {
            Dimension d = getPreferredSize();
            return new Dimension(d.width, d.height);
        }
    };
    JPanel nodesTemp = new JPanel(new GridLayout(1, 1));
    nodesTemp.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2), "Nodes (" + nodes.size() + ")"));
    nodesTemp.add(new JScrollPane(nodesComponent));
    Object[][] es = new String[edges.size()][3];
    int jj = 0;
    for (Edge eq : edges) {
        es[jj][0] = eq.name;
        es[jj][1] = eq.source.string;
        es[jj][2] = eq.target.string;
        jj++;
    }
    Arrays.sort(es, Comparator.comparing(f2 -> f2[0].toString()));
    JTable esC = new JTable(es, new String[] { "Name", "Source", "Target" }) {

        @Override
        public Dimension getPreferredScrollableViewportSize() {
            Dimension d = getPreferredSize();
            return new Dimension(d.width, d.height);
        }
    };
    JPanel edgesTemp = new JPanel(new GridLayout(1, 1));
    edgesTemp.add(new JScrollPane(esC));
    edgesTemp.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2), "Arrows (" + edges.size() + ")"));
    Object[][] as = new String[attrs.size()][3];
    jj = 0;
    for (Attribute<Node> a : attrs) {
        as[jj][0] = a.name;
        as[jj][1] = a.source.string;
        as[jj][2] = a.target.toString();
        jj++;
    }
    Arrays.sort(as, Comparator.comparing(f -> f[0].toString()));
    JTable asC = new JTable(as, new String[] { "Name", "Source", "Type" }) {

        @Override
        public Dimension getPreferredScrollableViewportSize() {
            Dimension d = getPreferredSize();
            return new Dimension(d.width, d.height);
        }
    };
    JPanel attrsTemp = new JPanel(new GridLayout(1, 1));
    attrsTemp.add(new JScrollPane(asC));
    attrsTemp.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2), "Attributes (" + attrs.size() + ")"));
    p.add(nodesTemp);
    p.add(edgesTemp);
    p.add(attrsTemp);
    p.add(eqsTemp);
    return FqlUtil.makeGrid(p);
}
Also used : Color(java.awt.Color) UIManager(javax.swing.UIManager) Arrays(java.util.Arrays) Map(java.util.Map) Int(catdata.fql.decl.Type.Int) DirectedSparseMultigraph(edu.uci.ics.jung.graph.DirectedSparseMultigraph) BorderLayout(java.awt.BorderLayout) Fn(catdata.fql.Fn) Pair(catdata.Pair) Function(com.google.common.base.Function) Font(java.awt.Font) Collection(java.util.Collection) Set(java.util.Set) Inst(catdata.fql.cat.Inst) PSMGen(catdata.fql.sql.PSMGen) BorderFactory(javax.swing.BorderFactory) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) List(java.util.List) Paint(java.awt.Paint) Entry(java.util.Map.Entry) Triple(catdata.Triple) JTable(javax.swing.JTable) BasicStroke(java.awt.BasicStroke) FqlUtil(catdata.fql.FqlUtil) JPanel(javax.swing.JPanel) DefunctGlobalOptions(catdata.ide.DefunctGlobalOptions) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) EmbeddedDependency(catdata.fql.sql.EmbeddedDependency) HashMap(java.util.HashMap) Constructor(java.lang.reflect.Constructor) FQLException(catdata.fql.FQLException) GridLayout(java.awt.GridLayout) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) ToStringLabeller(edu.uci.ics.jung.visualization.decorators.ToStringLabeller) FinCat(catdata.fql.cat.FinCat) JTabbedPane(javax.swing.JTabbedPane) Graph(edu.uci.ics.jung.graph.Graph) Const(catdata.fql.decl.SigExp.Const) LinkedList(java.util.LinkedList) Stroke(java.awt.Stroke) JComponent(javax.swing.JComponent) Layout(edu.uci.ics.jung.algorithms.layout.Layout) JButton(javax.swing.JButton) CodeTextPanel(catdata.ide.CodeTextPanel) IntRef(catdata.IntRef) ActionEvent(java.awt.event.ActionEvent) JScrollPane(javax.swing.JScrollPane) LeftKanCat(catdata.fql.cat.LeftKanCat) Arr(catdata.fql.cat.Arr) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) JTextArea(javax.swing.JTextArea) Comparator(java.util.Comparator) Collections(java.util.Collections) FqlOptions(catdata.fql.FqlOptions) Mode(edu.uci.ics.jung.visualization.control.ModalGraphMouse.Mode) JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) JComponent(javax.swing.JComponent) Dimension(java.awt.Dimension) Paint(java.awt.Paint) LinkedList(java.util.LinkedList) GridLayout(java.awt.GridLayout) JTable(javax.swing.JTable)

Example 24 with Arr

use of catdata.fql.cat.Arr in project fql by CategoricalData.

the class SigOps method visit.

@Override
public Const visit(FQLProgram env, Curry e) {
    try {
        Const F = e.f.accept(env, this);
        Pair<SigExp, SigExp> type = e.f.type(env);
        SigExp.Const C = type.second.toConst(env);
        Signature Csig = C.toSig(env);
        if (!(type.first instanceof Times)) {
            throw new RuntimeException();
        }
        Times src = (Times) type.first;
        SigExp.Const A = src.a.toConst(env);
        SigExp.Const B = src.b.toConst(env);
        // Signature Asig = A.toSig(env);
        Signature Bsig = B.toSig(env);
        if (!A.attrs.isEmpty()) {
            throw new RuntimeException("Cannot curry when context has attributes.");
        }
        Pair<Quad<SigExp.Const, Const, Const, Fn<Triple<SigExp.Const, Const, Const>, Const>>, Quad<Map<Pair<String, String>, String>, Map<Pair<String, String>, String>, Map<Pair<String, String>, String>, Map<Pair<String, String>, String>>> AB_stuff = prod(A, B);
        // SigExp.Const AB = AB_stuff.first.first;
        Quad<Map<Pair<String, String>, String>, Map<Pair<String, String>, String>, Map<Pair<String, String>, String>, Map<Pair<String, String>, String>> maps = AB_stuff.second;
        FinCat<Mapping, Map<Node, Path>> cat = exp(env, C.toSig(env), B.toSig(env));
        Quad<Signature, Pair<Map<Mapping, String>, Map<String, Mapping>>, Pair<Map<Arr<Mapping, Map<Node, Path>>, String>, Map<String, Arr<Mapping, Map<Node, Path>>>>, Pair<Map<Attribute<Mapping>, String>, Map<String, Attribute<Mapping>>>> CB_stuff = cat.toSig(env.enums);
        Signature CB = CB_stuff.first;
        List<Pair<String, String>> nmret = new LinkedList<>();
        for (String a : A.nodes) {
            Mapping m = curry_helper(F, Csig, B, Bsig, maps, a);
            String target = CB_stuff.second.first.get(m);
            nmret.add(new Pair<>(a, target));
        }
        List<Pair<String, List<String>>> amret = new LinkedList<>();
        for (Triple<String, String, String> a : A.arrows) {
            Mapping s = curry_helper(F, Csig, B, Bsig, maps, a.second);
            Mapping t = curry_helper(F, Csig, B, Bsig, maps, a.third);
            Map<Node, Path> nt = new HashMap<>();
            for (String b : B.nodes) {
                // edge A*B
                String p = maps.third.get(new Pair<>(a.first, b));
                // path C
                List<String> p0 = lookup(p, F.arrows);
                Path p1 = new Path(Csig, p0);
                nt.put(new Node(b), p1);
            }
            List<String> l = new LinkedList<>();
            l.add(CB_stuff.second.first.get(s));
            Arr<Mapping, Map<Node, Path>> arr = new Arr<>(nt, s, t);
            if (null != CB_stuff.third.first.get(arr)) {
                l.add(CB_stuff.third.first.get(arr));
            }
            amret.add(new Pair<>(a.first, l));
        }
        List<Pair<String, String>> attrs = new LinkedList<>();
        // A*B -> C
        // A -> C^B
        Const ret = new Const(nmret, attrs, amret, A, CB.toConst());
        ret.toMap(env);
        return ret;
    } catch (FQLException fe) {
        fe.printStackTrace();
        throw new RuntimeException(fe.getMessage());
    }
}
Also used : Arr(catdata.fql.cat.Arr) Quad(catdata.Quad) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FQLException(catdata.fql.FQLException) Pair(catdata.Pair) Const(catdata.fql.decl.MapExp.Const) LinkedList(java.util.LinkedList) Triple(catdata.Triple) Times(catdata.fql.decl.SigExp.Times) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

Arr (catdata.fql.cat.Arr)24 Pair (catdata.Pair)21 LinkedHashMap (java.util.LinkedHashMap)20 HashMap (java.util.HashMap)19 FQLException (catdata.fql.FQLException)17 LinkedList (java.util.LinkedList)16 Map (java.util.Map)15 Node (catdata.fql.decl.Node)14 Triple (catdata.Triple)11 Path (catdata.fql.decl.Path)11 Attribute (catdata.fql.decl.Attribute)10 Instance (catdata.fql.decl.Instance)9 HashSet (java.util.HashSet)7 Set (java.util.Set)7 Fn (catdata.fql.Fn)6 Edge (catdata.fql.decl.Edge)6 Signature (catdata.fql.decl.Signature)6 Transform (catdata.fql.decl.Transform)6 PSM (catdata.fql.sql.PSM)6 List (java.util.List)6