enum creation

17 views
Skip to first unread message

Luis Enrique Ramos García

unread,
Apr 17, 2024, 3:32:53 AMApr 17
to TopBraid Suite Users

I need to model an enum, 

and found this non uptodate tutorial:

https://topbraidcomposer.org/html/Create_an_enumeration.htm

Thus, I wonder if there is an uptodate procedure to create an enum in EDG?

 

Thanks


Luis

Holger Knublauch

unread,
Apr 17, 2024, 4:00:07 AMApr 17
to topbrai...@googlegroups.com
Hi Luis,

declaring an enumerated class is achieved in SHACL via sh:in. There is no dedicated user interface for creating those quickly, as this isn't anything that we have seen used much so far. I guess this is because the user interface for entering instance data is already a drop down box anyway, typically deemed good enough.

The main reason for creating enumerations would be to make sure that ONLY those enumerated values will ever be permitted. For example, the colors of a traffic light must only be red, green, yellow, but never blue even if someone adds such an instance later.

To create those, you have various options. Advanced users would use the source code panel to enter the sh:in expression. However, similar to what we had in TBC, I think this can be automated easily. Basically the following ADS script produces an sh:in enumeration for the selected class:

focusNode.add(sh.in, RDFNodeUtil.createList(graph.every(focusNode)))

We can wrap this into a Modify Action (feel free to add the below to your Ontology or a file that is included into your ontology):


myontology:ClassActionsGroup
a dash:ActionGroup ;
rdfs:label "Class actions group" ;
.
myontology:DeclareEnumerationFromInstances
a dash:ModifyAction ;
dash:actionGroup myontology:ClassActionsGroup ;
dash:js "focusNode.add(sh.in, RDFNodeUtil.createList(graph.every(focusNode)))" ;
rdfs:comment "Adds a sh:in declaration that enumerates all (current) instances of the selected class." ;
rdfs:label "Declare enumeration from instances" ;
.
rdfs:Class
dash:resourceAction myontology:DeclareEnumerationFromInstances ;
.

With this in place, you can run it from the Modify menu of any class:

PastedGraphic-1.png

which will produce

myontology:Color
a owl:Class ;
a sh:NodeShape ;
rdfs:label "Color" ;
rdfs:subClassOf owl:Thing ;
sh:in (
myontology:Green
myontology:Yellow
myontology:Red
) ;
sh:property myontology:Color-label ;
.

Note that sh:in isn't displayed by default on the form of classes - again because this isn't such a commonly used pattern. To make them visible, switch the form to Also show undeclared properties.

If people find this useful, we could add improvements to this for 8.1.

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/6621d600-2195-4e9c-9b5d-58ce8172722bn%40googlegroups.com.

Luis Enrique Ramos García

unread,
Apr 17, 2024, 4:51:42 AMApr 17
to topbrai...@googlegroups.com
Hi Holger,
Thanks for your answer, but to be frank I find these procedures very complicated.
In my opinion the enum is a very common pattern, and I understand when to use it.

Anyway, let's try to solve the issue

1. I tried to add the code by myself, but it seems there is something wrong with the code:
sh:in (
      myontology:value1
       myontology _:value2
      myontology :value3
    ) ;
myontology:property1;
myontology:property2;
myontology:enumproperty;

Please, take in account that I edited the enum property just after the sh:in, but the editor put it at the end
of the list of properties.

Part of the result was this black datatype property in properties list

image.png

and in the undeclared property there is a list with these values:

in                                          [myontology:property1;
                                          myontology:property1;
                                          myontology:enumproperty;]

is thát the expected result?

if not, for the second option,

where do I have to insert this code:

focusNode.add(sh.in, RDFNodeUtil.createList(graph.every(focusNode)))


do I have to add this code at the beginning of the code of my ontology?


