Using dash:BatchAction in EDG

57 views
Skip to first unread message

Marie Valadez

unread,
Mar 18, 2024, 6:04:46 PMMar 18
to TopBraid Suite Users
Hello Holger,

I am looking into BatchActions and only seemed to find a snippet in the documentation where it says it is the similar to dash:ModifyActions/dash:ExploreActions (https://archive.topquadrant.com/doc/7.8/scripting/actions.html?highlight=batchaction). I have a dash:ModifyActions instance that works, but tried to implement a similar case for dash:BatchAction to see if I can essentially take the action from dash:ModifyActions and apply it to multiple instances. However, I don't seem to even find it populating under the Batch Actions Menu. I am trying to test it out in EDG Studio version 7.8. Is there something I am missing with how to implement??

Here is an example of the script:

ex:Concept
  a owl:Class ;
  a sh:NodeShape ;
  dash:resourceAction exsh:CategoryBatchAction ;
...

exsh:CategoryBatchAction
  a dash:BatchAction ;
  dash:actionGroup exsh:CategoryActionGroup ;
  dash:actionIconClass "fas fa-plus" ;
  dash:canWrite true ;
  dash:js """
          focusNode.add(graph.node({qname: "ex:category"}), graph.node({qname: "ex_graph:_123"}))""" ;
  rdfs:comment "Add `example category to the concept" ;
  rdfs:label "Example Category Batch Action" ;
  sh:order 0 ;
...

Holger Knublauch

unread,
Mar 19, 2024, 4:36:23 AMMar 19
to 'Richard Nagelmaeker' via TopBraid Suite Users
Hi Marie,

BatchActions are not linked to specific classes. Instead they are invoked on a list of nodes as values of the variable focusNodes, and are called from the batch actions drop down buttons that are found in various places. For example, you can run them from the Asset List panel, the Instances Panel and other tabular displays. So there is no need to declare a dash:resourceAction triple.
The main difference to resource actions is that batch actions process all nodes at once. So their dash:js would be something like

focusNodes.forEach(node => node.add(graph.node....))

If things remain unclear, please ask again.

HTH
Holger



  rdfs:comment "Add `example category to the concept" ;
  rdfs:label "Example Category Batch Action" ;
  sh:order 0 ;
...

--
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/ba6bec74-cc10-4e9f-8fa5-8bb87aca61d9n%40googlegroups.com.

Marie Valadez

unread,
Mar 19, 2024, 12:41:32 PMMar 19
to TopBraid Suite Users
Thank you for the feedback. I found them in the Asset List panel. So if it is not associated with a specific class, how would you go about making sure you can't batch add the action to other classes by accident. So for instance, I only want it to add to Concept. I tried this, but it isn't working. I am assuming I am misunderstanding something or typing something incorrectly.  

dash:jsCondition "focusNodes.forEach(node => node.values(rdf.type).some((Class) => Class == ex.Concept))" ;

Holger Knublauch

unread,
Mar 19, 2024, 1:02:47 PMMar 19
to 'Richard Nagelmaeker' via TopBraid Suite Users
The jsCondition needs to return a boolean but the forEach doesn't return anything. Maybe you mean

focusNodes.every(node => node.instanceOf(ex.Concept))

Holger


Marie Valadez

unread,
Mar 21, 2024, 6:13:51 PMMar 21
to TopBraid Suite Users
I am trying to take in a parameter from the user that can be used as the object. In this example it would be for the category. I added the parameter like below, but I keep getting the error "Not a JSON string". I want to be able to get a drop down where the user selects the category and then it is added as the triple. I am able to populate the drop down but it keeps giving an error when selecting "Okay" to add the triple. My potential use case is actually use this to bulk add a blank node but first trying to get the parameter part working first and resolve the "Not a JSON string". 

dashjs: """focusNodes.forEach(node => node.add(graph.node({qname: "ex:category"}), graph.node(category)))""";
sh:parameter ex:Concept-categoryParameter

ex:Concept-categoryParameter
 a sh:Parameter;
sh:path ex:category ;
sh:class ex:Category ;
sh:name "category" ; 
sh:nodeKind sh:IRI ;
sh:description "Concept Category" ;

.



Holger Knublauch

unread,
Mar 22, 2024, 5:46:46 AMMar 22
to 'Richard Nagelmaeker' via TopBraid Suite Users
Hi Marie,

thanks for those details. I believe I was able to reproduce the same scenario. It happens when the sh:class of a parameter points at a class that isn't covered by the ADS code generation. I have just made this code more resilient for 8.0 but in the meantime I think the following work-around should allow you to proceed:

1) On the Script API tab of the Home asset of the collection/file that defines the batch action, add "ex" to "generate prefix classes". In my example this produces a triple such as dash:generatePrefixClasses "ex" ;

