0

I am trying to parse OWL2 file by using OWL API. But I have a problem when I am trying to parse label <SubClassOf></SubClassOf>. Please see the example below.


<?xml version="1.0"?>

<Ontology xmlns="http://www.w3.org/2006/12/owl2-xml#"
     ......>
    <SubClassOf>
        <Class URI="&ontology_people1;Address"/>
        <Class URI="&ontology_people1;Location"/>
    </SubClassOf>
   ......
</Ontology>

The content between <SubClassOf> and </SubClassOf> are written in order. The child class is written on the first line and parent class is written on the second line. But I parse it and print in the console. Their order is inverse. Meanwhile, others are not inverse. My code is on the below.


OWLOntologyManager manager = OWLManager.createOWLOntologyManager();

        File file = new File("src/main/resources/dataSet/PR/person1/ontology_people1.owl");

        OWLOntology o = manager.loadOntologyFromOntologyDocument(file);
List<OWLAxiom> subClassOf = o.axioms()
                .filter(axiom -> axiom.getAxiomType().toString().equals("SubClassOf"))
                .collect(Collectors.toList());

        for (OWLAxiom owlAxiom : subClassOf) {

            Stream<OWLEntity> owlEntityStream = owlAxiom.signature();
            owlEntityStream.forEach(entity->System.out.println(entity.getIRI()));
            System.out.println("**************");
        }

Why?

Rob
  • 14,746
  • 28
  • 47
  • 65
Xinze LYU
  • 105
  • 10
  • @Ignazio Excuse me, you have helped me many times, and I know you are the author of OWL API, can you help me again? Thank you ! – Xinze LYU Apr 24 '17 at 13:33

1 Answers1

1

That's because the signature() method is not what you need to use. The signature of an axiom is the set of entities appearing in that axiom, and is defined independently of the axiom type. The main feature, in this case, being that the order of entities in a signature has nothing to do with the semantic of the axiom.

To access reliably subclasses and superclasses, use code like this:

    List<OWLSubClassOfAxiom> subClassOf = OWLAPIStreamUtils.asList(o.axioms(AxiomType.SUBCLASS_OF));
    subClassOf.forEach(x->{
        System.out.println( x.getSubClass());
        System.out.println( x.getSuperClass());
        });
Ignazio
  • 10,504
  • 1
  • 14
  • 25