myontology:ClassActionsGroup
a dash:ActionGroup ;
rdfs:label "Class actions group" ;
.
myontology:DeclareEnumerationFromInstances
a dash:ModifyAction ;
dash:actionGroup myontology:ClassActionsGroup ;
dash:js "focusNode.add(sh.in, RDFNodeUtil.createList(graph.every(focusNode)))" ;
rdfs:comment "Adds a sh:in declaration that enumerates all (current) instances of the selected class." ;
rdfs:label "Declare enumeration from instances" ;
.
rdfs:Class
dash:resourceAction myontology:DeclareEnumerationFromInstances ;

I have not done this before, if you have a tutorial or some document I could read, I would really appreciate
if you can share it with me.




Best regards



Luis Ramos
















David Price

unread,
Apr 17, 2024, 5:07:22 AMApr 17
to 'Felix Sasaki' via TopBraid Suite Users
For cases where instances are being referenced, I’ve not found this feature all that useful. You an just make instances of the target class instead and then don't need sh:in at all. Maybe if in cases you want to ignore one or more possible values for some reason.

I have found it useful for string-valued cases more often - for example sh:in ( “Active” “Retired”).

Anyway, an example:

example_schema:ThingWithStatus-hasStatus
  a sh:PropertyShape ;
  sh:path example_schema:hasStatus ;
  sh:class example_schema:Status ;
  sh:description "only Active or Retired allowed" ;
  sh:in (
      example_schema:Active
      example_schema:Retired
    ) ;
  sh:maxCount 1 ;
  sh:name "has status" ;
.
Screenshot 2024-04-17 at 10.00.50.png

Cheers,
David


Luis Enrique Ramos García

unread,
Apr 17, 2024, 5:29:18 AMApr 17
to topbrai...@googlegroups.com
I added the code at the end of the code of the target class, and got this result:

image.png
When I click in "Declare enumeration from instances, I get this view:

image.png

image.png
Then, I wonder how to make the system know where my list of enum values are?


Luis

Holger Knublauch

unread,
Apr 17, 2024, 5:50:45 AMApr 17
to 'Luis Enrique Ramos García' via TopBraid Suite Users
On 17 Apr 2024, at 11:29 AM, 'Luis Enrique Ramos García' via TopBraid Suite Users <topbrai...@googlegroups.com> wrote:

I added the code at the end of the code of the target class, and got this result:

<image.png>
When I click in "Declare enumeration from instances, I get this view:

<image.png>

This looks unexpected. What version are you on? The RDFNodeUtil object should be there. Maybe try the Refresh button in the Script Editor panel.


<image.png>
Then, I wonder how to make the system know where my list of enum values are?

It will simply look at the already-existing instances of the currently selected class, see graph.every(focusNode) where focusNode is the current class.

Holger





Luis 



El mié, 17 abr 2024 a las 10:51, Luis Enrique Ramos García (<luisenriqu...@googlemail.com>) escribió:
Hi Holger, 
Thanks for your answer, but to be frank I find these procedures very complicated. 
In my opinion the enum is a very common pattern, and I understand when to use it. 

Anyway, let's try to solve the issue

1. I tried to add the code by myself, but it seems there is something wrong with the code:
sh:in (
      myontology:value1
       myontology _:value2
      myontology :value3
    ) ;
myontology:property1;
myontology:property2;
myontology:enumproperty;

Please, take in account that I edited the enum property just after the sh:in, but the editor put it at the end
of the list of properties.

Part of the result was this black datatype property in properties list

Luis Enrique Ramos García

unread,
Apr 17, 2024, 7:39:09 AMApr 17
to topbrai...@googlegroups.com
I am working with version Version: 7.5.1 (20230316-1531).

I included an script panel, refreshed it, and I have this view:
image.png
When I run the script I can see my class, the one for which I want to create the enum, is the result of focusNode.

But, when I click in "Declare enumerations from instances" I get the same result again:

image.png
I have a question:

how does my script know from which class I do want to get my instances for the enum list?.

Because I think you are using the same class color?, how do I relate the class traffic light there?

What I want to say is something like this:

Product hasSize oneof  Size (short, medium, large)

And at this moment my focus is in Product, not in Size.


Luis













Holger Knublauch

