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);
}
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;
}
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();
}
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;
}
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;
}
Aggregations