Search in sources :

Example 1 with OplSetTrans

use of catdata.opl.OplExp.OplSetTrans 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 OplSetTrans

use of catdata.opl.OplExp.OplSetTrans in project fql by CategoricalData.

the class OplParser method toTrans.

private static OplExp toTrans(Object c) {
    Tuple3 t = (Tuple3) c;
    if (!t.a.toString().equals("transform")) {
        throw new RuntimeException();
    }
    Map<String, Map<String, String>> map = new HashMap<>();
    Tuple3 tb = (Tuple3) t.b;
    List<Tuple5> l = (List<Tuple5>) tb.b;
    for (Tuple5 x : l) {
        String name = (String) x.a;
        List<Tuple5> y = (List<Tuple5>) x.d;
        Map<String, String> m = new HashMap<>();
        for (Tuple5 z : y) {
            String xx = (String) z.b;
            String yy = (String) z.d;
            if (m.containsKey(xx)) {
                throw new DoNotIgnore("Duplicate argument: " + xx);
            }
            m.put(xx, yy);
        }
        if (map.containsKey(name)) {
            throw new DoNotIgnore("Duplicate sort: " + name);
        }
        map.put(name, m);
    }
    Tuple4 tc = (Tuple4) t.c;
    return new OplSetTrans(map, (String) tc.b, (String) tc.d);
}
Also used : OplSetTrans(catdata.opl.OplExp.OplSetTrans) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Tuple4(org.jparsec.functors.Tuple4) 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)

Aggregations

OplSetTrans (catdata.opl.OplExp.OplSetTrans)2 OplMapping (catdata.opl.OplExp.OplMapping)1 OplSetInst (catdata.opl.OplExp.OplSetInst)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Tuple3 (org.jparsec.functors.Tuple3)1 Tuple4 (org.jparsec.functors.Tuple4)1 Tuple5 (org.jparsec.functors.Tuple5)1