use of catdata.fql.cat.Arr in project fql by CategoricalData.
the class Instance method toFunctor2.
public Inst<Node, Path, Object, Object> toFunctor2() throws FQLException {
FinCat<Node, Path> cat = thesig.toCategory2().first;
Map<Node, Set<Value<Object, Object>>> objM = new HashMap<>();
for (Node obj : cat.objects) {
if (data.get(obj.string) == null) {
throw new RuntimeException("No data for " + obj + " in " + data);
}
objM.put(obj, conv(data.get(obj.string)));
}
Map<Arr<Node, Path>, Map<Value<Object, Object>, Value<Object, Object>>> arrM = new HashMap<>();
for (Arr<Node, Path> arr : cat.arrows) {
List<String> es = arr.arr.asList();
String h = es.get(0);
Set<Pair<Object, Object>> h0 = data.get(h);
for (int i = 1; i < es.size(); i++) {
h0 = compose2(h0, data.get(es.get(i)));
}
Map<Value<Object, Object>, Value<Object, Object>> xxx = FDM.degraph(h0);
arrM.put(arr, xxx);
}
return new Inst<>(objM, arrM, cat);
}
use of catdata.fql.cat.Arr in project fql by CategoricalData.
the class Mapping method view.
/**
* The viewer for mappings.
*/
@SuppressWarnings("serial")
public JPanel view() {
Object[][] arr = new Object[nm.size()][2];
int i = 0;
for (Entry<Node, Node> eq : nm.entrySet()) {
arr[i][0] = eq.getKey();
arr[i][1] = eq.getValue();
i++;
}
Arrays.sort(arr, Comparator.comparing(f3 -> f3[0].toString()));
JTable nmC = new JTable(arr, new Object[] { "Source node", "Target node" }) {
@Override
public Dimension getPreferredScrollableViewportSize() {
Dimension d = getPreferredSize();
return new Dimension(d.width, d.height);
}
};
Object[][] arr2 = new Object[em.size()][2];
int i2 = 0;
for (Entry<Edge, Path> eq : em.entrySet()) {
arr2[i2][0] = eq.getKey();
arr2[i2][1] = eq.getValue().toLong();
i2++;
}
Arrays.sort(arr2, Comparator.comparing(f2 -> f2[0].toString()));
JTable emC = new JTable(arr2, new Object[] { "Source edge", "Target path" }) {
@Override
public Dimension getPreferredScrollableViewportSize() {
Dimension d = getPreferredSize();
return new Dimension(d.width, d.height);
}
};
Object[][] arr3 = new Object[am.size()][2];
int i3 = 0;
for (Entry<Attribute<Node>, Attribute<Node>> eq : am.entrySet()) {
arr3[i3][0] = eq.getKey();
arr3[i3][1] = eq.getValue();
i3++;
}
Arrays.sort(arr3, Comparator.comparing(f -> f[0].toString()));
JTable amC = new JTable(arr3, new Object[] { "Source attribute", "Target attribute" }) {
@Override
public Dimension getPreferredScrollableViewportSize() {
Dimension d = getPreferredSize();
return new Dimension(d.width, d.height);
}
};
List<JComponent> p = new LinkedList<>();
// JPanel p = new JPanel(new GridLayout(2, 2));
JScrollPane q1 = new JScrollPane(nmC);
JScrollPane q2 = new JScrollPane(emC);
JScrollPane q3 = new JScrollPane(amC);
JPanel j1 = new JPanel(new GridLayout(1, 1));
j1.add(q1);
j1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Node mapping"));
p.add(j1);
JPanel j2 = new JPanel(new GridLayout(1, 1));
j2.add(q2);
j2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Arrow mapping"));
p.add(j2);
JPanel j3 = new JPanel(new GridLayout(1, 1));
j3.add(q3);
j3.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Attribute mapping"));
p.add(j3);
// p.setBorder(BorderFactory.createEtchedBorder());
return FqlUtil.makeGrid(p);
}
use of catdata.fql.cat.Arr in project fql by CategoricalData.
the class Signature method view.
@SuppressWarnings("serial")
public JPanel view() {
Object[][] arr = new Object[eqs.size()][2];
int i = 0;
for (Eq eq : eqs) {
arr[i][0] = eq.lhs;
arr[i][1] = eq.rhs;
i++;
}
Arrays.sort(arr, Comparator.comparing(f4 -> f4[0].toString()));
JTable eqsComponent = new JTable(arr, new Object[] { "lhs", "rhs" }) {
@Override
public Dimension getPreferredScrollableViewportSize() {
Dimension d = getPreferredSize();
return new Dimension(d.width, d.height);
}
};
List<JComponent> p = new LinkedList<>();
JPanel eqsTemp = new JPanel(new GridLayout(1, 1));
eqsTemp.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2), "Equations (" + eqs.size() + ")"));
eqsTemp.add(new JScrollPane(eqsComponent));
Object[][] sn = new String[nodes.size()][1];
int ii = 0;
for (Node n : nodes) {
sn[ii++][0] = n.string;
}
Arrays.sort(sn, Comparator.comparing(f3 -> f3[0].toString()));
JTable nodesComponent = new JTable(sn, new String[] { "Name" }) {
@Override
public Dimension getPreferredScrollableViewportSize() {
Dimension d = getPreferredSize();
return new Dimension(d.width, d.height);
}
};
JPanel nodesTemp = new JPanel(new GridLayout(1, 1));
nodesTemp.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2), "Nodes (" + nodes.size() + ")"));
nodesTemp.add(new JScrollPane(nodesComponent));
Object[][] es = new String[edges.size()][3];
int jj = 0;
for (Edge eq : edges) {
es[jj][0] = eq.name;
es[jj][1] = eq.source.string;
es[jj][2] = eq.target.string;
jj++;
}
Arrays.sort(es, Comparator.comparing(f2 -> f2[0].toString()));
JTable esC = new JTable(es, new String[] { "Name", "Source", "Target" }) {
@Override
public Dimension getPreferredScrollableViewportSize() {
Dimension d = getPreferredSize();
return new Dimension(d.width, d.height);
}
};
JPanel edgesTemp = new JPanel(new GridLayout(1, 1));
edgesTemp.add(new JScrollPane(esC));
edgesTemp.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2), "Arrows (" + edges.size() + ")"));
Object[][] as = new String[attrs.size()][3];
jj = 0;
for (Attribute<Node> a : attrs) {
as[jj][0] = a.name;
as[jj][1] = a.source.string;
as[jj][2] = a.target.toString();
jj++;
}
Arrays.sort(as, Comparator.comparing(f -> f[0].toString()));
JTable asC = new JTable(as, new String[] { "Name", "Source", "Type" }) {
@Override
public Dimension getPreferredScrollableViewportSize() {
Dimension d = getPreferredSize();
return new Dimension(d.width, d.height);
}
};
JPanel attrsTemp = new JPanel(new GridLayout(1, 1));
attrsTemp.add(new JScrollPane(asC));
attrsTemp.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2), "Attributes (" + attrs.size() + ")"));
p.add(nodesTemp);
p.add(edgesTemp);
p.add(attrsTemp);
p.add(eqsTemp);
return FqlUtil.makeGrid(p);
}
use of catdata.fql.cat.Arr in project fql by CategoricalData.
the class SigOps method visit.
@Override
public Const visit(FQLProgram env, Curry e) {
try {
Const F = e.f.accept(env, this);
Pair<SigExp, SigExp> type = e.f.type(env);
SigExp.Const C = type.second.toConst(env);
Signature Csig = C.toSig(env);
if (!(type.first instanceof Times)) {
throw new RuntimeException();
}
Times src = (Times) type.first;
SigExp.Const A = src.a.toConst(env);
SigExp.Const B = src.b.toConst(env);
// Signature Asig = A.toSig(env);
Signature Bsig = B.toSig(env);
if (!A.attrs.isEmpty()) {
throw new RuntimeException("Cannot curry when context has attributes.");
}
Pair<Quad<SigExp.Const, Const, Const, Fn<Triple<SigExp.Const, Const, Const>, Const>>, Quad<Map<Pair<String, String>, String>, Map<Pair<String, String>, String>, Map<Pair<String, String>, String>, Map<Pair<String, String>, String>>> AB_stuff = prod(A, B);
// SigExp.Const AB = AB_stuff.first.first;
Quad<Map<Pair<String, String>, String>, Map<Pair<String, String>, String>, Map<Pair<String, String>, String>, Map<Pair<String, String>, String>> maps = AB_stuff.second;
FinCat<Mapping, Map<Node, Path>> cat = exp(env, C.toSig(env), B.toSig(env));
Quad<Signature, Pair<Map<Mapping, String>, Map<String, Mapping>>, Pair<Map<Arr<Mapping, Map<Node, Path>>, String>, Map<String, Arr<Mapping, Map<Node, Path>>>>, Pair<Map<Attribute<Mapping>, String>, Map<String, Attribute<Mapping>>>> CB_stuff = cat.toSig(env.enums);
Signature CB = CB_stuff.first;
List<Pair<String, String>> nmret = new LinkedList<>();
for (String a : A.nodes) {
Mapping m = curry_helper(F, Csig, B, Bsig, maps, a);
String target = CB_stuff.second.first.get(m);
nmret.add(new Pair<>(a, target));
}
List<Pair<String, List<String>>> amret = new LinkedList<>();
for (Triple<String, String, String> a : A.arrows) {
Mapping s = curry_helper(F, Csig, B, Bsig, maps, a.second);
Mapping t = curry_helper(F, Csig, B, Bsig, maps, a.third);
Map<Node, Path> nt = new HashMap<>();
for (String b : B.nodes) {
// edge A*B
String p = maps.third.get(new Pair<>(a.first, b));
// path C
List<String> p0 = lookup(p, F.arrows);
Path p1 = new Path(Csig, p0);
nt.put(new Node(b), p1);
}
List<String> l = new LinkedList<>();
l.add(CB_stuff.second.first.get(s));
Arr<Mapping, Map<Node, Path>> arr = new Arr<>(nt, s, t);
if (null != CB_stuff.third.first.get(arr)) {
l.add(CB_stuff.third.first.get(arr));
}
amret.add(new Pair<>(a.first, l));
}
List<Pair<String, String>> attrs = new LinkedList<>();
// A*B -> C
// A -> C^B
Const ret = new Const(nmret, attrs, amret, A, CB.toConst());
ret.toMap(env);
return ret;
} catch (FQLException fe) {
fe.printStackTrace();
throw new RuntimeException(fe.getMessage());
}
}
Aggregations