use of catdata.fql.decl.Instance in project fql by CategoricalData.
the class LeftKanCat method toCategory.
public static Pair<FinCat<Node, Path>, Fn<Path, Arr<Node, Path>>> toCategory(Signature sig) throws FQLException {
Signature A = sig.onlyObjects();
Instance X = A.terminal(null);
Mapping F = subset(A, sig);
LeftKan lk = new LeftKan(0, F, X);
if (!lk.compute()) {
throw new FQLException("Category computation has exceeded allowed iterations.");
}
return helper(lk, sig);
}
use of catdata.fql.decl.Instance 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;
}
use of catdata.fql.decl.Instance 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.decl.Instance in project fql by CategoricalData.
the class PSMNot method calcSub.
private Instance calcSub(Signature sig0, Triple<Instance, Map<Object, Path>, Map<Path, Object>> Hc, Instance A) throws FQLException {
Map<String, Set<Pair<Object, Object>>> notA_data = new HashMap<>();
for (Node d : sig.nodes) {
Set<Pair<Object, Object>> dd = new HashSet<>();
xxx: for (Object f : Hc.first.getNode(d)) {
Path ff = Hc.second.get(f);
// boolean b = true;
for (Node d0 : sig.nodes) {
for (Arr<Node, Path> g : sig.toCategory2().first.hom(d, d0)) {
Arr<Node, Path> fg = sig.toCategory2().first.compose(sig.toCategory2().second.of(ff), g);
Object xxx = Hc.third.get(fg.arr);
if (xxx == null) {
throw new RuntimeException();
}
if (A.getNode(d0).contains(xxx)) {
continue xxx;
}
}
}
dd.add(new Pair<>(f, f));
}
notA_data.put(d.string, dd);
}
for (Edge h : sig.edges) {
Set<Pair<Object, Object>> dd = new HashSet<>();
for (Pair<Object, Object> oo : notA_data.get(h.source.string)) {
Object f = oo.first;
Path ff = Hc.second.get(f);
Arr<Node, Path> fg = sig.toCategory2().first.compose(sig.toCategory2().second.of(ff), sig.toCategory2().second.of(new Path(sig, h)));
Object xxx = Hc.third.get(fg.arr);
dd.add(new Pair<>(f, xxx));
}
notA_data.put(h.name, dd);
}
Instance notA = new Instance(sig0, notA_data);
return notA;
}
use of catdata.fql.decl.Instance in project fql by CategoricalData.
the class PropPSM method exec.
@Override
public void exec(PSMInterp interp, Map<String, Set<Map<Object, Object>>> state) {
try {
IntRef ref = new IntRef(interp.guid);
Signature sigX = new Signature(sig.nodes, sig.edges, new LinkedList<>(), sig.eqs);
Map<Node, List<Pair<Arr<Node, Path>, Attribute<Node>>>> obs = sig.obs();
Pair<FinCat<Node, Path>, Fn<Path, Arr<Node, Path>>> ooo = sig.toCategory2();
Fn<Path, Arr<Node, Path>> fn = ooo.second;
Pair<Pair<Map<Node, Triple<Instance, Map<Object, Path>, Map<Path, Object>>>, Map<Edge, Transform>>, Pair<Instance, Map<Node, Pair<Map<Object, Instance>, Map<Instance, Object>>>>> xxx = sigX.omega(ref);
interp.prop1.put(pre, xxx.first);
interp.prop2.put(pre, xxx.second);
Instance old = xxx.second.first;
Map<Node, List<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>> m = sig.obsbar();
Map<String, Set<Pair<Object, Object>>> data = new HashMap<>();
Map<Node, Map<Object, Pair<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>>> m1 = new HashMap<>();
Map<Node, Map<Pair<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>, Object>> m2 = new HashMap<>();
for (Node n : sig.nodes) {
Map<Object, Pair<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>> map1 = new HashMap<>();
Map<Pair<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>, Object> map2 = new HashMap<>();
Set<Pair<Object, Object>> set = new HashSet<>();
m1.put(n, map1);
m2.put(n, map2);
for (Pair<Object, Object> i1 : old.data.get(n.string)) {
for (LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> i2 : m.get(n)) {
Object o = Integer.toString(++ref.i);
map1.put(o, new Pair<>(i1.first, i2));
map2.put(new Pair<>(i1.first, i2), o);
set.add(new Pair<>(o, o));
}
}
data.put(n.string, set);
}
for (Attribute<Node> a : sig.attrs) {
Set<Pair<Object, Object>> set = new HashSet<>();
for (Pair<Object, Object> k : data.get(a.source.string)) {
Pair<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>> kk = m1.get(a.source).get(k.first);
// Object old_id = kk.first;
LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> new_id = kk.second;
set.add(new Pair<>(k.first, new_id.get(new Pair<>(new Arr<>(new Path(sig, a.source), a.source, a.source), a))));
}
data.put(a.name, set);
}
for (Edge a : sig.edges) {
Set<Pair<Object, Object>> set = new HashSet<>();
for (Pair<Object, Object> k : data.get(a.source.string)) {
Pair<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>> kk = m1.get(a.source).get(k.first);
Object old_id = kk.first;
Object old_id0 = lookup(old.data.get(a.name), old_id);
LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> new_id = kk.second;
LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> new_id0 = truncate2(sig, new_id, fn.of(new Path(sig, a)), obs.get(a.target));
Object o = m2.get(a.target).get(new Pair<>(old_id0, new_id0));
set.add(new Pair<>(k.first, o));
}
data.put(a.name, set);
}
interp.prop3.put(pre, m1);
interp.prop4.put(pre, m2);
Instance ne = new Instance(sig, data);
PSMGen.shred(pre, ne, state);
interp.guid = ref.i;
} catch (FQLException fe) {
fe.printStackTrace();
throw new RuntimeException(fe.getMessage());
}
}
Aggregations