Menu

#83 annotation value short form provider needs redoing

open
None
5
2012-12-05
2012-11-23
No

On 23 November 2012 01:41, Ivan <utapyngo@gmail.com> wrote:
> I want AnnotationValueShortFormProvider to enclose all short forms obtained from annotation properties into double quotes.

Hi,

Just to be clear, is this what you want to achieve?
I want confirmation on the assertEquals()

@Test
public void shouldWrapWithDoubleQuotes() throws OWLOntologyCreationException {
OWLOntologyManager man = Factory.getManager();
PrefixManager pm = new DefaultPrefixManager("http://org.semanticweb.owlapi/ont#");
OWLAnnotationProperty prop = AnnotationProperty("prop", pm);
OWLNamedIndividual root = NamedIndividual("ind", pm);
String shortForm = "MyLabel";
Ontology(man, AnnotationAssertion(prop, root.getIRI(), Literal(shortForm)));
List<OWLAnnotationProperty> props = Arrays.asList(prop);
Map<OWLAnnotationProperty, List<String>> langMap = Collections.emptyMap();
AnnotationValueShortFormProvider sfp = new AnnotationValueShortFormProvider(man,
new SimpleShortFormProvider(), new SimpleIRIShortFormProvider(), props,
langMap, new OWLAnnotationValueVisitorEx<String>() {
@Override
public String visit(OWLLiteral literal) {
return "\"" + literal.getLiteral() + "\"";
}

@Override
public String visit(OWLAnonymousIndividual individual) {
return null;
}

@Override
public String visit(IRI iri) {
return null;
}
});
String shortForm2 = sfp.getShortForm(root);
System.out
.println("AnnotationShortFormProviderTestCase.shouldWrapWithDoubleQuotes() "
+ shortForm2);
assertEquals(shortForm2, "\"" + shortForm + "\"");
}

> My first intent was to subclass AnnotationValueShortFormProvider and override getRendering(), but it turned out that it was private. Then I tried to override getShortForm() which was public. It did not help because fields ontologySetProvider and alternateShortFormProvider had no public or protected getters. Moreover, the AnnotationLanguageFilter was not visible. So I could not just copy the implementation from AnnotationValueShortFormProvider.getShortForm(). But even if I could have done it, how would I knew whether the rendering returned by getRendering() was obtained from an annotation property value and not from one of the alternative providers? So I just copied all the code from AnnotationValueShortFormProvider class and changed one single line. Is this the right approach to extend the OWL API?
>

No, the right approach is to ask for utility classes like these to be changed, when they cannot be used as they are - it's called a feature request.

This class does not have a great implementation - it's doing case statements and basically what it wants is to have an OWLAnnotationValueVisitor, but it has also got a number of public constructors so it cannot just be changed.

As you may notice from the test above, I have added a new constructor with an extra visitor. This is used only for literals, and it can be used to override other behaviors. In the future, this class will be deprecated and a new one, taking a visitor instead of a variety of simple form providers, will be added, together with a visitor implementation doing the same work currently done by hand.

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.