2) On the Script Editor make sure to press Refresh so that the API gets rebuilt. This should produce a JS class such as ex_Category.

3) Reload the browser where this action is used and it should hopefully work.

Please let me know if this doesn't work.

Thanks,
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.

Marie Valadez

unread,
Mar 22, 2024, 4:14:37 PMMar 22
to TopBraid Suite Users
Hi Holger, 

Thank you for the advice. I was able to use that workaround to get it to add the blank node with the class dropdowns for the parameters in the Ontology. It did take some time for it to register and recognize it. 

I am now stuck on the dash:jsCondition. I am using your example from above. When I go to the Data Graph to apply the Batch Action on something that is not an instanceOf the class specified, it still allow me to. So for instance if I chose several Concept, Descriptions to apply the batch action to and have it where the condition is "focusNodes.every(node => node.instanceOf(ex.Concept))", I can still add it to description. I checked the log and says "Caught and gracefully handled exception during ADS script execution
org.topbraidlive.script.js.JSException: ReferenceError: ex is not defined". Is there something I am missing to get the Data Graph to ackowledge the prefix for Concept? I tried adding the dash:generatePrefixClasses there as well just in case, but that did not work either.

Holger Knublauch

unread,
Mar 23, 2024, 6:27:20 AMMar 23
to 'Richard Nagelmaeker' via TopBraid Suite Users

On 22 Mar 2024, at 8:14 PM, Marie Valadez <meval...@gmail.com> wrote:

Hi Holger, 

Thank you for the advice. I was able to use that workaround to get it to add the blank node with the class dropdowns for the parameters in the Ontology. It did take some time for it to register and recognize it. 

I am now stuck on the dash:jsCondition. I am using your example from above. When I go to the Data Graph to apply the Batch Action on something that is not an instanceOf the class specified, it still allow me to. So for instance if I chose several Concept, Descriptions to apply the batch action to and have it where the condition is "focusNodes.every(node => node.instanceOf(ex.Concept))", I can still add it to description. I checked the log and says "Caught and gracefully handled exception during ADS script execution
org.topbraidlive.script.js.JSException: ReferenceError: ex is not defined". Is there something I am missing to get the Data Graph to ackowledge the prefix for Concept? I tried adding the dash:generatePrefixClasses there as well just in case, but that did not work either.

To be on the safe side w.r.t. these prefix constants, try replacing it with the full URI, e.g. 

node.instanceOf(graph.namedNode('http://example.org/Concept'))

Holger


Marie Valadez

unread,
Mar 25, 2024, 1:23:54 PMMar 25
to TopBraid Suite Users
Thanks Holger! That worked for my use case. Appreciate the help. 
Is there a way to use sh:class to only populate instances of the root class instead of also populating ones that are a subclass? So for instance, if I want to only retrieve instances of Concept but not instances of the subClass say ex:ChildConcept. 

Holger Knublauch

unread,
Mar 25, 2024, 2:30:44 PMMar 25
to 'Richard Nagelmaeker' via TopBraid Suite Users

On 25 Mar 2024, at 5:23 PM, Marie Valadez <meval...@gmail.com> wrote:

