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