use of catdata.Triple in project fql by CategoricalData.
the class FqlppDisplay method build2Elements.
@SuppressWarnings("unchecked")
private static Graph build2Elements(Signature<Object, Object> sig, Transform<Object, Object, Set, Fn> trans) {
Functor<Object, Object, Set, Fn> I = trans.source;
Functor<Object, Object, Set, Fn> J = trans.target;
Graph<Object, Object> ret = new DirectedSparseMultigraph<>();
for (Node n : sig.nodes) {
for (Object o : I.applyO(n)) {
ret.addVertex(new Triple<>(o, n.name, "src"));
}
}
for (Edge e : sig.edges) {
for (Object o : I.applyO(e.source)) {
Object fo = I.applyA(sig.path(e)).apply(o);
Triple s = new Triple<>(o, e.source.name, "src");
Triple t = new Triple<>(fo, e.target.name, "dst");
ret.addEdge(new Quad<>(e.name, s, t, "src"), s, t);
}
}
for (Node n : sig.nodes) {
for (Object o : J.applyO(n)) {
ret.addVertex(new Triple<>(o, n.name, "dst"));
}
}
for (Edge e : sig.edges) {
for (Object o : J.applyO(e.source)) {
Object fo = J.applyA(sig.path(e)).apply(o);
Triple s = new Triple<>(o, e.source.name, "dst");
Triple t = new Triple<>(fo, e.target.name, "dst");
ret.addEdge(new Quad<>(e.name, s, t, "dst"), s, t);
}
}
int i = 0;
for (Node n : sig.nodes) {
for (Object o : I.applyO(n)) {
Object fo = trans.apply(n).apply(o);
Triple s = new Triple<>(o, n.name, "src");
Triple t = new Triple<>(fo, n.name, "dst");
ret.addEdge(new Quad<>("", s, t, i++), s, t);
}
}
return ret;
}
use of catdata.Triple 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.Triple in project fql by CategoricalData.
the class PPParser method toCatConst.
public static CatExp.Const toCatConst(Object y) {
Set<String> nodes = new HashSet<>();
Set<Triple<String, String, String>> arrows = new HashSet<>();
Set<Pair<Pair<String, List<String>>, Pair<String, List<String>>>> eqs = new HashSet<>();
Tuple3 s = (Tuple3) y;
Tuple3 nodes0 = (Tuple3) s.a;
Tuple3 arrows0 = (Tuple3) s.b;
Tuple3 eqs0 = (Tuple3) s.c;
List nodes1 = (List) nodes0.b;
List arrows1 = (List) arrows0.b;
List eqs1 = (List) eqs0.b;
for (Object o : nodes1) {
nodes.add((String) o);
}
for (Object o : arrows1) {
Tuple5 x = (Tuple5) o;
arrows.add(new Triple<>((String) x.a, (String) x.c, (String) x.e));
}
for (Object o : eqs1) {
Tuple3 x = (Tuple3) o;
List<String> l1 = (List<String>) x.a;
List<String> l2 = (List<String>) x.c;
String xxx = l1.remove(0);
String yyy = l2.remove(0);
eqs.add(new Pair<>(new Pair<>(xxx, l1), new Pair<>(yyy, l2)));
}
CatExp.Const c = new CatExp.Const(nodes, arrows, eqs);
return c;
}
use of catdata.Triple in project fql by CategoricalData.
the class PreProcessor method visit.
@Override
public CatExp visit(FQLPPProgram env, Union e) {
CatExp l = e.l.accept(env, this);
CatExp r = e.r.accept(env, this);
CatExp lx = CatOps.resolve(env, l);
CatExp rx = CatOps.resolve(env, r);
if (!(lx instanceof Const)) {
throw new RuntimeException("Not a const: " + lx);
}
if (!(rx instanceof Const)) {
throw new RuntimeException("Not a const: " + rx);
}
Const ly = (Const) lx;
Const ry = (Const) rx;
Set<Pair<Pair<String, List<String>>, Pair<String, List<String>>>> eqs = new HashSet<>();
Set<Triple<String, String, String>> arrows = new HashSet<>();
Set<String> nodes = new HashSet<>();
nodes.addAll(ly.nodes);
nodes.addAll(ry.nodes);
arrows.addAll(ly.arrows);
arrows.addAll(ry.arrows);
eqs.addAll(ly.eqs);
eqs.addAll(ry.eqs);
return new Const(nodes, arrows, eqs);
}
use of catdata.Triple in project fql by CategoricalData.
the class CatOps method toMapping.
private Triple<Category, Category, Mapping<String, String, String, String>> toMapping(FQLPPProgram env, MapConst ic) {
CatExp src0 = resolve(env, ic.src);
if (src0 == null) {
throw new RuntimeException("Missing category: " + ic.src);
}
if (!(src0 instanceof Const)) {
throw new RuntimeException("Can only create mappings for finitely-presented categories.");
}
Const src = (Const) src0;
CatExp dst0 = resolve(env, ic.dst);
if (!(dst0 instanceof Const)) {
throw new RuntimeException("Can only create mappings for finitely-presented categories.");
}
Const dst = (Const) dst0;
Category srcX = src.accept(env, this);
Category dstX = dst.accept(env, this);
Signature<String, String> srcY = new Signature<>(src.nodes, src.arrows, src.eqs);
Signature<String, String> dstY = new Signature<>(dst.nodes, dst.arrows, dst.eqs);
Map<Node, Node> nm = new HashMap<>();
for (String n0 : ic.nm.keySet()) {
Signature<String, String>.Node n = srcY.getNode(n0);
String v = ic.nm.get(n.name);
if (v == null) {
throw new RuntimeException("Missing object mapping for " + n.name);
}
nm.put(n, dstY.getNode(v));
}
Map<Edge, Path> em = new HashMap<>();
for (String n0 : ic.em.keySet()) {
Signature<String, String>.Edge n = srcY.getEdge(n0);
Pair<String, List<String>> k = ic.em.get(n.name);
if (k == null) {
throw new RuntimeException("Missing arrow mapping for " + n.name);
}
em.put(n, dstY.path(k.first, k.second));
}
Mapping<String, String, String, String> I = new Mapping(nm, em, srcY, dstY);
return new Triple<>(srcX, dstX, I);
}
Aggregations