Search in sources :

Example 1 with OplJavaInst

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;
}
Also used : OplSchema(catdata.opl.OplExp.OplSchema) OplPres(catdata.opl.OplExp.OplPres) OplJavaInst(catdata.opl.OplExp.OplJavaInst)

Example 2 with OplJavaInst

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);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) OplJavaInst(catdata.opl.OplExp.OplJavaInst) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair)

Example 3 with OplJavaInst

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;
}
Also used : OplPres(catdata.opl.OplExp.OplPres) OplJavaInst(catdata.opl.OplExp.OplJavaInst)

Example 4 with OplJavaInst

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);
}
Also used : OplSetInst(catdata.opl.OplExp.OplSetInst) OplSig(catdata.opl.OplExp.OplSig) OplJavaInst(catdata.opl.OplExp.OplJavaInst)

Aggregations

OplJavaInst (catdata.opl.OplExp.OplJavaInst)4 OplPres (catdata.opl.OplExp.OplPres)2 Pair (catdata.Pair)1 OplSchema (catdata.opl.OplExp.OplSchema)1 OplSetInst (catdata.opl.OplExp.OplSetInst)1 OplSig (catdata.opl.OplExp.OplSig)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Tuple3 (org.jparsec.functors.Tuple3)1