using inferred property inferred value in script constraint

93 views
Skip to first unread message

Hamid Abdirad

unread,
Feb 27, 2023, 7:19:03 PM2/27/23
to TopBraid Suite Users
Hello all,
Using TopBraid EDG, I am wondering if a script constraint for a property can read the inferred value of another property. Here is my case:

I have a string property named "win_est_assembly_code".
I have an object property "WinEstConcept" that infers a skos:concept based on the string value of "win_est_assembly_code". Inferred by "sh:values" and dash:js - searching and finding the matching skos:concept. 

I have a string property named "takeoff_unit_abbreviation", for which I want to check if its value equals to the "unit" property of the skos:concept in WinEstConcept. 

I am using a script constraint on takeoff_unit_abbreviation but it seems it cannot read the inferred WinEstConcept (it treats it as if it returns null).

Here is the script:


1.jpg

2.jpg

I appreciate any thoughts on whether we can read the value of inferred object properties, or any workarounds. 

Thank you,
Hamid

Holger Knublauch

unread,
Feb 28, 2023, 4:33:27 AM2/28/23
to topbrai...@googlegroups.com
Hello Hamid,

I have attached an example file that - I believe - demonstrates that inferences are being executed as part of constraint checks.

The main definitions are:

ex:TestClass
  a owl:Class ;
  a sh:NodeShape ;
  dash:scriptConstraint [
      a dash:ScriptConstraint ;
      dash:js "focusNode.value(ex.inferred) >= 30" ;
      sh:message "URI must have at least 30 chars" ;
    ] ;
  rdfs:label "Test class" ;
  rdfs:subClassOf owl:Thing ;
  sh:property ex:TestClass-inferred ;
.
ex:TestClass-inferred
  a sh:PropertyShape ;
  sh:path ex:inferred ;
  sh:datatype xsd:integer ;
  sh:name "inferred" ;
  sh:values [
      dash:js "focusNode.uri.length" ;
    ] ;
.

where ex:inferred is computed to be the length of the URI and the constraint requires that the length >= 30.

In my local tests that is working fine.

If that same example does not work for you, then you may be on a different version than I am.

Could you compare this with your own test and send me a minimal self-contained example that I can run locally if it still does not work for you?

Regards
Holger

constraint-inference.test.ttl

Hamid Abdirad

unread,
Feb 28, 2023, 2:42:30 PM2/28/23
to TopBraid Suite Users
Hi Holger, Thank you for your reply. 
The example you shared works fine for me. However, my example, is not self referencing. Basically, my property A (integer) wants to look at the inferred value of property B but it does not see any value in B (but UI shows the value). 
Here is the example shapes and screenshot:

ex:TestClass
  a owl:Class ;
  a sh:NodeShape ;
  dash:scriptConstraint [
      a dash:ScriptConstraint ;
      dash:js "focusNode.value(ex:integerProperty) == focusNode.value(ex:inferredProperty)" ;
      sh:message "Integer value must match the inferred value" ;

    ] ;
  rdfs:label "Test class" ;
  rdfs:subClassOf owl:Thing ;
  sh:property ex:TestClass-inferredProperty ;
  sh:property ex:TestClass-integerProperty ;
.
ex:TestClass-inferredProperty
  a sh:PropertyShape ;
  sh:path ex:inferredProperty ;
  sh:class xsd:integer ;
  sh:name "inferredProperty" ;

  sh:values [
      dash:js "focusNode.uri.length" ;
    ] ;
.
ex:TestClass-integerProperty
  a sh:PropertyShape ;
  sh:path ex:integerProperty ;
  sh:datatype xsd:integer ;
  sh:equals ex:inferredProperty ;
  sh:name "integerProperty" ;
.

I also added the sh:equals constraint to check if the persisted integer value equals the inferred property but neither the script nor the sh:equals worked as expected. 

3.jpg
Thank you,
Hamid

Holger Knublauch

unread,
Feb 28, 2023, 2:58:23 PM2/28/23
to topbrai...@googlegroups.com
This doesn't look right:

focusNode.value(ex:integerProperty) == focusNode.value(ex:inferredProperty)

Did you mean ex.integerProperty?

Holger

<3.jpg>
Thank you,
Hamid

-- 
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/8051c67f-905a-4c21-a973-e968faa6e5dan%40googlegroups.com.
<3.jpg>

Message has been deleted
Message has been deleted

Hamid Abdirad

unread,
Feb 28, 2023, 4:07:58 PM2/28/23
to TopBraid Suite Users
I attached the sample ttl file for your review. This screenshot shows that  the script editor evaluates the statement as true but the constraint evaluates it as false, thus 59 and 59 are not considered equal. 

5.jpg

Please let me know if this example clarifies the issue.
Thank you,
Hamid
constraint-inference.test(2).ttl

Holger Knublauch

unread,
Mar 1, 2023, 4:47:32 AM3/1/23
to topbrai...@googlegroups.com
Ah I now understand what you mean. The violation is produced by the sh:equals constraint at ex:TextClass-notInferred. It has nothing to do with the ADS ScriptConstraint.

None of the constraints outside of the ADS constraints will "see" the inferred values, because the inferences only happen when requested, e.g. from API calls like focusNode.value(ex.inferred) and from GraphQL which is used by the user interface forms. In other words, the inferences are only computed on-the-fly but do not become triples... unless you assert them, e.g. from the Transform tab.

