use of catdata.fql.FQLException in project fql by CategoricalData.
the class PSMGen method findEquiv.
private static Path findEquiv(Node c, Mapping f, Edge e) throws FQLException {
Signature C = f.source;
Signature D = f.target;
FinCat<Node, Path> C0 = C.toCategory2().first;
for (Arr<Node, Path> peqc : C0.arrows) {
Path path = peqc.arr;
// Path path = new Path(f.source, p);
if (!path.source.equals(c)) {
continue;
}
Path path_f = f.appy(D, path);
Fn<Path, Arr<Node, Path>> F = D.toCategory2().second;
if (F.of(path_f).equals(F.of(new Path(D, e)))) {
return path;
}
}
throw new FQLException("Could not find path mapping to " + e);
}
use of catdata.fql.FQLException in project fql by CategoricalData.
the class PSMGen method sigma.
public static List<PSM> sigma(Mapping F, String pre, String inst) throws FQLException {
Signature C = F.source;
Signature D = F.target;
List<PSM> ret = new LinkedList<>();
if (!FinFunctor.isDiscreteOpFib(F.toFunctor2().first)) {
throw new FQLException("Not a discrete op-fibration");
}
for (Node d : D.nodes) {
List<Flower> tn = new LinkedList<>();
for (Node c : C.nodes) {
if (F.nm.get(c).equals(d)) {
tn.add(new CopyFlower(inst + "_" + c.string, "c0", "c1"));
}
}
if (tn.isEmpty()) {
continue;
}
SQL y = foldUnion(tn);
ret.add(new InsertSQL(pre + "_" + d.string, y, "c0", "c1"));
}
for (Edge e : D.edges) {
Node d = e.source;
// Node d0 = e.target;
List<Flower> tn = new LinkedList<>();
for (Node c : C.nodes) {
if (F.nm.get(c).equals(d)) {
Path pc = findEquiv(c, F, e);
Flower q = compose(inst, pc);
tn.add(q);
}
}
if (tn.isEmpty()) {
continue;
}
SQL y = foldUnion(tn);
ret.add(new InsertSQL(pre + "_" + e.name, y, "c0", "c1"));
}
for (Attribute<Node> a : D.attrs) {
Node d = a.source;
// Node d0 = e.target;
List<Flower> tn = new LinkedList<>();
for (Node c : C.nodes) {
if (F.nm.get(c).equals(d)) {
Attribute<Node> pc = findEquiv(c, F, a);
Flower q = new CopyFlower(inst + "_" + pc.name, "c0", "c1");
tn.add(q);
}
}
if (tn.isEmpty()) {
continue;
}
SQL y = foldUnion(tn);
ret.add(new InsertSQL(pre + "_" + a.name, y, "c0", "c1"));
}
return ret;
}
use of catdata.fql.FQLException in project fql by CategoricalData.
the class PSMIso method exec.
@Override
public void exec(PSMInterp interp, Map<String, Set<Map<Object, Object>>> state) {
// throw new RuntimeException("Iso finder is not working right now");
try {
Instance li = new Instance(sig, PSMGen.gather(l, sig, state));
Instance ri = new Instance(sig, PSMGen.gather(r, sig, state));
Pair<Transform, Transform> k = Inst.iso(li, ri);
if (k == null) {
throw new RuntimeException("Cannot find iso between " + l + " and " + r);
}
if (lToR) {
PSMGen.shred(pre, k.first, state);
} else {
PSMGen.shred(pre, k.second, state);
}
} catch (FQLException fe) {
fe.printStackTrace();
throw new RuntimeException(fe.getMessage());
}
}
use of catdata.fql.FQLException in project fql by CategoricalData.
the class PSMNot method exec.
@Override
public void exec(PSMInterp interp, Map<String, Set<Map<Object, Object>>> state) {
try {
Signature sig0 = new Signature(sig.nodes, sig.edges, new LinkedList<>(), sig.eqs);
Pair<Map<Node, Triple<Instance, Map<Object, Path>, Map<Path, Object>>>, Map<Edge, Transform>> H1 = interp.prop1.get(prop);
Pair<Instance, Map<Node, Pair<Map<Object, Instance>, Map<Instance, Object>>>> H2 = interp.prop2.get(prop);
Instance prp = new Instance(sig, PSMGen.gather(prop, sig, state));
Map<Node, Map<Object, Pair<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>>> I1 = interp.prop3.get(prop);
Map<Node, Map<Pair<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>, Object>> I2 = interp.prop4.get(prop);
List<Pair<String, List<Pair<Object, Object>>>> data = new LinkedList<>();
for (Node c : sig.nodes) {
List<Pair<Object, Object>> data0 = new LinkedList<>();
Triple<Instance, Map<Object, Path>, Map<Path, Object>> Hc = H1.first.get(c);
for (Object id : prp.getNode(c)) {
Pair<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>> id0 = I1.get(c).get(id);
Instance A = H2.second.get(c).first.get(id0.first);
Instance notA = calcSub(sig0, /*H1, */
Hc, A);
Object notId = H2.second.get(c).second.get(notA);
Object x = I2.get(c).get(new Pair<>(notId, id0.second));
data0.add(new Pair<>(id, x));
}
data.add(new Pair<>(c.string, data0));
}
Transform ret = new Transform(prp, prp, data);
PSMGen.shred(pre, ret, state);
} catch (FQLException fe) {
fe.printStackTrace();
throw new RuntimeException(fe.getMessage());
}
}
use of catdata.fql.FQLException in project fql by CategoricalData.
the class PSMUnChi method exec.
@Override
public void exec(PSMInterp interp, Map<String, Set<Map<Object, Object>>> state) {
try {
Map<Object, Object> m1 = new HashMap<>();
Map<Object, Object> m2 = new HashMap<>();
Instance B = new Instance(sig, PSMGen.gather(b, sig, state));
Instance P = new Instance(sig, PSMGen.gather(prop, sig, state));
// Instance P = interp.prop2.get(prop).first;
Transform F = new Transform(B, P, PSMGen.gather(f, sig, state));
Map<String, Set<Pair<Object, Object>>> data = new HashMap<>();
List<Pair<String, List<Pair<Object, Object>>>> data2 = new LinkedList<>();
for (Node d : sig.nodes) {
Instance tofind = interp.prop1.get(prop).first.get(d).first;
Object found = interp.prop2.get(prop).second.get(d).second.get(tofind);
Set<Pair<Object, Object>> dta = new HashSet<>();
List<Pair<Object, Object>> dta2 = new LinkedList<>();
for (Pair<Object, Object> k : B.data.get(d.string)) {
Object v = lookup(F.data.get(d.string), k.first);
Pair<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>> vv = interp.prop3.get(prop).get(d).get(v);
if (vv.first.equals(found)) {
Object u = Integer.toString(++interp.guid);
m1.put(u, k.first);
m2.put(k.first, u);
dta.add(new Pair<>(u, u));
dta2.add(new Pair<>(u, k.first));
}
}
data.put(d.string, dta);
data2.add(new Pair<>(d.string, dta2));
}
for (Edge e : sig.edges) {
Set<Pair<Object, Object>> dta = new HashSet<>();
for (Pair<Object, Object> k : data.get(e.source.string)) {
Object v = m1.get(k.first);
Object vx = lookup(B.data.get(e.name), v);
Object vz = m2.get(vx);
dta.add(new Pair<>(k.first, vz));
}
data.put(e.name, dta);
}
for (Attribute<Node> e : sig.attrs) {
Set<Pair<Object, Object>> dta = new HashSet<>();
for (Pair<Object, Object> k : data.get(e.source.string)) {
Object v = m1.get(k.first);
Object vx = lookup(B.data.get(e.name), v);
dta.add(new Pair<>(k.first, vx));
}
data.put(e.name, dta);
}
Instance A = new Instance(sig, data);
Transform T = new Transform(A, B, data2);
PSMGen.shred(pre, A, state);
PSMGen.shred(pre + "_trans", T, state);
} catch (FQLException fe) {
fe.printStackTrace();
throw new RuntimeException(fe.getMessage());
}
}
Aggregations