use of catdata.fpql.XExp.XSchema in project fql by CategoricalData.
the class XEasikToFQL method translate1.
private static String translate1(Node sketch) {
List<String> ns = new LinkedList<>();
List<Triple<String, String, String>> es = new LinkedList<>();
List<Pair<List<String>, List<String>>> eqs = new LinkedList<>();
NodeList l = sketch.getChildNodes();
for (int temp = 0; temp < l.getLength(); temp++) {
Node n = l.item(temp);
NodeList j = n.getChildNodes();
for (int temp2 = 0; temp2 < j.getLength(); temp2++) {
Node m = j.item(temp2);
if (m.getNodeName().equals("entity")) {
String nodeName = m.getAttributes().getNamedItem("name").getTextContent();
ns.add(nodeName);
NodeList k = m.getChildNodes();
for (int temp3 = 0; temp3 < k.getLength(); temp3++) {
Node w = k.item(temp3);
if (w.getNodeName().equals("attribute")) {
String attName = w.getAttributes().getNamedItem("name").getTextContent();
es.add(new Triple<>(nodeName + "_" + attName.replace(" ", "_"), nodeName, "dom"));
}
}
} else if (m.getNodeName().equals("edge")) {
es.add(new Triple<>(m.getAttributes().getNamedItem("id").getTextContent(), m.getAttributes().getNamedItem("source").getTextContent(), m.getAttributes().getNamedItem("target").getTextContent()));
} else if (m.getNodeName().equals("commutativediagram")) {
NodeList k = m.getChildNodes();
Node w1 = null;
Node w2 = null;
for (int temp4 = 0; temp4 < k.getLength(); temp4++) {
Node wX = k.item(temp4);
if (wX.getNodeName().equals("path") && w1 == null) {
w1 = wX;
} else if (wX.getNodeName().equals("path") && w2 == null) {
w2 = wX;
}
}
if (w1 == null || w2 == null) {
throw new RuntimeException("Easik to FQL internal error");
}
String cod1 = w1.getAttributes().getNamedItem("domain").getTextContent();
String cod2 = w2.getAttributes().getNamedItem("domain").getTextContent();
List<String> lhs = new LinkedList<>();
List<String> rhs = new LinkedList<>();
lhs.add(cod1);
rhs.add(cod2);
NodeList lhsX = w1.getChildNodes();
for (int temp3 = 0; temp3 < lhsX.getLength(); temp3++) {
if (!lhsX.item(temp3).getNodeName().equals("edgeref")) {
continue;
}
String toAdd = lhsX.item(temp3).getAttributes().getNamedItem("id").getTextContent();
lhs.add(toAdd);
}
NodeList rhsX = w2.getChildNodes();
for (int temp3 = 0; temp3 < rhsX.getLength(); temp3++) {
if (!rhsX.item(temp3).getNodeName().equals("edgeref")) {
continue;
}
String toAdd = rhsX.item(temp3).getAttributes().getNamedItem("id").getTextContent();
rhs.add(toAdd);
}
eqs.add(new Pair<>(lhs, rhs));
}
}
}
XSchema sch = new XSchema(ns, es, eqs);
return sketch.getAttributes().getNamedItem("name").getTextContent().replace(" ", "_") + " = " + sch;
}
use of catdata.fpql.XExp.XSchema in project fql by CategoricalData.
the class OplParser method toCatConst.
public static XSchema toCatConst(Object y) {
List<String> nodes = new LinkedList<>();
List<Triple<String, String, String>> arrows = new LinkedList<>();
List<Pair<List<String>, List<String>>> eqs = new LinkedList<>();
Tuple3 s = (Tuple3) y;
Tuple3 nodes0 = (Tuple3) s.a;
Tuple3 arrows0 = (Tuple3) s.b;
Tuple3 eqs0 = (Tuple3) s.c;
List nodes1 = (List) nodes0.b;
List arrows1 = (List) arrows0.b;
List eqs1 = (List) eqs0.b;
for (Object o : nodes1) {
nodes.add((String) o);
}
for (Object o : arrows1) {
Tuple5 x = (Tuple5) o;
arrows.add(new Triple<>((String) x.a, (String) x.c, (String) x.e));
}
for (Object o : eqs1) {
Tuple3 x = (Tuple3) o;
List<String> l1 = (List<String>) x.a;
List<String> l2 = (List<String>) x.c;
eqs.add(new Pair<>(l1, l2));
}
XSchema c = new XSchema(nodes, arrows, eqs);
return c;
}
use of catdata.fpql.XExp.XSchema in project fql by CategoricalData.
the class XNeo4jToFQL method trans0.
private static String trans0(Map<String, Map<String, Object>> properties, Map<String, Set<Pair<String, String>>> edges) {
labelForProperty(properties);
Map<String, Set<String>> pfl = propsForLabels(properties);
Map<String, Pair<String, String>> sfe = sortsForEges(edges, properties);
XSchema xxx = toSchema(pfl, sfe);
XInst yyy = toInst(properties, edges);
return "dom : type\n" + Util.sep(adom(properties), " ") + " : dom\n\nS = " + xxx + "\n\nI = " + yyy + " : S\n";
}
use of catdata.fpql.XExp.XSchema in project fql by CategoricalData.
the class XNeo4jToFQL method toSchema.
private static XSchema toSchema(Map<String, Set<String>> propsForLabels, Map<String, Pair<String, String>> sortsForEdges) {
List<String> labels = new LinkedList<>(propsForLabels.keySet());
List<Triple<String, String, String>> arrows = new LinkedList<>();
for (String l : labels) {
for (String p : propsForLabels.get(l)) {
arrows.add(new Triple<>(p, l, "dom"));
}
}
for (String e : sortsForEdges.keySet()) {
Pair<String, String> p = sortsForEdges.get(e);
arrows.add(new Triple<>(e, p.first, p.second));
}
XSchema ret = new XSchema(labels, arrows, new LinkedList<>());
return ret;
}
use of catdata.fpql.XExp.XSchema in project fql by CategoricalData.
the class XOps method visit.
@Override
public XObject visit(XProgram env, XSOED e) {
XExp src0 = env.exps.get(e.src);
if (src0 == null) {
throw new RuntimeException("Missing: " + e.src);
}
if (!(src0 instanceof XSchema)) {
throw new RuntimeException("Not a schema: " + e.src);
}
XSchema src = (XSchema) src0;
XCtx src1 = (XCtx) ENV.objs.get(e.src);
XExp dst0 = env.exps.get(e.dst);
if (dst0 == null) {
throw new RuntimeException("Missing: " + e.dst);
}
if (!(dst0 instanceof XSchema)) {
throw new RuntimeException("Not a schema: " + e.dst);
}
XSchema dst = (XSchema) dst0;
XCtx dst1 = (XCtx) ENV.objs.get(e.dst);
XObject I0 = ENV.objs.get(e.I);
if (I0 == null) {
throw new RuntimeException("Missing: " + e.I);
}
if (!(I0 instanceof XCtx)) {
throw new RuntimeException("Not an instance: " + e.I);
}
XCtx I = (XCtx) I0;
if (!src1.equals(I.schema)) {
throw new RuntimeException("Instance schema does not match source");
}
List<String> nodes = new LinkedList<>();
List<Triple<String, String, String>> arrows = new LinkedList<>();
List<Pair<List<String>, List<String>>> eqs = new LinkedList<>();
Map em_s = new HashMap();
Map em_t = new HashMap();
nodes.addAll(src.nodes);
nodes.addAll(dst.nodes);
arrows.addAll(src.arrows);
arrows.addAll(dst.arrows);
arrows.addAll(e.es);
eqs.addAll(src.eqs);
eqs.addAll(dst.eqs);
for (FOED k : e.as) {
for (Pair<List<String>, List<String>> v : k.eqs) {
List<String> l = new LinkedList<>(v.first);
List<String> r = new LinkedList<>(v.second);
l.removeAll(Util.singList(k.a));
r.removeAll(Util.singList(k.a));
eqs.add(new Pair<>(l, r));
}
}
for (String n : src.nodes) {
em_s.put(n, Util.singList(n));
}
for (String n : dst.nodes) {
em_t.put(n, Util.singList(n));
}
for (Triple<String, String, String> n : src.arrows) {
em_s.put(n.first, Util.singList(n.first));
}
for (Triple<String, String, String> n : dst.arrows) {
em_t.put(n.first, Util.singList(n.first));
}
for (Object n : src1.allTerms()) {
if (em_s.containsKey(n)) {
continue;
}
em_s.put(n, Util.singList(n));
}
for (Object n : dst1.allTerms()) {
if (em_t.containsKey(n)) {
continue;
}
em_t.put(n, Util.singList(n));
}
XSchema X = new XSchema(nodes, arrows, eqs);
XCtx Y = (XCtx) X.accept(env, this);
XMapping F = new XMapping(src1, Y, em_s, "mapping");
XMapping G = new XMapping(dst1, Y, em_t, "mapping");
XCtx J = F.apply0(I);
return G.delta(J);
}
Aggregations