Thanks Holger! That worked for my use case. Appreciate the help. 
Is there a way to use sh:class to only populate instances of the root class instead of also populating ones that are a subclass? So for instance, if I want to only retrieve instances of Concept but not instances of the subClass say ex:ChildConcept. 

Yes, to do that, you need to combine sh:class with a sh:node constraint as follows:

ex:MyClass-myProperty    # or myParameter
    a sh:PropertyShape ;    # or sh:Parameter
    sh:path ex:myProperty ;
    sh:class skos:Concept ;
    sh:node [
        sh:property [
            sh:path rdf:type ;
            sh:hasValue skos:Concept ;
        ] ;
    ] .

This works because our auto-complete widget checks if there is a sh:node constraint on the property. If so, then it will filter all auto-completed value and drop those that do not conform to the given sh:node shape. In this case here, the constraint ensures that all values have skos:Concept as one of its values for rdf:type. This does not apply to subclasses.

Holger


Marie Valadez

unread,
Mar 26, 2024, 10:06:47 AMMar 26
to TopBraid Suite Users
I tried the provided example but it still populates the subClasses even after adding in the sh:node for the parameter. Any other thoughts on what I need to add to prevent the subClasses from populating in the widget?

ex:Concept-map
  a sh:Parameter ;
  sh:path ex:conceptMap ;
  sh:class ex:Concept ;
  sh:name "Concept Map" ;

  sh:node [
      sh:property [
          sh:path rdf:type ;
          sh:hasValue ex:Concept ;
        ] ;
    ] ;
.


Holger Knublauch

unread,
Mar 26, 2024, 10:08:04 AMMar 26
to 'Richard Nagelmaeker' via TopBraid Suite Users

On 26 Mar 2024, at 2:06 PM, Marie Valadez <meval...@gmail.com> wrote:

I tried the provided example but it still populates the subClasses even after adding in the sh:node for the parameter. Any other thoughts on what I need to add to prevent the subClasses from populating in the widget?

ex:Concept-map
  a sh:Parameter ;
  sh:path ex:conceptMap ;
  sh:class ex:Concept ;
  sh:name "Concept Map" ;
  sh:node [
      sh:property [
          sh:path rdf:type ;
          sh:hasValue ex:Concept ;

Replace ex:Concept with skos:Concept.

Holger


Marie Valadez

unread,
Mar 26, 2024, 10:49:52 AMMar 26
to TopBraid Suite Users
That provides me with no options in the drop down because there are no direct instances of skos:Concept in my data graph. The one I am looking for is ex:Concept.

Holger Knublauch

unread,
Mar 26, 2024, 10:51:40 AMMar 26
to 'Richard Nagelmaeker' via TopBraid Suite Users
Then I don't see what's wrong. I would need to get a minimal example that I can run myself to reproduce this. Feel free to send me a file off-list.

Holger


Holger Knublauch

unread,
Mar 26, 2024, 1:50:42 PMMar 26
to 'Richard Nagelmaeker' via TopBraid Suite Users
Thanks for your patience and the sample file that you have sent me off-list, Marie.

And I (publicly) admit that I made a mistake in my testing here. I was testing the sh:node solution using the Form Panel, but the Parameters dialog does not follow the exact same logic, even though it shares the same auto-complete widget. So for this particular case I don't see a work-around at this stage, to exclude subclasses. Apologies if I have wasted your time here. I have recorded a development ticket to try to address this moving forward.

Holger

Marie Valadez

unread,
Mar 26, 2024, 3:13:00 PMMar 26
to TopBraid Suite Users
Thank you for submitting a development ticket. Hopefully, this can be updated in the future. 

Holger Knublauch

unread,
Mar 27, 2024, 6:24:51 AMMar 27
to 'Richard Nagelmaeker' via TopBraid Suite Users
BTW this is now addressed for the upcoming 8.0 release.

Holger


Marie Valadez

unread,
Apr 2, 2024, 9:49:10 PMApr 2
to TopBraid Suite Users
Thank you Holger! Appreciate the help!
Reply all
Reply to author
Forward
0 new messages