Recherche d’annotations
La recherche d’annotations permet
de retrouver une annotation spécifique à une entité ontologique.
L’exemple ci-dessous effectue une recherche dans l’ensemble
des classes de l’ontologie pour en imprimer le commentaire
et l’étiquette en français.
Cette instruction définit un objet label de type OWLAnnotationProperty en
utilisant la méthode factory.getOWLAnnotationProperty().
OWLAnnotationProperty label = factory.getOWLAnnotationProperty(
OWLRDFVocabularyOWLRDFVocabulary.RDFS_LABEL.getIRI());
Cette instruction définit un objet comment de type OWLAnnotationProperty en
utilisant la méthode factory.getRDFSComment().
OWLAnnotationProperty comment = factory.getRDFSComment();
La boucle parcourt l’ensemble des
classes de l’ontologie.
for (OWLClass cls : ontology.getClassesInSignature()) {
Pour chaque annotation accessible par l’objet label…
for ( OWLAnnotationOWLAnnotation annotation : cls.getAnnotations(ontology,
label)) {
Vous pouvez obtenir la valeur du littéral,
et, si la valeur est liée à "fr"
par la propriété hasLang alors
imprimer la valeur du littéral.
if (annotation.getValue() instanceof OWLLiteral) {
OWLLiteralOWLLiteral val = (OWLLiteral) annotation.getValue();
if (val.hasLang("fr")) { ...