Search in sources :

Example 21 with Tuple3

use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.

the class XNeo4jToFQL method fromNodes.

/*			Parser<?> q = Parsers.tuple(ident(), term("="), string());
		Parser<?> p = Parsers.tuple(ident(), term(":"), ident(), Parsers.tuple(term("{"), q.sepBy(term(",")), term("}")));
		return Parsers.tuple(term("CREATE"), Parsers.tuple(term("("), p, term(")")).sepBy(term(",")));
	*/
@SuppressWarnings({ "rawtypes", "unchecked" })
private static Map<String, Map<String, Object>> fromNodes(Object oo) {
    Map<String, Map<String, Object>> ret = new HashMap<>();
    org.jparsec.functors.Pair o = (org.jparsec.functors.Pair) oo;
    List<Tuple3> xx = (List<Tuple3>) o.b;
    for (Tuple3 tt : xx) {
        Tuple4 t = (Tuple4) tt.b;
        String n = (String) t.a;
        String l = (String) t.c;
        if (ret.containsKey(n)) {
            throw new RuntimeException("Duplicate node: " + n);
        }
        Map<String, Object> m = new HashMap<>();
        m.put("label", l);
        Tuple3 pp = (Tuple3) t.d;
        List<Tuple3> p = (List<Tuple3>) pp.b;
        for (Tuple3 q : p) {
            String k = (String) q.a;
            String v = (String) q.c;
            if (m.containsKey(k)) {
                throw new RuntimeException("Duplicate property: " + k);
            }
            m.put(k, v);
        }
        ret.put(n, m);
    }
    return ret;
}
Also used : HashMap(java.util.HashMap) Tuple4(org.jparsec.functors.Tuple4) Tuple3(org.jparsec.functors.Tuple3) LinkedList(java.util.LinkedList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Pair(catdata.Pair)

Example 22 with Tuple3

use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.

the class XParser method toInstConst.

/* public static final Parser<?> instance(Reference ref) {
		Parser<?> node = Parsers.tuple(ident(), term(":"), ident());
		Parser<?> p3 = Parsers.tuple(path(), term("="), path());
		Parser<?> xxx = Parsers.tuple(section("variables", node), 
				section("equations", p3));
		Parser kkk = ((Parser)term("INSTANCE")).or((Parser) term("instance"));
		Parser<?> constant = Parsers
				.tuple(kkk, xxx.between(term("{"), term("}")), term(":"),
						ref.lazy());
		return constant;  */
private static XInst toInstConst(Object decl) {
    Tuple4 y = (Tuple4) decl;
    org.jparsec.functors.Pair x = (org.jparsec.functors.Pair) y.b;
    Tuple3 nodes = (Tuple3) x.a;
    Tuple3 arrows = (Tuple3) x.b;
    List nodes0 = (List) nodes.b;
    List arrows0 = (List) arrows.b;
    List<Pair<String, String>> nodesX = new LinkedList<>();
    for (Object o : nodes0) {
        Tuple3 u = (Tuple3) o;
        List<String> n2 = (List) u.a;
        String l = (String) u.c;
        for (String n : n2) {
            // String n = (String) u.a;
            nodesX.add(new Pair<>(n, l));
        }
    }
    List<Pair<List<String>, List<String>>> eqsX = new LinkedList<>();
    for (Object o : arrows0) {
        Tuple3 u = (Tuple3) o;
        List<String> n = (List<String>) u.a;
        List<String> m = (List<String>) u.c;
        eqsX.add(new Pair<>(n, m));
    }
    XInst ret = new XInst(toExp(y.d), nodesX, eqsX);
    if (y.a.toString().equals("INSTANCE")) {
        ret.saturated = true;
    }
    return ret;
}
Also used : XInst(catdata.fpql.XExp.XInst) LinkedList(java.util.LinkedList) Tuple4(org.jparsec.functors.Tuple4) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair) XPair(catdata.fpql.XExp.XPair)

Example 23 with Tuple3

use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.

the class XParser method toProgHelper.

private static void toProgHelper(String z, String s, List<Triple<String, Integer, XExp>> ret, Tuple3 decl) {
    String txt = z;
    int idx = s.indexOf(txt);
    if (idx < 0) {
        throw new RuntimeException();
    }
    if (decl.a instanceof Tuple3) {
        Tuple3 t = (Tuple3) decl.a;
        Object ooo = toExp(decl.c);
        if (ooo instanceof Flower) {
            Flower f = (Flower) toExp(decl.c);
            f.ty = t.c.toString();
            ret.add(new Triple<>(t.a.toString(), idx, f));
        } else if (ooo instanceof FLOWER2) {
            FLOWER2 f = (FLOWER2) toExp(decl.c);
            f.ty = t.c.toString();
            ret.add(new Triple<>(t.a.toString(), idx, f));
        } else {
            throw new RuntimeException("Can only use (v:T) for flowers");
        }
    } else {
        String name = decl.a.toString();
        if (decl.b.toString().equals(":")) {
            ret.add(new Triple<>(name, idx, newToExp(decl.c)));
        } else {
            ret.add(new Triple<>(name, idx, toExp(decl.c)));
        }
    }
}
Also used : Triple(catdata.Triple) FLOWER2(catdata.fpql.XExp.FLOWER2) Flower(catdata.fpql.XExp.Flower) Tuple3(org.jparsec.functors.Tuple3)

Example 24 with Tuple3

