Search in sources :

Example 1 with OplSetInst

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

Example 2 with OplSetInst

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

Example 3 with OplSetInst

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

Example 4 with OplSetInst

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

Example 5 with OplSetInst

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

Aggregations

OplSetInst (catdata.opl.OplExp.OplSetInst)5 OplSig (catdata.opl.OplExp.OplSig)2 Pair (catdata.Pair)1 OplJavaInst (catdata.opl.OplExp.OplJavaInst)1 OplMapping (catdata.opl.OplExp.OplMapping)1 OplSetTrans (catdata.opl.OplExp.OplSetTrans)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Tuple3 (org.jparsec.functors.Tuple3)1 Tuple5 (org.jparsec.functors.Tuple5)1