use of catdata.fqlpp.CatExp.Const in project fql by CategoricalData.
the class KBViewer method translate.
private static String translate(String s) {
Object o = PPParser.catConst().from(PPParser.TOKENIZER, PPParser.IGNORED).parse(s);
Const c = PPParser.toCatConst(o);
Signature<String, String> sig = new Signature<>(c.nodes, c.arrows, c.eqs);
List<Pair<List<String>, List<String>>> rules = new LinkedList<>();
for (Signature<String, String>.Eq eq : sig.eqs) {
rules.add(new Pair<>(eq.lhs.path.stream().map(x -> x.name).collect(Collectors.toList()), eq.rhs.path.stream().map(x -> x.name).collect(Collectors.toList())));
}
Thue<String> kb = new Thue<>(rules, 16);
kb.complete();
return kb.toString();
}
use of catdata.fqlpp.CatExp.Const in project fql by CategoricalData.
the class FqlppDisplay method showFtr.
@SuppressWarnings("unchecked")
private JPanel showFtr(Functor view, Color c, @SuppressWarnings("unused") FunctorExp e) {
JTabbedPane px = new JTabbedPane();
if (view.source.isInfinite()) {
CodeTextPanel p = new CodeTextPanel(BorderFactory.createEtchedBorder(), null, "Cannot display functors from " + view.source);
px.add("Text", p);
JPanel top = new JPanel(new GridLayout(1, 1));
top.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
top.add(px);
return top;
}
Signature<String, String> src_sig = null;
Signature<String, String> dst_sig = null;
String src_key = unr(env.cats, view.source, null);
if (src_key != null) {
CatExp r = CatOps.resolve(prog, prog.cats.get(src_key));
if (r instanceof Const) {
Const sig0 = (Const) r;
src_sig = new Signature<>(sig0.nodes, sig0.arrows, sig0.eqs);
}
}
String dst_key = unr(env.cats, view.target, null);
if (dst_key != null) {
CatExp r = CatOps.resolve(prog, prog.cats.get(dst_key));
if (r instanceof Const) {
Const sig0 = (Const) r;
dst_sig = new Signature<>(sig0.nodes, sig0.arrows, sig0.eqs);
}
}
if (src_sig != null && FinSet.FinSet.equals(view.target)) {
if (DefunctGlobalOptions.debug.fqlpp.ftr_instance) {
JPanel vwr = new JPanel(new GridLayout(1, 1));
if (view.source.objects().isEmpty()) {
px.add("Instance", vwr);
} else {
JComponent zzz = doFNView2(view, vwr, c, buildFromSig(src_sig), src_sig);
JSplitPane newthing = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
newthing.setResizeWeight(.5d);
newthing.add(zzz);
newthing.add(vwr);
JPanel xxx = new JPanel(new GridLayout(1, 1));
xxx.add(newthing);
px.add("Instance", xxx);
}
}
if (DefunctGlobalOptions.debug.fqlpp.ftr_joined) {
// cast needed for javac for some reason
px.add("Joined", (Component) makeJoined(src_sig, view).first);
}
if (DefunctGlobalOptions.debug.fqlpp.ftr_elements) {
Graph g = buildElements(src_sig, view);
if (g.getVertexCount() == 0) {
px.add("Elements", new JPanel());
} else if (g.getVertexCount() > DefunctGlobalOptions.debug.fqlpp.MAX_NODES) {
CodeTextPanel xxx = new CodeTextPanel(BorderFactory.createEtchedBorder(), "", "Graph has " + g.getVertexCount() + " nodes, which exceeds limit of " + DefunctGlobalOptions.debug.fqlpp.MAX_NODES);
px.add("Elements", xxx);
} else if (g.getEdgeCount() > DefunctGlobalOptions.debug.fqlpp.MAX_EDGES) {
CodeTextPanel xxx = new CodeTextPanel(BorderFactory.createEtchedBorder(), "", "Graph has " + g.getEdgeCount() + " edges, which exceeds limit of " + DefunctGlobalOptions.debug.fqlpp.MAX_EDGES);
px.add("Elements", xxx);
} else {
px.add("Elements", doElementsView(c, g));
}
}
}
if (src_sig != null && dst_sig != null && !view.source.isInfinite() && !view.target.isInfinite()) {
// JPanel vwr = new JPanel(new GridLayout(1, 1));
if (DefunctGlobalOptions.debug.fqlpp.ftr_mapping) {
Graph g = buildMapping(src_sig, dst_sig, view);
if (g.getVertexCount() == 0) {
px.add("Mapping", new JPanel());
} else if (g.getVertexCount() > DefunctGlobalOptions.debug.fqlpp.MAX_NODES) {
CodeTextPanel xxx = new CodeTextPanel(BorderFactory.createEtchedBorder(), "", "Graph has " + g.getVertexCount() + " nodes, which exceeds limit of " + DefunctGlobalOptions.debug.fqlpp.MAX_NODES);
px.add("Mapping", xxx);
} else if (g.getEdgeCount() > DefunctGlobalOptions.debug.fqlpp.MAX_EDGES) {
CodeTextPanel xxx = new CodeTextPanel(BorderFactory.createEtchedBorder(), "", "Graph has " + g.getEdgeCount() + " edges, which exceeds limit of " + DefunctGlobalOptions.debug.fqlpp.MAX_EDGES);
px.add("Mapping", xxx);
} else {
JComponent zzz = doMappingView(c, getColor(view.target), g);
JPanel xxx = new JPanel(new GridLayout(1, 1));
xxx.add(zzz);
px.add("Mapping", xxx);
}
}
}
if (DefunctGlobalOptions.debug.fqlpp.ftr_graph) {
JPanel vwr = new JPanel(new GridLayout(1, 1));
Graph g = buildFromCat(view.source);
if (view.source.objects().isEmpty()) {
px.add("Graph", vwr);
} else if (g.getVertexCount() > DefunctGlobalOptions.debug.fqlpp.MAX_NODES) {
CodeTextPanel xxx = new CodeTextPanel(BorderFactory.createEtchedBorder(), "", "Graph has " + g.getVertexCount() + " nodes, which exceeds limit of " + DefunctGlobalOptions.debug.fqlpp.MAX_NODES);
px.add("Graph", xxx);
} else if (g.getEdgeCount() > DefunctGlobalOptions.debug.fqlpp.MAX_EDGES) {
CodeTextPanel xxx = new CodeTextPanel(BorderFactory.createEtchedBorder(), "", "Graph has " + g.getEdgeCount() + " edges, which exceeds limit of " + DefunctGlobalOptions.debug.fqlpp.MAX_EDGES);
px.add("Graph", xxx);
} else {
JComponent zzz = doFNView(view, vwr, c, g);
JSplitPane newthing = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
newthing.setResizeWeight(.5d);
newthing.add(zzz);
newthing.add(vwr);
JPanel xxx = new JPanel(new GridLayout(1, 1));
xxx.add(newthing);
px.add("Graph", xxx);
}
}
if (DefunctGlobalOptions.debug.fqlpp.ftr_tabular) {
List<JComponent> gp = new LinkedList<>();
// JPanel gp = new JPanel(new GridLayout(2, 1));
Object[][] rowData = new Object[view.source.objects().size()][2];
int i = 0;
for (Object o : view.source.objects()) {
rowData[i][0] = Util.nice(o.toString());
rowData[i][1] = Util.nice(view.applyO(o).toString());
i++;
}
Object[] colNames = new Object[] { "Input", "Output" };
JPanel gp1 = GuiUtil.makeTable(BorderFactory.createEtchedBorder(), "On Objects (" + view.source.objects().size() + ")", rowData, colNames);
Object[][] rowData2 = new Object[view.source.arrows().size()][6];
i = 0;
for (Object o : view.source.arrows()) {
rowData2[i][0] = Util.nice(o.toString());
rowData2[i][1] = Util.nice(view.source.source(o).toString());
rowData2[i][2] = Util.nice(view.source.target(o).toString());
rowData2[i][3] = Util.nice(view.applyA(o).toString());
rowData2[i][4] = Util.nice(view.target.source(view.applyA(o)).toString());
rowData2[i][5] = Util.nice(view.target.target(view.applyA(o)).toString());
i++;
}
Object[] colNames2 = new Object[] { "Input", "Source", "Target", "Output", "Source", "Target" };
JPanel gp2 = GuiUtil.makeTable(BorderFactory.createEtchedBorder(), "On Arrows (" + view.source.arrows().size() + ")", rowData2, colNames2);
gp.add(gp1);
gp.add(gp2);
px.add("Table", GuiUtil.makeGrid(gp));
}
if (DefunctGlobalOptions.debug.fqlpp.ftr_textual) {
CodeTextPanel gp = new CodeTextPanel(BorderFactory.createEtchedBorder(), "", Util.nice(view.toString()));
px.add("Text", gp);
}
JPanel top = new JPanel(new GridLayout(1, 1));
top.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
top.add(px);
return top;
}
use of catdata.fqlpp.CatExp.Const in project fql by CategoricalData.
the class FqlppDisplay method showCat.
private JPanel showCat(Category<?, ?> view, Color c) {
JTabbedPane px = new JTabbedPane();
Signature<String, String> sig = null;
String key = unr(env.cats, view, null);
if (key != null) {
CatExp r = CatOps.resolve(prog, prog.cats.get(key));
if (r instanceof Const) {
Const sig0 = (Const) r;
sig = new Signature<>(sig0.nodes, sig0.arrows, sig0.eqs);
}
}
if (sig != null && !view.isInfinite()) {
if (DefunctGlobalOptions.debug.fqlpp.cat_schema) {
Graph g = buildFromSig(sig);
if (g.getVertexCount() == 0) {
px.add("Schema", new JPanel());
} else if (g.getVertexCount() > DefunctGlobalOptions.debug.fqlpp.MAX_NODES) {
CodeTextPanel xxx = new CodeTextPanel(BorderFactory.createEtchedBorder(), "", "Graph has " + g.getVertexCount() + " nodes, which exceeds limit of " + DefunctGlobalOptions.debug.fqlpp.MAX_NODES);
px.add("Schema", xxx);
} else if (g.getEdgeCount() > DefunctGlobalOptions.debug.fqlpp.MAX_EDGES) {
CodeTextPanel xxx = new CodeTextPanel(BorderFactory.createEtchedBorder(), "", "Graph has " + g.getEdgeCount() + " edges, which exceeds limit of " + DefunctGlobalOptions.debug.fqlpp.MAX_EDGES);
px.add("Schema", xxx);
} else {
px.add("Schema", doSchemaView(c, g));
}
}
}
if (DefunctGlobalOptions.debug.fqlpp.cat_graph && !view.isInfinite()) {
JComponent gp = makeCatViewer(view, c);
px.add("Graph", gp);
}
if (DefunctGlobalOptions.debug.fqlpp.cat_tabular && !view.isInfinite()) {
JPanel gp = catTable(view);
px.add("Table", gp);
}
if (DefunctGlobalOptions.debug.fqlpp.cat_textual) {
CodeTextPanel gp = new CodeTextPanel(BorderFactory.createEtchedBorder(), null, Util.nice(view.toString()));
px.add("Text", gp);
}
JPanel top = new JPanel(new GridLayout(1, 1));
top.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
top.add(px);
return top;
}
use of catdata.fqlpp.CatExp.Const 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.fqlpp.CatExp.Const in project fql by CategoricalData.
the class CatOps method visit.
@Override
public Transform visit(FQLPPProgram env, ToMap e) {
Functor s = e.src.accept(env, this);
Functor t = e.dst.accept(env, this);
CatExp scat = resolve(env, e.s);
if (!(scat instanceof Const)) {
throw new RuntimeException("Source category of " + e + " is not a constant.");
}
// CatExp.Const scon = (CatExp.Const) scat;
CatExp tcat = resolve(env, e.t);
if (!(tcat instanceof Const)) {
throw new RuntimeException("Target category of " + e + " is not a constant.");
}
Const tcon = (Const) tcat;
// Signature ssig = new Signature(scon.nodes, scon.arrows, scon.eqs);
Signature<String, String> tsig = new Signature<>(tcon.nodes, tcon.arrows, tcon.eqs);
FUNCTION o = x -> {
Node n = (Node) x;
// Set src = (Set) s.applyO(n);
// Set dst = (Set) t.applyO(n);
Pair<String, List<String>> k = e.fun.get(n.name);
Signature<String, String>.Path fun = tsig.path(k.first, k.second);
// new Fn(src, dst, fun);
return fun;
};
return new Transform(s, t, o);
}
Aggregations