use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.

the class XParser method toTrans.

private static XTransConst toTrans(Object decl) {
    Tuple5 y = (Tuple5) decl;
    // org.jparsec.functors.Pair x = (org.jparsec.functors.Pair) y.a;
    Tuple3 nodes = (Tuple3) y.a;
    // Tuple3 arrows = (Tuple3) x.b;
    List nodes0 = (List) nodes.b;
    // List arrows0 = (List) arrows.b;
    List<Pair<Pair<String, String>, List<String>>> eqsX = new LinkedList<>();
    for (Object o : nodes0) {
        Tuple3 u = (Tuple3) o;
        List<String> m = (List<String>) u.c;
        if (u.a instanceof Tuple3) {
            Tuple3 n = (Tuple3) u.a;
            eqsX.add(new Pair<>(new Pair<>(n.a.toString(), n.c.toString()), m));
        } else {
            String n = (String) u.a;
            eqsX.add(new Pair<>(new Pair<>(n, null), m));
        }
    }
    XTransConst ret = new XTransConst(toExp(y.c), toExp(y.e), eqsX);
    return ret;
}
Also used : Tuple5(org.jparsec.functors.Tuple5) XTransConst(catdata.fpql.XExp.XTransConst) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList) Pair(catdata.Pair) XPair(catdata.fpql.XExp.XPair)

Example 25 with Tuple3

use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.

the class XParser method fromSuperSoed.

/*
	J = soed {
		exists f:A->B, g:C->D;
		forall a:A, a.f = p.q, a.g = p.f;
		forall b:B, p = q; 
	} : X -> Y on I
		 */
private static XSuperED fromSuperSoed(Object ooo) {
    org.jparsec.functors.Pair ooo1 = (org.jparsec.functors.Pair) ooo;
    Tuple4 a = (Tuple4) ooo1.a;
    // List<Triple<String, List<String>, String>> es = new LinkedList<>();
    List<SuperFOED> as = new LinkedList<>();
    Map<String, List<String>> dom = new HashMap<>();
    Map<String, String> cod = new HashMap<>();
    List<Tuple5> es0 = (List<Tuple5>) a.b;
    for (Tuple5 t : es0) {
        if (dom.keySet().contains(t.a)) {
            throw new RuntimeException("Duplicate function name " + t.a);
        }
        dom.put((String) t.a, (List<String>) t.c);
        cod.put((String) t.a, (String) t.e);
    }
    List<Tuple4> as0 = (List<Tuple4>) a.d;
    for (Tuple4 t : as0) {
        List<Tuple3> aas = (List<Tuple3>) t.b;
        Map<String, String> aa = new HashMap<>();
        for (Tuple3 xxx : aas) {
            if (aa.containsKey(xxx.a)) {
                throw new RuntimeException("Duplicate var " + xxx.a);
            }
            aa.put((String) xxx.a, (String) xxx.c);
        }
        Tuple3 td = (Tuple3) t.d;
        List<Tuple3> lhss = (List<Tuple3>) td.a;
        List<Tuple3> rhss = (List<Tuple3>) td.c;
        List<Pair<Triple<String, List<List<String>>, List<String>>, Triple<String, List<List<String>>, List<String>>>> cc = new LinkedList<>();
        List<Pair<Triple<String, List<List<String>>, List<String>>, Triple<String, List<List<String>>, List<String>>>> bb = new LinkedList<>();
        for (Tuple3 o : lhss) {
            bb.add(new Pair<>(fromBulb(o.a), fromBulb(o.c)));
        }
        for (Tuple3 o : rhss) {
            cc.add(new Pair<>(fromBulb(o.a), fromBulb(o.c)));
        }
        as.add(new SuperFOED(aa, bb, cc));
    }
    Tuple4 b = (Tuple4) ooo1.b;
    String src = (String) b.b;
    String dst = (String) b.c;
    String i = (String) b.d;
    // es, as, src, dst, i);
    XSuperED ret = new XSuperED(dom, cod, as, src, dst, i);
    return ret;
}
Also used : HashMap(java.util.HashMap) LinkedList(java.util.LinkedList) XSuperED(catdata.fpql.XExp.XSuperED) Tuple4(org.jparsec.functors.Tuple4) Tuple5(org.jparsec.functors.Tuple5) SuperFOED(catdata.fpql.XExp.XSuperED.SuperFOED) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair) XPair(catdata.fpql.XExp.XPair)

Aggregations

Tuple3 (org.jparsec.functors.Tuple3)90 Pair (catdata.Pair)69 List (java.util.List)57 LinkedList (java.util.LinkedList)56 Tuple5 (org.jparsec.functors.Tuple5)41 HashMap (java.util.HashMap)33 Tuple4 (org.jparsec.functors.Tuple4)32 LinkedHashMap (java.util.LinkedHashMap)17 Triple (catdata.Triple)15 HashSet (java.util.HashSet)15 XPair (catdata.fpql.XExp.XPair)11 Map (java.util.Map)10 Set (java.util.Set)6 Chc (catdata.Chc)5 Var (catdata.fqlpp.FunctorExp.Var)5 Program (catdata.Program)4 Const (catdata.fql.decl.SigExp.Const)4 Plus (catdata.fqlpp.CatExp.Plus)4 Apply (catdata.fqlpp.FunctorExp.Apply)4 Zero (catdata.fqlpp.FunctorExp.Zero)4