owlcs / owlapi

OWL API main repository
822 stars 315 forks source link

annotation and value #1043

Closed hafsabajwa closed 2 years ago

hafsabajwa commented 2 years ago

Hello, I want to print the annotation property and its value for each class from the already loaded ontology. Is there any way I can do that?

ignazio1977 commented 2 years ago

Use:

import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.search.EntitySearcher;

OWLOntology o = ...// the already loaded ontology
o.classesInSignature().forEach(c->EntitySearcher.getAnnotations(c, o).forEach(System.out::println));
hafsabajwa commented 2 years ago

Hello, I managed to fetch rdfs: labels and domains/ranges using EntitySearcher. I am using this snippet:

IRI iri = .... OWLOntology ontology = ...

ontology.objectPropertiesInSignature().forEach(a->EntitySearcher.getAnnotationObjects(a, ontology).forEach(System.out::println));

    System.out.println("Ranges :" );    

    ontology.objectPropertiesInSignature().forEach(r->EntitySearcher.getRanges(r, ontology).forEach(System.out::println));

    System.out.println("Domains :" );
    ontology.objectPropertiesInSignature().forEach(d->EntitySearcher.getDomains(d, ontology).forEach(System.out::println));

//

The problem is they are all seperate. I want them in a block. indicating which domain range belongs to which property. What I want to do is to print all information in a block in the following form:

Objectproperty1label: domains ranges

Objectproperty2label: domains ranges

ignazio1977 commented 2 years ago

You can have more than one instruction executed on the same property:

ontology.objectPropertiesInSignature().forEach(r->{
            System.out.println("Ranges :" );    
            EntitySearcher.getRanges(r, ontology).forEach(System.out::println);
            System.out.println("Domains :" );
            EntitySearcher.getDomains(r, ontology).forEach(System.out::println);
           });