// comments and labels, so the creation of the annotation is a bit more
// involved. First we'll create a constant for the annotation value.
// Version info should probably contain a version number for the
// ontology, but in this case, we'll add some text to describe why the
// version has been updated
OWLLiteral lit = df.getOWLLiteral("Added a comment to the pizza class");
// The above constant is just a plain literal containing the version
// info text/comment we need to create an annotation, which pairs a URI
// with the constant
OWLAnnotation anno = df.getOWLAnnotation(df
.getOWLAnnotationProperty(OWLRDFVocabulary.OWL_VERSION_INFO
.getIRI()), lit);
// Now we can add this as an ontology annotation Apply the change in the
// usual way
man.applyChange(new AddOntologyAnnotation(ont, anno));
// The pizza ontology has labels attached to most classes which are
// translations of class names into Portuguese (pt) we can access these
// and print them out. At this point, it is worth noting that constants
// can be typed or untyped. If constants are untyped then they can have
// language tags, which are optional - typed constant cannot have
// language tags. For each class in the ontology, we retrieve its
// annotations and sift through them. If the annotation annotates the
// class with a constant which is untyped then we check the language tag
// to see if it is Portugeuse. Firstly, get the annotation property for
// rdfs:label
OWLAnnotationProperty label = df
.getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL.getIRI());
for (OWLClass cls : ont.getClassesInSignature()) {
// Get the annotations on the class that use the label property
for (OWLAnnotation annotation : annotations(ont.filterAxioms(
Filters.annotations, cls.getIRI(), INCLUDED), label)) {
if (annotation.getValue() instanceof OWLLiteral) {
OWLLiteral val = (OWLLiteral) annotation.getValue();
if (val.hasLang("pt")) {
// System.out.println(cls + " -> " + val.getLiteral());
}
}
}
}