use of catdata.opl.OplExp.OplSetInst in project fql by CategoricalData.
the class OplOps method visit.
@Override
public OplObject visit(Program<OplExp> env, OplDelta e) {
OplObject F = ENV.get(e.F);
if (!(F instanceof OplMapping)) {
throw new RuntimeException("Not a mapping: " + e.F);
}
OplMapping F0 = (OplMapping) F;
OplObject I = ENV.get(e.I);
if (I instanceof OplSetInst) {
OplSetInst I0 = (OplSetInst) I;
return F0.delta(I0);
}
if (I instanceof OplSetTrans) {
OplSetTrans h = (OplSetTrans) I;
return F0.delta(h);
}
throw new RuntimeException("Not a model or transform: " + e.I);
}
use of catdata.opl.OplExp.OplSetInst in project fql by CategoricalData.
the class OplOps method visit.
@Override
public OplObject visit(Program<OplExp> env, OplSetTrans e) {
OplObject src = ENV.get(e.src);
OplObject dst = ENV.get(e.dst);
if (!(src instanceof OplSetInst)) {
throw new RuntimeException("Source is not a model in " + e);
}
if (!(dst instanceof OplSetInst)) {
throw new RuntimeException("Target is not a model in " + e);
}
OplSetInst src0 = (OplSetInst) src;
OplSetInst dst0 = (OplSetInst) dst;
if (!src0.sig.equals(dst0.sig)) {
throw new RuntimeException("Theories of source and target do not match in " + e);
}
OplSig sig = (OplSig) ENV.get(src0.sig);
e.validate(sig, src0, dst0);
return e;
}
use of catdata.opl.OplExp.OplSetInst in project fql by CategoricalData.
the class OplParser method toModel.
private static OplExp toModel(Object o) {
if (!o.toString().contains("model")) {
throw new RuntimeException();
}
Tuple3 t = (Tuple3) o;
org.jparsec.functors.Pair b = (org.jparsec.functors.Pair) t.b;
org.jparsec.functors.Pair c = (org.jparsec.functors.Pair) t.c;
Tuple3 y = (Tuple3) b.a;
List<Tuple3> sorts = (List<Tuple3>) y.b;
Map<String, Set<String>> sorts0 = new HashMap<>();
for (Tuple3 x : sorts) {
String s = x.a.toString();
List<String> s0 = (List<String>) x.c;
if (sorts0.containsKey(s)) {
throw new DoNotIgnore("Duplicate sort: " + s);
}
Set<String> s1 = new HashSet<>(s0);
if (s1.size() != s0.size()) {
throw new DoNotIgnore("Duplicate member: " + s0);
}
sorts0.put(s, s1);
}
Map<String, Map<List<String>, String>> symbols0 = new HashMap<>();
Tuple3 z = (Tuple3) b.b;
List<Tuple3> q = (List<Tuple3>) z.b;
for (Tuple3 r : q) {
List<Tuple5> u = (List<Tuple5>) r.c;
String fname = (String) r.a;
if (symbols0.containsKey(fname)) {
throw new DoNotIgnore("Duplicte symbol " + fname);
}
Map<List<String>, String> toadd = new HashMap<>();
for (Tuple5 e : u) {
List<String> args = (List<String>) e.b;
String ret = (String) e.d;
if (toadd.containsKey(args)) {
throw new DoNotIgnore("Duplicate argument at " + args);
}
toadd.put(args, ret);
}
symbols0.put(fname, toadd);
}
return new OplSetInst(sorts0, symbols0, c.b.toString());
}
use of catdata.opl.OplExp.OplSetInst in project fql by CategoricalData.
the class OplOps method visit.
@Override
public OplObject visit(Program<OplExp> env, OplUnSat e) {
OplObject i = ENV.get(e.I);
if (!(i instanceof OplSetInst)) {
throw new RuntimeException("Not a model: " + e.I);
}
OplSetInst S = (OplSetInst) i;
return OplUnSat.desaturate(S.sig, S);
}
use of catdata.opl.OplExp.OplSetInst in project fql by CategoricalData.
the class OplOps method visit.
@Override
public OplObject visit(Program<OplExp> env, OplEval e) {
OplObject i = ENV.get(e.I);
if (i instanceof OplSetInst) {
OplSetInst i0 = (OplSetInst) i;
OplObject s = ENV.get(i0.sig);
OplSig s0 = (OplSig) s;
e.e.type(s0, new OplCtx<String, String>());
return new OplString(e.e.eval(s0, i0, new OplCtx<String, String>()).toString());
}
if (i instanceof OplJavaInst) {
OplJavaInst i0 = (OplJavaInst) i;
OplObject s = ENV.get(i0.sig);
OplSig s0 = (OplSig) s;
e.e.type(s0, new OplCtx<String, String>());
try {
return new OplString(OplTerm.strip(OplToKB.redBy(i0, OplToKB.convert(e.e.inLeft())).toString()));
// return new
// OplString(e.e.eval((Invocable)i0.engine).toString());
} catch (Exception ee) {
ee.printStackTrace();
throw new RuntimeException(ee.getMessage());
}
}
throw new RuntimeException("Not a set/js model: " + e.I);
}
Aggregations