Search in sources :

Example 1 with EmbeddedDependency

use of catdata.fql.sql.EmbeddedDependency in project fql by CategoricalData.

the class Chase method chaseEgd.

private static List<Pair<Object, Object>> chaseEgd(Map<String, Set<Pair<Object, Object>>> i, List<String> forall, List<Triple<String, String, String>> where, List<Pair<String, String>> t) {
    List<Pair<Object, Object>> ret = new LinkedList<>();
    EmbeddedDependency xxx0 = conv(forall, where, t);
    ED xxx = ED.from(xxx0);
    Flower front = xxx.front();
    Flower back = xxx.back();
    Set<Map<Object, Object>> frontX = front.eval(ED.conv(i));
    Set<Map<Object, Object>> backX = back.eval(ED.conv(i));
    if (frontX.equals(backX)) {
        return ret;
    }
    for (Pair<String, String> eq : t) {
        int a = getColNo(xxx0.forall, xxx0.where, eq.first);
        int b = getColNo(xxx0.forall, xxx0.where, eq.second);
        for (Map<Object, Object> row : frontX) {
            if (row.get("c" + a).toString().startsWith("_")) {
                ret.add(new Pair<>(row.get("c" + a), row.get("c" + b)));
            } else {
                ret.add(new Pair<>(row.get("c" + b), row.get("c" + a)));
            }
        }
    }
    return ret;
}
Also used : Flower(catdata.fql.sql.Flower) LinkedList(java.util.LinkedList) HashMap(java.util.HashMap) Map(java.util.Map) EmbeddedDependency(catdata.fql.sql.EmbeddedDependency) Pair(catdata.Pair) ED(catdata.fql.sql.ED)

Example 2 with EmbeddedDependency

use of catdata.fql.sql.EmbeddedDependency in project fql by CategoricalData.

the class Chase method run.

private static Pair<String, String> run(String eds, String inst, KIND kind) throws Exception {
    Partial<List<EmbeddedDependency>> xxx = eds_p.parse(new FqlTokenizer(eds));
    List<EmbeddedDependency> eds0 = xxx.value;
    if (!xxx.tokens.toString().trim().isEmpty()) {
        throw new FQLException("Unconsumed input: " + xxx.tokens);
    }
    Partial<List<Pair<String, List<Pair<String, String>>>>> yyy = inst_p.parse(new FqlTokenizer(inst));
    Map<String, Set<Pair<Object, Object>>> inst0 = conv(yyy.value);
    if (!yyy.tokens.toString().trim().isEmpty()) {
        throw new FQLException("Unconsumed input: " + yyy.tokens);
    }
    Pair<List<Triple<List<String>, List<Triple<String, String, String>>, List<Triple<String, String, String>>>>, List<Triple<List<String>, List<Triple<String, String, String>>, List<Pair<String, String>>>>> zzz = split(eds0);
    if (inst0.isEmpty()) {
        return new Pair<>(printNicely3(zzz), "");
    }
    Map<String, Set<Pair<Object, Object>>> res = chase(new HashSet<>(), zzz, inst0, kind);
    return new Pair<>(printNicely3(zzz), printNicely(res));
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) FqlTokenizer(catdata.fql.parse.FqlTokenizer) EmbeddedDependency(catdata.fql.sql.EmbeddedDependency) Pair(catdata.Pair)

Example 3 with EmbeddedDependency

use of catdata.fql.sql.EmbeddedDependency in project fql by CategoricalData.

the class Chase method chaseTgd.

private static Map<String, Set<Pair<Object, Object>>> chaseTgd(Map<String, Set<Pair<Object, Object>>> i, List<String> forall, List<Triple<String, String, String>> where, List<Triple<String, String, String>> t) {
    Map<String, Set<Pair<Object, Object>>> ret = new HashMap<>();
    for (String k : i.keySet()) {
        ret.put(k, new HashSet<>());
    }
    EmbeddedDependency xxx0 = conv2(forall, where, t);
    ED xxx = ED.from(xxx0);
    Flower front = xxx.front();
    Flower back = xxx.back();
    Set<Map<Object, Object>> frontX = front.eval(ED.conv(i));
    Set<Map<Object, Object>> backX = back.eval(ED.conv(i));
    if (frontX.equals(backX)) {
        return ret;
    }
    for (Map<Object, Object> eq : frontX) {
        Map<String, String> map = new HashMap<>();
        for (String v : xxx0.exists) {
            String v0 = "_" + (fresh++);
            map.put(v, v0);
        }
        for (Triple<String, String, String> fact : xxx0.tgd) {
            Object a;
            try {
                a = eq.get("c" + getColNo(xxx0.forall, xxx0.where, fact.second));
            } catch (Exception ee) {
                a = map.get(fact.second);
            }
            Object b;
            try {
                b = eq.get("c" + getColNo(xxx0.forall, xxx0.where, fact.third));
            } catch (Exception ee) {
                b = map.get(fact.third);
            }
            ret.get(fact.first).add(new Pair<>(a, b));
        }
    }
    return ret;
}
Also used : Flower(catdata.fql.sql.Flower) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) EmbeddedDependency(catdata.fql.sql.EmbeddedDependency) ED(catdata.fql.sql.ED)

Example 4 with EmbeddedDependency

