Search in sources :

Example 6 with RawTerm

use of catdata.aql.RawTerm in project fql by CategoricalData.

the class CombinatorParser method edExpRaw.

private static Parser<EdExpRaw> edExpRaw() {
    Parser<List<catdata.Pair<LocStr, String>>> as = Parsers.tuple(token("forall"), env(ident, ":")).map(x -> x.b).optional();
    Parser<catdata.Pair<List<catdata.Pair<LocStr, String>>, Boolean>> es = Parsers.tuple(token("exists"), token("unique").optional(), env(ident, ":")).map(x -> new catdata.Pair<>(x.c, x.b != null)).optional();
    Parser<catdata.Pair<Integer, catdata.Pair<RawTerm, RawTerm>>> eq = Parsers.tuple(Parsers.INDEX, Parsers.tuple(term(), token("="), term()).map(x -> new catdata.Pair<>(x.a, x.c))).map(x -> new catdata.Pair<>(x.a, x.b));
    Parser<List<catdata.Pair<Integer, catdata.Pair<RawTerm, RawTerm>>>> eqs = Parsers.tuple(token("where"), eq.many()).map(x -> x.b).optional();
    Parser<EdExpRaw> ret = Parsers.tuple(as, eqs, token("->"), es, eqs).map(x -> new EdExpRaw(Util.newIfNull(x.a), Util.newIfNull(x.b), x.d == null ? new LinkedList<>() : x.d.first, Util.newIfNull(x.e), x.d == null ? false : x.d.second));
    return ret;
}
Also used : AqlOptions(catdata.aql.AqlOptions) PragmaExpProc(catdata.aql.exp.PragmaExp.PragmaExpProc) Scanners(org.jparsec.Scanners) InstExpDelta(catdata.aql.exp.InstExp.InstExpDelta) GraphExpVar(catdata.aql.exp.GraphExp.GraphExpVar) GraphExpRaw(catdata.aql.exp.GraphExp.GraphExpRaw) StringLiteral(org.jparsec.Terminals.StringLiteral) EdsExpVar(catdata.aql.exp.EdsExp.EdsExpVar) SchExpInst(catdata.aql.exp.SchExp.SchExpInst) Pair(org.jparsec.functors.Pair) TransExpSigmaDeltaCounit(catdata.aql.exp.TransExp.TransExpSigmaDeltaCounit) QueryExpCompose(catdata.aql.exp.QueryExp.QueryExpCompose) PragmaExpConsistent(catdata.aql.exp.PragmaExp.PragmaExpConsistent) ParseException(catdata.ParseException) Quad(catdata.Quad) PragmaExpSql(catdata.aql.exp.PragmaExp.PragmaExpSql) SchExpVar(catdata.aql.exp.SchExp.SchExpVar) Parser(org.jparsec.Parser) InstExpColim(catdata.aql.exp.InstExp.InstExpColim) QueryExpDeltaCoEval(catdata.aql.exp.QueryExp.QueryExpDeltaCoEval) IntegerLiteral(org.jparsec.Terminals.IntegerLiteral) Program(catdata.Program) Triple(catdata.Triple) PragmaExpJs(catdata.aql.exp.PragmaExp.PragmaExpJs) PragmaExpCheck(catdata.aql.exp.PragmaExp.PragmaExpCheck) Ty(catdata.aql.exp.TyExpRaw.Ty) Terminals(org.jparsec.Terminals) PragmaExpMatch(catdata.aql.exp.PragmaExp.PragmaExpMatch) MapExpVar(catdata.aql.exp.MapExp.MapExpVar) TransExpDistinct(catdata.aql.exp.TransExp.TransExpDistinct) TyExpEmpty(catdata.aql.exp.TyExp.TyExpEmpty) TransExpVar(catdata.aql.exp.TransExp.TransExpVar) ColimSchExpQuotient(catdata.aql.exp.ColimSchExp.ColimSchExpQuotient) Token(org.jparsec.Token) PragmaExpToCsvInst(catdata.aql.exp.PragmaExp.PragmaExpToCsvInst) MapExpComp(catdata.aql.exp.MapExp.MapExpComp) InstExpCoEq(catdata.aql.exp.InstExp.InstExpCoEq) InstExpCod(catdata.aql.exp.InstExp.InstExpCod) InstExpCoProdFull(catdata.aql.exp.InstExp.InstExpCoProdFull) Att(catdata.aql.exp.SchExpRaw.Att) TransExpCoEvalEvalCoUnit(catdata.aql.exp.TransExp.TransExpCoEvalEvalCoUnit) TransExpDelta(catdata.aql.exp.TransExp.TransExpDelta) SchExpEmpty(catdata.aql.exp.SchExp.SchExpEmpty) ParserException(org.jparsec.error.ParserException) PragmaExpToJdbcTrans(catdata.aql.exp.PragmaExp.PragmaExpToJdbcTrans) Trans(catdata.aql.exp.QueryExpRaw.Trans) SchExpCod(catdata.aql.exp.SchExp.SchExpCod) InstExpChase(catdata.aql.exp.InstExp.InstExpChase) PragmaExpToJdbcQuery(catdata.aql.exp.PragmaExp.PragmaExpToJdbcQuery) InstExpFrozen(catdata.aql.exp.InstExp.InstExpFrozen) Sym(catdata.aql.exp.TyExpRaw.Sym) Tuple3(org.jparsec.functors.Tuple3) PragmaExpVar(catdata.aql.exp.PragmaExp.PragmaExpVar) Tuple4(org.jparsec.functors.Tuple4) Tuple5(org.jparsec.functors.Tuple5) InstExpAnonymize(catdata.aql.exp.InstExp.InstExpAnonymize) InstExpSigma(catdata.aql.exp.InstExp.InstExpSigma) TransExpEval(catdata.aql.exp.TransExp.TransExpEval) InstExpCoProdSigma(catdata.aql.exp.InstExp.InstExpCoProdSigma) InstExpVar(catdata.aql.exp.InstExp.InstExpVar) PreBlock(catdata.aql.exp.QueryExpRaw.PreBlock) TransExpSigmaDeltaUnit(catdata.aql.exp.TransExp.TransExpSigmaDeltaUnit) EdExpRaw(catdata.aql.exp.EdsExpRaw.EdExpRaw) Collectors(java.util.stream.Collectors) List(java.util.List) InstExpDom(catdata.aql.exp.InstExp.InstExpDom) Parsers(org.jparsec.Parsers) InstExpCoEval(catdata.aql.exp.InstExp.InstExpCoEval) TransExpSigma(catdata.aql.exp.TransExp.TransExpSigma) TransExpId(catdata.aql.exp.TransExp.TransExpId) MapExpId(catdata.aql.exp.MapExp.MapExpId) RawTerm(catdata.aql.RawTerm) En(catdata.aql.exp.SchExpRaw.En) InstExpSigmaChase(catdata.aql.exp.InstExp.InstExpSigmaChase) HashMap(java.util.HashMap) QueryExpDeltaEval(catdata.aql.exp.QueryExp.QueryExpDeltaEval) InstExpPi(catdata.aql.exp.InstExp.InstExpPi) ColimSchExpVar(catdata.aql.exp.ColimSchExp.ColimSchExpVar) ColimSchExpRaw(catdata.aql.exp.ColimSchExp.ColimSchExpRaw) PragmaExpLoadJars(catdata.aql.exp.PragmaExp.PragmaExpLoadJars) LinkedList(java.util.LinkedList) PragmaExpToCsvTrans(catdata.aql.exp.PragmaExp.PragmaExpToCsvTrans) Fk(catdata.aql.exp.SchExpRaw.Fk) TyExpSch(catdata.aql.exp.TyExp.TyExpSch) Reference(org.jparsec.Parser.Reference) ColimSchExpWrap(catdata.aql.exp.ColimSchExp.ColimSchExpWrap) Util(catdata.Util) QueryExpId(catdata.aql.exp.QueryExp.QueryExpId) QueryExpVar(catdata.aql.exp.QueryExp.QueryExpVar) InstExpEval(catdata.aql.exp.InstExp.InstExpEval) TransExpCoEval(catdata.aql.exp.TransExp.TransExpCoEval) TyExpVar(catdata.aql.exp.TyExp.TyExpVar) Identifier(org.jparsec.Terminals.Identifier) InstExpDistinct(catdata.aql.exp.InstExp.InstExpDistinct) PragmaExpToJdbcInst(catdata.aql.exp.PragmaExp.PragmaExpToJdbcInst) TransExpCoEvalEvalUnit(catdata.aql.exp.TransExp.TransExpCoEvalEvalUnit) Collections(java.util.Collections) InstExpEmpty(catdata.aql.exp.InstExp.InstExpEmpty) EdExpRaw(catdata.aql.exp.EdsExpRaw.EdExpRaw) RawTerm(catdata.aql.RawTerm) List(java.util.List) LinkedList(java.util.LinkedList) Pair(org.jparsec.functors.Pair)

