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));
}
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;
}
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);
}
}
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;
}
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);
}
Aggregations