use of catdata.Pair 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.Pair in project fql by CategoricalData.
the class AqlViewer method viewAlgebra.
private <X, Y> Component viewAlgebra(Algebra<Ty, En, Sym, Fk, Att, Gen, Sk, X, Y> alg) {
List<JComponent> list = new LinkedList<>();
Map<En, Pair<List<String>, Object[][]>> entables = makeEnTables(alg);
Map<Ty, Set<Y>> m = Util.revS(alg.talg().sks.map);
Map<Ty, Object[][]> tytables = makeTyTables(m, alg);
for (En en : entables.keySet()) {
Pair<List<String>, Object[][]> x = entables.get(en);
String str;
if (x.second.length == 0) {
continue;
} else if (x.second.length < alg.en(en).size()) {
str = en + " (" + x.second.length + " of " + alg.en(en).size() + ")";
} else {
str = en + " (" + x.second.length + ")";
}
JPanel p = GuiUtil.makeBoldHeaderTable(Util.toString(alg.schema().attsFrom(en)), BorderFactory.createEmptyBorder(), str, x.second, x.first.toArray(new String[x.first.size()]));
list.add(p);
}
List<String> header = Util.singList("ID");
for (Ty ty : tytables.keySet()) {
if (!m.containsKey(ty)) {
continue;
}
Object[][] arr = tytables.get(ty);
String str;
if (arr.length < m.get(ty).size()) {
str = ty + " (" + arr.length + " of " + m.get(ty).size() + ")";
} else {
str = ty + " (" + arr.length + ")";
}
// TODO: aql boldify attributes
list.add(GuiUtil.makeTable(BorderFactory.createEmptyBorder(), str, arr, header.toArray()));
}
JComponent c = GuiUtil.makeGrid(list);
c.setPreferredSize(new Dimension(600, 600));
return c;
}
use of catdata.Pair in project fql by CategoricalData.
the class AqlViewer method makeEnTables.
public <X, Y> Map<En, Pair<List<String>, Object[][]>> makeEnTables(Algebra<Ty, En, Sym, Fk, Att, Gen, Sk, X, Y> alg) {
Map<En, Pair<List<String>, Object[][]>> ret = new LinkedHashMap<>();
List<En> ens = Util.alphabetical(alg.schema().ens);
for (En en : ens) {
List<String> atts0 = Util.alphabetical(alg.schema().attsFrom(en).stream().map((Att x) -> x.str).collect(Collectors.toList()));
List<String> fks0 = Util.alphabetical(alg.schema().fksFrom(en).stream().map((Fk x) -> x.str).collect(Collectors.toList()));
List<String> header = Util.<String>append(atts0, fks0);
header.add(0, "ID");
int n = Integer.min(maxrows, alg.en(en).size());
Object[][] data = new Object[n][];
int i = 0;
List<X> lll = new LinkedList<>(alg.en(en));
lll.sort((x, y) -> Util.AlphabeticalComparator.compare(alg.printX(x), alg.printX(y)));
for (X x : lll) {
List<Object> row = new LinkedList<>();
row.add(alg.printX(x));
for (String att0 : atts0) {
row.add(alg.att(new Att(en, att0), x).toString(alg::printY, Util.voidFn()));
}
for (String fk0 : fks0) {
row.add(alg.printX(alg.fk(new Fk(en, fk0), x)));
}
data[i] = row.toArray();
i++;
if (i == n) {
break;
}
}
ret.put(en, new Pair<>(header, data));
}
return ret;
}
use of catdata.Pair in project fql by CategoricalData.
the class EnrichViewer method idPoly.
private static XPoly<String, String> idPoly(XSchema isa, String isa0, String merged) {
Map<Object, Pair<String, Block<String, String>>> blocks = new HashMap<>();
for (String node : isa.nodes) {
Map<Object, String> from = new HashMap<>();
from.put("v", node);
Set<Pair<List<Object>, List<Object>>> where = new HashSet<>();
Map<String, List<Object>> attrs = new HashMap<>();
Map<String, Pair<Object, Map<Object, List<Object>>>> edges = new HashMap<>();
for (Triple<String, String, String> arrow : isa.arrows) {
if (!arrow.second.equals(node)) {
continue;
}
if (isa.nodes.contains(arrow.third)) {
Map<String, List<String>> map = new HashMap<>();
List<String> l = new LinkedList<>();
l.add("v");
l.add(arrow.first);
map.put("v", l);
@SuppressWarnings({ "unchecked", "rawtypes" }) Pair<Object, Map<Object, List<Object>>> ppp = new Pair("q_" + arrow.third, map);
edges.put(arrow.first, ppp);
} else {
List<Object> l = new LinkedList<>();
l.add("v");
l.add(arrow.first);
attrs.put(arrow.first, l);
}
}
Block<String, String> block = new Block<>(from, where, attrs, edges);
blocks.put("q_" + node, new Pair<>(node, block));
}
return new XPoly<>(new Var(isa0), new Var(merged), blocks);
}
use of catdata.Pair in project fql by CategoricalData.
the class XChaser method massage.
private static Object massage(Triple<String, List<List<String>>, List<String>> x, XCtx I) {
if (x.first == null) {
return x.third;
}
List y = x.second.stream().map(z -> new Triple<>(I.type(z).first, I.type(z).second, z)).collect(Collectors.toList());
List z = new LinkedList<>();
z.add(new Pair<>(x.first, y));
if (x.third != null) {
z.addAll(x.third);
}
return z;
}
Aggregations