owlcs/owlapi

Type of annotation value

Closed this issue · 1 comments

Is there any way to say, If the annotation value is Literal, then print "This is literal."
I am doing:

OWLOntology ontology= ....
OWLDataFactory factory ;
String annotationPrefix = = "http://www.semanticweb.org/hafsa/ontologies/2021/9/test#";
IRI iri = IRI.create(annotationPrefix, "isLiteral");
OWLAnnotationProperty property = factory.getOWLAnnotationProperty(iri);
EntitySearcher( clazz.getIRI(), ontology, property);
if(property.isLiteral){
    System.out.println(property);
    System.out.println("\n\t\t this is literal value");
}

The problem in this code is that the EntitySearcher call result is ignored (the syntax isn't valid either but that's a compile problem).

property.isLiteral() will return whether the annotation property is a literal, which cannot be true - literals and annotation properties are distinct and no instance of one can be an instance of the other.

You should check the results returned by EntitySearcher to see if their annotation values are literals, and print them in that case

EntitySearcher.getannotationObjects(clazz, ontology, property)
    .map(OWLAnnotation::annotationValue)
    .map(OWLAnnotationValue::asLiteral)
    // contents of the stream are now Optional<OWLLiteral> instances
    .filter(Optional::isPresent)
    .forEach(value->System.out.println(value.get()));