Search in sources :

Example 6 with OplSchema

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

the class OplParser method toSchema.

private static OplExp toSchema(Object o) {
    Tuple4 t = (Tuple4) o;
    org.jparsec.functors.Pair e = (org.jparsec.functors.Pair) t.b;
    String yyy = (String) t.d;
    List<String> symbols0 = (List<String>) e.b;
    return new OplSchema<String, String, String>(yyy, new HashSet<>(symbols0));
}
Also used : Tuple4(org.jparsec.functors.Tuple4) OplSchema(catdata.opl.OplExp.OplSchema) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair)

Example 7 with OplSchema

use of catdata.opl.OplExp.OplSchema 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 8 with OplSchema

use of catdata.opl.OplExp.OplSchema 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 9 with OplSchema

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

the class OplOps method visit.

@Override
public OplObject visit(Program<OplExp> env, OplQuery e) {
    OplSchema I, J;
    OplObject I0 = ENV.get(e.src_e);
    if (I0 instanceof OplSchema) {
        I = (OplSchema) I0;
    } else {
        throw new RuntimeException("Not a schema: " + e.src_e);
    }
    OplObject J0 = ENV.get(e.dst_e);
    if (J0 instanceof OplSchema) {
        J = (OplSchema) J0;
    } else {
        throw new RuntimeException("Not a schema: " + e.dst_e);
    }
    e.validate(I, J);
    return e;
}
Also used : OplSchema(catdata.opl.OplExp.OplSchema)

Example 10 with OplSchema

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

the class OplOps method visit.

@Override
public OplObject visit(Program<OplExp> env, OplMapping e) {
    OplObject src = ENV.get(e.src0);
    OplObject dst = ENV.get(e.dst0);
    if (src instanceof OplSig && dst instanceof OplSig) {
        OplSig src0 = (OplSig) src;
        OplSig dst0 = (OplSig) dst;
        for (Object k2 : e.imports) {
            String k = (String) k2;
            OplExp o = env.exps.get(k);
            if (!(o instanceof OplMapping)) {
                throw new RuntimeException("Not a mapping: " + k);
            }
            OplMapping a = (OplMapping) o;
            Util.putAllSafely(e.sorts, a.sorts);
            Util.putAllSafely(e.symbols, a.symbols);
        }
        e.validate(src0, dst0);
        return e;
    } else if (src instanceof OplSchema && dst instanceof OplSchema) {
        OplSchema src0 = (OplSchema) src;
        OplSchema dst0 = (OplSchema) dst;
        for (Object k2 : e.imports) {
            String k = (String) k2;
            OplExp o = (OplExp) ENV.get(k);
            if (!(o instanceof OplTyMapping)) {
                throw new RuntimeException("Not a typed mapping: " + k + o.getClass());
            }
            OplTyMapping a = (OplTyMapping) o;
            Util.putAllSafely(e.sorts, a.m.sorts);
            Util.putAllSafely(e.symbols, a.m.symbols);
        }
        // e.validate(src0.projEA(), dst0.projEA());
        OplTyMapping ret = new OplTyMapping<>(e.src0, e.dst0, src0, dst0, e);
        return ret;
    }
    throw new RuntimeException("Source or Target is not a theory/schema in " + e);
}
Also used : OplSchema(catdata.opl.OplExp.OplSchema) OplSig(catdata.opl.OplExp.OplSig) OplMapping(catdata.opl.OplExp.OplMapping) OplTyMapping(catdata.opl.OplExp.OplTyMapping)

Aggregations

OplSchema (catdata.opl.OplExp.OplSchema)12 OplPres (catdata.opl.OplExp.OplPres)7 OplSig (catdata.opl.OplExp.OplSig)7 LinkedList (java.util.LinkedList)6 Pair (catdata.Pair)5 OplInst (catdata.opl.OplExp.OplInst)5 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 Triple (catdata.Triple)4 Chc (catdata.Chc)3 OplInst0 (catdata.opl.OplExp.OplInst0)3 List (java.util.List)3 Map (java.util.Map)3 OplGround (catdata.opl.OplExp.OplGround)2 OplJavaInst (catdata.opl.OplExp.OplJavaInst)2 OplMapping (catdata.opl.OplExp.OplMapping)2 OplSCHEMA0 (catdata.opl.OplExp.OplSCHEMA0)2 SqlColumn (catdata.sql.SqlColumn)2 SqlForeignKey (catdata.sql.SqlForeignKey)2 SqlTable (catdata.sql.SqlTable)2