use of catdata.Pair in project fql by CategoricalData.
the class EvalAlgebra method eval.
// TODO must convert back to original unfolded vars
private Pair<List<Var>, Collection<Row<En2, X>>> eval(En2 en2, Frozen<Ty, En1, Sym, Fk1, Att1> q, Connection conn, boolean useSql) {
Collection<Row<En2, X>> ret = null;
Integer k = maxTempSize();
if (useSql) {
Pair<List<Var>, Collection<Row<En2, X>>> ret2 = evalSql(en2, q, I.algebra().intifyX((int) options.getOrDefault(AqlOption.start_ids_at)), conn);
// TODO aql should also stop on max temp size?
return ret2;
} else {
ret = new LinkedList<>();
List<Var> plan = q.order(options, I);
boolean useIndices = useIndices() && q.gens.size() > 1 && I.algebra().hasFreeTypeAlgebra();
ret.add(new Row<>(en2));
for (Var v : plan) {
ret = Row.extend(en2, ret, v, q, I, k, useIndices);
}
return new Pair<>(plan, ret);
}
}
use of catdata.Pair in project fql by CategoricalData.
the class CatOps method visit.
@Override
public Functor visit(FQLPPProgram env, Iso e) {
Category l = e.l.accept(env, this);
Category r = e.r.accept(env, this);
Optional<Pair<Functor, Functor>> k = FinCat.iso(l, r);
if (!k.isPresent()) {
throw new RuntimeException("Not isomorphic: " + e.l + " and " + e.r);
}
return e.lToR ? k.get().first : k.get().second;
}
use of catdata.Pair in project fql by CategoricalData.
the class CatOps method visit.
@Override
public Transform visit(FQLPPProgram env, TransExp.Iso e) {
Functor l = e.l.accept(env, this);
Functor r = e.r.accept(env, this);
if (!l.source.equals(r.source)) {
throw new RuntimeException("Source categories do not match: " + l.source + "\nand\n" + r.source);
}
if (l.source.isInfinite()) {
throw new RuntimeException("Source category must be finite.");
}
if (!l.target.equals(FinSet.FinSet)) {
throw new RuntimeException("Target category must be Set.");
}
Optional<Pair<Transform, Transform>> k = Inst.get(l.source).iso(l, r);
if (!k.isPresent()) {
throw new RuntimeException("Not isomorphic: " + e.l + " and " + e.r);
}
return e.lToR ? k.get().first : k.get().second;
}
use of catdata.Pair in project fql by CategoricalData.
the class CatOps method visit.
@Override
public Transform visit(FQLPPProgram env, ToSet e) {
Functor s = e.src.accept(env, this);
Functor t = e.dst.accept(env, this);
FUNCTION o = x -> {
Node n = (Node) x;
Chc<FnExp, SetExp> chc = e.fun.get(n.name);
if (chc == null) {
throw new RuntimeException("Missing object mapping for: " + n.name);
}
if (chc.left) {
return chc.l.accept(env, new SetOps(ENV));
} else {
Set src = (Set) s.applyO(n);
Set dst = (Set) t.applyO(n);
Set<Pair> p = (Set<Pair>) chc.r.accept(env, new SetOps(ENV));
Map<Object, Object> map = new HashMap<>();
for (Pair h : p) {
if (map.containsKey(h.first)) {
throw new RuntimeException("Duplicate arg: " + e);
}
map.put(h.first, h.second);
}
return new Fn(src, dst, map::get);
}
};
return new Transform(s, t, o);
}
use of catdata.Pair in project fql by CategoricalData.
the class PPParser method toValue.
private static Object toValue(Object o) {
if (o.toString().equals("true")) {
return true;
}
if (o.toString().equals("false")) {
return false;
}
if (o instanceof Tuple5) {
Tuple5 t = (Tuple5) o;
if (t.a.toString().equals("(")) {
return new Pair(toValue(t.b), toValue(t.d));
}
List l = (List) t.b;
Map s = new HashMap();
for (Object y : l) {
Pair yy = (Pair) toValue(y);
if (s.containsKey(yy.first)) {
throw new RuntimeException("Duplicate domain entry in " + o);
}
s.put(yy.first, yy.second);
}
Tuple3 tt = (Tuple3) t.e;
Set ui = (Set) toValue(tt.a);
Set uj = (Set) toValue(tt.c);
return new Fn(ui, uj, s::get);
}
if (o instanceof Tuple3) {
Tuple3 p = (Tuple3) o;
List l = (List) p.b;
Set s = new HashSet();
for (Object y : l) {
s.add(toValue(y));
}
return s;
}
if (o instanceof org.jparsec.functors.Pair) {
org.jparsec.functors.Pair p = (org.jparsec.functors.Pair) o;
if (p.a.toString().equals("inl")) {
return Chc.inLeft(toValue(p.b));
} else if (p.a.toString().equals("inr")) {
return Chc.inRight(toValue(p.b));
} else {
return new Unit();
}
}
return o.toString();
}
Aggregations