Search in sources :

Example 6 with EmbeddedDependency

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

the class Chase method split.

private static 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>>>>> split(List<EmbeddedDependency> l) {
    List<Triple<List<String>, List<Triple<String, String, String>>, List<Triple<String, String, String>>>> ret1 = new LinkedList<>();
    List<Triple<List<String>, List<Triple<String, String, String>>, List<Pair<String, String>>>> ret2 = new LinkedList<>();
    for (EmbeddedDependency e : l) {
        Triple<List<String>, List<Triple<String, String, String>>, List<Triple<String, String, String>>> s = new Triple<>(e.forall, e.where, e.tgd);
        Triple<List<String>, List<Triple<String, String, String>>, List<Pair<String, String>>> t = new Triple<>(e.forall, e.where, e.egd);
        if (!s.third.isEmpty()) {
            ret1.add(s);
        }
        if (!t.third.isEmpty()) {
            ret2.add(t);
        }
    }
    return new Pair<>(ret1, ret2);
}
Also used : Triple(catdata.Triple) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) LinkedList(java.util.LinkedList) EmbeddedDependency(catdata.fql.sql.EmbeddedDependency) Pair(catdata.Pair)

Example 7 with EmbeddedDependency

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

the class Chase method delta.

public static Instance delta(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 = m.toEDs().first.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("dst_" + k, i.data.get(k));
    }
    List<EmbeddedDependency> eds0 = Signature.toED("", kkk.first);
    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("src_" + n.string);
    }
    for (Edge n : m.target.edges) {
        keys.add("src_" + n.name);
    }
    for (Attribute<Node> n : m.target.attrs) {
        keys.add("src_" + n.name);
    }
    // changed
    Map<String, Set<Pair<Object, Object>>> res = chase(keys, zzz, I, KIND.HYBRID);
    Map<String, Set<Pair<Object, Object>>> res0 = new HashMap<>();
    for (Node n : m.source.nodes) {
        res0.put(n.string, res.get("src_" + n.string));
    }
    for (Edge n : m.source.edges) {
        res0.put(n.name, res.get("src_" + n.name));
    }
    for (Attribute<Node> n : m.source.attrs) {
        res0.put(n.name, res.get("src_" + n.name));
    }
    Instance ret = new Instance(m.source, 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)

Example 8 with EmbeddedDependency

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

the class Mapping method quickConv.

private static String quickConv(List<EmbeddedDependency> ed) {
    String ret = "";
    for (EmbeddedDependency d : ed) {
        ret += d.toString();
        ret += "\n\n";
    }
    return ret.trim();
}
Also used : EmbeddedDependency(catdata.fql.sql.EmbeddedDependency)

Example 9 with EmbeddedDependency

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

the class Signature method constraint.

