use of catdata.fql.decl.Instance 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.decl.Instance 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.decl.Instance 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());
}
}
use of catdata.fql.decl.Instance in project fql by CategoricalData.
the class ExpPSM method exec.
@Override
public void exec(PSMInterp interp, Map<String, Set<Map<Object, Object>>> state) {
try {
Instance Ix = new Instance(sig, PSMGen.gather(I, sig, state));
Instance Jx = new Instance(sig, PSMGen.gather(J, sig, state));
IntRef idx = new IntRef(interp.guid);
Quad<Instance, Map<Pair<Node, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>, Triple<Instance, Map<Node, Map<Object, Pair<Arr<Node, Path>, Object>>>, Map<Node, Map<Pair<Arr<Node, Path>, Object>, Object>>>>, Map<Node, Map<Object, Pair<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Transform>>>, Map<Node, Map<Pair<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Transform>, Object>>> ret = Instance.exp2(idx, Ix, Jx);
interp.guid = idx.i;
interp.exps2.put(pre, ret);
PSMGen.shred(pre, ret.first, state);
} catch (FQLException fe) {
fe.printStackTrace();
throw new RuntimeException(fe.getLocalizedMessage());
}
}
use of catdata.fql.decl.Instance in project fql by CategoricalData.
the class FullSigma method exec.
@Override
public void exec(PSMInterp interp, Map<String, Set<Map<Object, Object>>> state) {
Signature C = f.source;
Signature D = f.target;
List<Pair<String, List<Pair<Object, Object>>>> I0 = PSMGen.gather(inst, C, state);
try {
Instance I = new Instance(C, I0);
interp.sigmas.put(pre, interp.guid);
Quad<Instance, Map<Node, Map<Object, Integer>>, Map<Node, Map<Integer, Object>>, Map<Object, List<Pair<String, Object>>>> xxx = LeftKanSigma.fullSigmaWithAttrs(interp, f, I, null, null, null);
interp.sigmas2.put(pre, interp.guid);
Instance J = xxx.first;
Map<Node, Map<Object, Integer>> yyy = xxx.second;
for (Node n : C.nodes) {
state.put(pre + "_" + n.string + "_e", conv2(yyy.get(n)));
}
for (Node n : D.nodes) {
state.put(pre + "_" + n.string, conv(J.data.get(n.string)));
}
for (Edge n : D.edges) {
state.put(pre + "_" + n.name, conv(J.data.get(n.name)));
}
for (Attribute<Node> n : D.attrs) {
state.put(pre + "_" + n.name, conv(J.data.get(n.name)));
}
Set<Map<Object, Object>> l = new HashSet<>();
for (Object k : xxx.fourth.keySet()) {
List<Pair<String, Object>> v = xxx.fourth.get(k);
if (v.isEmpty()) {
continue;
}
Map<Object, Object> m = new HashMap<>();
m.put("c0", k);
boolean first = true;
String rest = "";
for (Pair<String, Object> p : v) {
if (first) {
first = false;
m.put("c1", p.first);
m.put("c2", p.second);
} else {
rest += p.first;
}
}
m.put("c3", rest);
l.add(m);
}
state.put(pre + "_lineage", l);
} catch (Throwable e) {
e.printStackTrace();
throw new RuntimeException("Error in instance " + pre + ": " + e.getLocalizedMessage());
}
}
Aggregations