use of catdata.fql.decl.Edge in project fql by CategoricalData.
the class PSMGen method sigma.
public static List<PSM> sigma(Mapping F, String pre, String inst) throws FQLException {
Signature C = F.source;
Signature D = F.target;
List<PSM> ret = new LinkedList<>();
if (!FinFunctor.isDiscreteOpFib(F.toFunctor2().first)) {
throw new FQLException("Not a discrete op-fibration");
}
for (Node d : D.nodes) {
List<Flower> tn = new LinkedList<>();
for (Node c : C.nodes) {
if (F.nm.get(c).equals(d)) {
tn.add(new CopyFlower(inst + "_" + c.string, "c0", "c1"));
}
}
if (tn.isEmpty()) {
continue;
}
SQL y = foldUnion(tn);
ret.add(new InsertSQL(pre + "_" + d.string, y, "c0", "c1"));
}
for (Edge e : D.edges) {
Node d = e.source;
// Node d0 = e.target;
List<Flower> tn = new LinkedList<>();
for (Node c : C.nodes) {
if (F.nm.get(c).equals(d)) {
Path pc = findEquiv(c, F, e);
Flower q = compose(inst, pc);
tn.add(q);
}
}
if (tn.isEmpty()) {
continue;
}
SQL y = foldUnion(tn);
ret.add(new InsertSQL(pre + "_" + e.name, y, "c0", "c1"));
}
for (Attribute<Node> a : D.attrs) {
Node d = a.source;
// Node d0 = e.target;
List<Flower> tn = new LinkedList<>();
for (Node c : C.nodes) {
if (F.nm.get(c).equals(d)) {
Attribute<Node> pc = findEquiv(c, F, a);
Flower q = new CopyFlower(inst + "_" + pc.name, "c0", "c1");
tn.add(q);
}
}
if (tn.isEmpty()) {
continue;
}
SQL y = foldUnion(tn);
ret.add(new InsertSQL(pre + "_" + a.name, y, "c0", "c1"));
}
return ret;
}
use of catdata.fql.decl.Edge in project fql by CategoricalData.
the class PSMGen method shred.
public static void shred(String pre, Instance I, Map<String, Set<Map<Object, Object>>> state) {
for (Node n : I.thesig.nodes) {
Set<Map<Object, Object>> m = new HashSet<>();
for (Pair<Object, Object> k : I.data.get(n.string)) {
Map<Object, Object> map = new HashMap<>();
map.put("c0", k.first);
map.put("c1", k.second);
m.add(map);
}
state.put(pre + "_" + n.string, m);
}
for (Edge n : I.thesig.edges) {
Set<Map<Object, Object>> m = new HashSet<>();
for (Pair<Object, Object> k : I.data.get(n.name)) {
Map<Object, Object> map = new HashMap<>();
map.put("c0", k.first);
map.put("c1", k.second);
m.add(map);
}
state.put(pre + "_" + n.name, m);
}
for (Attribute<Node> n : I.thesig.attrs) {
Set<Map<Object, Object>> m = new HashSet<>();
for (Pair<Object, Object> k : I.data.get(n.name)) {
Map<Object, Object> map = new HashMap<>();
map.put("c0", k.first);
map.put("c1", k.second);
m.add(map);
}
state.put(pre + "_" + n.name, m);
}
}
use of catdata.fql.decl.Edge in project fql by CategoricalData.
the class PSMGen method guidify.
public static List<PSM> guidify(String pre0, Signature sig, boolean remember) {
List<PSM> ret = new LinkedList<>();
Map<String, String> guid_attrs = new HashMap<>();
Map<String, String> twocol_attrs = new HashMap<>();
twocol_attrs.put("c0", PSM.VARCHAR());
twocol_attrs.put("c1", PSM.VARCHAR());
guid_attrs.put("c0", PSM.VARCHAR());
guid_attrs.put("c1", PSM.VARCHAR());
guid_attrs.put("guid", PSM.VARCHAR());
List<String> attrs_foo = new LinkedList<>();
attrs_foo.add("c0");
attrs_foo.add("c1");
for (Node n : sig.nodes) {
String pre = pre0 + "_" + n;
// make new table with GUID
ret.add(new CreateTable(pre + "_guid", guid_attrs, false));
ret.add(new InsertKeygen(pre + "_guid", "guid", pre, attrs_foo));
// make a substitution table
ret.add(new CreateTable(pre + "_subst", twocol_attrs, false));
ret.add(new InsertSQL(pre + "_subst", makeSubst(pre0, n), "c0", "c1"));
ret.add(new CreateTable(pre + "_subst_inv", twocol_attrs, false));
ret.add(new InsertSQL(pre + "_subst_inv", invertSubst(pre0, n), "c0", "c1"));
// create a new table that applies the substitution
ret.add(new CreateTable(pre + "_applied", twocol_attrs, false));
ret.add(new InsertSQL(pre + "_applied", makeApplyNode(pre0, n), "c0", "c1"));
// drop guid table
ret.add(new DropTable(pre + "_guid"));
// drop original table
ret.add(new DropTable(pre));
// copy the new table
ret.add(new SimpleCreateTable(pre, PSM.VARCHAR(), false));
// ret.add(new CreateTable(pre, twocol_attrs, false));
ret.add(new InsertSQL(pre, new CopyFlower(pre + "_applied", "c0", "c1"), "c0", "c1"));
// drop the new table
ret.add(new DropTable(pre + "_applied"));
}
for (Edge e : sig.edges) {
String pre = pre0 + "_" + e.name;
// create a new table that applies the substitution
ret.add(new CreateTable(pre + "_applied", twocol_attrs, false));
ret.add(new InsertSQL(pre + "_applied", makeApplyEdge(pre0, e), "c0", "c1"));
// drop original table
ret.add(new DropTable(pre));
// copy the new table
ret.add(new SimpleCreateTable(pre, PSM.VARCHAR(), false));
// ret.add(new CreateTable(pre, twocol_attrs, false));
ret.add(new InsertSQL(pre, new CopyFlower(pre + "_applied", "c0", "c1"), "c0", "c1"));
// drop the new table
ret.add(new DropTable(pre + "_applied"));
}
for (Attribute<Node> a : sig.attrs) {
String pre = pre0 + "_" + a.name;
// create a new table that applies the substitution
ret.add(new CreateTable(pre + "_applied", colattrs(a), false));
ret.add(new InsertSQL(pre + "_applied", makeAttr(pre0, a), "c0", "c1"));
// drop original table
ret.add(new DropTable(pre));
// copy the new table
ret.add(new SimpleCreateTable(pre, a.target.psm(), false));
// ret.add(new CreateTable(pre, twocol_attrs, false));
ret.add(new InsertSQL(pre, new CopyFlower(pre + "_applied", "c0", "c1"), "c0", "c1"));
// drop the new table
ret.add(new DropTable(pre + "_applied"));
}
if (!remember) {
for (Node n : sig.nodes) {
String pre = pre0 + "_" + n;
ret.add(new DropTable(pre + "_subst"));
ret.add(new DropTable(pre + "_subst_inv"));
}
}
return ret;
}
use of catdata.fql.decl.Edge in project fql by CategoricalData.
the class PSMGen method doExternal.
public static List<PSM> doExternal(Signature sig, String in, String out) {
List<PSM> ret = new LinkedList<>();
ret.addAll(makeTables(in, sig, true));
for (Node n : sig.nodes) {
ret.add(new InsertSQL(out + "_" + n.string, new CopyFlower(in + "_" + n.string, "c0", "c1"), "c0", "c1"));
}
for (Edge e : sig.edges) {
ret.add(new InsertSQL(out + "_" + e.name, new CopyFlower(in + "_" + e.name, "c0", "c1"), "c0", "c1"));
}
for (Attribute<Node> a : sig.attrs) {
ret.add(new InsertSQL(out + "_" + a.name, new CopyFlower(in + "_" + a.name, "c0", "c1"), "c0", "c1"));
}
return ret;
}
use of catdata.fql.decl.Edge in project fql by CategoricalData.
the class PSMUnChi method exec.
@Override
public void exec(PSMInterp interp, Map<String, Set<Map<Object, Object>>> state) {
try {
Map<Object, Object> m1 = new HashMap<>();
Map<Object, Object> m2 = new HashMap<>();
Instance B = new Instance(sig, PSMGen.gather(b, sig, state));
Instance P = new Instance(sig, PSMGen.gather(prop, sig, state));
// Instance P = interp.prop2.get(prop).first;
Transform F = new Transform(B, P, PSMGen.gather(f, sig, state));
Map<String, Set<Pair<Object, Object>>> data = new HashMap<>();
List<Pair<String, List<Pair<Object, Object>>>> data2 = new LinkedList<>();
for (Node d : sig.nodes) {
Instance tofind = interp.prop1.get(prop).first.get(d).first;
Object found = interp.prop2.get(prop).second.get(d).second.get(tofind);
Set<Pair<Object, Object>> dta = new HashSet<>();
List<Pair<Object, Object>> dta2 = new LinkedList<>();
for (Pair<Object, Object> k : B.data.get(d.string)) {
Object v = lookup(F.data.get(d.string), k.first);
Pair<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>> vv = interp.prop3.get(prop).get(d).get(v);
if (vv.first.equals(found)) {
Object u = Integer.toString(++interp.guid);
m1.put(u, k.first);
m2.put(k.first, u);
dta.add(new Pair<>(u, u));
dta2.add(new Pair<>(u, k.first));
}
}
data.put(d.string, dta);
data2.add(new Pair<>(d.string, dta2));
}
for (Edge e : sig.edges) {
Set<Pair<Object, Object>> dta = new HashSet<>();
for (Pair<Object, Object> k : data.get(e.source.string)) {
Object v = m1.get(k.first);
Object vx = lookup(B.data.get(e.name), v);
Object vz = m2.get(vx);
dta.add(new Pair<>(k.first, vz));
}
data.put(e.name, dta);
}
for (Attribute<Node> e : sig.attrs) {
Set<Pair<Object, Object>> dta = new HashSet<>();
for (Pair<Object, Object> k : data.get(e.source.string)) {
Object v = m1.get(k.first);
Object vx = lookup(B.data.get(e.name), v);
dta.add(new Pair<>(k.first, vx));
}
data.put(e.name, dta);
}
Instance A = new Instance(sig, data);
Transform T = new Transform(A, B, data2);
PSMGen.shred(pre, A, state);
PSMGen.shred(pre + "_trans", T, state);
} catch (FQLException fe) {
fe.printStackTrace();
throw new RuntimeException(fe.getMessage());
}
}
Aggregations