unread,
Apr 17, 2024, 7:45:43 AMApr 17
to 'Luis Enrique Ramos García' via TopBraid Suite Users

On 17 Apr 2024, at 1:38 PM, 'Luis Enrique Ramos García' via TopBraid Suite Users <topbrai...@googlegroups.com> wrote:

I am working with version Version: 7.5.1 (20230316-1531).

Ok then the script may not work, assuming the RDFNodeUtil object was introduced later.

In that case source code editing may be your best solution, unless you know how to use this


createList: (nodes) => {
let nil = graph.namedNode(rdf.NS + 'nil');
if(nodes.length == 0) {
return nil;
}
let root = graph.blankNode();
let current = root;
nodes.forEach((node, index) => {
current.add(rdf.first, node);
let rest = index < nodes.length - 1 ? graph.blankNode() : nil;
current.add(rdf.rest, rest);
current = rest;
})
return root;
},



I included an script panel, refreshed it, and I have this view:
<image.png>
When I run the script I can see my class, the one for which I want to create the enum, is the result of focusNode.

But, when I click in "Declare enumerations from instances" I get the same result again:

<image.png>
I have a question:

how does my script know from which class I do want to get my instances for the enum list?.

The infrastructure around the ModifyAction will make sure that the variable focusNode points at the asset that
the action was called from (in the Modify menu).



Because I think you are using the same class color?, how do I relate the class traffic light there?

What I want to say is something like this:

Product hasSize oneof  Size (short, medium, large)

And at this moment my focus is in Product, not in Size.

In SHACL you can either add sh:in to a class/node shape or to a property shape. If you just want to add it to a specific property then a different script would be needed.

Holger


Luis Enrique Ramos García

unread,
Apr 17, 2024, 8:31:00 AMApr 17
to topbrai...@googlegroups.com
Thanks for your quick answer,

But, dear, where should I add this code?.

Because I tried to add it in the source code panel, and it didn't work, same with the script panel,
where I expected it should work, but it did not.

So, I owner in which panel should I add this code?.

I do not have any idea how to use it.


Luis



Holger Knublauch

unread,
Apr 17, 2024, 8:33:35 AMApr 17
to 'Luis Enrique Ramos García' via TopBraid Suite Users

On 17 Apr 2024, at 2:30 PM, 'Luis Enrique Ramos García' via TopBraid Suite Users <topbrai...@googlegroups.com> wrote:

Thanks for your quick answer,

But, dear, where should I add this code?.

Because I tried to add it in the source code panel, and it didn't work, same with the script panel,
where I expected it should work, but it did not.

So, I owner in which panel should I add this code?.

I do not have any idea how to use it.

Yes, it requires JS experience. There is no out-of-the-box solution for what you are trying to express.

How many enumerations do you need? If it's just a few, I would suggest going ahead with manual editing of sh:in lists in the Source Code.

Holger


Luis Enrique Ramos García

unread,
Apr 17, 2024, 8:38:55 AMApr 17
to topbrai...@googlegroups.com
I need only 3 elements in the enum,

But, I tried at the first the source code edition, and told you the result I got:

**********************************************************************************************************

1. I tried to add the code by myself, but it seems there is something wrong with the code:
sh:in (
      myontology:value1
       myontology _:value2
      myontology :value3
    ) ;
myontology:property1;
myontology:property2;
myontology:enumproperty;

Please, take in account that I edited the enum property just after the sh:in, but the editor put it at the end
of the list of properties.

Part of the result was this black datatype property in properties list

image.png

and in the undeclared property there is a list with these values:

in                                          [myontology:property1;
                                          myontology:property1;
                                          myontology:enumproperty;]

is thát the expected result?

******************************************************************************************************************


Luis

Holger Knublauch

unread,
Apr 17, 2024, 8:41:38 AMApr 17
to 'Luis Enrique Ramos García' via TopBraid Suite Users
Can you paste us the complete content of the source code panel, e.g. as a screenshot? It's hard to see otherwise and there are syntax errors below.

Holger