use of catdata.fql.sql.EmbeddedDependency in project fql by CategoricalData.

the class Chase method obeys.

private static boolean obeys(Map<String, Set<Pair<Object, Object>>> i0, List<Triple<List<String>, List<Triple<String, String, String>>, List<Triple<String, String, String>>>> tgds, List<Triple<List<String>, List<Triple<String, String, String>>, List<Pair<String, String>>>> egds) {
    for (Triple<List<String>, List<Triple<String, String, String>>, List<Pair<String, String>>> egd : egds) {
        EmbeddedDependency xxx0 = conv(egd.first, egd.second, egd.third);
        ED xxx = ED.from(xxx0);
        Flower front = xxx.front();
        Flower back = xxx.back();
        Set<Map<Object, Object>> frontX = front.eval(ED.conv(i0));
        Set<Map<Object, Object>> backX = back.eval(ED.conv(i0));
        if (!frontX.equals(backX)) {
            return false;
        }
    }
    for (Triple<List<String>, List<Triple<String, String, String>>, List<Triple<String, String, String>>> tgd : tgds) {
        EmbeddedDependency xxx0 = conv2(tgd.first, tgd.second, tgd.third);
        ED xxx = ED.from(xxx0);
        Flower front = xxx.front();
        Flower back = xxx.back();
        Set<Map<Object, Object>> frontX = front.eval(ED.conv(i0));
        Set<Map<Object, Object>> backX = back.eval(ED.conv(i0));
        if (!frontX.equals(backX)) {
            return false;
        }
    }
    return true;
}
Also used : Flower(catdata.fql.sql.Flower) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) EmbeddedDependency(catdata.fql.sql.EmbeddedDependency) ED(catdata.fql.sql.ED)

Example 5 with EmbeddedDependency

use of catdata.fql.sql.EmbeddedDependency in project fql by CategoricalData.

the class Chase method sigma.

public static Instance sigma(Mapping m, Instance i) throws FQLException {
    Triple<Pair<Signature, List<Pair<Attribute<Node>, Pair<Edge, Attribute<Node>>>>>, Pair<Signature, List<Pair<Attribute<Node>, Pair<Edge, Attribute<Node>>>>>, Pair<Signature, List<Pair<Attribute<Node>, Pair<Edge, Attribute<Node>>>>>> kkk = m.toEDs();
    Signature cd = kkk.second.first;
    Map<String, Set<Pair<Object, Object>>> I = new HashMap<>();
    for (Node n : cd.nodes) {
        I.put(n.string, new HashSet<>());
    }
    for (Edge n : cd.edges) {
        I.put(n.name, new HashSet<>());
    }
    for (Attribute<Node> n : cd.attrs) {
        I.put(n.name, new HashSet<>());
    }
    for (String k : i.data.keySet()) {
        I.put("src_" + k, i.data.get(k));
    }
    List<EmbeddedDependency> eds0 = Signature.toED("", kkk.second);
    Pair<List<Triple<List<String>, List<Triple<String, String, String>>, List<Triple<String, String, String>>>>, List<Triple<List<String>, List<Triple<String, String, String>>, List<Pair<String, String>>>>> zzz = split(eds0);
    Set<String> keys = new HashSet<>();
    for (Node n : m.target.nodes) {
        keys.add("dst_" + n.string);
    }
    for (Edge n : m.target.edges) {
        keys.add("dst_" + n.name);
    }
    for (Attribute<Node> n : m.target.attrs) {
        keys.add("dst_" + n.name);
    }
    Map<String, Set<Pair<Object, Object>>> res = chase(keys, zzz, I, KIND.PARALLEL);
    Map<String, Set<Pair<Object, Object>>> res0 = new HashMap<>();
    for (Node n : m.target.nodes) {
        res0.put(n.string, res.get("dst_" + n.string));
    }
    for (Edge n : m.target.edges) {
        res0.put(n.name, res.get("dst_" + n.name));
    }
    for (Attribute<Node> n : m.target.attrs) {
        res0.put(n.name, res.get("dst_" + n.name));
    }
    Instance ret = new Instance(m.target, res0);
    return ret;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Attribute(catdata.fql.decl.Attribute) HashMap(java.util.HashMap) Instance(catdata.fql.decl.Instance) Node(catdata.fql.decl.Node) Signature(catdata.fql.decl.Signature) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Edge(catdata.fql.decl.Edge) EmbeddedDependency(catdata.fql.sql.EmbeddedDependency) Pair(catdata.Pair) HashSet(java.util.HashSet)

Aggregations

EmbeddedDependency (catdata.fql.sql.EmbeddedDependency)10 LinkedList (java.util.LinkedList)7 Pair (catdata.Pair)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 List (java.util.List)5 HashSet (java.util.HashSet)4 Set (java.util.Set)4 ED (catdata.fql.sql.ED)3 Flower (catdata.fql.sql.Flower)3 Map (java.util.Map)3 Triple (catdata.Triple)2 Attribute (catdata.fql.decl.Attribute)2 Edge (catdata.fql.decl.Edge)2 Instance (catdata.fql.decl.Instance)2 Node (catdata.fql.decl.Node)2 Signature (catdata.fql.decl.Signature)2 Paint (java.awt.Paint)2 FqlTokenizer (catdata.fql.parse.FqlTokenizer)1 Font (java.awt.Font)1