use of catdata.Triple in project fql by CategoricalData.
the class ToJdbcPragmaInstance method deleteThenCreate.
private void deleteThenCreate(Connection conn) throws SQLException {
Map<En, Triple<List<Chc<Fk, Att>>, List<String>, List<String>>> m = I.schema().toSQL(prefix, "integer", "id", truncate, Object::toString, len);
Statement stmt = conn.createStatement();
for (En en : I.schema().ens) {
for (String x : m.get(en).second) {
// TODO aql drop foreign keys here first
// System.out.println(x);
// .replace("Varchar", "Varchar(" + len + ")").replace("Nvarchar", "Nvarchar(" + len + ")").replace("varchar", "Varchar(" + len + ")"));
stmt.execute(x);
}
}
stmt.close();
}
use of catdata.Triple in project fql by CategoricalData.
the class CatOps method visit.
@Override
public Functor visit(FQLPPProgram env, MapConst ic) {
Triple<Category, Category, Mapping<String, String, String, String>> xxx = toMapping(env, ic);
Mapping<String, String, String, String> I = xxx.third;
FUNCTION f = p0 -> {
Path p = (Path) p0;
return I.apply(p);
};
Functor et = new Functor(xxx.first, xxx.second, x -> I.nm.get(x), f);
et.mapping0 = xxx.third;
return et;
}
use of catdata.Triple in project fql by CategoricalData.
the class FDM method deltaPi.
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <O1, A1, O2, A2> Adjunction<Functor<O2, A2, Set, Fn>, Transform<O2, A2, Set, Fn>, Functor<O1, A1, Set, Fn>, Transform<O1, A1, Set, Fn>> deltaPi(Functor<O2, A2, O1, A1> F) {
Category<Functor<O2, A2, Set, Fn>, Transform<O2, A2, Set, Fn>> D = Inst.get(F.source);
Category<Functor<O1, A1, Set, Fn>, Transform<O1, A1, Set, Fn>> C = Inst.get(F.target);
FUNCTION<Functor<O1, A1, Set, Fn>, Transform<O1, A1, Set, Fn>> f = I -> {
Triple<Functor<O1, A1, Set, Fn>, Map<O1, Set<Map>>, Map<O1, Triple<O1, O2, A1>[]>> xxx = Pi.pi(F, Functor.compose(F, I));
FUNCTION<O1, Fn> j = n -> new Fn<>(I.applyO(n), xxx.first.applyO(n), i -> {
outer: for (Map m : xxx.second.get(n)) {
for (int p = 1; p < m.size(); p++) {
if (xxx.third.get(n)[p - 1].third.equals(F.target.identity(n))) {
if (!m.get(p).equals(i)) {
continue outer;
}
}
}
return m.get(0);
}
throw new RuntimeException("Cannot find diagonal of " + i + " in " + xxx.second.get(n));
});
return new Transform<>(I, xxx.first, j);
};
Transform<Functor<O1, A1, Set, Fn>, Transform<O1, A1, Set, Fn>, Functor<O1, A1, Set, Fn>, Transform<O1, A1, Set, Fn>> unit = new Transform<>(Functor.identity(C), Functor.compose(deltaF(F), piF(F)), f);
FUNCTION<Functor<O2, A2, Set, Fn>, Transform<O2, A2, Set, Fn>> g = I -> {
Triple<Functor<O1, A1, Set, Fn>, Map<O1, Set<Map>>, Map<O1, Triple<O1, O2, A1>[]>> xxx = Pi.pi(F, I);
Functor<O2, A2, Set, Fn> deltad = Functor.compose(F, xxx.first);
FUNCTION<O2, Fn> j = m -> {
O1 n = F.applyO(m);
Triple<O1, O2, A1>[] col = xxx.third.get(n);
Triple<O1, O2, A1> tofind = new Triple<>(n, m, F.target.identity(n));
Set<Map> lim = xxx.second.get(n);
int[] i = new int[] { 0 };
for (Triple<O1, O2, A1> cand : col) {
if (!cand.equals(tofind)) {
i[0]++;
continue;
}
FUNCTION h = id -> {
for (Map row : lim) {
if (row.get(0).equals(id)) {
return row.get(i[0] + 1);
}
}
throw new RuntimeException("Report this error to Ryan.");
};
return new Fn<>(deltad.applyO(m), I.applyO(m), h);
}
throw new RuntimeException("Report this error to Ryan.");
};
return new Transform<>(deltad, I, j);
};
Transform<Functor<O2, A2, Set, Fn>, Transform<O2, A2, Set, Fn>, Functor<O2, A2, Set, Fn>, Transform<O2, A2, Set, Fn>> counit = new Transform<>(Functor.compose(piF(F), deltaF(F)), Functor.identity(D), g);
return new Adjunction<>(deltaF(F), sigmaF(F), counit, unit);
}
use of catdata.Triple in project fql by CategoricalData.
the class FqlppDisplay method doElementsView.
private static JComponent doElementsView(Color clr, Graph<Pair, Triple> sgv) {
Layout<Pair, Triple> layout = new FRLayout<>(sgv);
layout.setSize(new Dimension(600, 400));
VisualizationViewer<Pair, Triple> vv = new VisualizationViewer<>(layout);
Function<Pair, Paint> vertexPaint = z -> clr;
DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
gm.setMode(Mode.TRANSFORMING);
vv.setGraphMouse(gm);
gm.setMode(Mode.PICKING);
vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
Function<Pair, String> ttt1 = arg0 -> Util.nice(arg0.second.toString());
vv.getRenderContext().setVertexLabelTransformer(ttt1);
Function<Triple, String> ttt2 = arg0 -> Util.nice(arg0.first.toString());
vv.getRenderContext().setEdgeLabelTransformer(ttt2);
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 Relationalizer method terminal.
public static Triple<Const, Map<Node, Map<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>>, Map<Node, Map<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Object>>> terminal(FQLProgram prog, SigExp.Const sig0) {
Triple<Const, Map<Node, Map<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>>, Map<Node, Map<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Object>>> jjj = cache.get(new Pair<>(prog, sig0));
if (jjj != null) {
// so do not have to recompute when doing omega operations
return jjj;
}
try {
Signature sig = sig0.toSig(prog);
Pair<FinCat<Node, Path>, Fn<Path, Arr<Node, Path>>> start = sig.toCategory2();
// FinCat<Node, Path> cat = start.first;
Fn<Path, Arr<Node, Path>> map = start.second;
Map<Node, List<Pair<Arr<Node, Path>, Attribute<Node>>>> obs = sig.obs();
Map<Node, List<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>> m = sig.obsbar();
List<Pair<String, List<Pair<Object, Object>>>> nodes = new LinkedList<>();
List<Pair<String, List<Pair<Object, Object>>>> attrs = new LinkedList<>();
List<Pair<String, List<Pair<Object, Object>>>> arrows = new LinkedList<>();
// Map<String, Set<Pair<Object, Object>>> data = new HashMap<>();
Map<Node, Map<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>> m1 = new HashMap<>();
Map<Node, Map<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Object>> m2 = new HashMap<>();
int i = 0;
for (Node n : sig.nodes) {
Map<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>> map1 = new HashMap<>();
Map<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Object> map2 = new HashMap<>();
List<Pair<Object, Object>> set = new LinkedList<>();
m1.put(n, map1);
m2.put(n, map2);
for (LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> i2 : m.get(n)) {
Object o = Integer.toString(++i);
map1.put(o, i2);
map2.put(i2, o);
set.add(new Pair<>(o, o));
}
nodes.add(new Pair<>(n.string, set));
}
for (Attribute<Node> a : sig.attrs) {
List<Pair<Object, Object>> set = new LinkedList<>();
for (Pair<Object, Object> k : PropPSM.lookup(nodes, a.source.string)) {
LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> new_id = m1.get(a.source).get(k.first);
set.add(new Pair<>(k.first, new_id.get(new Pair<>(map.of(new Path(sig, a.source)), a))));
}
attrs.add(new Pair<>(a.name, set));
}
for (Edge a : sig.edges) {
List<Pair<Object, Object>> set = new LinkedList<>();
for (Pair<Object, Object> k : PropPSM.lookup(nodes, a.source.string)) {
LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> new_id = m1.get(a.source).get(k.first);
LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> new_id0 = PropPSM.truncate2(sig, new_id, new Arr<>(new Path(sig, a), a.source, a.target), obs.get(a.target));
// LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> new_id0 = PropPSM.truncate(sig, new_id, a, m.get(a.target));
Object o = m2.get(a.target).get(new_id0);
set.add(new Pair<>(k.first, o));
}
arrows.add(new Pair<>(a.name, set));
}
// Instance ret0 = new Instance(sig, data);
Const retX = new Const(nodes, attrs, arrows, sig.toConst());
Triple<Const, Map<Node, Map<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>>, Map<Node, Map<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Object>>> ret = new Triple<>(retX, m1, m2);
cache.put(new Pair<>(prog, sig0), ret);
return ret;
} catch (FQLException fe) {
throw new RuntimeException(fe.getLocalizedMessage());
}
}
Aggregations