Example 7 with RawTerm

use of catdata.aql.RawTerm in project fql by CategoricalData.

the class CombinatorParser method schExpRaw.

private static Parser<SchExpRaw> schExpRaw() {
    Parser<List<LocStr>> entities = Parsers.tuple(token("entities"), locstr.many()).map(x -> x.b);
    Parser<Pair<Token, List<Tuple5<List<LocStr>, Token, String, Token, String>>>> fks = Parsers.tuple(token("foreign_keys"), Parsers.tuple(locstr.many1(), token(":"), ident, token("->"), ident).many());
    Parser<List<catdata.Pair<LocStr, catdata.Pair<String, String>>>> fks0 = fks.map(x -> {
        List<catdata.Pair<LocStr, catdata.Pair<String, String>>> ret = new LinkedList<>();
        for (Tuple5<List<LocStr>, Token, String, Token, String> a : x.b) {
            for (LocStr b : a.a) {
                ret.add(new catdata.Pair<>(b, new catdata.Pair<>(a.c, a.e)));
            }
        }
        return ret;
    });
    Parser<Pair<Token, List<Tuple5<List<LocStr>, Token, String, Token, String>>>> atts = Parsers.tuple(token("attributes"), Parsers.tuple(locstr.many1(), token(":"), ident, token("->"), ident).many());
    Parser<List<catdata.Pair<LocStr, catdata.Pair<String, String>>>> atts0 = atts.map(x -> {
        List<catdata.Pair<LocStr, catdata.Pair<String, String>>> ret = new LinkedList<>();
        for (Tuple5<List<LocStr>, Token, String, Token, String> a : x.b) {
            for (LocStr b : a.a) {
                ret.add(new catdata.Pair<>(b, new catdata.Pair<>(a.c, a.e)));
            }
        }
        return ret;
    });
    Parser<catdata.Pair<Integer, catdata.Pair<List<String>, List<String>>>> p_eq = Parsers.tuple(Parsers.INDEX, Parsers.tuple(ident.sepBy(token(".")), token("="), ident.sepBy(token(".")))).map(x -> new catdata.Pair<>(x.a, new catdata.Pair<>(x.b.a, x.b.c)));
    Parser<Pair<Token, List<catdata.Pair<Integer, catdata.Pair<List<String>, List<String>>>>>> p_eqs = Parsers.tuple(token("path_equations"), p_eq.many());
    Parser<List<catdata.Pair<Integer, catdata.Pair<List<String>, List<String>>>>> p_eqs0 = p_eqs.map(x -> x.b);
    Parser<catdata.Pair<Integer, Quad<String, String, RawTerm, RawTerm>>> o_eq_from_p_eq = p_eq.map(x -> new catdata.Pair<>(x.first, new Quad<>("_x", null, RawTerm.fold(x.second.first, "_x"), RawTerm.fold(x.second.second, "_x"))));
    Parser<catdata.Pair<Integer, Quad<String, String, RawTerm, RawTerm>>> o_eq_old = Parsers.tuple(Parsers.INDEX, Parsers.tuple(token("forall"), ident, Parsers.tuple(token(":"), ident).optional().followedBy(token(".")), term().followedBy(token("=")), term())).map(x -> new catdata.Pair<>(x.a, new Quad<>(x.b.b, x.b.c == null ? null : x.b.c.b, x.b.d, x.b.e)));
    Parser<catdata.Pair<Integer, Quad<String, String, RawTerm, RawTerm>>> o_eq = Parsers.or(o_eq_old, o_eq_from_p_eq);
    Parser<Pair<Token, List<catdata.Pair<Integer, Quad<String, String, RawTerm, RawTerm>>>>> o_eqs = Parsers.tuple(token("observation_equations"), o_eq.many());
    Parser<List<catdata.Pair<Integer, Quad<String, String, RawTerm, RawTerm>>>> o_eqs0 = o_eqs.map(x -> x.b);
    Parser<Tuple4<List<LocStr>, List<LocStr>, List<catdata.Pair<LocStr, catdata.Pair<String, String>>>, List<catdata.Pair<Integer, catdata.Pair<List<String>, List<String>>>>>> pa = Parsers.tuple(imports, entities.optional(), fks0.optional(), p_eqs0.optional());
    Parser<Tuple3<List<catdata.Pair<LocStr, catdata.Pair<String, String>>>, List<catdata.Pair<Integer, Quad<String, String, RawTerm, RawTerm>>>, List<catdata.Pair<String, String>>>> pb = Parsers.tuple(atts0.optional(), o_eqs0.optional(), options);
    Parser<Tuple4<Token, Token, TyExp<?, ?>, Token>> l = Parsers.tuple(token("literal"), token(":"), ty_ref.lazy(), // .map(x -> x.c);
    token("{"));
    // needs tyexp
    Parser<SchExpRaw> ret = Parsers.tuple(l, pa, pb, token("}")).map(x -> new SchExpRaw((TyExp<Ty, Sym>) x.a.c, x.b.a, Util.newIfNull(x.b.b), Util.newIfNull(x.b.c), Util.newIfNull(x.b.d), Util.newIfNull(x.c.a), Util.newIfNull(x.c.b), x.c.c));
    return ret;
}
Also used : Quad(catdata.Quad) Token(org.jparsec.Token) List(java.util.List) LinkedList(java.util.LinkedList) Pair(org.jparsec.functors.Pair) RawTerm(catdata.aql.RawTerm) LinkedList(java.util.LinkedList) Tuple4(org.jparsec.functors.Tuple4) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) ColimSchExpRaw(catdata.aql.exp.ColimSchExp.ColimSchExpRaw)

