use of catdata.opl.OplExp.OplJavaInst in project fql by CategoricalData.
the class OplOps method visit.
@Override
public OplObject visit(Program<OplExp> env, OplInst e) {
OplSchema S;
OplPres P;
OplJavaInst J = null;
OplObject S0 = ENV.get(e.S0);
if (S0 instanceof OplSchema) {
S = (OplSchema) S0;
} else {
throw new RuntimeException("Not a schema: " + e.S0);
}
OplObject P0 = ENV.get(e.P0);
if (P0 instanceof OplPres) {
P = (OplPres) P0;
} else {
throw new RuntimeException("Not a presentation: " + e.P0);
}
if (!e.J0.equals("none")) {
OplObject J0 = ENV.get(e.J0);
if (J0 instanceof OplJavaInst) {
J = (OplJavaInst) J0;
} else {
throw new RuntimeException("Not a JS model: " + e.J0);
}
}
e.validate(S, P, J);
return e;
}
use of catdata.opl.OplExp.OplJavaInst in project fql by CategoricalData.
the class OplParser method toJava.
private static OplExp toJava(Object x) {
Tuple3 t = (Tuple3) x;
Tuple3 b = (Tuple3) t.b;
List<Tuple3> l = (List<Tuple3>) b.b;
Map<String, String> defs = new HashMap<>();
for (Tuple3 k : l) {
String f = (String) k.a;
String body = (String) k.c;
if (defs.containsKey(f)) {
throw new DoNotIgnore("Duplicate symbol: " + f);
}
defs.put(f, body);
}
org.jparsec.functors.Pair c = (org.jparsec.functors.Pair) t.c;
return new OplJavaInst(defs, (String) c.b);
}
use of catdata.opl.OplExp.OplJavaInst in project fql by CategoricalData.
the class OplOps method visit.
@Override
public OplObject visit(Program<OplExp> env, OplUberSat e) {
OplObject p = ENV.get(e.P);
if (!(p instanceof OplPres)) {
throw new RuntimeException("Not a presentation: " + e.P);
}
OplPres S = (OplPres) p;
OplObject i = ENV.get(e.I);
if (!(i instanceof OplJavaInst)) {
throw new RuntimeException("Not a javascript model: " + e.I);
}
OplJavaInst I = (OplJavaInst) i;
OplObject ob = OplUberSat.saturate(I, S);
return ob;
}
use of catdata.opl.OplExp.OplJavaInst 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