public JPanel constraint() {
    List<EmbeddedDependency> l = toED("");
    JPanel ret = new JPanel(new GridLayout(1, 1));
    ret.setBorder(BorderFactory.createEtchedBorder());
    String s = "";
    int i = 0;
    for (EmbeddedDependency d : l) {
        if (i++ > 0) {
            s += "\n\n";
        }
        s += d.toString();
    }
    JTextArea area = new JTextArea(s);
    area.setFont(new Font("Courier", Font.PLAIN, 13));
    JScrollPane jsp = new JScrollPane(area);
    area.setWrapStyleWord(true);
    area.setLineWrap(true);
    jsp.setBorder(BorderFactory.createEmptyBorder());
    ret.add(jsp);
    return ret;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GridLayout(java.awt.GridLayout) JTextArea(javax.swing.JTextArea) EmbeddedDependency(catdata.fql.sql.EmbeddedDependency) Paint(java.awt.Paint) Font(java.awt.Font)

Example 10 with EmbeddedDependency

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

the class Signature method toED.

public static List<EmbeddedDependency> toED(String pre, Pair<Signature, List<Pair<Attribute<Node>, Pair<Edge, Attribute<Node>>>>> xxx) {
    Signature sig = xxx.first;
    // public List<EmbeddedDependency> toED(String pre) {
    List<EmbeddedDependency> ret = new LinkedList<>();
    int v = 0;
    for (Node n : sig.nodes) {
        List<String> forall = new LinkedList<>();
        List<String> exists = new LinkedList<>();
        List<Triple<String, String, String>> where = new LinkedList<>();
        List<Triple<String, String, String>> tgd = new LinkedList<>();
        List<Pair<String, String>> egd = new LinkedList<>();
        // List<Triple<String, String, String>> not = new LinkedList<>();
        String u = "v" + (v++);
        String w = "v" + (v++);
        forall.add(u);
        forall.add(w);
        where.add(new Triple<>(pre + n.string, u, w));
        egd.add(new Pair<>(u, w));
        EmbeddedDependency ed = new EmbeddedDependency(forall, exists, where, tgd, egd);
        ret.add(ed);
    }
    for (Edge e : sig.edges) {
        List<String> forall = new LinkedList<>();
        List<String> exists = new LinkedList<>();
        List<Triple<String, String, String>> where = new LinkedList<>();
        List<Triple<String, String, String>> tgd = new LinkedList<>();
        List<Pair<String, String>> egd = new LinkedList<>();
        // List<Triple<String, String, String>> not = new LinkedList<>();
        String u = "v" + (v++);
        String w = "v" + (v++);
        forall.add(u);
        forall.add(w);
        where.add(new Triple<>(pre + e.name, u, w));
        tgd.add(new Triple<>(pre + e.source.string, u, u));
        tgd.add(new Triple<>(pre + e.target.string, w, w));
        EmbeddedDependency ed = new EmbeddedDependency(forall, exists, where, tgd, egd);
        ret.add(ed);
        forall = new LinkedList<>();
        exists = new LinkedList<>();
        where = new LinkedList<>();
        tgd = new LinkedList<>();
        egd = new LinkedList<>();
        // not = new LinkedList<>();
        String x = "v" + (v++);
        forall.add(u);
        forall.add(w);
        forall.add(x);
        where.add(new Triple<>(pre + e.name, u, w));
        where.add(new Triple<>(pre + e.name, u, x));
        egd.add(new Pair<>(w, x));
        ed = new EmbeddedDependency(forall, exists, where, tgd, egd);
        ret.add(ed);
        forall = new LinkedList<>();
        exists = new LinkedList<>();
        where = new LinkedList<>();
        tgd = new LinkedList<>();
        egd = new LinkedList<>();
        // not = new LinkedList<>();
        forall.add(x);
        where.add(new Triple<>(pre + e.source.string, x, x));
        String z = "v" + (v++);
        exists.add(z);
        tgd.add(new Triple<>(pre + e.name, x, z));
        ed = new EmbeddedDependency(forall, exists, where, tgd, egd);
        ret.add(ed);
    }
    for (Attribute<Node> e : sig.attrs) {
        List<String> forall = new LinkedList<>();
        List<String> exists = new LinkedList<>();
        List<Triple<String, String, String>> where = new LinkedList<>();
        List<Triple<String, String, String>> tgd = new LinkedList<>();
        List<Pair<String, String>> egd = new LinkedList<>();
        // List<Triple<String, String, String>> not = new LinkedList<>();
        String u = "v" + (v++);
        String w = "v" + (v++);
        forall.add(u);
        forall.add(w);
        where.add(new Triple<>(pre + e.name, u, w));
        tgd.add(new Triple<>(pre + e.source.string, u, u));
        // tgd.add(new Triple<>(name0 + "." + e.target., w, w));
        EmbeddedDependency ed = new EmbeddedDependency(forall, exists, where, tgd, egd);
        ret.add(ed);
        forall = new LinkedList<>();
        exists = new LinkedList<>();
        where = new LinkedList<>();
        tgd = new LinkedList<>();
        egd = new LinkedList<>();
        // not = new LinkedList<>();
        String x = "v" + (v++);
        forall.add(u);
        forall.add(w);
        forall.add(x);
        where.add(new Triple<>(pre + e.name, u, w));
        where.add(new Triple<>(pre + e.name, u, x));
        egd.add(new Pair<>(w, x));
        ed = new EmbeddedDependency(forall, exists, where, tgd, egd);
        ret.add(ed);
        forall = new LinkedList<>();
        exists = new LinkedList<>();
        where = new LinkedList<>();
        tgd = new LinkedList<>();
        egd = new LinkedList<>();
        // not = new LinkedList<>();
        forall.add(x);
        where.add(new Triple<>(pre + e.source.string, x, x));
        String z = "v" + (v++);
        exists.add(z);
        tgd.add(new Triple<>(pre + e.name, x, z));
        ed = new EmbeddedDependency(forall, exists, where, tgd, egd);
        ret.add(ed);
    }
    for (Eq eq : sig.eqs) {
        // TODO phokion
        ret.add(EmbeddedDependency.eq2(pre, eq.lhs, eq.rhs));
    }
    for (Pair<Attribute<Node>, Pair<Edge, Attribute<Node>>> eq : xxx.second) {
        ret.add(EmbeddedDependency.eq3(pre, eq));
    }
    return ret;
}
Also used : LinkedList(java.util.LinkedList) Paint(java.awt.Paint) Triple(catdata.Triple) EmbeddedDependency(catdata.fql.sql.EmbeddedDependency) Pair(catdata.Pair)

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