Example 8 with RawTerm

use of catdata.aql.RawTerm in project fql by CategoricalData.

the class EasikAql method translate1.

private static Pair<SchExp<?, ?, ?, ?, ?>, List<Pair<String, EdsExpRaw>>> translate1(Node sketch, Set<String> used, Set<String> warnings, String sname) {
    List<String> ens = new LinkedList<>();
    List<Pair<String, Pair<String, Ty>>> atts = new LinkedList<>();
    List<Pair<String, Pair<String, String>>> fks = new LinkedList<>();
    List<Pair<List<String>, List<String>>> eqs = new LinkedList<>();
    // there shouldn't be observation equations in easik
    // List<Quad<String, String, RawTerm, RawTerm>> eqs2 = new
    // LinkedList<>();
    List<Pair<String, EdsExpRaw>> edsExps = 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 = safe(m.getAttributes().getNamedItem("name").getTextContent());
                ens.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 = safe(w.getAttributes().getNamedItem("name").getTextContent());
                        String tyName = w.getAttributes().getNamedItem("attributeTypeClass").getTextContent();
                        used.add(tyName);
                        atts.add(new Pair<>(nodeName + "_" + attName.replace(" ", "_"), new Pair<>(nodeName, new Ty(easikTypeToString(tyName)))));
                    }
                }
            } else if (m.getNodeName().equals("edge")) {
                String ename = safe(m.getAttributes().getNamedItem("id").getTextContent());
                String esrc = safe(m.getAttributes().getNamedItem("source").getTextContent());
                fks.add(new Pair<>(ename, new Pair<>(esrc, safe(m.getAttributes().getNamedItem("target").getTextContent()))));
                if (m.getAttributes().getNamedItem("type").getTextContent().equals("injective")) {
                    List<EdExpRaw> eds = new LinkedList<>();
                    List<Pair<String, String>> As = new LinkedList<>();
                    As.add(new Pair<>("x", esrc));
                    As.add(new Pair<>("y", esrc));
                    List<Pair<RawTerm, RawTerm>> Aeqs = new LinkedList<>();
                    Aeqs.add(new Pair<>(new RawTerm(ename, Util.singList(new RawTerm("x"))), new RawTerm(ename, Util.singList(new RawTerm("y")))));
                    List<Pair<String, String>> Es = new LinkedList<>();
                    List<Pair<RawTerm, RawTerm>> Eeqs = new LinkedList<>();
                    Eeqs.add(new Pair<>(new RawTerm("x"), new RawTerm("y")));
                    EdExpRaw ed = new EdExpRaw(As, Aeqs, Es, Eeqs, false, null);
                    eds.add(ed);
                    edsExps.add(new Pair<>("injective", new EdsExpRaw(new SchExpVar(sname), new LinkedList<>(), eds, null)));
                }
                if (m.getAttributes().getNamedItem("type").getTextContent().equals("partial")) {
                    warnings.add("Not exported - partial edges.  Their AQL semantics is unclear");
                }
            } else if (m.getNodeName().equals("uniqueKey")) {
                String esrc = safe(m.getAttributes().getNamedItem("noderef").getTextContent());
                List<String> atts0 = new LinkedList<>();
                for (int w = 0; w < m.getChildNodes().getLength(); w++) {
                    Node node = m.getChildNodes().item(w);
                    if (!node.getNodeName().equals("attref")) {
                        continue;
                    }
                    String att = safe(node.getAttributes().getNamedItem("name").getTextContent());
                    atts0.add(att);
                }
                List<EdExpRaw> eds = new LinkedList<>();
                List<Pair<String, String>> As = new LinkedList<>();
                As.add(new Pair<>("x", esrc));
                As.add(new Pair<>("y", esrc));
                List<Pair<RawTerm, RawTerm>> Aeqs = new LinkedList<>();
                for (String att : atts0) {
                    Aeqs.add(new Pair<>(new RawTerm(esrc + "_" + att, Util.singList(new RawTerm("x"))), new RawTerm(esrc + "_" + att, Util.singList(new RawTerm("y")))));
                }
                List<Pair<String, String>> Es = new LinkedList<>();
                List<Pair<RawTerm, RawTerm>> Eeqs = new LinkedList<>();
                Eeqs.add(new Pair<>(new RawTerm("x"), new RawTerm("y")));
                EdExpRaw ed = new EdExpRaw(As, Aeqs, Es, Eeqs, false, null);
                eds.add(ed);
                edsExps.add(new Pair<>("key", new EdsExpRaw(new SchExpVar(sname), new LinkedList<>(), eds, null)));
            } 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 AQL internal error");
                }
                String cod1 = safe(w1.getAttributes().getNamedItem("domain").getTextContent());
                String cod2 = safe(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 = safe(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 = safe(rhsX.item(temp3).getAttributes().getNamedItem("id").getTextContent());
                    rhs.add(toAdd);
                }
                eqs.add(new Pair<>(lhs, rhs));
            }
        }
    }
    SchExp<?, ?, ?, ?, ?> schExp = new SchExpRaw(new TyExpVar<>("sql"), new LinkedList<>(), ens, fks, eqs, atts, new LinkedList<>(), new LinkedList<>(), null);
    return new Pair<>(schExp, edsExps);
}
Also used : Node(org.w3c.dom.Node) EdExpRaw(catdata.aql.exp.EdsExpRaw.EdExpRaw) NodeList(org.w3c.dom.NodeList) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair) Ty(catdata.aql.exp.TyExpRaw.Ty) NodeList(org.w3c.dom.NodeList) RawTerm(catdata.aql.RawTerm) LinkedList(java.util.LinkedList) SchExpVar(catdata.aql.exp.SchExp.SchExpVar)

