Protege: how to express 'not hasNext'?
I am currently developing an ontology using a protégé and would like to determine if a node is the last one in the list. So basically the list points to a node and each node has some content and may have a different node:
List startsWith some Node
Node hasContent some Content
Node hasNext some Node
Now I would like to define a subclass with a name EndNode
that does not point to another Node
. This is what I have tried so far, but after classification it EndNode
always equals Nothing
:
Node and not(hasNext some Node)
Node and (hasNext exactly 0 Node)
source to share
First, RDF has a built-in List construct that you can use like this:
ex:mylist rdf:type rdf:List .
ex:myList rdf:first ex:firstElement .
ex:myList rdf:rest _:sublist1 .
_:sublist1 rdf:first ex:SecondElement .
_:sublist1 rdf:rest rdf:nil .
Here, to know when you get to the end of the list, you need a special list called rdf:nil
. This plays the same role as a pointer null
at the end of a linked list in programming languages.
However, while rdf:List
it is used well in existing data on the Internet, it does not in any way restrict the use of predicates rdf:first
and rdf:rest
therefore you can have many first items for a given list without causing inconsistencies.
So, if you really want to structure the linked list properly, you need some pretty expressive OWL features. I did this a while ago and it can be found at http://purl.org/az/List .
It's okay to have an empty class, as you specified what you Node
should have nextNode
. You shouldn't force content or next element on nodes. You have to say that the cardinality is at most 1, that the domain and range hasNext
is a Node, and EndNode
a node without the next node. But this is still not enough, since it does not impose what exists EndNode
at all. You can have an endless sequence or loop.
If you want to avoid loops or an infinite sequence, you must define a transitive property hasFollower
and say that EndNode
there is at least a successor in the class .
In general, the implementation of strict lists in OWL completely sucks from a performance standpoint and in most cases is completely useless, since it is rdf:List
sufficient for a wide majority of situations.
source to share