swp script rdfs:subClassOf

18 views
Skip to first unread message

Julia S.

unread,
Apr 26, 2023, 11:52:35 AM4/26/23
to TopBraid Suite Users
Hi,
I am trying to customize a SWP script for the first time (7.2.4) and I am struggling a little bit.

We have an existing script that does almost exactly what I want based on this:

SELECT DISTINCT ?a ?b ?c
WHERE { ?a ?b c?.
?b a <URI_of_class> .
}.

So a function is called if ?b is a specific class (specified by it's URI)

I wanted to change this so it uses that class' children instead of the class itself and found rdfs:subClassOf.

I tried the following versions, none of which work.

A)
SELECT DISTINCT ?a ?b ?c
WHERE { ?a ?b c?.
?b rdfs:subClassOf <URI_of_class> .
}.

B)
SELECT DISTINCT ?a ?b ?c
WHERE { ?a ?b c?.
?b (rdfs:subClassOf)* <URI_of_class> .
}.

C)
SELECT DISTINCT ?a ?b ?c
WHERE { ?a ?b c?.
?b (rdfs:subClassOf)+ <URI_of_class> .
}.

I double checked if rdfs:subClassOf (including * and +) works on its own using a SPARQL endpoint and it gives me the expected instances.        

I am guessing I still simply use the wrong syntax for swp scripts or don't understand what rdfs:subClassOf actually means.

Any advice?

Cheers
Julia

Holger Knublauch

unread,
Apr 26, 2023, 12:06:55 PM4/26/23
to topbrai...@googlegroups.com
To get all instances ?a of a given class $class, the pattern is

SELECT DISTINCT ?a
WHERE {
?type rdfs:subClassOf* $class .
?a rdf:type ?type .
}

It is not clear to me whether you are looking for instances of a class, or classes that are instances of a metaclass, or maybe you can clarify in prose what you mean?

(Also: c? looks incorrect but I guess that was a copy-and-paste problem).

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/85b221e7-5394-4fc4-900b-d2e2cc6d186cn%40googlegroups.com.

Julia S.

unread,
May 2, 2023, 2:52:42 AM5/2/23
to TopBraid Suite Users
Hi,

this is part of a longer customization.
The original version determines that all properties of a specific class automatically get metadata (I called it "URI_of_class" in the snippet - classA in image).

I would like this to work even if the property is of a class that is a sub class of the original class (sorry for all the "classes" - classA, classB AND classC in image).

I confirmed that this code snippet is where the class for automatic metadata generation is determined by simply pointing to a completely different class and checking if that one would then also get metadata. What I cannot work out is how to include sub-classes.

class_subclass.PNG

David Price

unread,
May 2, 2023, 5:51:24 AM5/2/23
to 'Felix Sasaki' via TopBraid Suite Users
FYI I checked SWP code I have used with other customers and see that rdfs:subClassOf* syntax does work in WHERE clauses within SWP (inside a <ui:update  in my case).

Cheers,
David

Julia S.

unread,
May 2, 2023, 8:06:22 AM5/2/23
to TopBraid Suite Users
Hi everyone,

I got it. I had to add some extra information as I was trying to find instances of a certain class/plus sub classes and not the sub classes itself.

This works:

SELECT DISTINCT ?a ?b ?c
WHERE { ?a ?b c?.
?b rdf:type/rdfs:subClassOf* &lt;URI_of_class&gt; .
}.

Thanks everyone!
Reply all
Reply to author
Forward
0 new messages