Does this clarify things?

Holger

On 28 Feb 2023, at 9:07 pm, Hamid Abdirad <habdir...@gmail.com> wrote:

I attached the sample ttl file for your review. This screenshot shows that  the script editor evaluates the statement as true but the constraint evaluates it as false, thus 59 and 59 are not considered equal. 

<5.jpg>
To view this discussion on the web visit https://groups.google.com/d/msgid/topbraid-users/a9e11bea-535a-403b-b388-3b4d6413e7c6n%40googlegroups.com.
<5.jpg><constraint-inference.test(2).ttl>

Hamid Abdirad

unread,
Mar 1, 2023, 10:44:31 AM3/1/23
to TopBraid Suite Users
Thank you for your response, Holger. There are two violations in the screenshot above. 

The big red flag in the screenshot with custom message "integer value does not match inferred value" actually comes from the ADS constraint. 
The turtle file I attached earlier shows it: dash:js "focusNode.value(ex.inferred) == focusNode.value(ex.notInferred)" ;

This part confuses me: how come  focusNode.value(ex.inferred) can be compared against a constant like 30 in your example, but not against the property value  focusNode.value(ex.notInferred). 

Thank you,
Hamid

Holger Knublauch

unread,
Mar 1, 2023, 11:27:19 AM3/1/23
to topbrai...@googlegroups.com
Ok, we have a disconnect then. I was running the file you had attached and in my version (7.5) I only got one violation while the script constraint worked fine.

What version are you on?

Also, note you can debug what's going on in your constraint by adding something like 

let inferred = focusNode.value(ex.inferred);
console.log('Inf: ' + inferred + ' type is ' + typeof inferred);

With the Script Console open you should get a better understanding of what it really is comparing. One theory is that it's returning a complex JS object instead of a JS number, although I have no explanation for that.

Holger

Message has been deleted

Hamid Abdirad

unread,
Mar 1, 2023, 2:42:16 PM3/1/23
to TopBraid Suite Users
We got upgraded to version 7.5 overnight, and with this version, the valid instance you shared is reporting the violation too.
Looking at the script editor the constraint focus.value(ex.inferred) >= 30 evaluates to true, but when compiled by the constraint reasoner it is evaluating to null. 
Put differently, if I change dash:js script to "focusNode.value(ex.inferred) == null" the violations disappear. 

6.jpg

Any thoughts as to why the script editor and the constraint evaluate  focusNode.value(ex.inferred) differently (the true value 58 vs  null)? 

Thank you,
Hamid

Holger Knublauch

unread,
Mar 2, 2023, 4:45:38 AM3/2/23
to topbrai...@googlegroups.com
This is working for me. I went back to the official 7.5.0 EDG Studio release, added your file to the workspace and opened it as File.

This is what I am getting, and it looks OK. Are you doing exactly the same things?

PastedGraphic-1.png

Holger



On 1 Mar 2023, at 7:42 pm, Hamid Abdirad <habdir...@gmail.com> wrote:

We got upgraded to version 7.5 overnight, and with this version, the valid instance you shared is reporting the violation too.
Looking at the script editor the constraint focus.value(ex.inferred) >= 30 evaluates to true, but when compiled by the constraint reasoner it is evaluating to null. 
Put differently, if I change dash:js script to "focusNode.value(ex.inferred) == null" the violations disappear. 

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

Hamid Abdirad

unread,
Mar 2, 2023, 11:38:49 AM3/2/23
to TopBraid Suite Users
I did not use File module. This is the SaaS version, and I imported the file into Ontology, included the ontology into a data graph, and then looked at the included asset instances. 
That is the general workflow we are aiming for, i.e. defining the ADS constraints in the ontology and validating instance data. 

Thank you,
Hamid

Holger Knublauch

unread,
Mar 2, 2023, 12:16:10 PM3/2/23
to topbrai...@googlegroups.com
Ok, this does make a difference - once a Data Graph is used, this particular script constraint fails to evaluate correctly.

I have understood what the problem is (in the code) and will provide a fix for 7.5.1 in the coming days. The problem had to do with the fact that the context graph provided to the ADS engine in this case did not include the owl:imports, and therefore the Ontology became invisible.

Meanwhile I thank you very much for your patience. In this case, small details mattered to be able to reproduce it.

Holger

PS: I am not aware of a work-around for now. If you need this fix urgently, please file a TSM ticket through our support system so we can check how quickly we could update your SaaS instance with the fix.


> On 2 Mar 2023, at 4:38 pm, Hamid Abdirad <habdir...@gmail.com> wrote:
>
> I did not use File module. This is the SaaS version, and I imported the file into Ontology, included the ontology into a data graph, and then looked at the included asset instances.
> That is the general workflow we are aiming for, i.e. defining the ADS constraints in the ontology and validating instance data.
>
> Thank you,
> Hamid
>
>
>
> On Thursday, March 2, 2023 at 1:45:38 AM UTC-8 Holger Knublauch wrote:
> This is working for me. I went back to the official 7.5.0 EDG Studio release, added your file to the workspace and opened it as File.
>
> This is what I am getting, and it looks OK. Are you doing exactly the same things?
>
>
> To view this discussion on the web visit https://groups.google.com/d/msgid/topbraid-users/df3595ec-b682-4447-9f87-b1520b40bf30n%40googlegroups.com.

Reply all
Reply to author
Forward
Message has been deleted
0 new messages