Search in sources :

Example 11 with OplSig

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

the class OplOps method visit.

@Override
public OplObject visit(Program<OplExp> env, OplSetInst e) {
    OplObject o = ENV.get(e.sig);
    if (!(o instanceof OplSig)) {
        throw new RuntimeException("Not a theory: " + o + " . is " + o.getClass());
    }
    OplSig s = (OplSig) o;
    e.validate(s);
    return e;
}
Also used : OplSig(catdata.opl.OplExp.OplSig)

Example 12 with OplSig

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

the class OplOps method visit.

@Override
public OplObject visit(Program<OplExp> env, OplSCHEMA0 e) {
    OplObject t0 = ENV.get(e.typeSide);
    if (!(t0 instanceof OplSig)) {
        throw new RuntimeException("Not a theory: " + e.typeSide);
    }
    OplSig t = (OplSig) t0;
    if (!t.implications.isEmpty()) {
        throw new RuntimeException("Can't use implications with SCHEMA");
    }
    OplSchema ret = new OplSchema("?", e.entities);
    ret.forSchema0 = e.typeSide;
    Map prec = new HashMap();
    prec.putAll(t.prec);
    prec.putAll(e.prec);
    Set sorts = new HashSet();
    sorts.addAll(t.sorts);
    sorts.addAll(e.entities);
    if (!Collections.disjoint(t.sorts, e.entities)) {
        throw new RuntimeException("Schema has an entity that is also a type side sort");
    }
    Map symbols = new HashMap();
    symbols.putAll(t.symbols);
    symbols.putAll(e.attrs);
    symbols.putAll(e.edges);
    if (!Collections.disjoint(t.symbols.keySet(), e.attrs.keySet())) {
        throw new RuntimeException("Schema has an attribute that is also a type side symbol");
    }
    if (!Collections.disjoint(t.symbols.keySet(), e.edges.keySet())) {
        throw new RuntimeException("Schema has an attribute that is also a type side symbol");
    }
    List equations = new LinkedList();
    equations.addAll(t.equations);
    equations.addAll(e.pathEqs);
    equations.addAll(e.obsEqs);
    for (Object k2 : e.imports) {
        String k = (String) k2;
        OplObject o = ENV.get(k);
        if (!(o instanceof OplSchema)) {
            throw new RuntimeException("Not a SCHEMA: " + k);
        }
        OplSchema a = (OplSchema) o;
        sorts.addAll(a.sig.sorts);
        Util.putAllSafely(symbols, a.sig.symbols);
        equations.addAll(a.sig.equations);
        e.entities.addAll(a.entities);
        prec.putAll(a.sig.prec);
    // Util.putAllSafely(prec, a.sig.prec);
    }
    OplSig sig = new OplSig(t.fr, prec, sorts, symbols, equations);
    sig.validate();
    ret.validate(sig);
    e.validate(sig);
    return ret;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) OplSchema(catdata.opl.OplExp.OplSchema) HashMap(java.util.HashMap) List(java.util.List) LinkedList(java.util.LinkedList) OplSig(catdata.opl.OplExp.OplSig) Map(java.util.Map) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Example 13 with OplSig

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

the class OplOps method visit.

@Override
public OplObject visit(Program<OplExp> env, OplPres e) {
    OplObject i = ENV.get(e.S);
    if (i instanceof OplSig) {
        OplSig S = (OplSig) i;
        OplPres ret = OplPres.OplPres0(e.prec, e.S, S, e.gens, e.equations);
        ret.toSig();
        return ret;
    } else if (i instanceof OplSchema) {
        OplSchema S = (OplSchema) i;
        OplPres ret = OplPres.OplPres0(e.prec, e.S, S.sig, e.gens, e.equations);
        ret.toSig();
        return ret;
    } else {
        throw new RuntimeException("Not a presentation or schema: " + e.S);
    }
}
Also used : OplSchema(catdata.opl.OplExp.OplSchema) OplPres(catdata.opl.OplExp.OplPres) OplSig(catdata.opl.OplExp.OplSig)

Example 14 with OplSig

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

the class OplOps method visit.

@Override
public OplObject visit(Program<OplExp> env, OplSat e) {
    OplObject i = ENV.get(e.I);
    if (i instanceof OplPres) {
        OplPres S = (OplPres) i;
        OplObject ob = OplSat.saturate(S);
        return ob;
    }
    if (i instanceof OplSig) {
        OplSig S = (OplSig) i;
        OplObject ob = S.saturate(e.I);
        return ob;
    }
    throw new RuntimeException("Not a presentation or theory");
}
Also used : OplPres(catdata.opl.OplExp.OplPres) OplSig(catdata.opl.OplExp.OplSig)

Example 15 with OplSig

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

OplSig (catdata.opl.OplExp.OplSig)19 HashMap (java.util.HashMap)9 LinkedList (java.util.LinkedList)9 Pair (catdata.Pair)8 Triple (catdata.Triple)7 OplPres (catdata.opl.OplExp.OplPres)7 OplSchema (catdata.opl.OplExp.OplSchema)7 HashSet (java.util.HashSet)7 List (java.util.List)6 Map (java.util.Map)6 Chc (catdata.Chc)4 OplInst (catdata.opl.OplExp.OplInst)4 OplInst0 (catdata.opl.OplExp.OplInst0)4 OplSCHEMA0 (catdata.opl.OplExp.OplSCHEMA0)4 Set (java.util.Set)4 Util (catdata.Util)3 OplMapping (catdata.opl.OplExp.OplMapping)3 OplSetInst (catdata.opl.OplExp.OplSetInst)3 LinkedHashMap (java.util.LinkedHashMap)3 Function (java.util.function.Function)3