Search code examples
owl-api

IRI.getShortForm() does not work as expected with spaces and some extra symbols


It seems that getShortForm() of the IRI class is not able to process the classnames with spaces and some other symbols.

Is there a method in the OWL-API that parses IRIs more corectly (the same way as Protege does).

For this code

 for (OWLClass cls : clses) {
     String s = cls.toString();
     String s1 = cls.asOWLClass().getIRI().getShortForm();
     System.out.println("SHORT: "+s1+"    LONG: "+s);
  }

I've got the following strange results:

SHORT: CAPECCWEAttackPatterns#DoS: resource consumption (memory)    LONG: <http://www.grsu.by/net/CAPECCWEAttackPatterns#DoS: resource consumption (memory)>
SHORT: restart    LONG: <http://www.grsu.by/net/CAPECCWEAttackPatterns#DoS: crash / exit / restart>
SHORT: data    LONG: <http://www.grsu.by/net/CAPECCWEAttackPatterns#Modify application data>

Solution

  • IRIs cannot contain spaces. They need to be escaped as %20 sequences. The same is true for a number of other characters.

    For spaces and other characters, the common approach is to use rdfs:label annotations. Protege has renderers that use these to show classes and properties on screen.