ADS to query and update a graph in a workflow

155 views
Skip to first unread message

Rebecca Jackson

unread,
Jan 3, 2024, 12:02:22 PM1/3/24
to TopBraid Suite Users
As part of a custom workflow, we want to create an entry script for the "Frozen for Review" status that queries the graph for any instances missing an rdfs:label, then adds a new rdfs:label triple for each of these instances with an auto-generated label. We want our SMEs to be able to review the auto-generated labels before committing to production.

I have created a Web Service that successfully does this with the following code (exact query removed as it is kind of long):

const rdfsLabel = graph.node({"qname": "rdfs:label"});
const currentGraph = teamwork.currentMasterGraph();

let noLabels = graph.select(`SELECT * WHERE { <QUERY BODY HERE> }`);
let results = noLabels.bindings;
let labels = {}
for (var i = 0; i < results.length; i++) {
let r = results[i];
let instance = r["s"]["uri"];

// some code to build a label goes here

let label = `<AUTO GENERATED LABEL HERE>`
labels[instance] = label;
graph.transaction(currentGraph, "Adding new label", () => {
graph.add(graph.node({"uri": instance}), rdfsLabel, graph.node(label));
});
}
labels;

I tried to tweak this to work for the dash:js of our WorkflowStatusEntryScript, but I can't figure out the "currentGraph" to query and use in the transaction. I know I can get the workflow tag, but that results in an error if I try to use it as the graph ID:

org.topbraidlive.script.js.JSException: Unknown named graph urn:x-tags:cir_workflow___rebecca_jackson_on_2024_jan_3_16_28_15

.. and if I just query the master graph, it will not return results that have been added in the workflow. Thanks in advance for any help!

Holger Knublauch

unread,
Jan 4, 2024, 3:12:38 AM1/4/24
to 'Bohms, H.M. (Michel)' via TopBraid Suite Users
Hi Rebecca,

the documentation of WorkflowStatusScript (the superclass of WorkflowStatusEntryScript) states:

---
The default query graph that these scripts run against is a sandbox above the workflow itself. The script may modify that graph using operations such as graph.add() and those changes will be applied to the sandbox where they will only be committed to the graph when all scripts have finished successfully.

Therefore scripts should not use graph.transaction. Using transactions would bypass the sandboxing mechanism and would commit the changes even if other parts of the script or other workflow status scripts fail with an exception.
---

So I think you can just remove the graph.transaction and do the graph.add directly. Have you tried this already?

Holger
> --
> The topics of this mailing list include TopBraid EDG and related technologies such as SHACL.
> To post to this group, send email to topbrai...@googlegroups.com
> ---
> You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to topbraid-user...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/topbraid-users/a9048189-dd2a-4369-839c-31723542df8an%40googlegroups.com.

Rebecca Jackson

unread,
Jan 4, 2024, 10:35:56 AM1/4/24
to TopBraid Suite Users
Hi Holger, thanks for getting back to me! Yes, I have tried this, and it does not update the labels. Is it possible that it has something to do with the "Frozen for Review" state, which is not editable?

Holger Knublauch

unread,
Jan 4, 2024, 10:48:41 AM1/4/24
to topbrai...@googlegroups.com
Would you be able to send me your workflow template definition? Private email to hol...@topquadrant.com is OK.

Holger


Rebecca Jackson

unread,
Jan 4, 2024, 10:53:32 AM1/4/24
to TopBraid Suite Users
Hi again! I actually just switched it to the exit script from "Uncommitted" and it is working now. Do you still want me to send it over? Otherwise, this is resolved.

Holger Knublauch

unread,
Jan 4, 2024, 11:27:12 AM1/4/24
to 'Bohms, H.M. (Michel)' via TopBraid Suite Users
Thanks for confirming, it actually makes sense this way. I consider this resolved too.

Holger


Reply all
Reply to author
Forward
0 new messages