On 17 Apr 2024, at 2:38 PM, 'Luis Enrique Ramos García' via TopBraid Suite Users <topbrai...@googlegroups.com> wrote:

I need only 3 elements in the enum,

But, I tried at the first the source code edition, and told you the result I got:

**********************************************************************************************************

1. I tried to add the code by myself, but it seems there is something wrong with the code:
sh:in (
      myontology:value1
       myontology _:value2
      myontology :value3
    ) ;
myontology:property1;
myontology:property2;
myontology:enumproperty;

Please, take in account that I edited the enum property just after the sh:in, but the editor put it at the end
of the list of properties.

Part of the result was this black datatype property in properties list

Luis Enrique Ramos García

unread,
Apr 17, 2024, 9:00:18 AMApr 17
to topbrai...@googlegroups.com
sure,

I created a similar ontology for testing with same results, here is the code:

tesontologyramosenum:Color

  a owl:Class ;
  a sh:NodeShape ;
  rdfs:label "Color" ;
  rdfs:subClassOf owl:Thing ;
  sh:in (
      tesontologyramosenum:Green
      tesontologyramosenum:Yellow
      tesontologyramosenum:Red
    ) ;
  sh:property tesontologyramosenum:Color-label ;
.

the screen shot is this:

image.png
image.png

with similar results, a datatype property without labeling, and a group of undeclared properties.

Is this the expected result?

How do I use this in traffic light instances, if that were the case?


Luis

















David Price

unread,
Apr 17, 2024, 9:04:31 AMApr 17
to 'Felix Sasaki' via TopBraid Suite Users
Need the sh:in do be defined in PropertyShaps, not NodeShape.

Example from eariler:

example_schema:ThingWithStatus-hasStatus
  a sh:PropertyShape ;
  sh:path example_schema:hasStatus ;
  sh:class example_schema:Status ;
  sh:description "only Active or Retired allowed" ;
  sh:in (
      example_schema:Active
      example_schema:Retired
    ) ;
  sh:maxCount 1 ;
  sh:name "has status" ;
.

Cheers,
David

On 17 Apr 2024, at 14:00, 'Luis Enrique Ramos García' via TopBraid Suite Users <topbrai...@googlegroups.com> wrote:

sure,

I created a similar ontology for testing with same results, here is the code:

tesontologyramosenum:Color
  a owl:Class ;
  a sh:NodeShape ;
  rdfs:label "Color" ;
  rdfs:subClassOf owl:Thing ;
  sh:in (
      tesontologyramosenum:Green
      tesontologyramosenum:Yellow
      tesontologyramosenum:Red
    ) ;
  sh:property tesontologyramosenum:Color-label ;
.

the screen shot is this:

<image.png>

Luis Enrique Ramos García

unread,
Apr 17, 2024, 9:18:18 AMApr 17
to topbrai...@googlegroups.com
Thanks or your answer David,

I did the following, but I do not see any change:

tesontologyramosenum:Color
  a owl:Class ;
  a sh:NodeShape ;
  rdfs:label "Color" ;
  rdfs:subClassOf owl:Thing ;
  sh:property tesontologyramosenum:Color-label ;
.
tesontologyramosenum:Color-label
  a sh:PropertyShape ;
  sh:path tesontologyramosenum:label ;
  sh:class tesontologyramosenum:Color ;

  sh:in (
      tesontologyramosenum:Green
      tesontologyramosenum:Yellow
      tesontologyramosenum:Red
    ) ;
  sh:name "label" ;
.

What should I be missing?


Luis






Luis Enrique Ramos García

unread,
Apr 17, 2024, 9:31:26 AMApr 17
to topbrai...@googlegroups.com
David,

With your recommendation, now at least I can see the following in the object property:

image.png
I created an instance of traffic light, and added the property Color-label to traffic light as domain,

but when I create the instance of the class traffic light, what I expect is to have the possibility of

viewing the three possible colors for my traffic light, however I can not visualize it.

image.png
previous property name was "label"


Luis


El mié, 17 abr 2024 a las 15:04, David Price (<dpr...@topquadrant.com>) escribió:

