Search in sources :

Example 1 with Node

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

the class PSMGen method findEquiv.

private static Path findEquiv(Node c, Mapping f, Edge e) throws FQLException {
    Signature C = f.source;
    Signature D = f.target;
    FinCat<Node, Path> C0 = C.toCategory2().first;
    for (Arr<Node, Path> peqc : C0.arrows) {
        Path path = peqc.arr;
        // Path path = new Path(f.source, p);
        if (!path.source.equals(c)) {
            continue;
        }
        Path path_f = f.appy(D, path);
        Fn<Path, Arr<Node, Path>> F = D.toCategory2().second;
        if (F.of(path_f).equals(F.of(new Path(D, e)))) {
            return path;
        }
    }
    throw new FQLException("Could not find path mapping to " + e);
}
Also used : Path(catdata.fql.decl.Path) Arr(catdata.fql.cat.Arr) FQLException(catdata.fql.FQLException) Signature(catdata.fql.decl.Signature) Node(catdata.fql.decl.Node)

Example 2 with Node

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

the class PSMGen method sigma.

public static List<PSM> sigma(Mapping F, String pre, String inst) throws FQLException {
    Signature C = F.source;
    Signature D = F.target;
    List<PSM> ret = new LinkedList<>();
    if (!FinFunctor.isDiscreteOpFib(F.toFunctor2().first)) {
        throw new FQLException("Not a discrete op-fibration");
    }
    for (Node d : D.nodes) {
        List<Flower> tn = new LinkedList<>();
        for (Node c : C.nodes) {
            if (F.nm.get(c).equals(d)) {
                tn.add(new CopyFlower(inst + "_" + c.string, "c0", "c1"));
            }
        }
        if (tn.isEmpty()) {
            continue;
        }
        SQL y = foldUnion(tn);
        ret.add(new InsertSQL(pre + "_" + d.string, y, "c0", "c1"));
    }
    for (Edge e : D.edges) {
        Node d = e.source;
        // Node d0 = e.target;
        List<Flower> tn = new LinkedList<>();
        for (Node c : C.nodes) {
            if (F.nm.get(c).equals(d)) {
                Path pc = findEquiv(c, F, e);
                Flower q = compose(inst, pc);
                tn.add(q);
            }
        }
        if (tn.isEmpty()) {
            continue;
        }
        SQL y = foldUnion(tn);
        ret.add(new InsertSQL(pre + "_" + e.name, y, "c0", "c1"));
    }
    for (Attribute<Node> a : D.attrs) {
        Node d = a.source;
        // Node d0 = e.target;
        List<Flower> tn = new LinkedList<>();
        for (Node c : C.nodes) {
            if (F.nm.get(c).equals(d)) {
                Attribute<Node> pc = findEquiv(c, F, a);
                Flower q = new CopyFlower(inst + "_" + pc.name, "c0", "c1");
                tn.add(q);
            }
        }
        if (tn.isEmpty()) {
            continue;
        }
        SQL y = foldUnion(tn);
        ret.add(new InsertSQL(pre + "_" + a.name, y, "c0", "c1"));
    }
    return ret;
}
Also used : Path(catdata.fql.decl.Path) Node(catdata.fql.decl.Node) LinkedList(java.util.LinkedList) FQLException(catdata.fql.FQLException) Signature(catdata.fql.decl.Signature) Edge(catdata.fql.decl.Edge)

Example 3 with Node

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

the class PSMGen method shred.

