use of catdata.Quad in project fql by CategoricalData.
the class FqlppDisplay method doElements2View.
private static JComponent doElements2View(Color clr, Graph<Triple, Quad> sgv) {
Layout<Triple, Quad> layout = new FRLayout<>(sgv);
layout.setSize(new Dimension(600, 400));
VisualizationViewer<Triple, Quad> vv = new VisualizationViewer<>(layout);
DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
gm.setMode(Mode.TRANSFORMING);
vv.setGraphMouse(gm);
gm.setMode(Mode.PICKING);
Color clr1 = clr.brighter().brighter();
Color clr2 = clr.darker().darker();
Function<Triple, Paint> vertexPaint = x -> x.third.equals("src") ? clr1 : clr2;
vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
Function<Triple, String> ttt1 = arg0 -> Util.nice(arg0.first.toString());
vv.getRenderContext().setVertexLabelTransformer(ttt1);
Function<Quad, String> ttt2 = arg0 -> Util.nice(arg0.first.toString());
vv.getRenderContext().setEdgeLabelTransformer(ttt2);
float[] dash = { 1.0f };
Stroke edgeStroke = new BasicStroke(0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 10.0f);
Stroke bs = new BasicStroke();
Function<Quad, Stroke> edgeStrokeTransformer = x -> x.fourth instanceof Integer ? edgeStroke : bs;
vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
GraphZoomScrollPane zzz = new GraphZoomScrollPane(vv);
JPanel ret = new JPanel(new GridLayout(1, 1));
ret.add(zzz);
ret.setBorder(BorderFactory.createEtchedBorder());
return ret;
}
use of catdata.Quad in project fql by CategoricalData.
the class LeftKanSigma method fullSigma.
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <O1, A1, O2, A2> Quad<Functor<O2, A2, Set, Fn>, Transform<O1, A1, Set, Fn>, Transform<O2, A2, Set, Fn>, Map<Object, List<Pair<A2, Object>>>> fullSigma(Functor<O1, A1, O2, A2> F, Functor<O1, A1, Set, Fn> I, Transform<O1, A1, Set, Fn> t, Functor<O2, A2, Set, Fn> JJJ) {
Mapping<O1, A1, O2, A2> G = F.toMapping();
FPTransform<O1, A1> m = null;
if (t != null) {
m = t.toFPTransform();
}
Instance<O2, A2> J = null;
if (JJJ != null) {
J = JJJ.toInstance();
}
Quad<Instance<O2, A2>, Map<Signature<O1, A1>.Node, Map<Object, Object>>, Map<Signature<O2, A2>.Node, Map<Object, Object>>, Map<Object, List<Pair<Signature<O2, A2>.Edge, Object>>>> q = fullSigmaOnPresentation(G, I.toInstance(), m, J, 100);
Functor<Signature<O2, A2>.Node, Signature<O2, A2>.Path, Set, Fn> f2 = q.first.toFunctor();
Functor<O2, A2, Set, Fn> f3 = new Functor<>(F.target, FinSet.FinSet, x -> f2.applyO(G.target.new Node(x)), a -> {
if (F.target.isId(a)) {
return Fn.id(f2.applyO(G.target.new Node(F.target.source(a))));
}
return f2.applyA(G.target.path(G.target.getEdge(a)));
});
// use third
Transform<O2, A2, Set, Fn> thr = null;
if (t != null) {
if (JJJ == null) {
throw new RuntimeException("Left kan sigma anomaly, please report");
}
thr = new Transform<>(f3, JJJ, x -> new Fn(f3.applyO(x), JJJ.applyO(x), q.third.get(G.target.new Node(x))::get));
}
Transform<O1, A1, Set, Fn> et = new Transform<>(I, Functor.compose(F, f3), x -> new Fn(I.applyO(x), Functor.compose(F, f3).applyO(x), q.second.get(G.source.new Node(x))::get));
Map<Object, List<Pair<A2, Object>>> nq = new HashMap<>();
for (Entry<Object, List<Pair<Signature<O2, A2>.Edge, Object>>> o : q.fourth.entrySet()) {
List<Pair<A2, Object>> rt = new LinkedList<>();
for (int j = 0; j < o.getValue().size(); j++) {
Pair<Signature<O2, A2>.Edge, Object> fst = o.getValue().get(j);
if (fst.first == null) {
// because no guids, have pairs as first
rt.add(new Pair<>(null, ((Pair) fst.second).second));
} else {
//
rt.add(new Pair<>(fst.first.name, fst.second));
}
}
nq.put(o.getKey(), rt);
}
return new Quad<>(f3, et, thr, nq);
}
use of catdata.Quad in project fql by CategoricalData.
the class Pi method lim2.
private static <OA, AA, OB, AB, AC> Set<Map> lim2(Functor<Triple<OA, OB, AC>, Quad<AA, AB, AC, AC>, Set, Fn> I) {
Category<Triple<OA, OB, AC>, Quad<AA, AB, AC, AC>> B = I.source;
if (B.objects().isEmpty()) {
Set<Map> ret = new HashSet<>();
Map m = new HashMap();
m.put(0, new Unit());
ret.add(m);
return ret;
}
Triple<OA, OB, AC>[] cnames = cnames(I.source);
int temp = 0;
List<Pair<Pair<String, String>, Pair<String, String>>> where = new LinkedList<>();
// store objects of B directly
Map<String, Object> from = new HashMap<>();
LinkedHashMap<String, Pair<String, String>> select = new LinkedHashMap<>();
Map<Object, Set<Map<Object, Object>>> state = new HashMap<>();
for (Triple<OA, OB, AC> n : B.objects()) {
from.put("t" + temp, n);
select.put("c" + temp, new Pair<>("t" + temp, "c0"));
temp++;
state.put(n, shred(I.applyO(n)));
}
for (Quad<AA, AB, AC, AC> e : B.arrows()) {
if (B.isId(e)) {
continue;
}
from.put("t" + temp, e);
where.add(new Pair<>(new Pair<>("t" + temp, "c0"), new Pair<>("t" + cnamelkp(cnames, B.source(e)), "c0")));
where.add(new Pair<>(new Pair<>("t" + temp, "c1"), new Pair<>("t" + cnamelkp(cnames, B.target(e)), "c0")));
temp++;
state.put(e, shred(I.applyA(e)));
}
Flower f = new Flower(select, from, where);
Set<Map<Object, Object>> uuu = f.eval(state);
Set<Map> x0 = unshred(B.objects().size(), uuu);
x0 = keygen(x0);
return x0;
}
use of catdata.Quad in project fql by CategoricalData.
the class LeftKanSigma method fullSigmaWithAttrs.
public static Quad<Instance, Map<Node, Map<Object, Integer>>, Map<Node, Map<Integer, Object>>, Map<Object, List<Pair<String, Object>>>> fullSigmaWithAttrs(PSMInterp inter, Mapping f, Instance i, Transform t, Instance JJJ, Integer xxx) throws FQLException {
Mapping F = deAttr(f);
Pair<Instance, Map<Attribute<Node>, Map<Object, Object>>> I = deAttr(inter, i, F.source);
Integer kkk = inter.guid;
Instance JJJ0 = null;
Transform ttt = null;
if (JJJ != null) {
inter.guid = xxx;
Pair<Instance, Map<Attribute<Node>, Map<Object, Object>>> JJJ0X = deAttr(inter, JJJ, F.target);
Pair<Instance, Map<Attribute<Node>, Map<Object, Object>>> qqq = delta(f, F, JJJ0X);
ttt = deAttr(f.source, I, qqq, t);
JJJ0 = JJJ0X.first;
inter.guid = kkk;
}
// System.out.println("!!!!!!!!!!!!!!!");
LeftKan D = new LeftKan(inter.guid, F, I.first, ttt, JJJ0);
Pair<Instance, Map<Object, List<Pair<String, Object>>>> hhh = sigma(D);
inter.guid = D.fresh;
Map<Node, Map<Object, Integer>> etables = makeE(D.ua);
Instance j = hhh.first;
Instance ret = reAttr(etables, f.target, j, I.second);
return new Quad<>(ret, etables, D.utables, hhh.second);
}
use of catdata.Quad in project fql by CategoricalData.
the class InstOps method visit.
@Override
public Pair<List<PSM>, Object> visit(String dst, Plus e) {
SigExp k = e.type(prog);
Signature s = k.toSig(prog);
List<PSM> ret = new LinkedList<>();
for (Node n : s.nodes) {
List<Flower> l = new LinkedList<>();
l.add(new CopyFlower(e.a + "_" + n.string, "c0", "c1"));
l.add(new CopyFlower(e.b + "_" + n.string, "c0", "c1"));
ret.add(new InsertSQL(dst + "_" + n.string, new Union(l), "c0", "c1"));
}
for (Attribute<Node> n : s.attrs) {
List<Flower> l = new LinkedList<>();
l.add(new CopyFlower(e.a + "_" + n.name, "c0", "c1"));
l.add(new CopyFlower(e.b + "_" + n.name, "c0", "c1"));
ret.add(new InsertSQL(dst + "_" + n.name, new Union(l), "c0", "c1"));
}
for (Edge n : s.edges) {
List<Flower> l = new LinkedList<>();
l.add(new CopyFlower(e.a + "_" + n.name, "c0", "c1"));
l.add(new CopyFlower(e.b + "_" + n.name, "c0", "c1"));
ret.add(new InsertSQL(dst + "_" + n.name, new Union(l), "c0", "c1"));
}
ret.addAll(PSMGen.guidify(dst, s, true));
ret.addAll(PSMGen.makeTables(dst + "_inl", s, false));
ret.addAll(PSMGen.makeTables(dst + "_inr", s, false));
for (Node n : s.nodes) {
SQL f = PSMGen.compose(e.a + "_" + n.string, dst + "_" + n.string + "_subst");
ret.add(new InsertSQL(dst + "_inl_" + n.string, f, "c0", "c1"));
SQL f0 = PSMGen.compose(e.b + "_" + n.string, dst + "_" + n.string + "_subst");
ret.add(new InsertSQL(dst + "_inr_" + n.string, f0, "c0", "c1"));
}
// (f+g) : A+B -> C f : A -> C g : B -> C
Fn<Quad<String, String, String, String>, List<PSM>> fn = x -> {
// e.a -> x.third
String f = x.first;
// e.b -> x.third
String g = x.second;
// String C = x.third;
String dst0 = x.fourth;
// must be a map dst -> x.third
List<PSM> ret1 = new LinkedList<>();
for (Node n : s.nodes) {
Flower sql1 = PSMGen.compose(dst + "_" + n.string + "_subst_inv", f + "_" + n.string);
Flower sql2 = PSMGen.compose(dst + "_" + n.string + "_subst_inv", g + "_" + n.string);
List<Flower> flowers = new LinkedList<>();
flowers.add(sql1);
flowers.add(sql2);
ret1.add(new InsertSQL(dst0 + "_" + n.string, new Union(flowers), "c0", "c1"));
}
return ret1;
};
return new Pair<>(ret, fn);
}
Aggregations