The thing you're after is any subject that has a owl:hasKey
property, regardless of value. So both the subject and the object are wildcards, you just want to filter by property name. The way to do that is like this:
model.filter(null, OWL.HASKEY, null)
Now, furthermore you say that you want to know the properties that have been used as annotation using this owl:hasKey
property. In your example, that would be ex:isDataProperty
. Note that in your model, this is not the subject of the owl:hasKey
relation - it's in the object values:
model.filter(null, OWL.HASKEY, null).objects()
To further complicate matters, the object values in your example are not simply single values. Instead, each class is annotated using a list of properties, so the object value is a list object (a.k.a. an RDF Collection). To process this list, there are some utility methods provided by the Models
and RDFCollections
classes.
For each of the objects you can do this to get the actual list of values:
RDFCollections.asValues(model, objectNode, new ArrayList<Value>())
(where objectNode
is one of the values that .objects()
returned)
Edit since objects()
returns objects of type Value
and RDFCollections
expects a Resource
, you'll either have to do a cast, or if you want to do all of this in a fluent way, you can use Models.objectResources
instead. The whole thing then becomes:
Models.objectResources(model.filter(null, OWL.HASKEY, null))
.asScala.map(o => RDFCollections.asValues(model, o, new ArrayList[Value]()));
(I may have the Scala-specific bits of this wrong, but you get the gist hopefully)
For more information on how to work with the rdf4j Model API and with RDF Collections, see the rdf4j documentation.