Search in sources :

Example 11 with Edge

use of catdata.fql.decl.Edge 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 12 with Edge

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

the class LeftKan method gamma1.

private void gamma1(Node b1, Pair<Integer, Integer> xy) {
    if (xy.first.equals(xy.second)) {
        Sb.get(b1).remove(xy);
        return;
    }
    Integer x, y;
    if (xy.first > xy.second) {
        x = xy.second;
        y = xy.first;
    } else {
        x = xy.first;
        y = xy.second;
    }
    Pb.get(b1).remove(new Pair<>(y, y));
    replace(x, y);
    Set<Pair<Integer, Integer>> set0 = new HashSet<>(Sb.get(b1));
    for (Pair<Integer, Integer> k : Sb.get(b1)) {
        if (k.first.equals(y)) {
            set0.add(new Pair<>(x, k.second));
        }
        if (k.second.equals(y)) {
            set0.add(new Pair<>(k.first, x));
        }
    }
    filter(set0, y);
    Sb.put(b1, set0);
    for (Edge g : Pg.keySet()) {
        Set<Pair<Integer, Integer>> set = Pg.get(g);
        Set<Pair<Integer, Integer>> a = new HashSet<>();
        if (g.source.equals(b1) && g.target.equals(b1)) {
            for (Pair<Integer, Integer> k : set) {
                if (k.first.equals(y) && k.second.equals(y)) {
                    a.add(new Pair<>(x, x));
                }
                if (k.first.equals(y) && !k.second.equals(y)) {
                    a.add(new Pair<>(x, k.second));
                }
                if (k.second.equals(y) && !k.first.equals(y)) {
                    a.add(new Pair<>(k.first, x));
                }
            }
        } else if (g.source.equals(b1)) {
            for (Pair<Integer, Integer> k : set) {
                if (k.first.equals(y) && !k.second.equals(y)) {
                    a.add(new Pair<>(x, k.second));
                }
            }
        } else if (g.target.equals(b1)) {
            for (Pair<Integer, Integer> k : set) {
                if (k.second.equals(y) && !k.first.equals(y)) {
                    a.add(new Pair<>(k.first, x));
                }
            }
        }
        set.addAll(a);
        filter(set, y);
    }
    // : not needed?
    lineage.remove(y);
}
Also used : Edge(catdata.fql.decl.Edge) Pair(catdata.Pair) HashSet(java.util.HashSet)

Example 13 with Edge

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

the class LeftKan method beta2.

// beta, delta, gamma
private boolean beta2() {
    boolean ret = false;
    try {
        for (Edge e : A.edges) {
            Path g = F.appy(B, new Path(A, e));
            Set<Pair<Object, Integer>> lhs = Instance.compose(X.data.get(e.name), ua.get(e.target));
            Set<Pair<Object, Integer>> rhs = Instance.compose(ua.get(e.source), eval(g));
            // System.out.println(lhs);
            // System.out.println(rhs);
            Node n = g.target;
            ret = ret || addCoincidences(lhs, rhs, n);
        }
    } catch (FQLException fe) {
        fe.printStackTrace();
        throw new RuntimeException(fe.getMessage());
    }
    return ret;
}
Also used : Path(catdata.fql.decl.Path) FQLException(catdata.fql.FQLException) Node(catdata.fql.decl.Node) Edge(catdata.fql.decl.Edge) Pair(catdata.Pair)

Example 14 with Edge

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

the class LeftKan method delta.

private boolean delta() {
    boolean ret = false;
    for (Edge g : B.edges) {
        for (Pair<Integer, Integer> x : Pb.get(g.source)) {
            Integer y = null;
            Iterator<Pair<Integer, Integer>> it = Pg.get(g).iterator();
            while (it.hasNext()) {
                Pair<Integer, Integer> z = it.next();
                if (!x.first.equals(z.first)) {
                    continue;
                }
                if (y == null) {
                    y = z.second;
                    continue;
                }
                // if (z.second.equals(y)) {
                ret = true;
                it.remove();
                Sb.get(g.target).add(new Pair<>(y, z.second));
                Sb.get(g.target).add(new Pair<>(z.second, y));
            // }
            }
        }
    }
    return ret;
}
Also used : Edge(catdata.fql.decl.Edge) Pair(catdata.Pair)

Example 15 with Edge

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

the class LeftKanSigma method reAttr.

private static Instance reAttr(Map<Node, Map<Object, Integer>> D, Signature thesig, Instance i, Map<Attribute<Node>, Map<Object, Object>> map0) throws FQLException {
    Map<String, Set<Pair<Object, Object>>> d = new HashMap<>();
    for (Node k : i.thesig.nodes) {
        d.put(k.string, i.data.get(k.string));
    }
    for (Edge k : thesig.edges) {
        d.put(k.name, i.data.get(k.name));
    }
    Map<Object, Object> map = new HashMap<>();
    for (Attribute<Node> k : map0.keySet()) {
        Map<Object, Object> v = map0.get(k);
        for (Object k0 : v.keySet()) {
            Object v0 = v.get(k0);
            if (map.containsKey(k0)) {
                throw new RuntimeException();
            }
            map.put(k0, v0);
        }
    }
    for (Attribute<Node> k : thesig.attrs) {
        Set<Pair<Object, Object>> t = new HashSet<>();
        for (Pair<Object, Object> v : i.data.get(k.name + "_edge")) {
            Object v1 = getFrom(k, D, map, /* ().get(k) */
            v.second.toString());
            t.add(new Pair<>(v.first, v1));
        }
        d.put(k.name, t);
    }
    return new Instance(thesig, d);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Instance(catdata.fql.decl.Instance) Node(catdata.fql.decl.Node) Edge(catdata.fql.decl.Edge) Pair(catdata.Pair) HashSet(java.util.HashSet)

Aggregations

Edge (catdata.fql.decl.Edge)37 Node (catdata.fql.decl.Node)33 HashMap (java.util.HashMap)27 Pair (catdata.Pair)25 HashSet (java.util.HashSet)19 LinkedList (java.util.LinkedList)19 LinkedHashMap (java.util.LinkedHashMap)17 Instance (catdata.fql.decl.Instance)15 Set (java.util.Set)13 Map (java.util.Map)12 FQLException (catdata.fql.FQLException)11 Path (catdata.fql.decl.Path)11 Attribute (catdata.fql.decl.Attribute)10 Signature (catdata.fql.decl.Signature)9 List (java.util.List)7 Arr (catdata.fql.cat.Arr)6 Fn (catdata.fql.Fn)4 Transform (catdata.fql.decl.Transform)4 Triple (catdata.Triple)3 FinCat (catdata.fql.cat.FinCat)3