use of catdata.fql.decl.Node in project fql by CategoricalData.
the class PSMGen method findEquiv.
private static Path findEquiv(Node c, Mapping f, Edge e) throws FQLException {
Signature C = f.source;
Signature D = f.target;
FinCat<Node, Path> C0 = C.toCategory2().first;
for (Arr<Node, Path> peqc : C0.arrows) {
Path path = peqc.arr;
// Path path = new Path(f.source, p);
if (!path.source.equals(c)) {
continue;
}
Path path_f = f.appy(D, path);
Fn<Path, Arr<Node, Path>> F = D.toCategory2().second;
if (F.of(path_f).equals(F.of(new Path(D, e)))) {
return path;
}
}
throw new FQLException("Could not find path mapping to " + e);
}
use of catdata.fql.decl.Node 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.Node 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.Node 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.Node 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;
}
Aggregations