Does TBCME support SHACL-JS?

54 views
Skip to first unread message

Angelo Frozza

unread,
Feb 19, 2020, 1:49:40 PM2/19/20
to TopBraid Suite Users
Hello,

I am developing a case study and I have 3 files:
- DataGraph.ttl - data graph
- ShapeGraph.ttl - shape graph with SHACL-JS
- Functions.js - functions for SHACL-JS

I'm using the SHACL API by command line, but I'm having trouble debugging the shapefile and the JavaScript function (I don't know what's being passed to the variables).

Apparently, the function is being accessed, however, it does not find the object to which the validation is applied (ex:coordinates).

Using TBCFE I tried to import the shapegraph and datagraph files for a new project (the functions.js file is accessed online), but I was unable to validate the data graph through the Model -> Refresh and show problems (constraints) menu.

Can TBCFE be used with SHAC-JS?

If yes, can someone help me with a step by step?


I believe that I may have several errors in the shapefile or in the Javascript function. My biggest difficulty is in debugging these codes.

Best regards,

Angelo

Holger Knublauch

unread,
Feb 19, 2020, 8:35:46 PM2/19/20
to topbrai...@googlegroups.com

Hi Angelo,

using TBC-FE (Free Edition), SHACL-JS does work. I have tested your previous file, fixing the www. in the label of one instance and get this:

I agree debugging JS can be difficult from a Java-based tool that goes into the JS Nashorn engine. One way to debug things is to run the JS queries separately. The JavaScript Query view in TBC-FE could be used potentially:

Basically you could write your JS code there and put them into the .js file when you are confident they work.

Other than this, feel free to send a minimal and complete example of where you are stuck, here or on the shacl w3c mailing list.

Holger

--
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/33b1fe62-6984-4725-8183-1fc7efe2906d%40googlegroups.com.

Angelo Frozza

unread,
Feb 20, 2020, 9:51:46 AM2/20/20
to TopBraid Suite Users
Hi Holger,

Thanks for your answer.

I was able to validate the files in this example using the SHACH API through the command line:

shaclvalidate.sh -datafile ../SHACL-JS-W3C-DataGraph.ttl -shapesfile ../SHACL-JS-W3C-ShapeGraph.ttl



But I am unable to do the same at TBCFE:
- I created a project
- Imported the shape graph and data graph files
- I can see my shape in Shapes view


When trying to use the SHACL Validation view on the Data Graph file, I get an error:

"...
Reason:
java.lang.IllegalArgumentException: Shapes graph does not include tosh: http: //datashapes.org/dash#DefaultValueTypeRule
... "

Then, I've imported dash.ttl from / workspace / TopBraid / SHACL.

The error no longer appears, but it also does not validate.

I am trying to reproduce this example that I know is working, and then return to my case study.

Here is a print of my interface on TBCFE.

Captura de Tela 2020-02-20 às 11.46.39.png


Message has been deleted

Angelo Frozza

unread,
Feb 20, 2020, 3:04:23 PM2/20/20
to topbrai...@googlegroups.com
Hello Holger,

I was able to validate shapes using the SHACL core in TBCFE.

Now I'm looking for some examples of javascript code that can be executed in the Javascript query view.

At first, I need to read the value of the $ this variable, then proceed with the test.

The syntax does not seem to be exactly as it will be in the function.js file.

I'm relying on this example code that you already know.

====
function validateGermanLabel($this) {
    var results = [];
    var p = TermFactory.namedNode("http://www.example.org#germanLabel");
    var s = $data.find($this, p, null);
    for(var t = s.next(); t; t = s.next()) {
        var object = t.object;
        if(!object.isLiteral() || !object.language.startsWith("de")) {
            results.push({
                value : object
            });
        }
    }
    return results;
}
====

Hugs,

Angelo
Message has been deleted
Message has been deleted

Angelo Frozza

unread,
Feb 21, 2020, 2:49:42 PM2/21/20
to topbrai...@googlegroups.com
Hi Holger,

Are there any tutorials for using the Javascript query in TBC?

I couldn't understand how to start my test script on that interface.

In my case study, I need to:
- read the instances of ex: coordinates (a list of geographical coordinates)
- Browse the list and, for each member of the list, do:
   a) check if it is of the data type xsd:decimal
   b) accumulate 1 in the element counter

a) is a restriction of the members of the list
b) it is an instance constraint and must be compared against ex:minOccur in my shape (e.g.: it must have at least 2 geographic coordinates).

An attempt to start the code was:
  propertyName = TermFactory.namedNode("http://www.example.org/ns#coordinates");  
  propertyObject 
= $data.find($this, propertyName, null) ; 
  
for (= propertyObject.next(); t; t = propertyObject.next()) { 
     coordTriple 
= propertyObject.next(); 
     
if (!coordTriple) { 
        
return null; 
     
} 
     coordinate 
= coordTriple.object; 
     
if (coordinates.length < $minSize ) {    
        results
.push({ 
           value 
: coordinates 
        
}); 
     
} 
  
}


But the Javascript query is not accepting that way (I think it's syntax).

Hugs,

Angelo



--

-----
Prof. Angelo Augusto Frozza, M.Sc.
Doutorando PPGCC/UFSC

Professor EBTT
IFC - Instituto Federal Catarinense - Campus Camboriú
http://about.me/tilfrozza

Sugestões de leitura:

Case_1-DataGraph.ttl
Case_1-ShapeGraph.ttl
Case_1-Functions.javascript

Holger Knublauch

unread,
Feb 23, 2020, 11:46:57 PM2/23/20
to topbrai...@googlegroups.com

The syntax supported in the JS Query view is based on this library

https://github.com/TopQuadrant/shacl-js/blob/master/shared/rdfquery.js

which provides syntactic sugar to more efficiently walk through RDF results.

So instead of doing a "for" loop you can use match as in

var result = $data.query().
        match("owl:Class", "rdfs:label", "?label").
        match("?otherClass", "rdfs:label", "?label").
        filter(function(sol) { return !T("owl:Class").equals(sol.otherClass) }).
        getNode("?otherClass");

This library is also used for the implementation of most built-in constraints in TopBraid's SHACL-JS implementation, see

https://github.com/TopQuadrant/shacl-js/blob/master/shared/dash.js

Not sure if this helps or distracts in your SHACL-JS exercises, so I just wanted to point it out.

Holger

Angelo Frozza

unread,
Feb 24, 2020, 1:06:43 PM2/24/20
to topbrai...@googlegroups.com

Hi Holger,

Thanks again for the answer.

I accessed the two files you indicated (rdfquery.js and dash.js), but due to my inexperience in working with RDF, it is still fuzzy for me how to build a query in JS Query View.

I am trying to rewrite the function below, but still to no avail. If you can help me to build this example I would appreciate it. Perhaps I can move forward from that example.

=====
function validateGermanLabel ($ this) {
     var results = [];
     var p = TermFactory.namedNode ("http: //www.example.org#germanLabel");

     var s = $ data.find ($ this, p, null);
     for (var t = s.next (); t; t = s.next ()) {
         var object = t.object;
         if (! object.isLiteral () ||! object.language.startsWith ("de")) {
             results.push ({
                 value: object
             });
         }
     }
     return results;
}
=====

Hugs,

Angelo
Reply all
Reply to author
Forward
0 new messages