Example 9 with RawTerm

use of catdata.aql.RawTerm in project fql by CategoricalData.

the class InstExpRaw method toString.

@Override
public synchronized String toString() {
    if (toString != null) {
        return toString;
    }
    toString = "";
    if (!imports.isEmpty()) {
        toString += "\timports";
        toString += "\n\t\t" + Util.sep(imports, " ") + "\n";
    }
    List<String> temp = new LinkedList<>();
    if (!gens.isEmpty()) {
        toString += "\tgenerators";
        Map<String, Set<String>> n = Util.revS(Util.toMapSafely(gens));
        temp = new LinkedList<>();
        for (Object x : Util.alphabetical(n.keySet())) {
            temp.add(Util.sep(Util.alphabetical(n.get(x)), " ") + " : " + x);
        }
        toString += "\n\t\t" + Util.sep(temp, "\n\t\t") + "\n";
    }
    if (!eqs.isEmpty()) {
        toString += "\tequations";
        temp = new LinkedList<>();
        for (Pair<RawTerm, RawTerm> sym : Util.alphabetical(eqs)) {
            temp.add(sym.first + " = " + sym.second);
        }
        if (eqs.size() < 9) {
            toString += "\n\t\t" + Util.sep(temp, "\n\t\t") + "\n";
        } else {
            int step = 3;
            int longest = 32;
            for (String s : temp) {
                if (s.length() > longest) {
                    longest = s.length() + 4;
                }
            }
            for (int i = 0; i < temp.size(); i += step) {
                StringBuilder sb = new StringBuilder();
                Formatter formatter = new Formatter(sb, Locale.US);
                List<String> args = new LinkedList<>();
                List<String> format = new LinkedList<>();
                for (int j = i; j < Integer.min(temp.size(), i + step); j++) {
                    args.add(temp.get(j));
                    format.add("%-" + longest + "s");
                }
                String x = formatter.format(Util.sep(format, ""), args.toArray(new String[0])).toString();
                formatter.close();
                toString += "\n\t\t" + x;
            }
            toString += "\n";
        }
    }
    if (!options.isEmpty()) {
        toString += "\toptions";
        temp = new LinkedList<>();
        for (Entry<String, String> sym : options.entrySet()) {
            temp.add(sym.getKey() + " = " + sym.getValue());
        }
        toString += "\n\t\t" + Util.sep(temp, "\n\t\t") + "\n";
    }
    return "literal : " + schema + " {\n" + toString + "}";
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Formatter(java.util.Formatter) RawTerm(catdata.aql.RawTerm) LinkedList(java.util.LinkedList)

Example 10 with RawTerm

use of catdata.aql.RawTerm in project fql by CategoricalData.

the class AqlViewer method viewDP.

/*public static <Ty, En, Sym, Fk, Att> JComponent viewSchema2(Schema<Ty, En, Sym, Fk, Att> schema) {
		mxGraph graph = new mxGraph();
		Object parent = graph.getDefaultParent();

		Ctx<Chc<En,Ty>, Object> nodes = new Ctx<>();
		for (En en : schema.ens) {
			Object v1 = graph.insertVertex(parent, null, en.toString(), 20, 20, 80, 30);
			nodes.put(Chc.inLeft(en), v1);
		}
		for (Ty ty : schema.typeSide.tys) {
			Object v1 = graph.insertVertex(parent, null, ty.toString(), 20, 20, 80, 30);
			nodes.put(Chc.inRight(ty), v1);
		}
		for (Att att : schema.atts.keySet()) {
			graph.insertEdge(parent, null, att.toString(), nodes.get(Chc.inLeft(schema.atts.get(att).first)), nodes.get(Chc.inRight(schema.atts.get(att).second)));
		}
		for (Fk fk : schema.fks.keySet()) {
			graph.insertEdge(parent, null, fk.toString(), nodes.get(Chc.inLeft(schema.fks.get(fk).first)), nodes.get(Chc.inLeft(schema.fks.get(fk).second)));
		}
		mxGraphLayout layout = new mxOrganicLayout(graph); // or whatever layouting algorithm
		layout.execute(parent);
		
		mxGraphComponent graphComponent = new mxGraphComponent(graph);
		
		//  Map<String, Object> style = graph.getStylesheet().getDefaultEdgeStyle();
		 // style.put(mxConstants.STYLE_ROUNDED, true);
		//  style.put(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_ENTITY_RELATION);
		
		return graphComponent;
	}	*/
private static <Ty, En, Sym, Fk, Att, Gen, Sk> JComponent viewDP(DP<Ty, En, Sym, Fk, Att, Gen, Sk> dp, Collage col, AqlJs js) {
    CodeTextPanel input = new CodeTextPanel("Input (either equation-in-ctx or term-in-ctx)", "");
    CodeTextPanel output = new CodeTextPanel("Output", "");
    JButton eq = new JButton("Decide Equation-in-ctx");
    JButton nf = new JButton("Normalize Term-in-ctx");
    /*
		 * if (!dp.hasNFs()) { nf.setEnabled(false); }
		 */
    JButton print = new JButton("Show Info");
    JPanel buttonPanel = new JPanel(new GridLayout(1, 3));
    buttonPanel.add(eq);
    buttonPanel.add(nf);
    buttonPanel.add(print);
    // TODO: aql does not position correctly
    Split split = new Split(.5, JSplitPane.VERTICAL_SPLIT);
    split.add(input);
    split.add(output);
    JPanel main = new JPanel(new BorderLayout());
    main.add(split, BorderLayout.CENTER);
    main.add(buttonPanel, BorderLayout.NORTH);
    print.addActionListener(x -> output.setText(dp.toStringProver()));
    eq.addActionListener(x -> {
        try {
            Triple<List<Pair<String, String>>, RawTerm, RawTerm> y = AqlParser.getParser().parseEq(input.getText());
            Triple<Ctx<Var, Chc<Ty, En>>, Term<Ty, En, Sym, Fk, Att, Gen, Sk>, Term<Ty, En, Sym, Fk, Att, Gen, Sk>> z = RawTerm.infer2(y.first, y.second, y.third, col, js);
            boolean isEq = dp.eq(z.first, z.second, z.third);
            output.setText(Boolean.toString(isEq));
        } catch (Exception ex) {
            ex.printStackTrace();
            output.setText(ex.getMessage());
        }
    });
    nf.addActionListener(x -> {
        try {
            Pair<List<Pair<String, String>>, RawTerm> y = AqlParser.getParser().parseTermInCtx(input.getText());
            Triple<Ctx<Var, Chc<Ty, En>>, Term<Ty, En, Sym, Fk, Att, Gen, Sk>, Term<Ty, En, Sym, Fk, Att, Gen, Sk>> z = RawTerm.infer2(y.first, y.second, y.second, col, js);
            Term<Ty, En, Sym, Fk, Att, Gen, Sk> w = dp.nf(z.first, z.second);
            output.setText(w.toString());
        } catch (Exception ex) {
            ex.printStackTrace();
            output.setText(ex.getMessage());
        }
    });
    return main;
}
Also used : Att(catdata.aql.exp.SchExpRaw.Att) JPanel(javax.swing.JPanel) Ty(catdata.aql.exp.TyExpRaw.Ty) Fk(catdata.aql.exp.SchExpRaw.Fk) Ctx(catdata.Ctx) Sym(catdata.aql.exp.TyExpRaw.Sym) JButton(javax.swing.JButton) En(catdata.aql.exp.SchExpRaw.En) Term(catdata.aql.Term) RawTerm(catdata.aql.RawTerm) RawTerm(catdata.aql.RawTerm) Gen(catdata.aql.exp.InstExpRaw.Gen) GridLayout(java.awt.GridLayout) BorderLayout(java.awt.BorderLayout) CodeTextPanel(catdata.ide.CodeTextPanel) Sk(catdata.aql.exp.InstExpRaw.Sk) List(java.util.List) LinkedList(java.util.LinkedList) Split(catdata.ide.Split)

Aggregations

RawTerm (catdata.aql.RawTerm)23 LinkedList (java.util.LinkedList)18 Ty (catdata.aql.exp.TyExpRaw.Ty)15 List (java.util.List)15 En (catdata.aql.exp.SchExpRaw.En)13 Sym (catdata.aql.exp.TyExpRaw.Sym)13 Att (catdata.aql.exp.SchExpRaw.Att)12 Fk (catdata.aql.exp.SchExpRaw.Fk)12 Ctx (catdata.Ctx)11 AqlOptions (catdata.aql.AqlOptions)11 Term (catdata.aql.Term)11 Chc (catdata.Chc)10 Pair (catdata.Pair)10 Triple (catdata.Triple)9 Collage (catdata.aql.Collage)9 Gen (catdata.aql.exp.InstExpRaw.Gen)8 Sk (catdata.aql.exp.InstExpRaw.Sk)8 HashSet (java.util.HashSet)8 Var (catdata.aql.Var)7 HashMap (java.util.HashMap)7