Search in sources :

Example 46 with Node

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

the class LeftKanSigma method getFrom.

private static Object getFrom(Attribute<Node> attr, Map<Node, Map<Object, Integer>> etables, Map<Object, Object> saved, String newkey) {
    List<Pair<Object, Object>> pre = new LinkedList<>();
    for (Node kkk : etables.keySet()) {
        Map<Object, Integer> nt = etables.get(kkk);
        for (Object k : nt.keySet()) {
            if (nt.get(k).toString().equals(newkey)) {
                if (saved.get(k.toString()) == null) {
                    throw new RuntimeException();
                }
                pre.add(new Pair<>(k, saved.get(k.toString())));
            }
        }
    }
    if (pre.isEmpty()) {
        if (!DefunctGlobalOptions.debug.fql.ALLOW_NULLS) {
            throw new RuntimeException("Full sigma not surjective: transform is " + etables + " saved " + saved + " new key " + newkey);
        }
    }
    Set<Object> x = new HashSet<>();
    for (Pair<Object, Object> i : pre) {
        x.add(i.second);
    }
    if (x.size() > 1) {
        throw new RuntimeException("Full sigma not unique: transform is " + etables + " saved " + saved + " new key " + newkey);
    }
    for (Object ret : x) {
        return ret;
    }
    if (DefunctGlobalOptions.debug.fql.ALLOW_NULLS) {
        if (!(attr.target instanceof Varchar)) {
            throw new RuntimeException("Cannot create nulls for any type but string");
        }
        // null hack
        return "NULL" + newkey;
    }
    throw new RuntimeException();
}
Also used : Node(catdata.fql.decl.Node) LinkedList(java.util.LinkedList) Varchar(catdata.fql.decl.Type.Varchar) Pair(catdata.Pair) HashSet(java.util.HashSet)

Example 47 with Node

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

the class LeftKanSigma method sigma.

private static Pair<Instance, Map<Object, List<Pair<String, Object>>>> sigma(LeftKan lk) throws FQLException {
    if (!lk.compute()) {
        throw new FQLException("Too many sigma iterations.");
    }
    Map<String, Set<Pair<Object, Object>>> data = new HashMap<>();
    for (Node e : lk.Pb.keySet()) {
        Set<Pair<Integer, Integer>> t = lk.Pb.get(e);
        data.put(e.string, conc(t));
    }
    for (Edge e : lk.Pg.keySet()) {
        Set<Pair<Integer, Integer>> t = lk.Pg.get(e);
        data.put(e.name, conc(t));
    }
    Instance ret = new Instance(lk.F.target, data);
    return new Pair<>(ret, lk.lineage);
}
Also used : FQLException(catdata.fql.FQLException) 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)

Example 48 with Node

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

the class LeftKanSigma method delta.

private static Pair<Instance, Map<Attribute<Node>, Map<Object, Object>>> delta(Mapping f0, Mapping f, Pair<Instance, Map<Attribute<Node>, Map<Object, Object>>> p) throws FQLException {
    Map<String, Set<Pair<Object, Object>>> data = new HashMap<>();
    for (Node n : f.source.nodes) {
        data.put(n.string, p.first.data.get(f.nm.get(n).string));
    }
    for (Edge e : f.source.edges) {
        data.put(e.name, p.first.evaluate(f.em.get(e)));
    }
    Instance J = new Instance(f.source, data);
    Map<Attribute<Node>, Map<Object, Object>> m = new HashMap<>();
    for (Attribute<Node> a : f0.source.attrs) {
        m.put(a, p.second.get(f0.am.get(a)));
    }
    return new Pair<>(J, m);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Instance(catdata.fql.decl.Instance) Attribute(catdata.fql.decl.Attribute) Node(catdata.fql.decl.Node) Edge(catdata.fql.decl.Edge) HashMap(java.util.HashMap) Map(java.util.Map) Pair(catdata.Pair)

Example 49 with Node

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

the class LeftKanSigma method deAttr.

private static Mapping deAttr(Mapping f) throws FQLException {
    Mapping ret = f.clone();
    deAttr(ret.source);
    deAttr(ret.target);
    for (Attribute<Node> k : ret.am.keySet()) {
        Attribute<Node> v = ret.am.get(k);
        Node src = new Node(k.name);
        Node dst = new Node(v.name);
        Edge srcE = new Edge(k.name + "_edge", k.source, src);
        Edge dstE = new Edge(v.name + "_edge", v.source, dst);
        ret.nm.put(src, dst);
        ret.em.put(srcE, new Path(ret.target, dstE));
    }
    ret.am.clear();
    return ret;
}
Also used : Path(catdata.fql.decl.Path) Node(catdata.fql.decl.Node) Mapping(catdata.fql.decl.Mapping) Edge(catdata.fql.decl.Edge)

Example 50 with Node

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

the class JDBCBridge method makeInserts.

private static List<PSM> makeInserts(String k, Map<String, Set<Map<Object, Object>>> state, Signature sig, Signature src_sig) {
    List<PSM> ret = new LinkedList<>();
    List<String> attrs = new LinkedList<>();
    attrs.add("c0");
    attrs.add("c1");
    if (src_sig != null) {
        for (Node n : src_sig.nodes) {
            Set<Map<Object, Object>> v = state.get(k + "_" + n.string + "_e");
            ret.add(new SimpleCreateTable(k + "_" + n.string + "_e", PSM.VARCHAR(), false));
            if (v.isEmpty()) {
                continue;
            }
            ret.add(new InsertValues(k + "_" + n.string + "_e", attrs, v));
        }
        Set<Map<Object, Object>> v = state.get(k + "_lineage");
        Map<String, String> at = new LinkedHashMap<>();
        at.put("c0", PSM.VARCHAR());
        at.put("c1", PSM.VARCHAR());
        at.put("c2", PSM.VARCHAR());
        at.put("c3", PSM.VARCHAR());
        ret.add(new CreateTable(k + "_lineage", at, false));
        if (!v.isEmpty()) {
            ret.add(new InsertValues(k + "_lineage", new LinkedList<>(at.keySet()), v));
        }
    }
    for (Node n : sig.nodes) {
        Set<Map<Object, Object>> v = state.get(k + "_" + n.string);
        if (v.isEmpty()) {
            continue;
        }
        ret.add(new InsertValues(k + "_" + n.string, attrs, v));
    }
    for (Edge e : sig.edges) {
        Set<Map<Object, Object>> v = state.get(k + "_" + e.name);
        if (v.isEmpty()) {
            continue;
        }
        ret.add(new InsertValues(k + "_" + e.name, attrs, v));
    }
    for (Attribute<Node> a : sig.attrs) {
        Set<Map<Object, Object>> v = state.get(k + "_" + a.name);
        if (v.isEmpty()) {
            continue;
        }
        ret.add(new InsertValues(k + "_" + a.name, attrs, v));
    }
    return ret;
}
Also used : Node(catdata.fql.decl.Node) SimpleCreateTable(catdata.fql.sql.SimpleCreateTable) CreateTable(catdata.fql.sql.CreateTable) PSM(catdata.fql.sql.PSM) PropPSM(catdata.fql.sql.PropPSM) ExpPSM(catdata.fql.sql.ExpPSM) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) SimpleCreateTable(catdata.fql.sql.SimpleCreateTable) InsertValues(catdata.fql.sql.InsertValues) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Edge(catdata.fql.decl.Edge)

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