Holger Knublauch

unread,
Apr 17, 2024, 9:37:58 AMApr 17
to 'Luis Enrique Ramos García' via TopBraid Suite Users
Yes that looks right. To use it in traffic lights, just declare a color property there which has sh:class :Color.

Holger


On 17 Apr 2024, at 3:00 PM, 'Luis Enrique Ramos García' via TopBraid Suite Users <topbrai...@googlegroups.com> wrote:

sure,

I created a similar ontology for testing with same results, here is the code:

tesontologyramosenum:Color
  a owl:Class ;
  a sh:NodeShape ;
  rdfs:label "Color" ;
  rdfs:subClassOf owl:Thing ;
  sh:in (
      tesontologyramosenum:Green
      tesontologyramosenum:Yellow
      tesontologyramosenum:Red
    ) ;
  sh:property tesontologyramosenum:Color-label ;
.

the screen shot is this:

<image.png>

Luis Enrique Ramos García

unread,
Apr 17, 2024, 9:55:57 AMApr 17
to topbrai...@googlegroups.com
it works now in this ontology,

now, if I want to add a color in any instance (for testing purpose),
it is only by modifying the code?, like this?:

image.png
That is moreless the expected result on my end.


Thanks,


Luis

Holger Knublauch

unread,
Apr 17, 2024, 10:45:58 AMApr 17
to 'Luis Enrique Ramos García' via TopBraid Suite Users

On 17 Apr 2024, at 3:55 PM, 'Luis Enrique Ramos García' via TopBraid Suite Users <topbrai...@googlegroups.com> wrote:

it works now in this ontology,

now, if I want to add a color in any instance (for testing purpose),
it is only by modifying the code?, like this?:

If you have properly declared the color property then you should be able to select values from the form, not just source code.

Holger


Luis Enrique Ramos García

unread,
Apr 18, 2024, 1:52:52 AMApr 18
to topbrai...@googlegroups.com
Hi Holger,

good morning,

Unfortunately it is not the case, and I can not see the options in the editor.

The code of the traffic light class and color property are:

tesontologyramosenum:TrafficLight

  a owl:Class ;
  a sh:NodeShape ;
  rdfs:label "TrafficLight" ;
  rdfs:subClassOf owl:Thing ;
  sh:property tesontologyramosenum:TrafficLight-color ;
.
tesontologyramosenum:TrafficLight-color
  a sh:PropertyShape ;
  sh:path tesontologyramosenum:color ;
  sh:name "color" ;
  sh:node tesontologyramosenum:Color ;
  sh:nodeKind sh:IRI ;
.
and when I create an instance of traffic light, this is what I see:

image.png
Thus, I wonder what I am doing wrong?.


best regards


Luis Ramos












You received this message because you are subscribed to a topic in the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/topbraid-users/OlXTT8d8kwc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to topbraid-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/topbraid-users/96FB1BF8-067D-4FF2-84BD-97F0DE0D807C%40topquadrant.com.

Holger Knublauch

unread,
Apr 18, 2024, 2:22:11 AMApr 18
to 'Luis Enrique Ramos García' via TopBraid Suite Users

On 18 Apr 2024, at 7:52 AM, 'Luis Enrique Ramos García' via TopBraid Suite Users <topbrai...@googlegroups.com> wrote:

Hi Holger,

good morning,

Unfortunately it is not the case, and I can not see the options in the editor.

The code of the traffic light class and color property are:

tesontologyramosenum:TrafficLight
  a owl:Class ;
  a sh:NodeShape ;
  rdfs:label "TrafficLight" ;
  rdfs:subClassOf owl:Thing ;
  sh:property tesontologyramosenum:TrafficLight-color ;
.
tesontologyramosenum:TrafficLight-color
  a sh:PropertyShape ;
  sh:path tesontologyramosenum:color ;
  sh:name "color" ;
  sh:node tesontologyramosenum:Color ;
  sh:nodeKind sh:IRI ;

Replace the sh:node with:

   sh:class tesontologyramosenum:Color ;

