I am looking at extracting classes and subclasses from an owl file. I am using the OwlApi with some guidance from dlquery tutorial example. It works well except for handling entities with reserved characters. I have been advised to use label annotation instead of extracting entities from IRIs, and specifically use the AnnotationValueShortFormProvider instead of SimpleShortFormProvider. Here is my piece of code to retrieve all subclasses. Let's use 'United States' for example as the entity.
private Set<OWLClass> getSubClasses(String cls, boolean direct) {
if (cls.trim().length() == 0) {
return Collections.emptySet();
}
OWLClassExpression classExpression = this.parser.parseClassExpression(cls);
NodeSet<OWLClass> subClasses = this.reasoner.getSubClasses(classExpression, direct);
return subClasses.getFlattened();
}
My parser is set as such:
this.parser = new DLQueryParser(rootOntology, shortFormProvider);
where shortFormProvider is an instance of AnnotationValueShortFormProvider
My question is, how do I instantiate classExpression without parsing the String 'United States', since parsing the string will extract the prefix/token ‘United’? Or is there another sample code block we could use to retrieve subclasses from using label annotations instead of an IRIs?