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