Skip to content

Commit 0c108c1

Browse files
Kris Brownepatters
authored andcommitted
Use obj / mor ids rather than human names
.
1 parent 76bdeca commit 0c108c1

3 files changed

Lines changed: 21 additions & 32 deletions

File tree

packages/algjulia-interop/ext/CatlabExt.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ Receiver of the data already knows the schema, so the JSON payload to CatColab
6666
just includes the columns of data. Every part is named, so we use the names
6767
(including for primary key columns) rather than numeric indices.
6868
"""
69-
function acset_to_json(X::ACSet, S::Schema, names::Dict{Symbol, Vector{String}}
69+
function acset_to_json(X::ACSet, S::Schema, ids::Dict{String, Symbol}, names::Dict{Symbol, Vector{String}}
7070
)::AbstractDict
71-
Dict{Symbol, Vector{String}}(
72-
[t => names[t] for t in types(S)]
73-
[f => names[c][X[f]] for (f,_,c) in homs(S)]
74-
[f => names[c][getvalue.(X[f])] for (f,_,c) in attrs(S)] )
71+
Dict{String, Vector{String}}(
72+
[findfirst(==(t), ids) => names[t] for t in types(S)]
73+
[findfirst(==(f), ids) => names[c][X[f]] for (f,_,c) in homs(S)]
74+
[findfirst(==(f), ids) => names[c][getvalue.(X[f])] for (f,_,c) in attrs(S)] )
7575
end
7676

7777
"""
@@ -107,13 +107,13 @@ Top level function called by CatColab. Computes an ACSet colimit of a
107107
function endpoint(::Val{:ACSetColim})
108108
@post "/acsetcolim" function(req::HTTP.Request)
109109
payload = json(req, ModelDiagram)
110-
schema, names = model_to_schema(payload.model)
111-
data = diagram_to_data(payload.diagram, names)
110+
schema, ids = model_to_schema(payload.model)
111+
data = diagram_to_data(payload.diagram, ids)
112112
acset_type = AnonACSet(
113113
schema; type_assignment=Dict(a=>Nothing for a in schema.attrtypes))
114114
y = yoneda(constructor(acset_type))
115115
names, res = colimit_representables(data, y)
116-
acset_to_json(res, schema, make_names(res, names))
116+
acset_to_json(res, schema, ids, make_names(res, names))
117117
end
118118
end
119119

packages/frontend/src/stdlib/analyses/tabular_view.tsx

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,33 +37,28 @@ function createTable(headers: Array<string>, data: Array<Array<string>>) {
3737
and a particular object `obname` in the schema, create an HTML table with
3838
the outgoing homs/attributes from that object.
3939
*/
40-
function createACSetTable(model: DblModel, rawdata: Record<string, string[]>, obname: string) {
40+
function createACSetTable(model: DblModel, rawdata: Record<string, string[]>, obId: string) {
4141
// The primary key of this table is given by `rawdata[obname]`
42-
const rows: Array<string> = rawdata[obname as keyof typeof rawdata];
42+
const rows: Array<string> = rawdata[obId] || [];
43+
const obname: string = model.obGeneratorLabel(obId)?.toString() || "";
4344

4445
// Get the homs and attrs with source `obname`
4546
const outhoms = model
4647
.morGenerators()
47-
.filter(
48-
(m) =>
49-
obname ===
50-
model
51-
.obGeneratorLabel(model.morPresentation(m)?.dom.content.toString() || "")
52-
?.toString(),
53-
);
48+
.filter((m) => obId === model.morPresentation(m)?.dom.content.toString());
5449

5550
// Convert morgenerators to user-friendly names
5651
const headers = [obname].concat(
5752
outhoms.map((m) => model.morGeneratorLabel(m)?.join(".") ?? ""),
5853
);
5954

6055
// Data for column from indexing rawdata
61-
const columnardata: Array<Array<string>> = headers.map(
62-
(m: string) => rawdata[m as keyof typeof rawdata] || [""],
63-
);
56+
const columnardata: Array<Array<string>> = [obId]
57+
.concat(outhoms)
58+
.map((m: string) => rawdata[m as keyof typeof rawdata] || [""]);
6459

6560
// Convert columnar data to row data
66-
const data = Array.from(rows.keys()).map((colIndex) =>
61+
const data = Array.from(rows?.keys()).map((colIndex) =>
6762
columnardata.map((row) => row[colIndex] || ""),
6863
);
6964

@@ -75,11 +70,7 @@ function createACSet(model: DblModel, rawdata: Record<string, string[]>) {
7570
return (
7671
<div class="simulation">
7772
<PanelHeader title="Tabular view" />
78-
<For each={model?.obGenerators()}>
79-
{(ob) =>
80-
createACSetTable(model, rawdata, model.obGeneratorLabel(ob)?.toString() || "")
81-
}
82-
</For>
73+
<For each={model?.obGenerators()}>{(ob) => createACSetTable(model, rawdata, ob)}</For>
8374
</div>
8475
);
8576
}
@@ -135,7 +126,7 @@ export default function TabularView(
135126
</Match>
136127
<Match when={res()}>
137128
{(data) => {
138-
let result = data();
129+
const result = data();
139130
return <div>{createACSet(result.model, result.data)}</div>;
140131
}}
141132
</Match>

packages/frontend/src/stdlib/theories/simple-schema.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
import { ThSchema } from "catlog-wasm";
2-
import { Theory, type TheoryMeta, DiagramAnalysisMeta } from "../../theory";
2+
import { type DiagramAnalysisMeta, Theory, type TheoryMeta } from "../../theory";
33
import * as analyses from "../analyses";
44
import styles from "../styles.module.css";
55
import svgStyles from "../svg_styles.module.css";
66
import textStyles from "../text_styles.module.css";
77

88
export default function createSchemaTheory(theoryMeta: TheoryMeta): Theory {
99
const thSchema = new ThSchema();
10-
let diagramAnalyses: DiagramAnalysisMeta[] = [];
11-
12-
diagramAnalyses.push(
10+
let diagramAnalyses: DiagramAnalysisMeta[] = [
1311
analyses.diagramGraph({
1412
id: "graph",
1513
name: "Visualization",
1614
description: "Visualize the instance as a graph",
1715
help: "visualization",
1816
}),
19-
);
17+
];
2018

2119
if (import.meta.env.DEV) {
2220
diagramAnalyses.push(

0 commit comments

Comments
 (0)