简体   繁体   中英

Using classes or concepts to model enums

SKOS has the notion of concept and concept schemes, which can be roughly used to model enums known from standard programming languages. Concepts can also be defined to be wider or narrower than each other, roughly equivalent to bit flags enums.

Assuming one would like to describe something like cardinal directions, the following is possible:

<CardinalDirections> a skos:ConceptScheme .

<north> skos:inScheme <CardinalDirections> .
<east> skos:inScheme <CardinalDirections> .
<south> skos:inScheme <CardinalDirections> .
<west> skos:inScheme <CardinalDirections> .

Yet enums are usually also part of the type system in various languages, so I could also choose this interpretation:

<CardinalDirection> a rdfs:Class .

<north> a <CardinalDirection> .
<east> a <CardinalDirection> .
<south> a <CardinalDirection> .
<west> a <CardinalDirection> .

So, a) is there any benefit of using one model instead of the other? And b) does it make sense to combine them?

<CardinalDirection> a rdfs:Class , skos:ConceptScheme .

<north> a <CardinalDirection> ; skos:inScheme <CardinalDirection> .
<east> a <CardinalDirection> ; skos:inScheme <CardinalDirection> .
<south> a <CardinalDirection> ; skos:inScheme <CardinalDirection> .
<west> a <CardinalDirection> ; skos:inScheme <CardinalDirection> .

In programming an enum is a unique type of class where the instances of the class is predefined and final. That is, new instances cannot be added to an enum.

Strictly speaking I do not think that what you refer to as representing an enum in RDF is in fact an enum. Rather, it is a number of instances of the same class. In particular, there is nothing that prohibits making the following statement:

<apple> a <CardinalDirection> . 

To see this more clearly, consider the following example:

<Person> a rdfs:Class .

<peter> a <Person> .
<susan> a <Person> .
<kyle> a <Person> .

Clearly the Person class is not an enum.

In RDF there is no way to prohibit adding additional instances to a class as is needed for defining an enum.

If you want to define an enum, you will need to use OWL. Then you could define an enum in the following way:

:CardinalDirection rdf:type owl:Class ;
               owl:equivalentClass [ rdf:type owl:Class ;
                                     owl:oneOf ( :East
                                                 :North
                                                 :South
                                                 :West
                                               )

where you define, for example :East , as follows:

:East rdf:type owl:NamedIndividual ,
           :CardinalDirection .

When will you define an enum in this way? When you plan to run an OWL reasoner over your schema or data. In that case adding :apple a:CardinalDirection. will result in an inconsistency.

If you do not require running a reasoner, there is no reason to consider using enums.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM