use of catdata.Pair in project fql by CategoricalData.
the class XMapping method counit.
@SuppressWarnings({ "rawtypes", "unchecked" })
public XMapping<Pair<Triple<D, D, List<D>>, C>, D> counit(XCtx<D> I) {
XCtx<Pair<Triple<D, D, List<D>>, C>> FI = delta(I);
XMapping<Pair<Triple<D, D, List<D>>, C>, Pair<Triple<D, D, List<D>>, C>> f = (XMapping<Pair<Triple<D, D, List<D>>, C>, Pair<Triple<D, D, List<D>>, C>>) this;
XCtx<Pair<Triple<D, D, List<D>>, C>> FFI = f.apply0(FI);
Map m = new HashMap<>();
for (Pair<Triple<D, D, List<D>>, C> c : FFI.terms()) {
List<D> l = new LinkedList<>(c.first.third);
l.add(0, c.first.first);
m.put(c, l);
}
for (Object o : FFI.allTerms()) {
if (m.containsKey(o)) {
continue;
}
List l = new LinkedList();
l.add(o);
m.put(o, l);
}
return new XMapping<>(FFI, I, m, "homomorphism");
}
use of catdata.Pair in project fql by CategoricalData.
the class XNeo4jToFQL method trans0.
private static String trans0(Map<String, Map<String, Object>> properties, Map<String, Set<Pair<String, String>>> edges) {
labelForProperty(properties);
Map<String, Set<String>> pfl = propsForLabels(properties);
Map<String, Pair<String, String>> sfe = sortsForEges(edges, properties);
XSchema xxx = toSchema(pfl, sfe);
XInst yyy = toInst(properties, edges);
return "dom : type\n" + Util.sep(adom(properties), " ") + " : dom\n\nS = " + xxx + "\n\nI = " + yyy + " : S\n";
}
use of catdata.Pair in project fql by CategoricalData.
the class XNeo4jToFQL method fromEdges.
/* Parser<?> n = ident().between(term("("), term(")"));
Parser<?> e = Parsers.tuple(term("["), term(":"), ident(), term("]"));
Parser<?> p = Parsers.tuple(n, term("-"), e, term("->"), n);
return Parsers.tuple(term("CREATE"), p.sepBy(term(","))); */
@SuppressWarnings({ "rawtypes", "unchecked" })
private static Map<String, Set<Pair<String, String>>> fromEdges(Object oo) {
Map<String, Set<Pair<String, String>>> ret = new HashMap<>();
org.jparsec.functors.Pair o = (org.jparsec.functors.Pair) oo;
List<Tuple5> xx = (List<Tuple5>) o.b;
for (Tuple5 tt : xx) {
String s = (String) tt.a;
String t = (String) tt.e;
Tuple4 e0 = (Tuple4) tt.c;
String e = (String) e0.c;
Set<Pair<String, String>> set = ret.computeIfAbsent(e, k -> new HashSet<>());
set.add(new Pair<>(s, t));
}
return ret;
}
use of catdata.Pair in project fql by CategoricalData.
the class XOps method visit.
@Override
public XObject visit(XProgram env, XSOED e) {
XExp src0 = env.exps.get(e.src);
if (src0 == null) {
throw new RuntimeException("Missing: " + e.src);
}
if (!(src0 instanceof XSchema)) {
throw new RuntimeException("Not a schema: " + e.src);
}
XSchema src = (XSchema) src0;
XCtx src1 = (XCtx) ENV.objs.get(e.src);
XExp dst0 = env.exps.get(e.dst);
if (dst0 == null) {
throw new RuntimeException("Missing: " + e.dst);
}
if (!(dst0 instanceof XSchema)) {
throw new RuntimeException("Not a schema: " + e.dst);
}
XSchema dst = (XSchema) dst0;
XCtx dst1 = (XCtx) ENV.objs.get(e.dst);
XObject I0 = ENV.objs.get(e.I);
if (I0 == null) {
throw new RuntimeException("Missing: " + e.I);
}
if (!(I0 instanceof XCtx)) {
throw new RuntimeException("Not an instance: " + e.I);
}
XCtx I = (XCtx) I0;
if (!src1.equals(I.schema)) {
throw new RuntimeException("Instance schema does not match source");
}
List<String> nodes = new LinkedList<>();
List<Triple<String, String, String>> arrows = new LinkedList<>();
List<Pair<List<String>, List<String>>> eqs = new LinkedList<>();
Map em_s = new HashMap();
Map em_t = new HashMap();
nodes.addAll(src.nodes);
nodes.addAll(dst.nodes);
arrows.addAll(src.arrows);
arrows.addAll(dst.arrows);
arrows.addAll(e.es);
eqs.addAll(src.eqs);
eqs.addAll(dst.eqs);
for (FOED k : e.as) {
for (Pair<List<String>, List<String>> v : k.eqs) {
List<String> l = new LinkedList<>(v.first);
List<String> r = new LinkedList<>(v.second);
l.removeAll(Util.singList(k.a));
r.removeAll(Util.singList(k.a));
eqs.add(new Pair<>(l, r));
}
}
for (String n : src.nodes) {
em_s.put(n, Util.singList(n));
}
for (String n : dst.nodes) {
em_t.put(n, Util.singList(n));
}
for (Triple<String, String, String> n : src.arrows) {
em_s.put(n.first, Util.singList(n.first));
}
for (Triple<String, String, String> n : dst.arrows) {
em_t.put(n.first, Util.singList(n.first));
}
for (Object n : src1.allTerms()) {
if (em_s.containsKey(n)) {
continue;
}
em_s.put(n, Util.singList(n));
}
for (Object n : dst1.allTerms()) {
if (em_t.containsKey(n)) {
continue;
}
em_t.put(n, Util.singList(n));
}
XSchema X = new XSchema(nodes, arrows, eqs);
XCtx Y = (XCtx) X.accept(env, this);
XMapping F = new XMapping(src1, Y, em_s, "mapping");
XMapping G = new XMapping(dst1, Y, em_t, "mapping");
XCtx J = F.apply0(I);
return G.delta(J);
}
use of catdata.Pair in project fql by CategoricalData.
the class XOps method visit.
@Override
public XObject visit(XProgram env, XToQuery e) {
Object o = e.inst.accept(env, this);
if (!(o instanceof XCtx)) {
throw new RuntimeException("Not instance: " + o);
}
XCtx c = (XCtx) o;
int i = 0;
// Map m1 = new HashMap();
Map m2 = new HashMap();
// Map mty = new HashMap();
Map from = new HashMap<>();
for (Object t : c.terms()) {
// m1.put("v_v"+i, t);
m2.put(t, "v_v" + i);
from.put("v_v" + i, c.type(t).second);
// from.put("v"+i, c.type(((Pair)t).second);
i++;
}
List where = new LinkedList<>();
Function f = x -> {
Object j = m2.get(x);
if (j == null) {
return x;
}
return j;
};
for (Object k : c.eqs) {
List l = (List) ((Pair) k).first;
List r = (List) ((Pair) k).second;
// lookup m2
where.add(new Pair<>(l.stream().map(f).collect(Collectors.toList()), r.stream().map(f).collect(Collectors.toList())));
}
Flower iii = new Flower(new HashMap<>(), from, where, e.applyTo);
return iii.accept(env, this);
}
Aggregations