Thanks again, that worked to fetch statement predicates as both
OntResource and OntProperty.
This came up while experimenting to better understand rdf-frames (see
earlier apologetically lengthy Question about RDF Frames). However, this
might be useful when using SPARQL with OntModels and dealing with
imports that do not fully conform to OWL (e.g., use vanilla
rdf:property, which I have seen happen in files that have owl:Ontology
declarations).
On 1/1/2023 3:22 AM, Lorenz Buehmann wrote:
Hi Steve!
Looks like you're looking for something similar to
Individual::getOntClasses, but I think there is no such method in the
code.
Also, once getting statements, the type itself would be opaque.
What you can do is to call .canAs() and then .as() methods, for example
OntModel m = ...
ExtendedIterator<Individual> individuals = m.listIndividuals();
individuals.forEach(i -> {
i.listProperties().forEach(stmt -> {
Property predicate = stmt.getPredicate();
if (predicate.canAs(OntProperty.class)) {
OntProperty property =
predicate.as(OntProperty.class);
}
});
});
But I think this is not what you want, but I can't think of why you
would need this?
Cheers,
Lorenz
On 31.12.22 17:45, Steve Vestal wrote:
I am using Individual#listProperties (inherited
Resource#listProperties) to get the property instances (triples) for
Individuals in an OntModel. This method returns an iterator of
Statements. The statement objects are returned as ResourceImpl java
objects, and the predicates are returned as PropertyImpl java
objects. What I would like to get as statement objects and
predicates are the OntResource and OntProperty implementations from
the OntModel. I could find no methods such as Resource#isOntResource
or Resource#asOntResource. What is a good way to list property
triples that maintains existing Ontology natures of statement
objects, predicates, subjects?