as sh:node is not enough to tell the system which values can be selected.

Holger



.
and when I create an instance of traffic light, this is what I see:

Luis Enrique Ramos García

unread,
Apr 18, 2024, 9:41:50 AMApr 18
to topbrai...@googlegroups.com
Holger,

I think I did the recommended change:

tesontologyramosenum:TrafficLight
  a owl:Class ;
  a sh:NodeShape ;
  rdfs:label "TrafficLight" ;
  rdfs:subClassOf owl:Thing ;
  sh:property tesontologyramosenum:TrafficLight-color ;
.
tesontologyramosenum:TrafficLight-color
  a sh:PropertyShape ;
  sh:path tesontologyramosenum:color ;
  sh:class tesontologyramosenum:Color ;
  sh:name "color" ;
  sh:nodeKind sh:IRI ;


But, when I create a trafficlight1 instance, I still have the same view, the color property is present, however it is blank, no colors:

image.png
So, I am still not able to find out where the problem is..


Luis Ramos


Holger Knublauch

unread,
Apr 18, 2024, 9:46:53 AMApr 18
to topbrai...@googlegroups.com

On 18 Apr 2024, at 3:41 PM, 'Luis Enrique Ramos García' via TopBraid Suite Users <topbrai...@googlegroups.com> wrote:

Holger,

I think I did the recommended change:

tesontologyramosenum:TrafficLight
  a owl:Class ;
  a sh:NodeShape ;
  rdfs:label "TrafficLight" ;
  rdfs:subClassOf owl:Thing ;
  sh:property tesontologyramosenum:TrafficLight-color ;
.
tesontologyramosenum:TrafficLight-color
  a sh:PropertyShape ;
  sh:path tesontologyramosenum:color ;
  sh:class tesontologyramosenum:Color ;
  sh:name "color" ;
  sh:nodeKind sh:IRI ;


But, when I create a trafficlight1 instance, I still have the same view, the color property is present, however it is blank, no colors:

New instances will not have a default value for it, but what happens when you switch to edit mode? Don't you see a drop down for colors when you add a new value/row?

Holger


Luis Enrique Ramos García

unread,
Apr 18, 2024, 9:56:28 AMApr 18
to topbrai...@googlegroups.com
When I edit TrafficColor I do not see anything new,

Luis

Holger Knublauch

unread,
Apr 18, 2024, 9:58:10 AMApr 18
to 'Luis Enrique Ramos García' via TopBraid Suite Users
So what do you see in edit mode? Can you share a screenshot?

Holger


Luis Enrique Ramos García

unread,
Apr 22, 2024, 5:33:53 AMApr 22
to topbrai...@googlegroups.com
sure, for the traffic light, I see this:
image.png


for the color property I see this:

image.png

and for Color class I see this.

image.png


I hope we could find the issue, or error with these screenshots.

Best R.


Luis



Holger Knublauch

unread,
Apr 22, 2024, 6:28:42 AMApr 22
to 'Luis Enrique Ramos García' via TopBraid Suite Users
We are probably talking about different things, still. I was hoping you could send a screenshot of this

image.png

but in edit mode. I believe you were asking for why you cannot select anything under color?

Alternatively, feel free to send us a zip export of the data graph + ontology (or TTL file)

Holger


On 22 Apr 2024, at 11:33 AM, 'Luis Enrique Ramos García' via TopBraid Suite Users <topbrai...@googlegroups.com> wrote:

sure, for the traffic light, I see this:
<image.png>


for the color property I see this:

<image.png>

and for Color class I see this.

Luis Enrique Ramos García

unread,
Apr 22, 2024, 7:07:08 AMApr 22
to topbrai...@googlegroups.com
Sorry for the misunderstanding

image.png


Luis Enrique Ramos García

unread,
Apr 22, 2024, 7:10:33 AMApr 22
to topbrai...@googlegroups.com
Holger,

I found the issue, I had to select this in the manage:

image.png

Now I can see what I expected:

image.png
Thanks a lot


Luis Ramos

Reply all
Reply to author
Forward
0 new messages