public static void shred(String pre, Instance I, Map<String, Set<Map<Object, Object>>> state) {
    for (Node n : I.thesig.nodes) {
        Set<Map<Object, Object>> m = new HashSet<>();
        for (Pair<Object, Object> k : I.data.get(n.string)) {
            Map<Object, Object> map = new HashMap<>();
            map.put("c0", k.first);
            map.put("c1", k.second);
            m.add(map);
        }
        state.put(pre + "_" + n.string, m);
    }
    for (Edge n : I.thesig.edges) {
        Set<Map<Object, Object>> m = new HashSet<>();
        for (Pair<Object, Object> k : I.data.get(n.name)) {
            Map<Object, Object> map = new HashMap<>();
            map.put("c0", k.first);
            map.put("c1", k.second);
            m.add(map);
        }
        state.put(pre + "_" + n.name, m);
    }
    for (Attribute<Node> n : I.thesig.attrs) {
        Set<Map<Object, Object>> m = new HashSet<>();
        for (Pair<Object, Object> k : I.data.get(n.name)) {
            Map<Object, Object> map = new HashMap<>();
            map.put("c0", k.first);
            map.put("c1", k.second);
            m.add(map);
        }
        state.put(pre + "_" + n.name, m);
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Node(catdata.fql.decl.Node) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Edge(catdata.fql.decl.Edge) HashSet(java.util.HashSet)

Example 4 with Node

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

the class PSMGen method guidify.

public static List<PSM> guidify(String pre0, Signature sig, boolean remember) {
    List<PSM> ret = new LinkedList<>();
    Map<String, String> guid_attrs = new HashMap<>();
    Map<String, String> twocol_attrs = new HashMap<>();
    twocol_attrs.put("c0", PSM.VARCHAR());
    twocol_attrs.put("c1", PSM.VARCHAR());
    guid_attrs.put("c0", PSM.VARCHAR());
    guid_attrs.put("c1", PSM.VARCHAR());
    guid_attrs.put("guid", PSM.VARCHAR());
    List<String> attrs_foo = new LinkedList<>();
    attrs_foo.add("c0");
    attrs_foo.add("c1");
    for (Node n : sig.nodes) {
        String pre = pre0 + "_" + n;
        // make new table with GUID
        ret.add(new CreateTable(pre + "_guid", guid_attrs, false));
        ret.add(new InsertKeygen(pre + "_guid", "guid", pre, attrs_foo));
        // make a substitution table
        ret.add(new CreateTable(pre + "_subst", twocol_attrs, false));
        ret.add(new InsertSQL(pre + "_subst", makeSubst(pre0, n), "c0", "c1"));
        ret.add(new CreateTable(pre + "_subst_inv", twocol_attrs, false));
        ret.add(new InsertSQL(pre + "_subst_inv", invertSubst(pre0, n), "c0", "c1"));
        // create a new table that applies the substitution
        ret.add(new CreateTable(pre + "_applied", twocol_attrs, false));
        ret.add(new InsertSQL(pre + "_applied", makeApplyNode(pre0, n), "c0", "c1"));
        // drop guid table
        ret.add(new DropTable(pre + "_guid"));
        // drop original table
        ret.add(new DropTable(pre));
        // copy the new table
        ret.add(new SimpleCreateTable(pre, PSM.VARCHAR(), false));
        // ret.add(new CreateTable(pre, twocol_attrs, false));
        ret.add(new InsertSQL(pre, new CopyFlower(pre + "_applied", "c0", "c1"), "c0", "c1"));
        // drop the new table
        ret.add(new DropTable(pre + "_applied"));
    }
    for (Edge e : sig.edges) {
        String pre = pre0 + "_" + e.name;
        // create a new table that applies the substitution
        ret.add(new CreateTable(pre + "_applied", twocol_attrs, false));
        ret.add(new InsertSQL(pre + "_applied", makeApplyEdge(pre0, e), "c0", "c1"));
        // drop original table
        ret.add(new DropTable(pre));
        // copy the new table
        ret.add(new SimpleCreateTable(pre, PSM.VARCHAR(), false));
        // ret.add(new CreateTable(pre, twocol_attrs, false));
        ret.add(new InsertSQL(pre, new CopyFlower(pre + "_applied", "c0", "c1"), "c0", "c1"));
        // drop the new table
        ret.add(new DropTable(pre + "_applied"));
    }
    for (Attribute<Node> a : sig.attrs) {
        String pre = pre0 + "_" + a.name;
        // create a new table that applies the substitution
        ret.add(new CreateTable(pre + "_applied", colattrs(a), false));
        ret.add(new InsertSQL(pre + "_applied", makeAttr(pre0, a), "c0", "c1"));
        // drop original table
        ret.add(new DropTable(pre));
        // copy the new table
        ret.add(new SimpleCreateTable(pre, a.target.psm(), false));
        // ret.add(new CreateTable(pre, twocol_attrs, false));
        ret.add(new InsertSQL(pre, new CopyFlower(pre + "_applied", "c0", "c1"), "c0", "c1"));
        // drop the new table
        ret.add(new DropTable(pre + "_applied"));
    }
    if (!remember) {
        for (Node n : sig.nodes) {
            String pre = pre0 + "_" + n;
            ret.add(new DropTable(pre + "_subst"));
            ret.add(new DropTable(pre + "_subst_inv"));
        }
    }
    return ret;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Node(catdata.fql.decl.Node) LinkedList(java.util.LinkedList) Edge(catdata.fql.decl.Edge)

Example 5 with Node

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

the class PSMGen method doExternal.

public static List<PSM> doExternal(Signature sig, String in, String out) {
    List<PSM> ret = new LinkedList<>();
    ret.addAll(makeTables(in, sig, true));
    for (Node n : sig.nodes) {
        ret.add(new InsertSQL(out + "_" + n.string, new CopyFlower(in + "_" + n.string, "c0", "c1"), "c0", "c1"));
    }
    for (Edge e : sig.edges) {
        ret.add(new InsertSQL(out + "_" + e.name, new CopyFlower(in + "_" + e.name, "c0", "c1"), "c0", "c1"));
    }
    for (Attribute<Node> a : sig.attrs) {
        ret.add(new InsertSQL(out + "_" + a.name, new CopyFlower(in + "_" + a.name, "c0", "c1"), "c0", "c1"));
    }
    return ret;
}
Also used : Node(catdata.fql.decl.Node) Edge(catdata.fql.decl.Edge) LinkedList(java.util.LinkedList)

Aggregations

Node (catdata.fql.decl.Node)51 Pair (catdata.Pair)38 HashMap (java.util.HashMap)36 Edge (catdata.fql.decl.Edge)33 LinkedList (java.util.LinkedList)26 LinkedHashMap (java.util.LinkedHashMap)25 Instance (catdata.fql.decl.Instance)22 Path (catdata.fql.decl.Path)21 Map (java.util.Map)21 FQLException (catdata.fql.FQLException)20 Attribute (catdata.fql.decl.Attribute)19 HashSet (java.util.HashSet)19 Arr (catdata.fql.cat.Arr)14 Signature (catdata.fql.decl.Signature)13 Set (java.util.Set)13 Transform (catdata.fql.decl.Transform)11 List (java.util.List)10 Triple (catdata.Triple)5 Fn (catdata.fql.Fn)4 FinCat (catdata.fql.cat.FinCat)3